diff mbox series

[v1,3/4] linux-gen: ring_st: move ring mask and data pointer

Message ID 1535119206-23556-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/4] linux-gen: ring_mpmc: new multi-producer, multi-consumer ring | expand

Commit Message

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


Store mask and data pointer in queue entry instead of ring
structure. Data is constant and can be stored among other
frequently used read only data. Also other ring type use
the same variables.

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

---
/** Email created from pull request 683 (psavol:master-queue-lockless-enqdeq-3)
 ** https://github.com/Linaro/odp/pull/683
 ** Patch: https://github.com/Linaro/odp/pull/683.patch
 ** Base sha: 989df5d2f97ab4711328b11282dcc743f5740e00
 ** Merge commit sha: 28073c54671148efdd01c9cf38c1a235d5a133f0
 **/
 .../include/odp_ring_st_internal.h            | 34 ++++++++-----------
 platform/linux-generic/odp_queue_basic.c      | 12 ++++---
 2 files changed, 23 insertions(+), 23 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_ring_st_internal.h b/platform/linux-generic/include/odp_ring_st_internal.h
index 5fb37d4ef..1bc18cda0 100644
--- a/platform/linux-generic/include/odp_ring_st_internal.h
+++ b/platform/linux-generic/include/odp_ring_st_internal.h
@@ -19,30 +19,25 @@  extern "C" {
 typedef struct {
 	uint32_t head;
 	uint32_t tail;
-	uint32_t mask;
-	uint32_t *data;
-
 } ring_st_t;
 
 /* Initialize ring. Ring size must be a power of two. */
-static inline void ring_st_init(ring_st_t *ring, uint32_t *data, uint32_t size)
+static inline void ring_st_init(ring_st_t *ring)
 {
 	ring->head = 0;
 	ring->tail = 0;
-	ring->mask = size - 1;
-	ring->data = data;
 }
 
 /* Dequeue data from the ring head. Max_num is smaller than ring size.*/
-static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t data[],
+static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t *ring_data,
+					 uint32_t ring_mask, uint32_t data[],
 					 uint32_t max_num)
 {
-	uint32_t head, tail, mask, idx;
+	uint32_t head, tail, idx;
 	uint32_t num, i;
 
 	head = ring->head;
 	tail = ring->tail;
-	mask = ring->mask;
 	num  = tail - head;
 
 	/* Empty */
@@ -52,11 +47,11 @@  static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t data[],
 	if (num > max_num)
 		num = max_num;
 
-	idx = head & mask;
+	idx = head & ring_mask;
 
 	for (i = 0; i < num; i++) {
-		data[i] = ring->data[idx];
-		idx     = (idx + 1) & mask;
+		data[i] = ring_data[idx];
+		idx     = (idx + 1) & ring_mask;
 	}
 
 	ring->head = head + num;
@@ -65,16 +60,17 @@  static inline uint32_t ring_st_deq_multi(ring_st_t *ring, uint32_t data[],
 }
 
 /* Enqueue data into the ring tail. Num_data is smaller than ring size. */
-static inline uint32_t ring_st_enq_multi(ring_st_t *ring, const uint32_t data[],
+static inline uint32_t ring_st_enq_multi(ring_st_t *ring, uint32_t *ring_data,
+					 uint32_t ring_mask,
+					 const uint32_t data[],
 					 uint32_t num_data)
 {
-	uint32_t head, tail, mask, size, idx;
+	uint32_t head, tail, size, idx;
 	uint32_t num, i;
 
 	head = ring->head;
 	tail = ring->tail;
-	mask = ring->mask;
-	size = mask + 1;
+	size = ring_mask + 1;
 	num  = size - (tail - head);
 
 	/* Full */
@@ -84,11 +80,11 @@  static inline uint32_t ring_st_enq_multi(ring_st_t *ring, const uint32_t data[],
 	if (num > num_data)
 		num = num_data;
 
-	idx = tail & mask;
+	idx = tail & ring_mask;
 
 	for (i = 0; i < num; i++) {
-		ring->data[idx] = data[i];
-		idx     = (idx + 1) & mask;
+		ring_data[idx] = data[i];
+		idx     = (idx + 1) & ring_mask;
 	}
 
 	ring->tail = tail + num;
diff --git a/platform/linux-generic/odp_queue_basic.c b/platform/linux-generic/odp_queue_basic.c
index 8b9a70bbc..7e8b7e34d 100644
--- a/platform/linux-generic/odp_queue_basic.c
+++ b/platform/linux-generic/odp_queue_basic.c
@@ -687,7 +687,8 @@  static inline int _sched_queue_enq_multi(odp_queue_t handle,
 		return -1;
 	}
 
-	num_enq = ring_st_enq_multi(ring_st, buf_idx, num);
+	num_enq = ring_st_enq_multi(ring_st, queue->s.ring_data,
+				    queue->s.ring_mask, buf_idx, num);
 
 	if (odp_unlikely(num_enq == 0)) {
 		UNLOCK(queue);
@@ -728,7 +729,8 @@  int sched_queue_deq(uint32_t queue_index, odp_event_t ev[], int max_num,
 		return -1;
 	}
 
-	num_deq = ring_st_deq_multi(ring_st, buf_idx, max_num);
+	num_deq = ring_st_deq_multi(ring_st, queue->s.ring_data,
+				    queue->s.ring_mask, buf_idx, max_num);
 
 	if (num_deq == 0) {
 		/* Already empty queue */
@@ -875,8 +877,10 @@  static int queue_init(queue_entry_t *queue, const char *name,
 		} else {
 			queue->s.enqueue            = sched_queue_enq;
 			queue->s.enqueue_multi      = sched_queue_enq_multi;
-			ring_st_init(&queue->s.ring_st,
-				     &queue_glb->ring_data[offset], queue_size);
+
+			queue->s.ring_data = &queue_glb->ring_data[offset];
+			queue->s.ring_mask = queue_size - 1;
+			ring_st_init(&queue->s.ring_st);
 		}
 	}