From patchwork Fri Sep 8 12:00:07 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: 112062 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp207846qgf; Fri, 8 Sep 2017 05:03:11 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCNBzOmFXWNctcweKja7UPub2nwNnzYRNBpB3ObPnQv1zhAxUVeP6cEmgnlWAPwZzV9gNrh X-Received: by 10.200.36.78 with SMTP id d14mr3709540qtd.273.1504872190985; Fri, 08 Sep 2017 05:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504872190; cv=none; d=google.com; s=arc-20160816; b=lo/FHGuIqM/E5AZVqqSkdPo+zuInrBWFo+N9TUGZ09YO5sMYgIdJJv9rRqG/u2bUEi D3SAuebpDPDXM/BaBMra4UUFFM8LkqJikNOaIF5SJuvRk3lLxVudyqw2Wnt3a12IQfTF rLpXH5RnCCiXMA3sj7ulTqZVB3Dvxz/EmsAHrwxrtDylkOK/vFr5j+TkKBN/dyXsR/if KqpWI0JkRnoAUFdokWIiW0A57KWax0Wc77CpgdWw/3Km4hewVkxYVfjcWJsrqXXEcVRt RA1tAqvSziEu7pq/GIhA25LoVSd6rKvF1/O8f1UJMvWZAI5xBiM1DQclLIGwZP6kt+kI 6+xg== 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=mVEg0Wgb1GycSo9u/Hr7ltXvReyHNeX3306mnXDSt/I=; b=w1MUare9qCioaCN7N45DGqyvFQzAc9oTUd+Xet5jms6vMHCP4NXwJGTzHIQxaRcdTq a9A6EwoKwAzvzRBqcFimxcwp+cBn6ykNGY0ijtAtzNq5Gji+2GZPadgeGO4RfEeYuplA 3BtKdZqBOFlrr4fGTSpVeUJFHOPQ0LCRcfA3BrxHEGI5hmE0/gLMu9SZx5qHse+MI1pO 5bDWpzcSge7Nmg//b0UcgCZth68ce8J0CJlKjUU9u5QCDUmjcWndC1vggpSPk68dsL16 J/c832EEAuX/q6hQqj7hPC2Q7UkfxGMoGuYj0++wJYSnCoxDy+HuNFP7ADHl5rs/uz/v JIrA== 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 a23si1790068qtj.15.2017.09.08.05.02.59; Fri, 08 Sep 2017 05:03:10 -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 05D9E608A8; Fri, 8 Sep 2017 12:02:59 +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 CB6DD65BE0; Fri, 8 Sep 2017 12:02:18 +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 87AC2608E4; Fri, 8 Sep 2017 12:02:13 +0000 (UTC) Received: from forward101o.mail.yandex.net (forward101o.mail.yandex.net [37.140.190.181]) by lists.linaro.org (Postfix) with ESMTPS id 4802C65BDF for ; Fri, 8 Sep 2017 12:00:19 +0000 (UTC) Received: from mxback1j.mail.yandex.net (mxback1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10a]) by forward101o.mail.yandex.net (Yandex) with ESMTP id ECA4513443B7 for ; Fri, 8 Sep 2017 15:00:17 +0300 (MSK) Received: from smtp1o.mail.yandex.net (smtp1o.mail.yandex.net [2a02:6b8:0:1a2d::25]) by mxback1j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 7oizxyGAFn-0BhWKU4i; Fri, 08 Sep 2017 15:00:11 +0300 Received: by smtp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id FPRaqreMlB-0BMuR4ER; Fri, 08 Sep 2017 15:00:11 +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, 8 Sep 2017 15:00:07 +0300 Message-Id: <1504872007-322-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504872007-322-1-git-send-email-odpbot@yandex.ru> References: <1504872007-322-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 169 Subject: [lng-odp] [PATCH CLOUD-DEV v1 1/1] 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: 344fe21a06ef4273f34c4441edd0caef876517d9 ** Merge commit sha: 49983ec8b979704383292911ae92f4d186e069da **/ platform/linux-dpdk/Makefile.am | 5 +- platform/linux-dpdk/buffer/dpdk.c | 207 ++++++++++++++++++++++++++++++++++++++ platform/linux-dpdk/odp_buffer.c | 113 --------------------- platform/linux-dpdk/pool/dpdk.c | 62 ------------ 4 files changed, 211 insertions(+), 176 deletions(-) create mode 100644 platform/linux-dpdk/buffer/dpdk.c delete mode 100644 platform/linux-dpdk/odp_buffer.c diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 6e7f0b1dd..89818a737 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 \ @@ -225,7 +226,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/odp_atomic.c \ ../linux-generic/odp_barrier.c \ ../linux-generic/odp_bitmap.c \ - odp_buffer.c \ + buffer/dpdk.c \ ../linux-generic/odp_byteorder.c \ ../linux-generic/odp_classification.c \ ../linux-generic/odp_cpu.c \ @@ -251,6 +252,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.c \ ../linux-generic/odp_schedule_if.c \ ../linux-generic/odp_schedule_iquery.c \ @@ -295,6 +297,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 # Build modular framework into odp-linux library modularframeworkdir = $(top_srcdir)/frameworks/modular diff --git a/platform/linux-dpdk/buffer/dpdk.c b/platform/linux-dpdk/buffer/dpdk.c new file mode 100644 index 000000000..f39ab31f1 --- /dev/null +++ b/platform/linux-dpdk/buffer/dpdk.c @@ -0,0 +1,207 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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; +} + +static odp_event_t dpdk_buffer_to_event(odp_buffer_t buf) +{ + return (odp_event_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; +} + +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; + + return mbuf->buf_len; +} + +int _odp_buffer_type(odp_buffer_t buf) +{ + odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf); + + return hdr->type; +} + +void _odp_buffer_type_set(odp_buffer_t buf, int type) +{ + odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf); + + hdr->type = type; +} + +static int dpdk_buffer_is_valid(odp_buffer_t buf) +{ + /* We could call rte_mbuf_sanity_check, but that panics + * and aborts the program */ + return buf != ODP_BUFFER_INVALID; +} + +int odp_buffer_snprint(char *str, uint32_t n, odp_buffer_t buf) +{ + odp_buffer_hdr_t *hdr; + int len = 0; + + if (!odp_buffer_is_valid(buf)) { + ODP_PRINT("Buffer is not valid.\n"); + return len; + } + + hdr = buf_hdl_to_hdr(buf); + + len += snprintf(&str[len], n - len, + "Buffer\n"); + 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, + " addr %p\n", hdr->mb.buf_addr); + len += snprintf(&str[len], n - len, + " size %u\n", hdr->mb.buf_len); + len += snprintf(&str[len], n - len, + " ref_count %i\n", + rte_mbuf_refcnt_read(&hdr->mb)); + len += snprintf(&str[len], n - len, + " odp type %i\n", hdr->type); + + return len; +} + +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); + str[len] = 0; + + ODP_PRINT("\n%s\n", str); +} + +static uint64_t dpdk_buffer_to_u64(odp_buffer_t hdl) +{ + return _odp_pri(hdl); +} + +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_buffer.c b/platform/linux-dpdk/odp_buffer.c deleted file mode 100644 index 3c71fef84..000000000 --- a/platform/linux-dpdk/odp_buffer.c +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include -#include -#include - -#include -#include -#include - -odp_buffer_t odp_buffer_from_event(odp_event_t ev) -{ - return (odp_buffer_t)ev; -} - -odp_event_t odp_buffer_to_event(odp_buffer_t buf) -{ - return (odp_event_t)buf; -} - -void *odp_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) -{ - odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf); - struct rte_mbuf *mbuf = (struct rte_mbuf *)hdr; - - return mbuf->buf_len; -} - -int _odp_buffer_type(odp_buffer_t buf) -{ - odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf); - - return hdr->type; -} - -void _odp_buffer_type_set(odp_buffer_t buf, int type) -{ - odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf); - - hdr->type = type; -} - -int odp_buffer_is_valid(odp_buffer_t buf) -{ - /* We could call rte_mbuf_sanity_check, but that panics - * and aborts the program */ - return buf != ODP_BUFFER_INVALID; -} - -int odp_buffer_snprint(char *str, uint32_t n, odp_buffer_t buf) -{ - odp_buffer_hdr_t *hdr; - int len = 0; - - if (!odp_buffer_is_valid(buf)) { - ODP_PRINT("Buffer is not valid.\n"); - return len; - } - - hdr = buf_hdl_to_hdr(buf); - - len += snprintf(&str[len], n-len, - "Buffer\n"); - 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, - " addr %p\n", hdr->mb.buf_addr); - len += snprintf(&str[len], n-len, - " size %u\n", hdr->mb.buf_len); - len += snprintf(&str[len], n-len, - " ref_count %i\n", - rte_mbuf_refcnt_read(&hdr->mb)); - len += snprintf(&str[len], n-len, - " odp type %i\n", hdr->type); - - return len; -} - -void odp_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); - str[len] = 0; - - ODP_PRINT("\n%s\n", str); -} - -uint64_t odp_buffer_to_u64(odp_buffer_t hdl) -{ - return _odp_pri(hdl); -} - -odp_pool_t odp_buffer_pool(odp_buffer_t buf) -{ - return buf_hdl_to_hdr(buf)->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);