From patchwork Wed Sep 13 09:00:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112418 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp716287edi; Wed, 13 Sep 2017 02:02:11 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBy+JWoL78Lhm812Fjbn4dwuyPIFvXZsGvzzoozszTJYlNK/s8tStdS82R6svrxvOs6uD5h X-Received: by 10.237.33.199 with SMTP id m7mr26513301qtc.328.1505293331296; Wed, 13 Sep 2017 02:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505293331; cv=none; d=google.com; s=arc-20160816; b=ETGdCFufT8AdmDyYP1qlWljXNVXC/D2cgx3Yitxy+2eEdVAEw6Tw2dut6JeJVXt5NZ 3ipZoumhs8DE5ALxI0sHwYMj3EBPyChxAA1C2MDijI1uotOrLWNtcZfg/5/5rERZFFPd usC61rU4ilpgQuUh1iwlHCKHWOKvXp1OmmidV9HCx68jVhcXOR1kTrd07Voo5Db8wmBo 8YikwLAjuZZkayIrsxwAYO1Wxs/mIFeoRl3d9cl3h3sTqgYauJZ+ceyOTzGRYUgBwBSk nmENITCm8sweks7rAZijlXZtxGisSJkkdoYnkNzvS20BWY4VEwhqphfTy/ly7cgxAdd/ Yc7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=J2r00AKCYgb10JrIahKd4FRm7+e9spBVV3Laszw1PY8=; b=0i46yKjWxQ0sdAmVT1qk4rrTBLVtK+gysvqBNyMprfizIgOflsna+/CHrB19MwtjdC ujrz3i5CI73TJWnO+k6fLHE2hnJH+iVcUgDHwBXQFhlRSHYITBt+Hh6rm4UxBsY2lOxz 2K4zClakSt8IRpnT3Luf28vFVFMBQivcQf/mpYuN9WI4N04XyV6wnL+kG1IhYaxfpCVF XmrLAeV1TO/wKeJ/WPtOYK7Za6RqtA8b6ymGV6FJmEoO48cwIXLnlaxZ/0bXVLK3btE2 m/EvmB606CyQWDjxzU1ds5I7AdZkBGXmtK/MhmxIUAnf6uL8b+0edVGCYPALlA7wnWvl opaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m9si14000471qkl.317.2017.09.13.02.02.11; Wed, 13 Sep 2017 02:02:11 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id DBB3C60EC3; Wed, 13 Sep 2017 09:02:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 3DFDB60C1E; Wed, 13 Sep 2017 09:00:32 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A8682608B4; Wed, 13 Sep 2017 09:00:25 +0000 (UTC) Received: from forward101o.mail.yandex.net (forward101o.mail.yandex.net [37.140.190.181]) by lists.linaro.org (Postfix) with ESMTPS id 821A360B33 for ; Wed, 13 Sep 2017 09:00:23 +0000 (UTC) Received: from mxback2g.mail.yandex.net (mxback2g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:163]) by forward101o.mail.yandex.net (Yandex) with ESMTP id 1DBEE1343335 for ; Wed, 13 Sep 2017 12:00:22 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback2g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id l0U4l9xBw2-0LVW7oGl; Wed, 13 Sep 2017 12:00:22 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id hb9UV9p28a-0K7qTeNw; Wed, 13 Sep 2017 12:00:20 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 13 Sep 2017 12:00:15 +0300 Message-Id: <1505293215-15165-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505293215-15165-1-git-send-email-odpbot@yandex.ru> References: <1505293215-15165-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 169 Subject: [lng-odp] [PATCH CLOUD-DEV v3 2/2] linux-dpdk:introduce buffer submodule X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Balakrishna Garapati Signed-off-by: Balakrishna Garapati --- /** Email created from pull request 169 (GBalakrishna:dpdk_buffer_submodule) ** https://github.com/Linaro/odp/pull/169 ** Patch: https://github.com/Linaro/odp/pull/169.patch ** Base sha: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: dff16717c6e54c01ff51764e12d56fe938e87b86 **/ platform/linux-dpdk/Makefile.am | 3 + platform/linux-dpdk/buffer/dpdk.c | 128 +++++++++++++++++++++++++++++++++----- platform/linux-dpdk/pool/dpdk.c | 62 ------------------ 3 files changed, 114 insertions(+), 79 deletions(-) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index a006d0da8..bf6485adf 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -168,6 +168,7 @@ odpdrvplatinclude_HEADERS = \ noinst_HEADERS = \ + ${top_srcdir}/platform/linux-generic/include/odp_buffer_subsystem.h \ ${top_srcdir}/platform/linux-generic/include/_fdserver_internal.h \ ${top_srcdir}/platform/linux-generic/include/_ishm_internal.h \ ${top_srcdir}/platform/linux-generic/include/_ishmphy_internal.h \ @@ -252,6 +253,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/odp_rwlock.c \ ../linux-generic/odp_rwlock_recursive.c \ ../linux-generic/pool/subsystem.c \ + ../linux-generic/buffer/subsystem.c \ ../linux-generic/odp_schedule_if.c \ ../linux-generic/schedule/generic.c \ ../linux-generic/schedule/iquery.c \ @@ -300,6 +302,7 @@ __LIB__libodp_dpdk_la_SOURCES += arch/x86/cpu_flags.c \ endif pool/dpdk.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE +buffer/dpdk.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE if ODP_SCHEDULE_SCALABLE ../linux-generic/schedule/scalable.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE else diff --git a/platform/linux-dpdk/buffer/dpdk.c b/platform/linux-dpdk/buffer/dpdk.c index 3c71fef84..f39ab31f1 100644 --- a/platform/linux-dpdk/buffer/dpdk.c +++ b/platform/linux-dpdk/buffer/dpdk.c @@ -7,30 +7,96 @@ #include #include #include +#include #include +#include #include #include #include -odp_buffer_t odp_buffer_from_event(odp_event_t ev) +static odp_buffer_t buffer_alloc(odp_pool_t pool_hdl) +{ + odp_buffer_t buffer; + pool_entry_cp_t *pool_cp; + pool_entry_dp_t *pool_dp; + + pool_cp = odp_pool_to_entry_cp(pool_hdl); + pool_dp = odp_pool_to_entry_dp(pool_hdl); + + ODP_ASSERT(pool_cp->params.type != ODP_POOL_BUFFER || + pool_cp->params.type != ODP_POOL_TIMEOUT); + + buffer = (odp_buffer_t)rte_ctrlmbuf_alloc(pool_dp->rte_mempool); + + if ((struct rte_mbuf *)buffer == NULL) { + rte_errno = ENOMEM; + return ODP_BUFFER_INVALID; + } + + buf_hdl_to_hdr(buffer)->next = NULL; + return buffer; +} + +static odp_buffer_t dpdk_buffer_alloc(odp_pool_t pool_hdl) +{ + ODP_ASSERT(ODP_POOL_INVALID != pool_hdl); + + return buffer_alloc(pool_hdl); +} + +static int dpdk_buffer_alloc_multi(odp_pool_t pool_hdl, + odp_buffer_t buf[], + int num) +{ + int i; + + ODP_ASSERT(ODP_POOL_INVALID != pool_hdl); + + for (i = 0; i < num; i++) { + buf[i] = buffer_alloc(pool_hdl); + if (buf[i] == ODP_BUFFER_INVALID) + return rte_errno == ENOMEM ? i : -EINVAL; + } + return i; +} + +static void dpdk_buffer_free(odp_buffer_t buf) +{ + struct rte_mbuf *mbuf = (struct rte_mbuf *)buf; + + rte_ctrlmbuf_free(mbuf); +} + +static void dpdk_buffer_free_multi(const odp_buffer_t buf[], int num) +{ + int i; + + for (i = 0; i < num; i++) { + struct rte_mbuf *mbuf = (struct rte_mbuf *)buf[i]; + + rte_ctrlmbuf_free(mbuf); + } +} + +static odp_buffer_t dpdk_buffer_from_event(odp_event_t ev) { return (odp_buffer_t)ev; } -odp_event_t odp_buffer_to_event(odp_buffer_t buf) +static odp_event_t dpdk_buffer_to_event(odp_buffer_t buf) { return (odp_event_t)buf; } -void *odp_buffer_addr(odp_buffer_t buf) +static void *dpdk_buffer_addr(odp_buffer_t buf) { odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf); return hdr->mb.buf_addr; } -uint32_t odp_buffer_size(odp_buffer_t buf) +static uint32_t dpdk_buffer_size(odp_buffer_t buf) { odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf); struct rte_mbuf *mbuf = (struct rte_mbuf *)hdr; @@ -52,7 +118,7 @@ void _odp_buffer_type_set(odp_buffer_t buf, int type) hdr->type = type; } -int odp_buffer_is_valid(odp_buffer_t buf) +static int dpdk_buffer_is_valid(odp_buffer_t buf) { /* We could call rte_mbuf_sanity_check, but that panics * and aborts the program */ @@ -71,43 +137,71 @@ int odp_buffer_snprint(char *str, uint32_t n, odp_buffer_t buf) hdr = buf_hdl_to_hdr(buf); - len += snprintf(&str[len], n-len, + len += snprintf(&str[len], n - len, "Buffer\n"); - len += snprintf(&str[len], n-len, + len += snprintf(&str[len], n - len, " pool %p\n", hdr->mb.pool); - len += snprintf(&str[len], n-len, - " phy_addr %"PRIu64"\n", hdr->mb.buf_physaddr); - len += snprintf(&str[len], n-len, + len += snprintf(&str[len], n - len, + " phy_addr %" PRIu64 "\n", hdr->mb.buf_physaddr); + len += snprintf(&str[len], n - len, " addr %p\n", hdr->mb.buf_addr); - len += snprintf(&str[len], n-len, + len += snprintf(&str[len], n - len, " size %u\n", hdr->mb.buf_len); - len += snprintf(&str[len], n-len, + len += snprintf(&str[len], n - len, " ref_count %i\n", rte_mbuf_refcnt_read(&hdr->mb)); - len += snprintf(&str[len], n-len, + len += snprintf(&str[len], n - len, " odp type %i\n", hdr->type); return len; } -void odp_buffer_print(odp_buffer_t buf) +static void dpdk_buffer_print(odp_buffer_t buf) { int max_len = 512; char str[max_len]; int len; - len = odp_buffer_snprint(str, max_len-1, buf); + len = odp_buffer_snprint(str, max_len - 1, buf); str[len] = 0; ODP_PRINT("\n%s\n", str); } -uint64_t odp_buffer_to_u64(odp_buffer_t hdl) +static uint64_t dpdk_buffer_to_u64(odp_buffer_t hdl) { return _odp_pri(hdl); } -odp_pool_t odp_buffer_pool(odp_buffer_t buf) +static odp_pool_t dpdk_buffer_pool(odp_buffer_t buf) { return buf_hdl_to_hdr(buf)->pool_hdl; } + +odp_buffer_module_t dpdk_buffer = { + .base = { + .name = "dpdk_buffer", + .init_local = NULL, + .term_local = NULL, + .init_global = NULL, + .term_global = NULL, + }, + .buffer_alloc = dpdk_buffer_alloc, + .buffer_alloc_multi = dpdk_buffer_alloc_multi, + .buffer_free = dpdk_buffer_free, + .buffer_free_multi = dpdk_buffer_free_multi, + .buffer_from_event = dpdk_buffer_from_event, + .buffer_to_event = dpdk_buffer_to_event, + .buffer_addr = dpdk_buffer_addr, + .buffer_size = dpdk_buffer_size, + .buffer_is_valid = dpdk_buffer_is_valid, + .buffer_print = dpdk_buffer_print, + .buffer_to_u64 = dpdk_buffer_to_u64, + .buffer_pool = dpdk_buffer_pool, +}; + +ODP_MODULE_CONSTRUCTOR(dpdk_buffer) +{ + odp_module_constructor(&dpdk_buffer); + odp_subsystem_register_module(buffer, &dpdk_buffer); +} diff --git a/platform/linux-dpdk/pool/dpdk.c b/platform/linux-dpdk/pool/dpdk.c index 499bea127..6acc4e901 100644 --- a/platform/linux-dpdk/pool/dpdk.c +++ b/platform/linux-dpdk/pool/dpdk.c @@ -549,68 +549,6 @@ static odp_pool_t dpdk_pool_lookup(const char *name) return pool_hdl; } -static odp_buffer_t buffer_alloc(odp_pool_t pool_hdl) -{ - odp_buffer_t buffer; - pool_entry_cp_t *pool_cp; - pool_entry_dp_t *pool_dp; - - pool_cp = odp_pool_to_entry_cp(pool_hdl); - pool_dp = odp_pool_to_entry_dp(pool_hdl); - - ODP_ASSERT(pool_cp->params.type != ODP_POOL_BUFFER && - pool_cp->params.type != ODP_POOL_TIMEOUT); - - buffer = (odp_buffer_t)rte_ctrlmbuf_alloc(pool_dp->rte_mempool); - - if ((struct rte_mbuf *)buffer == NULL) { - rte_errno = ENOMEM; - return ODP_BUFFER_INVALID; - } - - buf_hdl_to_hdr(buffer)->next = NULL; - return buffer; -} - -odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl) -{ - ODP_ASSERT(ODP_POOL_INVALID != pool_hdl); - - return buffer_alloc(pool_hdl); -} - -int odp_buffer_alloc_multi(odp_pool_t pool_hdl, odp_buffer_t buf[], int num) -{ - int i; - - ODP_ASSERT(ODP_POOL_INVALID != pool_hdl); - - for (i = 0; i < num; i++) { - buf[i] = buffer_alloc(pool_hdl); - if (buf[i] == ODP_BUFFER_INVALID) - return rte_errno == ENOMEM ? i : -EINVAL; - } - return i; -} - -void odp_buffer_free(odp_buffer_t buf) -{ - struct rte_mbuf *mbuf = (struct rte_mbuf *)buf; - - rte_ctrlmbuf_free(mbuf); -} - -void odp_buffer_free_multi(const odp_buffer_t buf[], int num) -{ - int i; - - for (i = 0; i < num; i++) { - struct rte_mbuf *mbuf = (struct rte_mbuf *)buf[i]; - - rte_ctrlmbuf_free(mbuf); - } -} - static void dpdk_pool_print(odp_pool_t pool_hdl) { pool_entry_dp_t *pool_dp = odp_pool_to_entry_dp(pool_hdl);