[lng-odp] [PATCH CLOUD-DEV v1 2/2] linux-gen: pool: add generic pool module to mempool subsystem

2017-08-09 Thread Github ODP bot
From: Kevin Wang 

Signed-off-by: Kevin Wang 
---
/** Email created from pull request 120 (kevinwangsk:cloud-dev-pool-modular)
 ** https://github.com/Linaro/odp/pull/120
 ** Patch: https://github.com/Linaro/odp/pull/120.patch
 ** Base sha: 863d61cc3ed82f9f0725c792910e8a05cc5d5a82
 ** Merge commit sha: 2946a7225316eb82bffa62cd0ab02f4a6e079037
 **/
 platform/linux-generic/Makefile.am |   4 +-
 platform/linux-generic/include/odp_pool_internal.h |  37 +++
 platform/linux-generic/odp_buffer.c| 244 
 .../linux-generic/{odp_pool.c => pool/generic.c}   | 324 +++--
 platform/linux-generic/pool/subsystem.c| 220 ++
 5 files changed, 540 insertions(+), 289 deletions(-)
 rename platform/linux-generic/{odp_pool.c => pool/generic.c} (69%)

diff --git a/platform/linux-generic/Makefile.am 
b/platform/linux-generic/Makefile.am
index d74e2e31..cdb868b1 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -268,9 +268,9 @@ __LIB__libodp_linux_la_SOURCES = \
   pktio/sysfs.c \
   pktio/tap.c \
   pktio/ring.c \
+  pool/generic.c \
   pool/subsystem.c \
   odp_pkt_queue.c \
-  odp_pool.c \
   odp_queue.c \
   odp_queue_if.c \
   odp_queue_scalable.c \
@@ -326,6 +326,8 @@ if HAVE_PCAP
 __LIB__libodp_linux_la_SOURCES += pktio/pcap.c
 endif
 
+pool/generic.lo: CFLAGS += -DIM_ACTIVE_MODULE
+
 # Build modular framework into odp-linux library
 modularframeworkdir = $(top_srcdir)/frameworks/modular
 noinst_HEADERS += $(modularframeworkdir)/list.h \
diff --git a/platform/linux-generic/include/odp_pool_internal.h 
b/platform/linux-generic/include/odp_pool_internal.h
index f2d2e2ca..bc7305c4 100644
--- a/platform/linux-generic/include/odp_pool_internal.h
+++ b/platform/linux-generic/include/odp_pool_internal.h
@@ -21,11 +21,14 @@ extern "C" {
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
 #include 
 
+#define CACHE_BURST32
+
 typedef struct pool_cache_t {
uint32_t num;
uint32_t buf_index[CONFIG_POOL_CACHE_SIZE];
@@ -88,6 +91,14 @@ typedef struct pool_table_t {
 
 extern pool_table_t *pool_tbl;
 
+/* Thread local variables */
+typedef struct pool_local_t {
+   pool_cache_t *cache[ODP_CONFIG_POOLS];
+   int thr_id;
+} pool_local_t;
+
+extern __thread pool_local_t local;
+
 static inline pool_t *pool_entry(uint32_t pool_idx)
 {
return _tbl->pool[pool_idx];
@@ -103,6 +114,32 @@ static inline odp_buffer_hdr_t 
*buf_hdl_to_hdr(odp_buffer_t buf)
return (odp_buffer_hdr_t *)(uintptr_t)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 pool_t *pool_from_buf(odp_buffer_t buf)
+{
+   odp_buffer_hdr_t *buf_hdr = buf_hdl_to_hdr(buf);
+
+   return buf_hdr->pool_ptr;
+}
+
+static inline odp_buffer_hdr_t *buf_hdr_from_index(pool_t *pool,
+  uint32_t buffer_idx)
+{
+   uint32_t block_offset;
+   odp_buffer_hdr_t *buf_hdr;
+
+   block_offset = buffer_idx * pool->block_size;
+
+   /* clang requires cast to uintptr_t */
+   buf_hdr = (odp_buffer_hdr_t *)(uintptr_t)>base_addr[block_offset];
+
+   return buf_hdr;
+}
+
 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_buffer.c 
b/platform/linux-generic/odp_buffer.c
index 9c7dc1f5..b7ea88e6 100644
--- a/platform/linux-generic/odp_buffer.c
+++ b/platform/linux-generic/odp_buffer.c
@@ -83,3 +83,247 @@ uint64_t odp_buffer_to_u64(odp_buffer_t hdl)
 {
return _odp_pri(hdl);
 }
+
+odp_event_type_t _odp_buffer_event_type(odp_buffer_t buf)
+{
+   return buf_hdl_to_hdr(buf)->event_type;
+}
+
+void _odp_buffer_event_type_set(odp_buffer_t buf, int ev)
+{
+   buf_hdl_to_hdr(buf)->event_type = ev;
+}
+
+odp_event_subtype_t _odp_buffer_event_subtype(odp_buffer_t buf)
+{
+   return buf_hdl_to_hdr(buf)->event_subtype;
+}
+
+void _odp_buffer_event_subtype_set(odp_buffer_t buf, int ev)
+{
+   buf_hdl_to_hdr(buf)->event_subtype = ev;
+}
+
+int buffer_alloc_multi(pool_t *pool, odp_buffer_hdr_t *buf_hdr[], int max_num)
+{
+   ring_t *ring;
+   uint32_t mask, i;
+   pool_cache_t *cache;
+   uint32_t cache_num, num_ch, num_deq, burst;
+   odp_buffer_hdr_t *hdr;
+
+   cache = local.cache[pool->pool_idx];
+
+   cache_num = cache->num;
+   num_ch= max_num;
+   num_deq   = 0;
+   burst = CACHE_BURST;
+
+   if (odp_unlikely(cache_num < (uint32_t)max_num)) {
+   /* Cache does 

[lng-odp] [PATCH CLOUD-DEV v1 2/2] linux-gen: pool: add generic pool module to mempool subsystem

2017-08-08 Thread Github ODP bot
From: Kevin Wang 

---
/** Email created from pull request 117 (kevinwangsk:cloud-dev)
 ** https://github.com/Linaro/odp/pull/117
 ** Patch: https://github.com/Linaro/odp/pull/117.patch
 ** Base sha: 370f93139e16633390cb28acda6296da8fee006d
 ** Merge commit sha: b2fdd36c723fee970da5c3bcd487cfd4b5eb18a9
 **/
 platform/linux-generic/Makefile.am |   4 +-
 platform/linux-generic/include/odp_pool_internal.h |  24 ++
 platform/linux-generic/odp_buffer.c| 251 
 .../linux-generic/{odp_pool.c => pool/generic.c}   | 315 +++--
 platform/linux-generic/pool/subsystem.c| 220 ++
 5 files changed, 532 insertions(+), 282 deletions(-)
 rename platform/linux-generic/{odp_pool.c => pool/generic.c} (70%)

diff --git a/platform/linux-generic/Makefile.am 
b/platform/linux-generic/Makefile.am
index dec8a0f4..3360c0f1 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -240,9 +240,9 @@ __LIB__libodp_linux_la_SOURCES = \
   pktio/sysfs.c \
   pktio/tap.c \
   pktio/ring.c \
+  pool/generic.c \
   pool/subsystem.c \
   odp_pkt_queue.c \
-  odp_pool.c \
   odp_queue.c \
   odp_queue_if.c \
   odp_rwlock.c \
@@ -295,6 +295,8 @@ if HAVE_PCAP
 __LIB__libodp_linux_la_SOURCES += pktio/pcap.c
 endif
 
+pool/generic.lo: CFLAGS += -DIM_ACTIVE_MODULE
+
 # Build modular framework into odp-linux library
 modularframeworkdir = $(top_srcdir)/frameworks/modular
 noinst_HEADERS += $(modularframeworkdir)/list.h \
diff --git a/platform/linux-generic/include/odp_pool_internal.h 
b/platform/linux-generic/include/odp_pool_internal.h
index ebb779da..533abefc 100644
--- a/platform/linux-generic/include/odp_pool_internal.h
+++ b/platform/linux-generic/include/odp_pool_internal.h
@@ -21,11 +21,14 @@ extern "C" {
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
 #include 
 
+#define CACHE_BURST32
+
 typedef struct pool_cache_t {
uint32_t num;
 
@@ -82,6 +85,14 @@ typedef struct pool_table_t {
 
 extern pool_table_t *pool_tbl;
 
+/* Thread local variables */
+typedef struct pool_local_t {
+   pool_cache_t *cache[ODP_CONFIG_POOLS];
+   int thr_id;
+} pool_local_t;
+
+extern __thread pool_local_t local;
+
 static inline pool_t *pool_entry(uint32_t pool_idx)
 {
return _tbl->pool[pool_idx];
@@ -109,6 +120,19 @@ static inline odp_buffer_hdr_t *pool_buf_hdl_to_hdr(pool_t 
*pool,
return buf_hdr;
 }
 
+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;
+}
+
 static inline odp_buffer_hdr_t *buf_hdl_to_hdr(odp_buffer_t buf)
 {
odp_buffer_bits_t handle;
diff --git a/platform/linux-generic/odp_buffer.c 
b/platform/linux-generic/odp_buffer.c
index 88c8140b..d44ada6f 100644
--- a/platform/linux-generic/odp_buffer.c
+++ b/platform/linux-generic/odp_buffer.c
@@ -81,3 +81,254 @@ uint64_t odp_buffer_to_u64(odp_buffer_t hdl)
 {
return _odp_pri(hdl);
 }
+
+odp_event_type_t _odp_buffer_event_type(odp_buffer_t buf)
+{
+   return buf_hdl_to_hdr(buf)->event_type;
+}
+
+void _odp_buffer_event_type_set(odp_buffer_t buf, int ev)
+{
+   buf_hdl_to_hdr(buf)->event_type = ev;
+}
+
+int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[],
+  odp_buffer_hdr_t *buf_hdr[], int max_num)
+{
+   ring_t *ring;
+   uint32_t mask, i;
+   pool_cache_t *cache;
+   uint32_t cache_num, num_ch, num_deq, burst;
+   odp_buffer_hdr_t *hdr;
+
+   cache = local.cache[pool->pool_idx];
+
+   cache_num = cache->num;
+   num_ch= max_num;
+   num_deq   = 0;
+   burst = CACHE_BURST;
+
+   if (odp_unlikely(cache_num < (uint32_t)max_num)) {
+   /* Cache does not have enough buffers */
+   num_ch  = cache_num;
+   num_deq = max_num - cache_num;
+
+   if (odp_unlikely(num_deq > CACHE_BURST))
+   burst = num_deq;
+   }
+
+   /* Get buffers from the cache */
+   for (i = 0; i < num_ch; i++) {
+   buf[i] = cache->buf[cache_num - num_ch + i];
+
+   if (odp_likely(buf_hdr != NULL))
+   buf_hdr[i] = pool_buf_hdl_to_hdr(pool, buf[i]);
+   }
+
+   /* If needed, get more from the global pool */
+   if (odp_unlikely(num_deq)) {
+   /* Temporary copy needed since odp_buffer_t is uintptr_t
+* and not uint32_t. */
+   uint32_t data[burst];
+
+   ring  = >ring->hdr;
+