[CLOUD-DEV,v3,2/2] linux-dpdk:introduce buffer submodule

Message ID 1505296808-16618-3-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series
  • [CLOUD-DEV,v3,1/2] linux-dpdk:prepare for buffer submodule
Related show

Commit Message

Github ODP bot Sept. 13, 2017, 10 a.m.
From: Balakrishna Garapati <balakrishna.garapati@linaro.org>


Signed-off-by: Balakrishna Garapati <balakrishna.garapati@linaro.org>

---
/** Email created from pull request 169 (GBalakrishna:dpdk_buffer_submodule)
 ** https://github.com/Linaro/odp/pull/169
 ** Patch: https://github.com/Linaro/odp/pull/169.patch
 ** Base sha: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a
 ** Merge commit sha: dff16717c6e54c01ff51764e12d56fe938e87b86
 **/
 platform/linux-dpdk/Makefile.am   |   3 +
 platform/linux-dpdk/buffer/dpdk.c | 128 +++++++++++++++++++++++++++++++++-----
 platform/linux-dpdk/pool/dpdk.c   |  62 ------------------
 3 files changed, 114 insertions(+), 79 deletions(-)

Patch

diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am
index a006d0da8..bf6485adf 100644
--- a/platform/linux-dpdk/Makefile.am
+++ b/platform/linux-dpdk/Makefile.am
@@ -168,6 +168,7 @@  odpdrvplatinclude_HEADERS = \
 
 
 noinst_HEADERS = \
+		  ${top_srcdir}/platform/linux-generic/include/odp_buffer_subsystem.h \
 		  ${top_srcdir}/platform/linux-generic/include/_fdserver_internal.h \
 		  ${top_srcdir}/platform/linux-generic/include/_ishm_internal.h \
 		  ${top_srcdir}/platform/linux-generic/include/_ishmphy_internal.h \
@@ -252,6 +253,7 @@  __LIB__libodp_dpdk_la_SOURCES = \
 			   ../linux-generic/odp_rwlock.c \
 			   ../linux-generic/odp_rwlock_recursive.c \
 			   ../linux-generic/pool/subsystem.c \
+			   ../linux-generic/buffer/subsystem.c \
 			   ../linux-generic/odp_schedule_if.c \
 			   ../linux-generic/schedule/generic.c \
 			   ../linux-generic/schedule/iquery.c \
@@ -300,6 +302,7 @@  __LIB__libodp_dpdk_la_SOURCES += arch/x86/cpu_flags.c \
 endif
 
 pool/dpdk.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE
+buffer/dpdk.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE
 if ODP_SCHEDULE_SCALABLE
 ../linux-generic/schedule/scalable.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE
 else
diff --git a/platform/linux-dpdk/buffer/dpdk.c b/platform/linux-dpdk/buffer/dpdk.c
index 3c71fef84..f39ab31f1 100644
--- a/platform/linux-dpdk/buffer/dpdk.c
+++ b/platform/linux-dpdk/buffer/dpdk.c
@@ -7,30 +7,96 @@ 
 #include <odp/api/buffer.h>
 #include <odp_buffer_internal.h>
 #include <odp_buffer_inlines.h>
+#include <odp_buffer_subsystem.h>
 #include <odp_debug_internal.h>
+#include <odp_pool_internal.h>
 
 #include <string.h>
 #include <stdio.h>
 #include <inttypes.h>
 
-odp_buffer_t odp_buffer_from_event(odp_event_t ev)
+static odp_buffer_t buffer_alloc(odp_pool_t pool_hdl)
+{
+	odp_buffer_t buffer;
+	pool_entry_cp_t *pool_cp;
+	pool_entry_dp_t *pool_dp;
+
+	pool_cp = odp_pool_to_entry_cp(pool_hdl);
+	pool_dp = odp_pool_to_entry_dp(pool_hdl);
+
+	ODP_ASSERT(pool_cp->params.type != ODP_POOL_BUFFER ||
+		   pool_cp->params.type != ODP_POOL_TIMEOUT);
+
+	buffer = (odp_buffer_t)rte_ctrlmbuf_alloc(pool_dp->rte_mempool);
+
+	if ((struct rte_mbuf *)buffer == NULL) {
+		rte_errno = ENOMEM;
+		return ODP_BUFFER_INVALID;
+	}
+
+	buf_hdl_to_hdr(buffer)->next = NULL;
+	return buffer;
+}
+
+static odp_buffer_t dpdk_buffer_alloc(odp_pool_t pool_hdl)
+{
+	ODP_ASSERT(ODP_POOL_INVALID != pool_hdl);
+
+	return buffer_alloc(pool_hdl);
+}
+
+static int dpdk_buffer_alloc_multi(odp_pool_t pool_hdl,
+				   odp_buffer_t buf[],
+				   int num)
+{
+	int i;
+
+	ODP_ASSERT(ODP_POOL_INVALID != pool_hdl);
+
+	for (i = 0; i < num; i++) {
+		buf[i] = buffer_alloc(pool_hdl);
+		if (buf[i] == ODP_BUFFER_INVALID)
+			return rte_errno == ENOMEM ? i : -EINVAL;
+	}
+	return i;
+}
+
+static void dpdk_buffer_free(odp_buffer_t buf)
+{
+	struct rte_mbuf *mbuf = (struct rte_mbuf *)buf;
+
+	rte_ctrlmbuf_free(mbuf);
+}
+
+static void dpdk_buffer_free_multi(const odp_buffer_t buf[], int num)
+{
+	int i;
+
+	for (i = 0; i < num; i++) {
+		struct rte_mbuf *mbuf = (struct rte_mbuf *)buf[i];
+
+		rte_ctrlmbuf_free(mbuf);
+	}
+}
+
+static odp_buffer_t dpdk_buffer_from_event(odp_event_t ev)
 {
 	return (odp_buffer_t)ev;
 }
 
-odp_event_t odp_buffer_to_event(odp_buffer_t buf)
+static odp_event_t dpdk_buffer_to_event(odp_buffer_t buf)
 {
 	return (odp_event_t)buf;
 }
 
-void *odp_buffer_addr(odp_buffer_t buf)
+static void *dpdk_buffer_addr(odp_buffer_t buf)
 {
 	odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf);
 
 	return hdr->mb.buf_addr;
 }
 
-uint32_t odp_buffer_size(odp_buffer_t buf)
+static uint32_t dpdk_buffer_size(odp_buffer_t buf)
 {
 	odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf);
 	struct rte_mbuf *mbuf = (struct rte_mbuf *)hdr;
@@ -52,7 +118,7 @@  void _odp_buffer_type_set(odp_buffer_t buf, int type)
 	hdr->type = type;
 }
 
-int odp_buffer_is_valid(odp_buffer_t buf)
+static int dpdk_buffer_is_valid(odp_buffer_t buf)
 {
 	/* We could call rte_mbuf_sanity_check, but that panics
 	 * and aborts the program */
@@ -71,43 +137,71 @@  int odp_buffer_snprint(char *str, uint32_t n, odp_buffer_t buf)
 
 	hdr = buf_hdl_to_hdr(buf);
 
-	len += snprintf(&str[len], n-len,
+	len += snprintf(&str[len], n - len,
 			"Buffer\n");
-	len += snprintf(&str[len], n-len,
+	len += snprintf(&str[len], n - len,
 			"  pool         %p\n", hdr->mb.pool);
-	len += snprintf(&str[len], n-len,
-			"  phy_addr     %"PRIu64"\n", hdr->mb.buf_physaddr);
-	len += snprintf(&str[len], n-len,
+	len += snprintf(&str[len], n - len,
+			"  phy_addr     %" PRIu64 "\n", hdr->mb.buf_physaddr);
+	len += snprintf(&str[len], n - len,
 			"  addr         %p\n",        hdr->mb.buf_addr);
-	len += snprintf(&str[len], n-len,
+	len += snprintf(&str[len], n - len,
 			"  size         %u\n",        hdr->mb.buf_len);
-	len += snprintf(&str[len], n-len,
+	len += snprintf(&str[len], n - len,
 			"  ref_count    %i\n",
 			rte_mbuf_refcnt_read(&hdr->mb));
-	len += snprintf(&str[len], n-len,
+	len += snprintf(&str[len], n - len,
 			"  odp type     %i\n",        hdr->type);
 
 	return len;
 }
 
-void odp_buffer_print(odp_buffer_t buf)
+static void dpdk_buffer_print(odp_buffer_t buf)
 {
 	int max_len = 512;
 	char str[max_len];
 	int len;
 
-	len = odp_buffer_snprint(str, max_len-1, buf);
+	len = odp_buffer_snprint(str, max_len - 1, buf);
 	str[len] = 0;
 
 	ODP_PRINT("\n%s\n", str);
 }
 
-uint64_t odp_buffer_to_u64(odp_buffer_t hdl)
+static uint64_t dpdk_buffer_to_u64(odp_buffer_t hdl)
 {
 	return _odp_pri(hdl);
 }
 
-odp_pool_t odp_buffer_pool(odp_buffer_t buf)
+static odp_pool_t dpdk_buffer_pool(odp_buffer_t buf)
 {
 	return buf_hdl_to_hdr(buf)->pool_hdl;
 }
+
+odp_buffer_module_t dpdk_buffer = {
+	.base = {
+		.name = "dpdk_buffer",
+		.init_local = NULL,
+		.term_local = NULL,
+		.init_global = NULL,
+		.term_global = NULL,
+		},
+	.buffer_alloc = dpdk_buffer_alloc,
+	.buffer_alloc_multi = dpdk_buffer_alloc_multi,
+	.buffer_free = dpdk_buffer_free,
+	.buffer_free_multi = dpdk_buffer_free_multi,
+	.buffer_from_event = dpdk_buffer_from_event,
+	.buffer_to_event = dpdk_buffer_to_event,
+	.buffer_addr = dpdk_buffer_addr,
+	.buffer_size = dpdk_buffer_size,
+	.buffer_is_valid = dpdk_buffer_is_valid,
+	.buffer_print = dpdk_buffer_print,
+	.buffer_to_u64 = dpdk_buffer_to_u64,
+	.buffer_pool = dpdk_buffer_pool,
+};
+
+ODP_MODULE_CONSTRUCTOR(dpdk_buffer)
+{
+	odp_module_constructor(&dpdk_buffer);
+	odp_subsystem_register_module(buffer, &dpdk_buffer);
+}
diff --git a/platform/linux-dpdk/pool/dpdk.c b/platform/linux-dpdk/pool/dpdk.c
index 499bea127..6acc4e901 100644
--- a/platform/linux-dpdk/pool/dpdk.c
+++ b/platform/linux-dpdk/pool/dpdk.c
@@ -549,68 +549,6 @@  static odp_pool_t dpdk_pool_lookup(const char *name)
 	return pool_hdl;
 }
 
-static odp_buffer_t buffer_alloc(odp_pool_t pool_hdl)
-{
-	odp_buffer_t buffer;
-	pool_entry_cp_t *pool_cp;
-	pool_entry_dp_t *pool_dp;
-
-	pool_cp = odp_pool_to_entry_cp(pool_hdl);
-	pool_dp = odp_pool_to_entry_dp(pool_hdl);
-
-	ODP_ASSERT(pool_cp->params.type != ODP_POOL_BUFFER &&
-		   pool_cp->params.type != ODP_POOL_TIMEOUT);
-
-	buffer = (odp_buffer_t)rte_ctrlmbuf_alloc(pool_dp->rte_mempool);
-
-	if ((struct rte_mbuf *)buffer == NULL) {
-		rte_errno = ENOMEM;
-		return ODP_BUFFER_INVALID;
-	}
-
-	buf_hdl_to_hdr(buffer)->next = NULL;
-	return buffer;
-}
-
-odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)
-{
-	ODP_ASSERT(ODP_POOL_INVALID != pool_hdl);
-
-	return buffer_alloc(pool_hdl);
-}
-
-int odp_buffer_alloc_multi(odp_pool_t pool_hdl, odp_buffer_t buf[], int num)
-{
-	int i;
-
-	ODP_ASSERT(ODP_POOL_INVALID != pool_hdl);
-
-	for (i = 0; i < num; i++) {
-		buf[i] = buffer_alloc(pool_hdl);
-		if (buf[i] == ODP_BUFFER_INVALID)
-			return rte_errno == ENOMEM ? i : -EINVAL;
-	}
-	return i;
-}
-
-void odp_buffer_free(odp_buffer_t buf)
-{
-	struct rte_mbuf *mbuf = (struct rte_mbuf *)buf;
-
-	rte_ctrlmbuf_free(mbuf);
-}
-
-void odp_buffer_free_multi(const odp_buffer_t buf[], int num)
-{
-	int i;
-
-	for (i = 0; i < num; i++) {
-		struct rte_mbuf *mbuf = (struct rte_mbuf *)buf[i];
-
-		rte_ctrlmbuf_free(mbuf);
-	}
-}
-
 static void dpdk_pool_print(odp_pool_t pool_hdl)
 {
 	pool_entry_dp_t *pool_dp = odp_pool_to_entry_dp(pool_hdl);