From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hemant Agrawal Subject: [PATCH 1/2] mbuf: update default Mempool ops with HW active pool Date: Fri, 15 Dec 2017 15:54:42 +0530 Message-ID: <1513333483-4372-2-git-send-email-hemant.agrawal@nxp.com> References: <1499170968-23016-1-git-send-email-hemant.agrawal@nxp.com> <1513333483-4372-1-git-send-email-hemant.agrawal@nxp.com> Mime-Version: 1.0 Content-Type: text/plain Cc: To: , Return-path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0054.outbound.protection.outlook.com [104.47.36.54]) by dpdk.org (Postfix) with ESMTP id 0B5BE1B01C for ; Fri, 15 Dec 2017 11:25:46 +0100 (CET) In-Reply-To: <1513333483-4372-1-git-send-email-hemant.agrawal@nxp.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" With this patch the specific HW mempool are no longer required to be specified in the config file at compile. A default active hw mempool can be detected dynamically and published to default mempools ops config at run time. Only one type of HW mempool can be active default. Signed-off-by: Hemant Agrawal --- lib/librte_mbuf/rte_mbuf.c | 33 ++++++++++++++++++++++++++++++++- lib/librte_mbuf/rte_mbuf.h | 13 +++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 7543662..e074afa 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -148,6 +148,37 @@ rte_pktmbuf_init(struct rte_mempool *mp, m->next = NULL; } +static const char *active_mbuf_pool_ops_name; + +int +rte_pktmbuf_reg_active_mempool_ops(const char *ops_name) +{ + if (active_mbuf_pool_ops_name == NULL) { + active_mbuf_pool_ops_name = ops_name; + return 0; + } + RTE_LOG(ERR, MBUF, + "%s is already registered as active pktmbuf pool ops\n", + active_mbuf_pool_ops_name); + return -EACCES; +} + +/* Return mbuf pool ops name */ +static const char * +rte_pktmbuf_active_mempool_ops(void) +{ + const char *default_ops = rte_eal_mbuf_default_mempool_ops(); + + /* If mbuf default ops is same as compile time default + * Just to be sure that no one has updated it by other means. + */ + if ((strcmp(default_ops, RTE_MBUF_DEFAULT_MEMPOOL_OPS) == 0) && + (active_mbuf_pool_ops_name != NULL)) + return active_mbuf_pool_ops_name; + else + return default_ops; +} + /* helper to create a mbuf pool */ struct rte_mempool * rte_pktmbuf_pool_create(const char *name, unsigned n, @@ -176,7 +207,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, if (mp == NULL) return NULL; - mp_ops_name = rte_eal_mbuf_default_mempool_ops(); + mp_ops_name = rte_pktmbuf_active_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.h b/lib/librte_mbuf/rte_mbuf.h index ce8a05d..3140a0b 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1081,6 +1081,19 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, int socket_id); /** + * Register the active HW pkt mbuf pool + * + * Register the active pktmbuf HW pool to overwrite the default pool + * + * @param pool ops name + * @return + * - 0: Success + * - -EACCES: Active mempool is already registered. + */ +int +rte_pktmbuf_reg_active_mempool_ops(const char *ops_name); + +/** * Get the data room size of mbufs stored in a pktmbuf_pool * * The data room size is the amount of data that can be stored in a -- 2.7.4