From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 036FAA05D3 for ; Mon, 25 Mar 2019 07:08:44 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8CDEC4CC5; Mon, 25 Mar 2019 07:08:36 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 24FF14CA0 for ; Mon, 25 Mar 2019 07:08:31 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Mar 2019 23:08:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,256,1549958400"; d="scan'208";a="129891763" Received: from yexl-server.sh.intel.com ([10.67.110.206]) by orsmga006.jf.intel.com with ESMTP; 24 Mar 2019 23:08:28 -0700 From: Xiaolong Ye To: dev@dpdk.org, David Marchand Cc: Qi Zhang , Karlsson Magnus , Topel Bjorn , Maxime Coquelin , Stephen Hemminger , Ferruh Yigit , Luca Boccassi , Bruce Richardson , Ananyev Konstantin , Xiaolong Ye Date: Mon, 25 Mar 2019 14:03:57 +0800 Message-Id: <20190325060400.40291-3-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325060400.40291-1-xiaolong.ye@intel.com> References: <20190301080947.91086-1-xiaolong.ye@intel.com> <20190325060400.40291-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH v5 2/5] lib/mbuf: introduce helper to create mempool with flags X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190325060357.sCDFeA61TjVnvJp9vGynj1G1zLQFuj1-AHfse3IfuzE@z> This allows applications to create mbuf mempool with specific flags such as MEMPOOL_F_NO_SPREAD if they want fixed size memory objects. Signed-off-by: Qi Zhang Signed-off-by: Xiaolong Ye --- lib/librte_mbuf/rte_mbuf.c | 29 ++++++++++++++---- lib/librte_mbuf/rte_mbuf.h | 45 ++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf_version.map | 1 + 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 21f6f7404..c1db9e298 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -106,11 +106,10 @@ rte_pktmbuf_init(struct rte_mempool *mp, m->next = NULL; } -/* Helper to create a mbuf pool with given mempool ops name*/ -struct rte_mempool * -rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n, +static struct rte_mempool * +rte_pktmbuf_pool_create_by_ops_with_flags(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) + unsigned int flags, int socket_id, const char *ops_name) { struct rte_mempool *mp; struct rte_pktmbuf_pool_private mbp_priv; @@ -130,7 +129,7 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n, mbp_priv.mbuf_priv_size = priv_size; mp = rte_mempool_create_empty(name, n, elt_size, cache_size, - sizeof(struct rte_pktmbuf_pool_private), socket_id, 0); + sizeof(struct rte_pktmbuf_pool_private), socket_id, flags); if (mp == NULL) return NULL; @@ -157,6 +156,16 @@ rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n, return mp; } +/* Helper to create a mbuf pool with given mempool ops name*/ +struct rte_mempool * +rte_pktmbuf_pool_create_by_ops(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) +{ + return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size, + priv_size, data_room_size, 0, socket_id, ops_name); +} + /* helper to create a mbuf pool */ struct rte_mempool * rte_pktmbuf_pool_create(const char *name, unsigned int n, @@ -167,6 +176,16 @@ rte_pktmbuf_pool_create(const char *name, unsigned int n, data_room_size, socket_id, NULL); } +/* helper to create a mbuf pool with flags (e.g. NO_SPREAD) */ +struct rte_mempool * __rte_experimental +rte_pktmbuf_pool_create_with_flags(const char *name, unsigned int n, + unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, + unsigned int flags, int socket_id) +{ + return rte_pktmbuf_pool_create_by_ops_with_flags(name, n, cache_size, + priv_size, data_room_size, flags, 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 d961ccaf6..105ead6de 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1266,6 +1266,51 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id); +/** + * Create a mbuf pool with flags. + * + * This function creates and initializes a packet mbuf pool. It is + * a wrapper to rte_mempool functions. + * + * @warning + * @b EXPERIMENTAL: This API may change without prior notice. + * + * @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 flags + * Flags controlling the behavior of the mempool. See + * rte_mempool_create() for details. + * @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. + * @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_experimental +rte_pktmbuf_pool_create_with_flags(const char *name, unsigned int n, + unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, + unsigned int flags, int socket_id); + /** * Create a mbuf pool with a given mempool ops name * diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index 2662a37bf..2579538e0 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -50,4 +50,5 @@ EXPERIMENTAL { global: rte_mbuf_check; + rte_pktmbuf_pool_create_with_flags; } DPDK_18.08; -- 2.17.1