[PATCHv2,01/11] linux-generic: pool: restructure pool routines

Message ID 20170312123045.3852-2-bill.fischofer@linaro.org
State New
Headers show
Series
  • Optimized Packet References
Related show

Commit Message

Bill Fischofer March 12, 2017, 12:30 p.m.
Restructure pool routines in preparation for introducing
packet references.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
 platform/linux-generic/include/odp_pool_internal.h | 33 ++++++++++++++-
 platform/linux-generic/odp_pool.c                  | 47 +---------------------
 2 files changed, 34 insertions(+), 46 deletions(-)

-- 
2.12.0.rc1

Patch hide | download patch | download mbox

diff --git a/platform/linux-generic/include/odp_pool_internal.h b/platform/linux-generic/include/odp_pool_internal.h
index ebb779da..e767251a 100644
--- a/platform/linux-generic/include/odp_pool_internal.h
+++ b/platform/linux-generic/include/odp_pool_internal.h
@@ -122,9 +122,40 @@  static inline odp_buffer_hdr_t *buf_hdl_to_hdr(odp_buffer_t buf)
 	return pool_buf_hdl_to_hdr(pool, buf);
 }
 
+static inline odp_pool_t pool_index_to_handle(uint32_t pool_idx)
+{
+	return _odp_cast_scalar(odp_pool_t, pool_idx);
+}
+
+static inline uint32_t pool_id_from_buf(odp_buffer_t buf)
+{
+	odp_buffer_bits_t handle;
+
+	handle.handle = buf;
+	return handle.pool_id;
+}
+
 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);
+void buffer_free_to_pool(uint32_t pool_id, const odp_buffer_t buf[], int num);
+
+static inline void buffer_free_multi(const odp_buffer_t buf[], int num)
+{
+	uint32_t next_pool, pool_id = pool_id_from_buf(buf[0]);
+	int i, first = 0;
+
+	for (i = 1; i < num; i++) {
+		next_pool = pool_id_from_buf(buf[i]);
+
+		if (odp_unlikely(next_pool != pool_id)) {
+			buffer_free_to_pool(pool_id, &buf[first], i - first);
+			first = i;
+			pool_id = next_pool;
+		}
+	}
+
+	buffer_free_to_pool(pool_id, &buf[first], num - first);
+}
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index 145002d9..9df9ba21 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -47,19 +47,6 @@  typedef struct pool_local_t {
 pool_table_t *pool_tbl;
 static __thread pool_local_t local;
 
-static inline odp_pool_t pool_index_to_handle(uint32_t pool_idx)
-{
-	return _odp_cast_scalar(odp_pool_t, pool_idx);
-}
-
-static inline uint32_t pool_id_from_buf(odp_buffer_t buf)
-{
-	odp_buffer_bits_t handle;
-
-	handle.handle = buf;
-	return handle.pool_id;
-}
-
 int odp_pool_init_global(void)
 {
 	uint32_t i;
@@ -672,8 +659,8 @@  int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[],
 	return num_ch + num_deq;
 }
 
-static inline void buffer_free_to_pool(uint32_t pool_id,
-				       const odp_buffer_t buf[], int num)
+void buffer_free_to_pool(uint32_t pool_id,
+			 const odp_buffer_t buf[], int num)
 {
 	pool_t *pool;
 	int i;
@@ -733,36 +720,6 @@  static inline void buffer_free_to_pool(uint32_t pool_id,
 	cache->num = cache_num + num;
 }
 
-void buffer_free_multi(const odp_buffer_t buf[], int num_total)
-{
-	uint32_t pool_id;
-	int num;
-	int i;
-	int first = 0;
-
-	while (1) {
-		num = 1;
-		i   = 1;
-		pool_id = pool_id_from_buf(buf[first]);
-
-		/* 'num' buffers are from the same pool */
-		if (num_total > 1) {
-			for (i = first; i < num_total; i++)
-				if (pool_id != pool_id_from_buf(buf[i]))
-					break;
-
-			num = i - first;
-		}
-
-		buffer_free_to_pool(pool_id, &buf[first], num);
-
-		if (i == num_total)
-			return;
-
-		first = i;
-	}
-}
-
 odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)
 {
 	odp_buffer_t buf;