From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7B83C76188 for ; Tue, 23 Jul 2019 05:39:04 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 4BE1B2229A for ; Tue, 23 Jul 2019 05:39:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="YxFbG7mk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BE1B2229A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=marvell.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 91BC21BF97; Tue, 23 Jul 2019 07:38:52 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 7EB5E1BF97 for ; Tue, 23 Jul 2019 07:38:51 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x6N5ZZmk011959; Mon, 22 Jul 2019 22:38:50 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0818; bh=euKoEAbOGOWQfl1djKkBrUtXmOAoDdNRqzcjr1o3/v4=; b=YxFbG7mksgMPeUg1LCcU7lo28iW1os/bHBw6hLgshWFm1BgfcEUgwlLabvC9pWOHUKy0 9GApTgSfRhkWqB7NImCaIxGQpnQMcDzMVo4PCtLNThwiS+ayJ038cz8doRUqP91YUDu4 9wpgpIANDdoG2caJxNbDV3hf8cB+WhwsDvLrmgQUKWCv9UbmEWc0boe/y+/qOk2aZyXO ZD6MOBNUD/2klBA/riiiBfsQWc4XDZD3ya9JkgBpWPEGZjtPK1D/VLz1J/UTprsj/+9P 5CoEeLI/Mf4x75sC+9wAu5vx0s7hLF5I/mRkQsDDIjPAAkS4NKCaBAuQ55li/LOFM4gh Kw== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 2tv2fj9gvk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 22 Jul 2019 22:38:50 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 22 Jul 2019 22:38:48 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 22 Jul 2019 22:38:48 -0700 Received: from hyd1vattunuru-dt.caveonetworks.com (unknown [10.29.52.72]) by maili.marvell.com (Postfix) with ESMTP id 7229D3F7040; Mon, 22 Jul 2019 22:38:45 -0700 (PDT) From: To: CC: , , , , , , , Vamsi Attunuru Date: Tue, 23 Jul 2019 11:08:19 +0530 Message-ID: <20190723053821.30227-4-vattunuru@marvell.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20190723053821.30227-1-vattunuru@marvell.com> References: <20190717090408.13717-1-vattunuru@marvell.com> <20190723053821.30227-1-vattunuru@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:5.22.84,1.0.8 definitions=2019-07-23_03:2019-07-23,2019-07-23 signatures=0 Subject: [dpdk-dev] [PATCH v8 3/5] kni: add app specific mempool create & free routine 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" From: Vamsi Attunuru When KNI operates in IOVA = VA mode, it requires mbuf memory to be physically contiguous to ensure KNI kernel module could translate IOVA addresses properly. Patch adds a KNI specific mempool create routine to populate the KNI packet mbuf pool with memory objects that are being on a page. KNI applications need to use this mempool create & free routines so that mbuf related requirements in IOVA = VA mode are handled inside those routines based on the enabled mode. Updated the release notes with these new routine details. Signed-off-by: Vamsi Attunuru Signed-off-by: Kiran Kumar K --- doc/guides/rel_notes/release_19_08.rst | 6 ++++ examples/kni/main.c | 6 +++- lib/librte_kni/Makefile | 1 + lib/librte_kni/meson.build | 1 + lib/librte_kni/rte_kni.c | 59 ++++++++++++++++++++++++++++++++++ lib/librte_kni/rte_kni.h | 49 ++++++++++++++++++++++++++++ lib/librte_kni/rte_kni_version.map | 2 ++ 7 files changed, 123 insertions(+), 1 deletion(-) diff --git a/doc/guides/rel_notes/release_19_08.rst b/doc/guides/rel_notes/release_19_08.rst index 0a3f840..bd01e99 100644 --- a/doc/guides/rel_notes/release_19_08.rst +++ b/doc/guides/rel_notes/release_19_08.rst @@ -281,6 +281,12 @@ API Changes offload flag from the library. The application must set this flag if it is supported by the platform and application wishes to use it. +* kni: ``rte_kni_pktmbuf_pool_create`` ``rte_kni_pktmbuf_pool_free`` functions + were introduced for KNI applications for creating & freeing packet pool. + Since IOVA=VA mode was added in KNI, packet pool's mbuf memory should be + physically contiguous for the KNI kernel module to work in IOVA=VA mode, + this requirment was taken care in the kni packet pool creation fucntions. + ABI Changes ----------- diff --git a/examples/kni/main.c b/examples/kni/main.c index 4710d71..3b9c067 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -975,7 +975,7 @@ main(int argc, char** argv) rte_exit(EXIT_FAILURE, "Could not parse input parameters\n"); /* Create the mbuf pool */ - pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, + pktmbuf_pool = rte_kni_pktmbuf_pool_create("mbuf_pool", NB_MBUF, MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id()); if (pktmbuf_pool == NULL) { rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n"); @@ -1043,6 +1043,10 @@ main(int argc, char** argv) continue; kni_free_kni(port); } + + if (pktmbuf_pool) + rte_kni_pktmbuf_pool_free(pktmbuf_pool); + for (i = 0; i < RTE_MAX_ETHPORTS; i++) if (kni_port_params_array[i]) { rte_free(kni_port_params_array[i]); diff --git a/lib/librte_kni/Makefile b/lib/librte_kni/Makefile index ab15d10..5e3dd01 100644 --- a/lib/librte_kni/Makefile +++ b/lib/librte_kni/Makefile @@ -6,6 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk # library name LIB = librte_kni.a +CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing CFLAGS += -I$(RTE_SDK)/drivers/bus/pci LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev diff --git a/lib/librte_kni/meson.build b/lib/librte_kni/meson.build index fd46f87..e357445 100644 --- a/lib/librte_kni/meson.build +++ b/lib/librte_kni/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +allow_experimental_apis = true if not is_linux or not dpdk_conf.get('RTE_ARCH_64') build = false reason = 'only supported on 64-bit linux' diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index ae17075..897a5bb 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -687,6 +687,65 @@ kni_allocate_mbufs(struct rte_kni *kni) } } +struct rte_mempool * +rte_kni_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) +{ + struct rte_pktmbuf_pool_private mbp_priv; + const char *mp_ops_name; + struct rte_mempool *mp; + unsigned int elt_size; + int ret; + + if (RTE_ALIGN(priv_size, RTE_MBUF_PRIV_ALIGN) != priv_size) { + RTE_LOG(ERR, MBUF, "mbuf priv_size=%u is not aligned\n", + priv_size); + rte_errno = EINVAL; + return NULL; + } + elt_size = sizeof(struct rte_mbuf) + (unsigned int)priv_size + + (unsigned int)data_room_size; + mbp_priv.mbuf_data_room_size = data_room_size; + 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); + if (mp == NULL) + return 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"); + rte_mempool_free(mp); + rte_errno = -ret; + return NULL; + } + rte_pktmbuf_pool_init(mp, &mbp_priv); + + if (rte_eal_iova_mode() == RTE_IOVA_VA) + ret = rte_mempool_populate_from_pg_sz_chunks(mp); + else + ret = rte_mempool_populate_default(mp); + + if (ret < 0) { + rte_mempool_free(mp); + rte_errno = -ret; + return NULL; + } + + rte_mempool_obj_iter(mp, rte_pktmbuf_init, NULL); + + return mp; +} + +void +rte_kni_pktmbuf_pool_free(struct rte_mempool *mp) +{ + rte_mempool_free(mp); +} + struct rte_kni * rte_kni_get(const char *name) { diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 5699a64..7f11927 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -184,6 +185,54 @@ unsigned rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned num); /** + * Create a kni packet mbuf pool. + * + * This function creates and initializes a packet mbuf pool for KNI applications + * It calls the required mempool populate routine based on the IOVA mode. + * + * @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. + * @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 + */ +__rte_experimental +struct rte_mempool *rte_kni_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); + +/** + * Free the given packet mempool. + * + * @param mp + * The mempool pointer. + */ +__rte_experimental +void rte_kni_pktmbuf_pool_free(struct rte_mempool *mp); + +/** * Get the KNI context of its name. * * @param name diff --git a/lib/librte_kni/rte_kni_version.map b/lib/librte_kni/rte_kni_version.map index c877dc6..aba9728 100644 --- a/lib/librte_kni/rte_kni_version.map +++ b/lib/librte_kni/rte_kni_version.map @@ -20,4 +20,6 @@ EXPERIMENTAL { global: rte_kni_update_link; + rte_kni_pktmbuf_pool_create; + rte_kni_pktmbuf_pool_free; }; -- 2.8.4