[v7,3/7] mbuf: add pool ops name selection API helpers

Message ID 1517213449-678-4-git-send-email-hemant.agrawal@nxp.com
State New
Headers show
Series
  • Dynamic HW Mempool Detection Support
Related show

Commit Message

Hemant Agrawal Jan. 29, 2018, 8:10 a.m.
This patch add support for various mempool ops config helper APIs.

1.User defined mempool ops
2.Platform detected HW mempool ops (active).
3.Best selection of mempool ops by looking into user defined,
  platform registered and compile time configured.

Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>

Acked-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>

---
 doc/api/doxy-api-index.md            |  1 +
 lib/librte_mbuf/Makefile             |  4 +-
 lib/librte_mbuf/rte_mbuf.c           |  5 +-
 lib/librte_mbuf/rte_mbuf_pool_ops.c  | 96 ++++++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_pool_ops.h  | 96 ++++++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_version.map | 11 +++++
 6 files changed, 208 insertions(+), 5 deletions(-)
 create mode 100644 lib/librte_mbuf/rte_mbuf_pool_ops.c
 create mode 100644 lib/librte_mbuf/rte_mbuf_pool_ops.h

-- 
2.7.4

Comments

Andrew Rybchenko Jan. 29, 2018, 8:44 a.m. | #1
On 01/29/2018 11:10 AM, Hemant Agrawal wrote:
> This patch add support for various mempool ops config helper APIs.

>

> 1.User defined mempool ops

> 2.Platform detected HW mempool ops (active).

> 3.Best selection of mempool ops by looking into user defined,

>    platform registered and compile time configured.

>

> Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>

> Acked-by: Olivier Matz <olivier.matz@6wind.com>

> Acked-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>

> ---

>   doc/api/doxy-api-index.md            |  1 +

>   lib/librte_mbuf/Makefile             |  4 +-

>   lib/librte_mbuf/rte_mbuf.c           |  5 +-

>   lib/librte_mbuf/rte_mbuf_pool_ops.c  | 96 ++++++++++++++++++++++++++++++++++++

>   lib/librte_mbuf/rte_mbuf_pool_ops.h  | 96 ++++++++++++++++++++++++++++++++++++

>   lib/librte_mbuf/rte_mbuf_version.map | 11 +++++

>   6 files changed, 208 insertions(+), 5 deletions(-)

>   create mode 100644 lib/librte_mbuf/rte_mbuf_pool_ops.c

>   create mode 100644 lib/librte_mbuf/rte_mbuf_pool_ops.h


<...>

> diff --git a/lib/librte_mbuf/rte_mbuf_pool_ops.h b/lib/librte_mbuf/rte_mbuf_pool_ops.h

> new file mode 100644

> index 0000000..e8ee20f

> --- /dev/null

> +++ b/lib/librte_mbuf/rte_mbuf_pool_ops.h


<...>

> +

> +/**

> + * Set the platform supported pktmbuf HW mempool ops name

> + *

> + * This function allow the HW to register the actively supported HW mempool

> + * ops_name. Only one HW mempool ops can be registered at any point of time.

> + *

> + * @param ops_name

> + * @return

> + *   - On success, zero.

> + *   - On failure, a negative value.

> + */

> +int

> +rte_mbuf_set_platform_mempool_ops(const char *ops_name);


Just one minor note:
As far as I can see it is not strictly followed in DPDK headers, but coding
standard [1] says that "Short function prototypes should be contained
on a single line." and all examples in coding style follow it. There is 
a known
practical reason behind it: grep -r ^function_nameĀ  will find single place
where the function is implemented.

<...>

[1] http://dpdk.org/doc/guides/contributing/coding_style.html#prototypes

Patch

diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md
index 76d606f..8cbd92a 100644
--- a/doc/api/doxy-api-index.md
+++ b/doc/api/doxy-api-index.md
@@ -136,6 +136,7 @@  The public API headers are grouped by topics:
 
 - **containers**:
   [mbuf]               (@ref rte_mbuf.h),
+  [mbuf pool ops]      (@ref rte_mbuf_pool_ops.h)
   [ring]               (@ref rte_ring.h),
   [tailq]              (@ref rte_tailq.h),
   [bitmap]             (@ref rte_bitmap.h)
diff --git a/lib/librte_mbuf/Makefile b/lib/librte_mbuf/Makefile
index 398f724..e2e3ec6 100644
--- a/lib/librte_mbuf/Makefile
+++ b/lib/librte_mbuf/Makefile
@@ -14,9 +14,9 @@  EXPORT_MAP := rte_mbuf_version.map
 LIBABIVER := 3
 
 # all source are stored in SRCS-y
-SRCS-$(CONFIG_RTE_LIBRTE_MBUF) := rte_mbuf.c rte_mbuf_ptype.c
+SRCS-$(CONFIG_RTE_LIBRTE_MBUF) := rte_mbuf.c rte_mbuf_ptype.c rte_mbuf_pool_ops.c
 
 # install includes
-SYMLINK-$(CONFIG_RTE_LIBRTE_MBUF)-include := rte_mbuf.h rte_mbuf_ptype.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_MBUF)-include := rte_mbuf.h rte_mbuf_ptype.h rte_mbuf_pool_ops.h
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index c085c37..0c4d374 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -54,6 +54,7 @@ 
 #include <rte_branch_prediction.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_pool_ops.h>
 #include <rte_string_fns.h>
 #include <rte_hexdump.h>
 #include <rte_errno.h>
@@ -176,9 +177,7 @@  rte_pktmbuf_pool_create(const char *name, unsigned n,
 	if (mp == NULL)
 		return NULL;
 
-	mp_ops_name = rte_eal_mbuf_default_mempool_ops();
-	if (mp_ops_name == NULL)
-		mp_ops_name = RTE_MBUF_DEFAULT_MEMPOOL_OPS;
+	mp_ops_name = rte_mbuf_best_mempool_ops();
 	ret = rte_mempool_set_ops_byname(mp, mp_ops_name, NULL);
 	if (ret != 0) {
 		RTE_LOG(ERR, MBUF, "error setting mempool handler\n");
diff --git a/lib/librte_mbuf/rte_mbuf_pool_ops.c b/lib/librte_mbuf/rte_mbuf_pool_ops.c
new file mode 100644
index 0000000..9aa1541
--- /dev/null
+++ b/lib/librte_mbuf/rte_mbuf_pool_ops.c
@@ -0,0 +1,96 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2018 NXP
+ */
+
+#include <string.h>
+#include <rte_eal.h>
+#include <rte_mbuf.h>
+#include <rte_errno.h>
+#include <rte_mbuf_pool_ops.h>
+
+int
+rte_mbuf_set_platform_mempool_ops(const char *ops_name)
+{
+	const struct rte_memzone *mz;
+
+	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
+		return -ENAMETOOLONG;
+
+	mz = rte_memzone_lookup("mbuf_platform_pool_ops");
+	if (mz == NULL) {
+		mz = rte_memzone_reserve("mbuf_platform_pool_ops",
+			RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0);
+		if (mz == NULL)
+			return -rte_errno;
+		strncpy(mz->addr, ops_name, strlen(ops_name));
+		return 0;
+	} else if (strcmp(mz->addr, ops_name) == 0) {
+		return 0;
+	}
+
+	RTE_LOG(ERR, MBUF,
+		"%s is already registered as platform mbuf pool ops\n",
+		(char *)mz->addr);
+	return -EEXIST;
+}
+
+const char *
+rte_mbuf_platform_mempool_ops(void)
+{
+	const struct rte_memzone *mz;
+
+	mz = rte_memzone_lookup("mbuf_platform_pool_ops");
+	if (mz == NULL)
+		return NULL;
+	return mz->addr;
+}
+
+int
+rte_mbuf_set_user_mempool_ops(const char *ops_name)
+{
+	const struct rte_memzone *mz;
+
+	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
+		return -ENAMETOOLONG;
+
+	mz = rte_memzone_lookup("mbuf_user_pool_ops");
+	if (mz == NULL) {
+		mz = rte_memzone_reserve("mbuf_user_pool_ops",
+			RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0);
+		if (mz == NULL)
+			return -rte_errno;
+	}
+
+	strncpy(mz->addr, ops_name, strlen(ops_name));
+	return 0;
+
+}
+
+const char *
+rte_mbuf_user_mempool_ops(void)
+{
+	const struct rte_memzone *mz;
+
+	mz = rte_memzone_lookup("mbuf_user_pool_ops");
+	if (mz == NULL)
+		return rte_eal_mbuf_default_mempool_ops();
+	return mz->addr;
+}
+
+/* Return mbuf pool ops name */
+const char *
+rte_mbuf_best_mempool_ops(void)
+{
+	/* User defined mempool ops takes the priority */
+	const char *best_ops = rte_mbuf_user_mempool_ops();
+	if (best_ops)
+		return best_ops;
+
+	/* Next choice is platform configured mempool ops */
+	best_ops = rte_mbuf_platform_mempool_ops();
+	if (best_ops)
+		return best_ops;
+
+	/* Last choice is to use the compile time config pool */
+	return RTE_MBUF_DEFAULT_MEMPOOL_OPS;
+}
diff --git a/lib/librte_mbuf/rte_mbuf_pool_ops.h b/lib/librte_mbuf/rte_mbuf_pool_ops.h
new file mode 100644
index 0000000..e8ee20f
--- /dev/null
+++ b/lib/librte_mbuf/rte_mbuf_pool_ops.h
@@ -0,0 +1,96 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2018 NXP
+ */
+
+#ifndef _RTE_MBUF_POOL_OPS_H_
+#define _RTE_MBUF_POOL_OPS_H_
+
+/**
+ * @file
+ * RTE Mbuf Pool Ops
+ *
+ * These APIs are for configuring the mbuf pool ops names to be largely used by
+ * rte_pktmbuf_pool_create(). However, this can also be used to set and inquire
+ * the best mempool ops available.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Set the platform supported pktmbuf HW mempool ops name
+ *
+ * This function allow the HW to register the actively supported HW mempool
+ * ops_name. Only one HW mempool ops can be registered at any point of time.
+ *
+ * @param ops_name
+ * @return
+ *   - On success, zero.
+ *   - On failure, a negative value.
+ */
+int
+rte_mbuf_set_platform_mempool_ops(const char *ops_name);
+
+/**
+ * Get configured platform supported pktmbuf HW mempool ops name
+ *
+ * This function returns the platform supported mempool ops name.
+ *
+ * @return
+ *   - On success, platform pool ops name.
+ *   - On failure, NULL.
+ */
+const char *
+rte_mbuf_platform_mempool_ops(void);
+
+/**
+ * Set the user preferred pktmbuf mempool ops name
+ *
+ * This function can be used by the user to configure user preferred
+ * mempool ops name.
+ *
+ * @param ops_name
+ * @return
+ *   - On success, zero.
+ *   - On failure, a negative value.
+ */
+int
+rte_mbuf_set_user_mempool_ops(const char *ops_name);
+
+/**
+ * Get user preferred pool ops name for mbuf
+ *
+ * This function returns the user configured mempool ops name.
+ *
+ * @return
+ *   - On success, user pool ops name..
+ *   - On failure, NULL.
+ */
+const char *
+rte_mbuf_user_mempool_ops(void);
+
+/**
+ * Get the best mempool ops name for pktmbuf.
+ *
+ * This function is used to determine the best options for mempool ops for
+ * pktmbuf allocations. Following are the priority order:
+ * 1. User defined, 2. Platform HW supported, 3. Compile time configured.
+ * This function is also used by the rte_pktmbuf_pool_create to get the best
+ * mempool ops name.
+ *
+ * @return
+ *   returns preferred mbuf pool ops name
+ */
+const char *
+rte_mbuf_best_mempool_ops(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_MBUF_POOL_OPS_H_ */
diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map
index 6e2ea84..db87819 100644
--- a/lib/librte_mbuf/rte_mbuf_version.map
+++ b/lib/librte_mbuf/rte_mbuf_version.map
@@ -35,3 +35,14 @@  DPDK_16.11 {
 	rte_get_tx_ol_flag_list;
 
 } DPDK_2.1;
+
+EXPERIMENTAL {
+	global:
+
+	rte_mbuf_best_mempool_ops;
+	rte_mbuf_platform_mempool_ops;
+	rte_mbuf_set_platform_mempool_ops;
+	rte_mbuf_set_user_mempool_ops;
+	rte_mbuf_user_mempool_ops;
+
+} DPDK_16.11;