From patchwork Fri Sep 15 10:00:13 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: 112694 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp425294qgf; Fri, 15 Sep 2017 03:03:04 -0700 (PDT) X-Google-Smtp-Source: AOwi7QC478/rGNw8alBR/7o+9JNkrrRO8WimqkHRb5Qze34byIm7aC4tMMDk4W5Kt+hNWzPseeJZ X-Received: by 10.55.181.129 with SMTP id e123mr7094018qkf.128.1505469783936; Fri, 15 Sep 2017 03:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505469783; cv=none; d=google.com; s=arc-20160816; b=b2dFGbcbApdLziqi4eiBzHobKB7vgGSiHY8ok4Dvmz70IiaWvXyJFXdLVy3BWaxFoV 28DNxDI3zb1ZZkqloopOI8hus/2sKfWVt1E1mrKsxx6LAzfgyKZTKha5Rug2qxFCOVk5 FbVhlRa/K7fTCwyeM8yP6DZb1516jDc4HiTt2Ce2Jv5AHW2u9AUgjJJKHxT4NvuMafLn vNn3q224OyiF5A/gSDKpV/MSzFIg7kWEIBR3E0U7qTV2c7DJ5K0eFAFurKFtJXbiXZaW A2lrEFabKm0/JKQBcyMP879hTFq/iIuGGbkfjeEg/xGzS3WiTQ4gnTFbLCzhQi4E9NEj nrIw== 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=XU8cDP5ORH+59u8teqzk51FtLKC3pxrOamWb6OEYP1s=; b=mgWiwvrBxpwepU30peO0n6tj9Anxwvwb4WsaRfqPuvP5QBa0EhMbvbZ4sLpAAzimLo 8o1mbiIexANCS4IgtVeZdGs3EZG48DWRoKsYL3cft3XKKRh/1vcerIa+Efxgp/F3zjF5 oNNhNgM/x0ds5/YogzdJ9holct5od8VI4J25AnqUV5CfgfiUawRkWqWUAUO/EBYROCXC bo7+gyNND/Gewfebqk1mWEizFj+FK8trS2l/lUpDG/it2P4kvYG7mE4uqSakMQK/6gwj 22d3KiedhLstgQZFeKFp2aTd+9IjrxO2N47qxR0aS9ti9CC1mXUCJT/kkkchuwMA4bxy OnEw== 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 l37si573594qtl.0.2017.09.15.03.03.03; Fri, 15 Sep 2017 03:03:03 -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 960A160B3F; Fri, 15 Sep 2017 10:03:03 +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 5B1AB60A38; Fri, 15 Sep 2017 10:00:44 +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 11BFD60999; Fri, 15 Sep 2017 10:00:38 +0000 (UTC) Received: from forward102p.mail.yandex.net (forward102p.mail.yandex.net [77.88.28.102]) by lists.linaro.org (Postfix) with ESMTPS id 9531860999 for ; Fri, 15 Sep 2017 10:00:31 +0000 (UTC) Received: from mxback19j.mail.yandex.net (mxback19j.mail.yandex.net [IPv6:2a02:6b8:0:1619::95]) by forward102p.mail.yandex.net (Yandex) with ESMTP id 8D5904302726 for ; Fri, 15 Sep 2017 13:00:24 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback19j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id mfYV27l2fX-0O5KGu8b; Fri, 15 Sep 2017 13:00:24 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id azwhva3VGv-0NMmq9We; Fri, 15 Sep 2017 13:00:23 +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: Fri, 15 Sep 2017 13:00:13 +0300 Message-Id: <1505469613-12867-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505469613-12867-1-git-send-email-odpbot@yandex.ru> References: <1505469613-12867-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 169 Subject: [lng-odp] [PATCH CLOUD-DEV v4 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: 82e735abd80bf47929a654c98409f3e82891bae0 **/ platform/linux-dpdk/Makefile.am | 3 + platform/linux-dpdk/buffer/dpdk.c | 128 +++++++++++++++++++++++++++++++++----- platform/linux-dpdk/odp_packet.c | 2 +- platform/linux-dpdk/pool/dpdk.c | 62 ------------------ 4 files changed, 115 insertions(+), 80 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..346549ec0 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_dp_t *pool_dp; + + ODP_ASSERT(odp_pool_to_entry_cp(pool_hdl)->params.type == + ODP_POOL_BUFFER || + odp_pool_to_entry_cp(pool_hdl)->params.type == + ODP_POOL_TIMEOUT); + + pool_dp = odp_pool_to_entry_dp(pool_hdl); + + 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/odp_packet.c b/platform/linux-dpdk/odp_packet.c index 23aec95ec..b2860a77b 100644 --- a/platform/linux-dpdk/odp_packet.c +++ b/platform/linux-dpdk/odp_packet.c @@ -90,7 +90,7 @@ static odp_packet_t packet_alloc(odp_pool_t pool_hdl, uint32_t len) struct rte_mbuf *mbuf; ODP_ASSERT(odp_pool_to_entry_cp(pool_hdl)->params.type - != ODP_POOL_PACKET); + == ODP_POOL_PACKET); pool_dp = odp_pool_to_entry_dp(pool_hdl); 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);