diff mbox series

[v1,6/6] linux-gen: ring: change ring_deq return value

Message ID 1536674416-8465-7-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/6] linux-gen: queue: remove extra checks | expand

Commit Message

Github ODP bot Sept. 11, 2018, 2 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Return number of data values dequeued (0 or 1) instead of
the data value. This improves error tolerance as there's no
data value reserved to indicate empty ring. Also CPU may
speculate further before the actual data value is actually
needed.

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

---
/** Email created from pull request 699 (psavol:master-sched-optim-clean-ups)
 ** https://github.com/Linaro/odp/pull/699
 ** Patch: https://github.com/Linaro/odp/pull/699.patch
 ** Base sha: 33fbc04b6373960ec3f84de4e7e7b34c49d71508
 ** Merge commit sha: 32d7a11f22e6f2e1e378b653993c5377d4116d8f
 **/
 platform/linux-generic/include/odp_ring_internal.h | 10 ++++------
 platform/linux-generic/odp_schedule_basic.c        |  8 +++-----
 platform/linux-generic/odp_schedule_iquery.c       |  5 ++---
 platform/linux-generic/odp_schedule_sp.c           |  3 +--
 4 files changed, 10 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_ring_internal.h b/platform/linux-generic/include/odp_ring_internal.h
index 97673bef4..9a637afb3 100644
--- a/platform/linux-generic/include/odp_ring_internal.h
+++ b/platform/linux-generic/include/odp_ring_internal.h
@@ -18,9 +18,6 @@  extern "C" {
 #include <odp/api/plat/atomic_inlines.h>
 #include <odp/api/plat/cpu_inlines.h>
 
-/* Ring empty, not a valid data value. */
-#define RING_EMPTY ((uint32_t)-1)
-
 /* Ring of uint32_t data
  *
  * Ring stores head and tail counters. Ring indexes are formed from these
@@ -59,7 +56,7 @@  static inline void ring_init(ring_t *ring)
 }
 
 /* Dequeue data from the ring head */
-static inline uint32_t ring_deq(ring_t *ring, uint32_t mask)
+static inline uint32_t ring_deq(ring_t *ring, uint32_t mask, uint32_t *data)
 {
 	uint32_t head, tail, new_head;
 
@@ -73,7 +70,7 @@  static inline uint32_t ring_deq(ring_t *ring, uint32_t mask)
 		tail = odp_atomic_load_acq_u32(&ring->w_tail);
 
 		if (head == tail)
-			return RING_EMPTY;
+			return 0;
 
 		new_head = head + 1;
 
@@ -83,7 +80,8 @@  static inline uint32_t ring_deq(ring_t *ring, uint32_t mask)
 
 	/* Read data. CAS acquire-release ensures that data read
 	 * does not move above from here. */
-	return ring->data[new_head & mask];
+	*data = ring->data[new_head & mask];
+	return 1;
 }
 
 /* Dequeue multiple data from the ring head. Num is smaller than ring size. */
diff --git a/platform/linux-generic/odp_schedule_basic.c b/platform/linux-generic/odp_schedule_basic.c
index 77fee74dd..a285edc3c 100644
--- a/platform/linux-generic/odp_schedule_basic.c
+++ b/platform/linux-generic/odp_schedule_basic.c
@@ -416,8 +416,7 @@  static int schedule_term_global(void)
 				ring_t *ring = &sched->prio_q[grp][i][j].ring;
 				uint32_t qi;
 
-				while ((qi = ring_deq(ring, ring_mask)) !=
-				       RING_EMPTY) {
+				while (ring_deq(ring, ring_mask, &qi)) {
 					odp_event_t events[1];
 					int num;
 
@@ -907,10 +906,9 @@  static inline int do_schedule_grp(odp_queue_t *out_queue, odp_event_t out_ev[],
 
 			/* Get queue index from the priority queue */
 			ring = &sched->prio_q[grp][prio][id].ring;
-			qi   = ring_deq(ring, ring_mask);
 
-			/* Priority queue empty */
-			if (qi == RING_EMPTY) {
+			if (ring_deq(ring, ring_mask, &qi) == 0) {
+				/* Priority queue empty */
 				i++;
 				id++;
 				continue;
diff --git a/platform/linux-generic/odp_schedule_iquery.c b/platform/linux-generic/odp_schedule_iquery.c
index f76942ff3..e1ef10c46 100644
--- a/platform/linux-generic/odp_schedule_iquery.c
+++ b/platform/linux-generic/odp_schedule_iquery.c
@@ -271,7 +271,7 @@  static int schedule_init_global(void)
 		ring_init(&queue->ring);
 
 		for (k = 0; k < PKTIO_RING_SIZE; k++)
-			queue->cmd_index[k] = RING_EMPTY;
+			queue->cmd_index[k] = -1;
 	}
 
 	for (i = 0; i < NUM_PKTIO_CMD; i++)
@@ -668,9 +668,8 @@  static inline void pktio_poll_input(void)
 	for (i = 0; i < PKTIO_CMD_QUEUES; i++,
 	     hash = (hash + 1) % PKTIO_CMD_QUEUES) {
 		ring = &sched->pktio_poll.queues[hash].ring;
-		index = ring_deq(ring, PKTIO_RING_MASK);
 
-		if (odp_unlikely(index == RING_EMPTY))
+		if (odp_unlikely(ring_deq(ring, PKTIO_RING_MASK, &index) == 0))
 			continue;
 
 		cmd = &sched->pktio_poll.commands[index];
diff --git a/platform/linux-generic/odp_schedule_sp.c b/platform/linux-generic/odp_schedule_sp.c
index 8ddd1e94e..6b9431b69 100644
--- a/platform/linux-generic/odp_schedule_sp.c
+++ b/platform/linux-generic/odp_schedule_sp.c
@@ -401,9 +401,8 @@  static inline sched_cmd_t *rem_head(int group, int prio)
 	int pktio;
 
 	prio_queue = &sched_global->prio_queue[group][prio];
-	ring_idx = ring_deq(&prio_queue->ring, RING_MASK);
 
-	if (ring_idx == RING_EMPTY)
+	if (ring_deq(&prio_queue->ring, RING_MASK, &ring_idx) == 0)
 		return NULL;
 
 	pktio = index_from_ring_idx(&index, ring_idx);