[CATERPILLAR,v1,2/2] linux-generic: buffer: remove handle/index in metadata

Message ID 1514282408-4987-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • remove some metadata with less effort from odp_buffer
Related show

Commit Message

Github ODP bot Dec. 26, 2017, 10 a.m.
From: Joyce Kong <joyce.kong@arm.com>


Signed-off-by: Joyce Kong <joyce.kong@arm.com>

---
/** Email created from pull request 368 (JoyceKong-arm:buffer_metadata)
 ** https://github.com/Linaro/odp/pull/368
 ** Patch: https://github.com/Linaro/odp/pull/368.patch
 ** Base sha: bbbe6c0ef65c16f6d7d327712f177fbf6740e96f
 ** Merge commit sha: 8d61f6ed1d683276c6c3108517741a543b05a574
 **/
 platform/linux-generic/buffer/generic.c              | 4 ++--
 platform/linux-generic/include/odp_buffer_internal.h | 4 ----
 platform/linux-generic/include/odp_pool_internal.h   | 8 ++++++++
 platform/linux-generic/odp_packet.c                  | 4 +++-
 platform/linux-generic/pool/generic.c                | 1 -
 5 files changed, 13 insertions(+), 8 deletions(-)

Patch

diff --git a/platform/linux-generic/buffer/generic.c b/platform/linux-generic/buffer/generic.c
index cf99407cc..543cc530c 100644
--- a/platform/linux-generic/buffer/generic.c
+++ b/platform/linux-generic/buffer/generic.c
@@ -193,7 +193,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_hdr[i]->index;
+			buf_index[i] = buf_hdr_to_index(buf_hdr[i]);
 
 		ring_enq_multi(ring, mask, buf_index, num);
 
@@ -233,7 +233,7 @@  static inline void buffer_free_to_pool(pool_t *pool,
 	}
 
 	for (i = 0; i < num; i++)
-		cache->buf_index[cache_num + i] = buf_hdr[i]->index;
+		cache->buf_index[cache_num + i] = buf_hdr_to_index(buf_hdr[i]);
 
 	cache->num = cache_num + num;
 }
diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h
index 514e24798..b8e8c1717 100644
--- a/platform/linux-generic/include/odp_buffer_internal.h
+++ b/platform/linux-generic/include/odp_buffer_internal.h
@@ -43,10 +43,6 @@  typedef struct seg_entry_t {
 
 /* Common buffer header */
 struct odp_buffer_hdr_t {
-
-	/* Buffer index in the pool */
-	uint32_t  index;
-
 	/* Total segment count */
 	uint16_t  segcount;
 
diff --git a/platform/linux-generic/include/odp_pool_internal.h b/platform/linux-generic/include/odp_pool_internal.h
index a124697e9..cf1a423fb 100644
--- a/platform/linux-generic/include/odp_pool_internal.h
+++ b/platform/linux-generic/include/odp_pool_internal.h
@@ -139,6 +139,14 @@  static inline odp_buffer_hdr_t *buf_hdr_from_index(pool_t *pool,
 	return buf_hdr;
 }
 
+static inline uint32_t buf_hdr_to_index(odp_buffer_hdr_t *buf_hdr)
+{
+	pool_t *pool = buf_hdr->pool_ptr;
+	uint32_t index = ((uint8_t *)buf_hdr - pool->base_addr)
+			 / pool->block_size;
+
+	return index;
+}
 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);
 
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 853d3baa9..cb20eeda8 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -10,6 +10,7 @@ 
 #include <odp/api/packet.h>
 #include <odp_packet_internal.h>
 #include <odp_debug_internal.h>
+#include <odp_pool_internal.h>
 #include <odp/api/hints.h>
 #include <odp/api/byteorder.h>
 
@@ -1796,7 +1797,8 @@  void odp_packet_print_data(odp_packet_t pkt, uint32_t offset,
 	len += snprintf(&str[len], n - len,
 			"  pool index    %" PRIu32 "\n", pool->pool_idx);
 	len += snprintf(&str[len], n - len,
-			"  buf index     %" PRIu32 "\n", hdr->buf_hdr.index);
+			"  buf index     %" PRIu32 "\n",
+			buf_hdr_to_index(&hdr->buf_hdr));
 	len += snprintf(&str[len], n - len,
 			"  segcount      %" PRIu16 "\n", hdr->buf_hdr.segcount);
 	len += snprintf(&str[len], n - len,
diff --git a/platform/linux-generic/pool/generic.c b/platform/linux-generic/pool/generic.c
index 7a068472c..4d5f59461 100644
--- a/platform/linux-generic/pool/generic.c
+++ b/platform/linux-generic/pool/generic.c
@@ -259,7 +259,6 @@  static void init_buffers(pool_t *pool)
 		seg_size = pool->headroom + pool->seg_len + pool->tailroom;
 
 		/* Initialize buffer metadata */
-		buf_hdr->index = i;
 		buf_hdr->size = seg_size;
 		buf_hdr->type = type;
 		buf_hdr->event_type = type;