diff mbox series

[3/3] linux-gen: pool: avoid extra conversions

Message ID 20170707133219.1611-4-petri.savolainen@linaro.org
State Superseded
Headers show
Series Change buffer handle to pointer | expand

Commit Message

Petri Savolainen July 7, 2017, 1:32 p.m. UTC
Avoid conversions between buffer/packet handles and
buffer/packet header pointers.

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

---
 platform/linux-generic/include/odp_pool_internal.h |  5 +--
 platform/linux-generic/odp_packet.c                | 49 +++++++++++-----------
 platform/linux-generic/odp_pool.c                  | 49 +++++++---------------
 3 files changed, 42 insertions(+), 61 deletions(-)

-- 
2.13.0
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_pool_internal.h b/platform/linux-generic/include/odp_pool_internal.h
index 1fb55d7d..a4c0e532 100644
--- a/platform/linux-generic/include/odp_pool_internal.h
+++ b/platform/linux-generic/include/odp_pool_internal.h
@@ -96,9 +96,8 @@  static inline odp_buffer_hdr_t *buf_hdl_to_hdr(odp_buffer_t buf)
 	return (odp_buffer_hdr_t *)(uintptr_t)buf;
 }
 
-int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[],
-		       odp_buffer_hdr_t *buf_hdr[], int num);
-void buffer_free_multi(const odp_buffer_t buf[], int num_free);
+int buffer_alloc_multi(pool_t *pool, odp_buffer_hdr_t *buf_hdr[], int num);
+void buffer_free_multi(odp_buffer_hdr_t *buf_hdr[], int num_free);
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index e6de2558..3cde2086 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -361,14 +361,14 @@  static inline void copy_num_segs(odp_packet_hdr_t *to, odp_packet_hdr_t *from,
 
 static inline odp_packet_hdr_t *alloc_segments(pool_t *pool, int num)
 {
-	odp_buffer_t buf[num];
 	odp_packet_hdr_t *pkt_hdr[num];
 	int ret;
 
-	ret = buffer_alloc_multi(pool, buf, (odp_buffer_hdr_t **)pkt_hdr, num);
+	ret = buffer_alloc_multi(pool, (odp_buffer_hdr_t **)pkt_hdr, num);
+
 	if (odp_unlikely(ret != num)) {
 		if (ret > 0)
-			buffer_free_multi(buf, ret);
+			buffer_free_multi((odp_buffer_hdr_t **)pkt_hdr, ret);
 
 		return NULL;
 	}
@@ -427,12 +427,12 @@  static inline odp_packet_hdr_t *add_segments(odp_packet_hdr_t *pkt_hdr,
 static inline void free_bufs(odp_packet_hdr_t *pkt_hdr, int first, int num)
 {
 	int i;
-	odp_buffer_t buf[num];
+	odp_buffer_hdr_t *buf_hdr[num];
 
 	for (i = 0; i < num; i++)
-		buf[i] = buffer_handle(pkt_hdr->buf_hdr.seg[first + i].hdr);
+		buf_hdr[i] = pkt_hdr->buf_hdr.seg[first + i].hdr;
 
-	buffer_free_multi(buf, num);
+	buffer_free_multi(buf_hdr, num);
 }
 
 static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr,
@@ -444,10 +444,10 @@  static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr,
 	if (head) {
 		odp_packet_hdr_t *new_hdr;
 		int i;
-		odp_buffer_t buf[num];
+		odp_buffer_hdr_t *buf_hdr[num];
 
 		for (i = 0; i < num; i++)
-			buf[i] = buffer_handle(pkt_hdr->buf_hdr.seg[i].hdr);
+			buf_hdr[i] = pkt_hdr->buf_hdr.seg[i].hdr;
 
 		/* First remaining segment is the new packet descriptor */
 		new_hdr = pkt_hdr->buf_hdr.seg[num].hdr;
@@ -464,7 +464,7 @@  static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr,
 
 		pkt_hdr = new_hdr;
 
-		buffer_free_multi(buf, num);
+		buffer_free_multi(buf_hdr, num);
 	} else {
 		/* Free last 'num' bufs */
 		free_bufs(pkt_hdr, num_remain, num);
@@ -487,10 +487,9 @@  static inline int packet_alloc(pool_t *pool, uint32_t len, int max_pkt,
 	int num_buf, i;
 	int num     = max_pkt;
 	int max_buf = max_pkt * num_seg;
-	odp_buffer_t buf[max_buf];
 	odp_packet_hdr_t *pkt_hdr[max_buf];
 
-	num_buf = buffer_alloc_multi(pool, buf, (odp_buffer_hdr_t **)pkt_hdr,
+	num_buf = buffer_alloc_multi(pool, (odp_buffer_hdr_t **)pkt_hdr,
 				     max_buf);
 
 	/* Failed to allocate all segments */
@@ -500,8 +499,12 @@  static inline int packet_alloc(pool_t *pool, uint32_t len, int max_pkt,
 		num      = num_buf / num_seg;
 		num_free = num_buf - (num * num_seg);
 
-		if (num_free > 0)
-			buffer_free_multi(&buf[num_buf - num_free], num_free);
+		if (num_free > 0) {
+			odp_buffer_hdr_t **p;
+
+			p = (odp_buffer_hdr_t **)&pkt_hdr[num_buf - num_free];
+			buffer_free_multi(p, num_free);
+		}
 
 		if (num == 0)
 			return 0;
@@ -584,43 +587,39 @@  void odp_packet_free(odp_packet_t pkt)
 	int num_seg = pkt_hdr->buf_hdr.segcount;
 
 	if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1))
-		buffer_free_multi(&hdl, 1);
+		buffer_free_multi((odp_buffer_hdr_t **)&hdl, 1);
 	else
 		free_bufs(pkt_hdr, 0, num_seg);
 }
 
 void odp_packet_free_multi(const odp_packet_t pkt[], int num)
 {
-	odp_buffer_t buf[num * CONFIG_PACKET_MAX_SEGS];
-	int i;
-
 	if (CONFIG_PACKET_MAX_SEGS == 1) {
-		for (i = 0; i < num; i++)
-			buf[i] = buffer_handle(packet_hdr(pkt[i]));
-
-		buffer_free_multi(buf, num);
+		buffer_free_multi((odp_buffer_hdr_t **)(uintptr_t)pkt, num);
 	} else {
+		odp_buffer_hdr_t *buf_hdr[num * CONFIG_PACKET_MAX_SEGS];
+		int i;
 		int j;
 		int bufs = 0;
 
 		for (i = 0; i < num; i++) {
 			odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt[i]);
 			int num_seg = pkt_hdr->buf_hdr.segcount;
-			odp_buffer_hdr_t *buf_hdr = &pkt_hdr->buf_hdr;
+			odp_buffer_hdr_t *hdr = &pkt_hdr->buf_hdr;
 
-			buf[bufs] = buffer_handle(pkt_hdr);
+			buf_hdr[bufs] = hdr;
 			bufs++;
 
 			if (odp_likely(num_seg == 1))
 				continue;
 
 			for (j = 1; j < num_seg; j++) {
-				buf[bufs] = buffer_handle(buf_hdr->seg[j].hdr);
+				buf_hdr[bufs] = hdr->seg[j].hdr;
 				bufs++;
 			}
 		}
 
-		buffer_free_multi(buf, bufs);
+		buffer_free_multi(buf_hdr, bufs);
 	}
 }
 
diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index 7e0c7606..e08c8985 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -73,13 +73,6 @@  static inline odp_buffer_hdr_t *buf_hdr_from_index(pool_t *pool,
 	return buf_hdr;
 }
 
-static inline uint32_t buf_index_from_hdl(odp_buffer_t buf)
-{
-	odp_buffer_hdr_t *buf_hdr = buf_hdl_to_hdr(buf);
-
-	return buf_hdr->index;
-}
-
 int odp_pool_init_global(void)
 {
 	uint32_t i;
@@ -604,8 +597,7 @@  int odp_pool_info(odp_pool_t pool_hdl, odp_pool_info_t *info)
 	return 0;
 }
 
-int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[],
-		       odp_buffer_hdr_t *buf_hdr_out[], int max_num)
+int buffer_alloc_multi(pool_t *pool, odp_buffer_hdr_t *buf_hdr[], int max_num)
 {
 	ring_t *ring;
 	uint32_t mask, i;
@@ -633,11 +625,7 @@  int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[],
 	for (i = 0; i < num_ch; i++) {
 		uint32_t j = cache_num - num_ch + i;
 
-		hdr    = buf_hdr_from_index(pool, cache->buf_index[j]);
-		buf[i] = buf_from_buf_hdr(hdr);
-
-		if (odp_likely(buf_hdr_out != NULL))
-			buf_hdr_out[i] = hdr;
+		buf_hdr[i] = buf_hdr_from_index(pool, cache->buf_index[j]);
 	}
 
 	/* If needed, get more from the global pool */
@@ -661,11 +649,7 @@  int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[],
 
 			hdr = buf_hdr_from_index(pool, data[i]);
 			odp_prefetch(hdr);
-
-			buf[idx] = buf_from_buf_hdr(hdr);
-
-			if (odp_likely(buf_hdr_out != NULL))
-				buf_hdr_out[idx] = hdr;
+			buf_hdr[idx] = hdr;
 		}
 
 		/* Cache extra buffers. Cache is currently empty. */
@@ -681,7 +665,7 @@  int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[],
 }
 
 static inline void buffer_free_to_pool(pool_t *pool,
-				       const odp_buffer_t buf[], int num)
+				       odp_buffer_hdr_t *buf_hdr[], int num)
 {
 	int i;
 	ring_t *ring;
@@ -699,7 +683,7 @@  static inline void buffer_free_to_pool(pool_t *pool,
 		ring  = &pool->ring->hdr;
 		mask  = pool->ring_mask;
 		for (i = 0; i < num; i++)
-			buf_index[i] = buf_index_from_hdl(buf[i]);
+			buf_index[i] = buf_hdr[i]->index;
 
 		ring_enq_multi(ring, mask, buf_index, num);
 
@@ -737,12 +721,12 @@  static inline void buffer_free_to_pool(pool_t *pool,
 	}
 
 	for (i = 0; i < num; i++)
-		cache->buf_index[cache_num + i] = buf_index_from_hdl(buf[i]);
+		cache->buf_index[cache_num + i] = buf_hdr[i]->index;
 
 	cache->num = cache_num + num;
 }
 
-void buffer_free_multi(const odp_buffer_t buf[], int num_total)
+void buffer_free_multi(odp_buffer_hdr_t *buf_hdr[], int num_total)
 {
 	pool_t *pool;
 	int num;
@@ -750,21 +734,20 @@  void buffer_free_multi(const odp_buffer_t buf[], int num_total)
 	int first = 0;
 
 	while (1) {
-		num = 1;
-		i   = 1;
-
-		pool = pool_from_buf(buf[first]);
+		num  = 1;
+		i    = 1;
+		pool = buf_hdr[first]->pool_ptr;
 
 		/* 'num' buffers are from the same pool */
 		if (num_total > 1) {
 			for (i = first; i < num_total; i++)
-				if (pool != pool_from_buf(buf[i]))
+				if (pool != buf_hdr[i]->pool_ptr)
 					break;
 
 			num = i - first;
 		}
 
-		buffer_free_to_pool(pool, &buf[first], num);
+		buffer_free_to_pool(pool, &buf_hdr[first], num);
 
 		if (i == num_total)
 			return;
@@ -782,7 +765,7 @@  odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)
 	ODP_ASSERT(ODP_POOL_INVALID != pool_hdl);
 
 	pool = pool_entry_from_hdl(pool_hdl);
-	ret = buffer_alloc_multi(pool, &buf, NULL, 1);
+	ret  = buffer_alloc_multi(pool, (odp_buffer_hdr_t **)&buf, 1);
 
 	if (odp_likely(ret == 1))
 		return buf;
@@ -798,17 +781,17 @@  int odp_buffer_alloc_multi(odp_pool_t pool_hdl, odp_buffer_t buf[], int num)
 
 	pool = pool_entry_from_hdl(pool_hdl);
 
-	return buffer_alloc_multi(pool, buf, NULL, num);
+	return buffer_alloc_multi(pool, (odp_buffer_hdr_t **)buf, num);
 }
 
 void odp_buffer_free(odp_buffer_t buf)
 {
-	buffer_free_multi(&buf, 1);
+	buffer_free_multi((odp_buffer_hdr_t **)&buf, 1);
 }
 
 void odp_buffer_free_multi(const odp_buffer_t buf[], int num)
 {
-	buffer_free_multi(buf, num);
+	buffer_free_multi((odp_buffer_hdr_t **)(uintptr_t)buf, num);
 }
 
 int odp_pool_capability(odp_pool_capability_t *capa)