diff mbox series

[v1,6/6] linux-gen: queue: separate plain and sched enqueue functions

Message ID 1534510807-11066-7-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/6] api: queue: split queue spec header file | expand

Commit Message

Github ODP bot Aug. 17, 2018, 1 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Separate enqueue function implementations for plain and scheduled
queues. Plain queue implementation is simplified and scheduled
queue implementation does not change.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 675 (psavol:master-queue-inline)
 ** https://github.com/Linaro/odp/pull/675
 ** Patch: https://github.com/Linaro/odp/pull/675.patch
 ** Base sha: dc28824415ea510e3ef62e47f7640bf4a8420fde
 ** Merge commit sha: a68fc608f4c460289d09e09e68f3646d1846737a
 **/
 platform/linux-generic/odp_queue_basic.c | 126 ++++++++++++++---------
 1 file changed, 77 insertions(+), 49 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/odp_queue_basic.c b/platform/linux-generic/odp_queue_basic.c
index d2de677df..22a76b935 100644
--- a/platform/linux-generic/odp_queue_basic.c
+++ b/platform/linux-generic/odp_queue_basic.c
@@ -485,11 +485,9 @@  static inline void buffer_index_to_buf(odp_buffer_hdr_t *buf_hdr[],
 	}
 }
 
-static inline int _sched_queue_enq_multi(odp_queue_t handle,
+static inline int _plain_queue_enq_multi(odp_queue_t handle,
 					 odp_buffer_hdr_t *buf_hdr[], int num)
 {
-	int sched = 0;
-	int ret;
 	queue_entry_t *queue;
 	int num_enq;
 	ring_st_t *ring_st;
@@ -498,9 +496,6 @@  static inline int _sched_queue_enq_multi(odp_queue_t handle,
 	queue = qentry_from_handle(handle);
 	ring_st = &queue->s.ring_st;
 
-	if (sched_fn->ord_enq_multi(handle, (void **)buf_hdr, num, &ret))
-		return ret;
-
 	buffer_index_from_buf(buf_idx, buf_hdr, num);
 
 	LOCK(queue);
@@ -513,43 +508,11 @@  static inline int _sched_queue_enq_multi(odp_queue_t handle,
 
 	num_enq = ring_st_enq_multi(ring_st, buf_idx, num);
 
-	if (odp_unlikely(num_enq == 0)) {
-		UNLOCK(queue);
-		return 0;
-	}
-
-	if (queue->s.status == QUEUE_STATUS_NOTSCHED) {
-		queue->s.status = QUEUE_STATUS_SCHED;
-		sched = 1;
-	}
-
 	UNLOCK(queue);
 
-	/* Add queue to scheduling */
-	if (sched && sched_fn->sched_queue(queue->s.index))
-		ODP_ABORT("schedule_queue failed\n");
-
 	return num_enq;
 }
 
-static int plain_queue_enq_multi(odp_queue_t handle,
-				 odp_buffer_hdr_t *buf_hdr[], int num)
-{
-	return _sched_queue_enq_multi(handle, buf_hdr, num);
-}
-
-static int plain_queue_enq(odp_queue_t handle, odp_buffer_hdr_t *buf_hdr)
-{
-	int ret;
-
-	ret = _sched_queue_enq_multi(handle, &buf_hdr, 1);
-
-	if (ret == 1)
-		return 0;
-	else
-		return -1;
-}
-
 static inline int _plain_queue_deq_multi(odp_queue_t handle,
 					 odp_buffer_hdr_t *buf_hdr[], int num)
 {
@@ -581,6 +544,24 @@  static inline int _plain_queue_deq_multi(odp_queue_t handle,
 	return num_deq;
 }
 
+static int plain_queue_enq_multi(odp_queue_t handle,
+				 odp_buffer_hdr_t *buf_hdr[], int num)
+{
+	return _plain_queue_enq_multi(handle, buf_hdr, num);
+}
+
+static int plain_queue_enq(odp_queue_t handle, odp_buffer_hdr_t *buf_hdr)
+{
+	int ret;
+
+	ret = _plain_queue_enq_multi(handle, &buf_hdr, 1);
+
+	if (ret == 1)
+		return 0;
+	else
+		return -1;
+}
+
 static int plain_queue_deq_multi(odp_queue_t handle,
 				 odp_buffer_hdr_t *buf_hdr[], int num)
 {
@@ -693,22 +674,51 @@  static int queue_info(odp_queue_t handle, odp_queue_info_t *info)
 	return 0;
 }
 
-static int sched_queue_enq_multi(odp_queue_t handle,
-				 odp_buffer_hdr_t *buf_hdr[], int num)
-{
-	return _sched_queue_enq_multi(handle, buf_hdr, num);
-}
-
-static int sched_queue_enq(odp_queue_t handle, odp_buffer_hdr_t *buf_hdr)
+static inline int _sched_queue_enq_multi(odp_queue_t handle,
+					 odp_buffer_hdr_t *buf_hdr[], int num)
 {
+	int sched = 0;
 	int ret;
+	queue_entry_t *queue;
+	int num_enq;
+	ring_st_t *ring_st;
+	uint32_t buf_idx[num];
 
-	ret = _sched_queue_enq_multi(handle, &buf_hdr, 1);
+	queue = qentry_from_handle(handle);
+	ring_st = &queue->s.ring_st;
 
-	if (ret == 1)
-		return 0;
-	else
+	if (sched_fn->ord_enq_multi(handle, (void **)buf_hdr, num, &ret))
+		return ret;
+
+	buffer_index_from_buf(buf_idx, buf_hdr, num);
+
+	LOCK(queue);
+
+	if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) {
+		UNLOCK(queue);
+		ODP_ERR("Bad queue status\n");
 		return -1;
+	}
+
+	num_enq = ring_st_enq_multi(ring_st, buf_idx, num);
+
+	if (odp_unlikely(num_enq == 0)) {
+		UNLOCK(queue);
+		return 0;
+	}
+
+	if (queue->s.status == QUEUE_STATUS_NOTSCHED) {
+		queue->s.status = QUEUE_STATUS_SCHED;
+		sched = 1;
+	}
+
+	UNLOCK(queue);
+
+	/* Add queue to scheduling */
+	if (sched && sched_fn->sched_queue(queue->s.index))
+		ODP_ABORT("schedule_queue failed\n");
+
+	return num_enq;
 }
 
 int sched_queue_deq(uint32_t queue_index, odp_event_t ev[], int max_num,
@@ -757,6 +767,24 @@  int sched_queue_deq(uint32_t queue_index, odp_event_t ev[], int max_num,
 	return num_deq;
 }
 
+static int sched_queue_enq_multi(odp_queue_t handle,
+				 odp_buffer_hdr_t *buf_hdr[], int num)
+{
+	return _sched_queue_enq_multi(handle, buf_hdr, num);
+}
+
+static int sched_queue_enq(odp_queue_t handle, odp_buffer_hdr_t *buf_hdr)
+{
+	int ret;
+
+	ret = _sched_queue_enq_multi(handle, &buf_hdr, 1);
+
+	if (ret == 1)
+		return 0;
+	else
+		return -1;
+}
+
 int sched_queue_empty(uint32_t queue_index)
 {
 	queue_entry_t *queue = qentry_from_index(queue_index);