diff mbox series

[v2,4/5] mbuf: pktmbuf pool create helper for specific mempool ops

Message ID 1515996674-26338-5-git-send-email-hemant.agrawal@nxp.com
State Superseded
Headers show
Series Dynamic HW Mempool Detection Support | expand

Commit Message

Hemant Agrawal Jan. 15, 2018, 6:11 a.m. UTC
Introduce a new helper for pktmbuf pool, which will allow
the application to optionally specify the mempool ops name
as well.

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

---
 lib/librte_mbuf/rte_mbuf.c           | 23 ++++++++++++++------
 lib/librte_mbuf/rte_mbuf.h           | 42 ++++++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_version.map |  1 +
 3 files changed, 60 insertions(+), 6 deletions(-)

-- 
2.7.4

Comments

Jerin Jacob Jan. 15, 2018, 12:31 p.m. UTC | #1
-----Original Message-----
> Date: Mon, 15 Jan 2018 11:41:13 +0530

> From: Hemant Agrawal <hemant.agrawal@nxp.com>

> To: dev@dpdk.org

> CC: jerin.jacob@caviumnetworks.com, olivier.matz@6wind.com,

>  santosh.shukla@caviumnetworks.com

> Subject: [PATCH v2 4/5] mbuf: pktmbuf pool create helper for specific

>  mempool ops

> X-Mailer: git-send-email 2.7.4

> 

> Introduce a new helper for pktmbuf pool, which will allow

> the application to optionally specify the mempool ops name

> as well.

> 

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

> ---

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

>  lib/librte_mbuf/rte_mbuf.h           | 42 ++++++++++++++++++++++++++++++++++++

>  lib/librte_mbuf/rte_mbuf_version.map |  1 +

>  3 files changed, 60 insertions(+), 6 deletions(-)

> 

> diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c

> index fd3b6f5..482676c 100644

> --- a/lib/librte_mbuf/rte_mbuf.c

> +++ b/lib/librte_mbuf/rte_mbuf.c

> @@ -186,15 +186,15 @@ rte_mbuf_best_mempool_ops(void)

>  	return RTE_MBUF_DEFAULT_MEMPOOL_OPS;

>  }

>  

> -/* helper to create a mbuf pool */

> +/* helper to create a mbuf pool with given mempool ops*/

>  struct rte_mempool *

> -rte_pktmbuf_pool_create(const char *name, unsigned n,

> -	unsigned cache_size, uint16_t priv_size, uint16_t data_room_size,

> -	int socket_id)

> +rte_pktmbuf_pool_create_specific(const char *name, unsigned int n,


No strong opinion on name. I think, rte_pktmbuf_pool_create_by_op() may be 
a better name than rte_pktmbuf_pool_create_specific()

> +	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,

> +	int socket_id, const char *ops_name)
Hemant Agrawal Jan. 15, 2018, 2:32 p.m. UTC | #2
On 1/15/2018 6:01 PM, Jerin Jacob wrote:
>> Introduce a new helper for pktmbuf pool, which will allow

>> the application to optionally specify the mempool ops name

>> as well.

>>

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

>> ---

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

>>  lib/librte_mbuf/rte_mbuf.h           | 42 ++++++++++++++++++++++++++++++++++++

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

>>  3 files changed, 60 insertions(+), 6 deletions(-)

>>

<snip>...
>> +rte_pktmbuf_pool_create_specific(const char *name, unsigned int n,

>

> No strong opinion on name. I think, rte_pktmbuf_pool_create_by_op() may be

> a better name than rte_pktmbuf_pool_create_specific()


yes. looks better. I will change it in next rev.
diff mbox series

Patch

diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index fd3b6f5..482676c 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -186,15 +186,15 @@  rte_mbuf_best_mempool_ops(void)
 	return RTE_MBUF_DEFAULT_MEMPOOL_OPS;
 }
 
-/* helper to create a mbuf pool */
+/* helper to create a mbuf pool with given mempool ops*/
 struct rte_mempool *
-rte_pktmbuf_pool_create(const char *name, unsigned n,
-	unsigned cache_size, uint16_t priv_size, uint16_t data_room_size,
-	int socket_id)
+rte_pktmbuf_pool_create_specific(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	int socket_id, const char *ops_name)
 {
 	struct rte_mempool *mp;
 	struct rte_pktmbuf_pool_private mbp_priv;
-	const char *mp_ops_name;
+	const char *mp_ops_name = ops_name;
 	unsigned elt_size;
 	int ret;
 
@@ -214,7 +214,8 @@  rte_pktmbuf_pool_create(const char *name, unsigned n,
 	if (mp == NULL)
 		return NULL;
 
-	mp_ops_name = rte_mbuf_best_mempool_ops();
+	if (mp_ops_name == NULL)
+		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");
@@ -236,6 +237,16 @@  rte_pktmbuf_pool_create(const char *name, unsigned n,
 	return mp;
 }
 
+/* helper to create a mbuf pool */
+struct rte_mempool *
+rte_pktmbuf_pool_create(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	int socket_id)
+{
+	return rte_pktmbuf_pool_create_specific(name, n, cache_size, priv_size,
+			data_room_size, socket_id, NULL);
+}
+
 /* do some sanity checks on a mbuf: panic if it fails */
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index d26e8cd..f958e3c 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1081,6 +1081,48 @@  rte_pktmbuf_pool_create(const char *name, unsigned n,
 	int socket_id);
 
 /**
+ * Create a mbuf pool with specific mempool ops
+ *
+ * This function creates and initializes a packet mbuf pool. It is
+ * a wrapper to rte_mempool functions.
+ *
+ * @param name
+ *   The name of the mbuf pool.
+ * @param n
+ *   The number of elements in the mbuf pool. The optimum size (in terms
+ *   of memory usage) for a mempool is when n is a power of two minus one:
+ *   n = (2^q - 1).
+ * @param cache_size
+ *   Size of the per-core object cache. See rte_mempool_create() for
+ *   details.
+ * @param priv_size
+ *   Size of application private are between the rte_mbuf structure
+ *   and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN.
+ * @param data_room_size
+ *   Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
+ * @param socket_id
+ *   The socket identifier where the memory should be allocated. The
+ *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
+ *   reserved zone.
+ * @param ops_name
+ *   The mempool ops name to be used for this mempool instead of
+ *   default mempool. The value can be *NULL* to use default mempool.
+ * @return
+ *   The pointer to the new allocated mempool, on success. NULL on error
+ *   with rte_errno set appropriately. Possible rte_errno values include:
+ *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
+ *    - E_RTE_SECONDARY - function was called from a secondary process instance
+ *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
+ *    - ENOSPC - the maximum number of memzones has already been allocated
+ *    - EEXIST - a memzone with the same name already exists
+ *    - ENOMEM - no appropriate memory area found in which to create memzone
+ */
+struct rte_mempool *
+rte_pktmbuf_pool_create_specific(const char *name, unsigned int n,
+	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
+	int socket_id, const char *ops_name);
+
+/**
  * Register the platform supported pktmbuf HW pool
  *
  * @param pool ops name
diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map
index b8e258f..9b53502 100644
--- a/lib/librte_mbuf/rte_mbuf_version.map
+++ b/lib/librte_mbuf/rte_mbuf_version.map
@@ -41,5 +41,6 @@  DPDK_18.02 {
 
 	rte_mbuf_platform_mempool_ops;
 	rte_mbuf_register_platform_mempool_ops;
+	rte_pktmbuf_pool_create_specific;
 
 } DPDK_16.11;