From patchwork Tue Aug 22 15:00:09 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: 110664 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2803186qge; Tue, 22 Aug 2017 08:01:15 -0700 (PDT) X-Received: by 10.55.185.199 with SMTP id j190mr1346510qkf.340.1503414075429; Tue, 22 Aug 2017 08:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503414075; cv=none; d=google.com; s=arc-20160816; b=YHmCCvLeVOmhDNOG+iBMXnJFmSsxRi/Vre0LXRXWaHefKws1xweh7dxmJprJwVRkm+ TnR4qun01V7gXEIEWqujCCy7/CF01abHuqzaSkJmdjYtjjtPVupoGV46VGy6GksQHO9c vFeEoVcNdUppkYnzk0s0XdpWYi2y49kplCCVV8vghYbhLICHfe/ZQQvmQuj2bfpsJue9 PoC6Cb3xAJVX+7UFiGr+Su/IDQmITFTME6PQahcOC6zbefCrTi+Ob/ifvS5cxxtfqyZX mSJS6nlyKmn7ASMOM2zIZ2aX2x9t2Ciqz8Q5OY5gUL5Q9QZjWCXgSH9ym9+pABF3djvA +ovQ== 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=gZBWFyxHMTLsih3Ys325GTZ7+exqGaHBHhyrISxI/mo=; b=MAyrSHZ80KY/99YO/Isuj288J1awqM0PQlkwkStTiokyuDNF2UWd5f7piyskojnojw K7gJblxzTsxscUexibFAzoNd8Fy5JalAOUYYc4U5rTK6t6+iibtLDrW9MqQ1RtiAShKP FFoP7sDsfVDe33G4ezuK73emOOqI+k9870rSfTfFs0QjGjnQF0vGJaVn4/J2N3imwlyV AVsE02AGNJk10udY7YQleJzH/P/pDSWUGkBSNeoBdyQWRh3H3FRL2FB3oBwlS/FHBtca zHGec1Y0HTmUQi/ztBzEqlbeIu8bu7J5cy8Qg27wEpQCUqVtDEyUFtuXdOS8Wg4w0CY1 S8DA== 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 f30si13613555qkh.381.2017.08.22.08.01.14; Tue, 22 Aug 2017 08:01:15 -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 836AB60A02; Tue, 22 Aug 2017 15:01:14 +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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM 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 67F69644B7; Tue, 22 Aug 2017 15: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 B5BCB6447C; Tue, 22 Aug 2017 15:00:24 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 57B9A6447C for ; Tue, 22 Aug 2017 15:00:17 +0000 (UTC) Received: from mxback19j.mail.yandex.net (mxback19j.mail.yandex.net [IPv6:2a02:6b8:0:1619::95]) by forward106o.mail.yandex.net (Yandex) with ESMTP id E5FDB784DFD for ; Tue, 22 Aug 2017 18:00:15 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback19j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id aDj2YDWD9U-0FZiUkq2; Tue, 22 Aug 2017 18:00:15 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id uTOShBXSMo-0Ffe6Xat; Tue, 22 Aug 2017 18:00:15 +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: Tue, 22 Aug 2017 18:00:09 +0300 Message-Id: <1503414009-4051-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1503414009-4051-1-git-send-email-odpbot@yandex.ru> References: <1503414009-4051-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 138 Subject: [lng-odp] [PATCH CLOUD-DEV v1 1/1] linux-dpdk: introduce pool modular framework 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 138 (GBalakrishna:pool_modular_framework) ** https://github.com/Linaro/odp/pull/138 ** Patch: https://github.com/Linaro/odp/pull/138.patch ** Base sha: 3cdc8a07993b93b145dc3b4a373b5ebc33bae882 ** Merge commit sha: a94e37611c37ade3ba7387056233247ec3aef281 **/ platform/linux-dpdk/Makefile.am | 7 ++- platform/linux-dpdk/include/odp_pool_internal.h | 1 + platform/linux-dpdk/odp_buffer.c | 5 ++ platform/linux-dpdk/{odp_pool.c => pool/dpdk.c} | 83 +++++++++++++++---------- 4 files changed, 63 insertions(+), 33 deletions(-) rename platform/linux-dpdk/{odp_pool.c => pool/dpdk.c} (90%) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 3789da3d..6e7f0b1d 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -17,6 +17,7 @@ endif AM_CFLAGS += $(PLAT_CFLAGS) AM_CFLAGS += -I$(srcdir)/include AM_CFLAGS += -I$(top_srcdir)/platform/linux-generic/include +AM_CFLAGS += -I$(top_srcdir)/frameworks/modular AM_CFLAGS += -I$(top_srcdir)/include/odp/arch/@ARCH_ABI@ AM_CFLAGS += -I$(top_srcdir)/include AM_CFLAGS += -I$(top_builddir)/include @@ -196,6 +197,7 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_packet_socket.h \ ${top_srcdir}/platform/linux-generic/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pool_subsystem.h \ ${srcdir}/include/odp_posix_extensions.h \ ${top_srcdir}/platform/linux-generic/include/odp_queue_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_queue_if.h \ @@ -243,11 +245,12 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/odp_packet_io.c \ ../linux-generic/pktio/loop.c \ ../linux-generic/odp_pkt_queue.c \ - odp_pool.c \ + pool/dpdk.c \ ../linux-generic/odp_queue.c \ ../linux-generic/odp_queue_if.c \ ../linux-generic/odp_rwlock.c \ ../linux-generic/odp_rwlock_recursive.c \ + ../linux-generic/pool/subsystem.c \ ../linux-generic/odp_schedule.c \ ../linux-generic/odp_schedule_if.c \ ../linux-generic/odp_schedule_iquery.c \ @@ -291,6 +294,8 @@ __LIB__libodp_dpdk_la_SOURCES += arch/x86/cpu_flags.c \ arch/x86/odp_sysinfo_parse.c endif +pool/dpdk.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE + # Build modular framework into odp-linux library modularframeworkdir = $(top_srcdir)/frameworks/modular noinst_HEADERS += $(modularframeworkdir)/list.h \ diff --git a/platform/linux-dpdk/include/odp_pool_internal.h b/platform/linux-dpdk/include/odp_pool_internal.h index 0c157592..b49cc114 100644 --- a/platform/linux-dpdk/include/odp_pool_internal.h +++ b/platform/linux-dpdk/include/odp_pool_internal.h @@ -20,6 +20,7 @@ extern "C" { #include #include +#include #include #include #include diff --git a/platform/linux-dpdk/odp_buffer.c b/platform/linux-dpdk/odp_buffer.c index 5207f253..3c71fef8 100644 --- a/platform/linux-dpdk/odp_buffer.c +++ b/platform/linux-dpdk/odp_buffer.c @@ -106,3 +106,8 @@ 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/odp_pool.c b/platform/linux-dpdk/pool/dpdk.c similarity index 90% rename from platform/linux-dpdk/odp_pool.c rename to platform/linux-dpdk/pool/dpdk.c index b67c2aa8..1209553b 100644 --- a/platform/linux-dpdk/odp_pool.c +++ b/platform/linux-dpdk/pool/dpdk.c @@ -48,15 +48,13 @@ typedef struct pool_table_t { odp_shm_t shm; } pool_table_t; - /* The pool table ptr - resides in shared memory */ static pool_table_t *pool_tbl; /* Pool entry pointers (for inlining) */ void *pool_entry_ptr[ODP_CONFIG_POOLS]; - -int odp_pool_init_global(void) +static int dpdk_pool_init_global(void) { uint32_t i; odp_shm_t shm; @@ -76,6 +74,7 @@ int odp_pool_init_global(void) for (i = 0; i < ODP_CONFIG_POOLS; i++) { /* init locks */ pool_entry_t *pool = &pool_tbl->pool[i]; + LOCK_INIT(&pool->s.lock); pool->s.pool_hdl = pool_index_to_handle(i); @@ -91,12 +90,12 @@ int odp_pool_init_global(void) return 0; } -int odp_pool_init_local(void) +static int dpdk_pool_init_local(void) { return 0; } -int odp_pool_term_global(void) +static int dpdk_pool_term_global(void) { int ret; @@ -107,12 +106,12 @@ int odp_pool_term_global(void) return ret; } -int odp_pool_term_local(void) +static int dpdk_pool_term_local(void) { return 0; } -int odp_pool_capability(odp_pool_capability_t *capa) +static int dpdk_pool_capability(odp_pool_capability_t *capa) { memset(capa, 0, sizeof(odp_pool_capability_t)); @@ -163,8 +162,8 @@ odp_dpdk_mbuf_pool_ctor(struct rte_mempool *mp, if (mp->private_data_size < sizeof(struct mbuf_pool_ctor_arg)) { ODP_ERR("(%s) private_data_size %d < %d", - mp->name, (int) mp->private_data_size, - (int) sizeof(struct mbuf_pool_ctor_arg)); + mp->name, (int)mp->private_data_size, + (int)sizeof(struct mbuf_pool_ctor_arg)); return; } mbp_priv = rte_mempool_get_priv(mp); @@ -205,6 +204,7 @@ odp_dpdk_mbuf_ctor(struct rte_mempool *mp, /* keep some headroom between start of buffer and data */ if (mb_ctor_arg->type == ODP_POOL_PACKET) { odp_packet_hdr_t *pkt_hdr; + mb->data_off = RTE_PKTMBUF_HEADROOM; mb->nb_segs = 1; mb->port = 0xff; @@ -299,7 +299,8 @@ static int check_params(odp_pool_param_t *params) return 0; } -odp_pool_t odp_pool_create(const char *name, odp_pool_param_t *params) +static odp_pool_t dpdk_pool_create(const char *name, + odp_pool_param_t *params) { struct mbuf_pool_ctor_arg mbp_ctor_arg; struct mbuf_ctor_arg mb_ctor_arg; @@ -325,7 +326,7 @@ odp_pool_t odp_pool_create(const char *name, odp_pool_param_t *params) pool_name[ODP_POOL_NAME_LEN - 1] = 0; } - /* Find an unused buffer pool slot and initalize it as requested */ + /* Find an unused buffer pool slot and initialize it as requested */ for (i = 0; i < ODP_CONFIG_POOLS; i++) { uint32_t num; struct rte_mempool *mp; @@ -424,7 +425,6 @@ odp_pool_t odp_pool_create(const char *name, odp_pool_param_t *params) params->type); UNLOCK(&pool->s.lock); return ODP_POOL_INVALID; - break; } mb_ctor_arg.seg_buf_offset = @@ -448,7 +448,7 @@ odp_pool_t odp_pool_create(const char *name, odp_pool_param_t *params) break; } if (odp_unlikely(cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE || - (uint32_t) cache_size * 1.5 > num)) { + (uint32_t)cache_size * 1.5 > num)) { ODP_ERR("cache_size calc failure: %d\n", cache_size); cache_size = 0; } @@ -506,8 +506,7 @@ odp_pool_t odp_pool_create(const char *name, odp_pool_param_t *params) return pool_hdl; } - -odp_pool_t odp_pool_lookup(const char *name) +static odp_pool_t dpdk_pool_lookup(const char *name) { struct rte_mempool *mp = NULL; odp_pool_t pool_hdl = ODP_POOL_INVALID; @@ -519,6 +518,7 @@ odp_pool_t odp_pool_lookup(const char *name) for (i = 0; i < ODP_CONFIG_POOLS; i++) { pool_entry_t *pool = get_pool_entry(i); + LOCK(&pool->s.lock); if (pool->s.rte_mempool != mp) { UNLOCK(&pool->s.lock); @@ -530,7 +530,6 @@ odp_pool_t odp_pool_lookup(const char *name) return pool_hdl; } - static odp_buffer_t buffer_alloc(pool_entry_t *pool) { odp_buffer_t buffer; @@ -546,10 +545,10 @@ static odp_buffer_t buffer_alloc(pool_entry_t *pool) if ((struct rte_mbuf *)buffer == NULL) { rte_errno = ENOMEM; return ODP_BUFFER_INVALID; - } else { - buf_hdl_to_hdr(buffer)->next = NULL; - return buffer; } + + buf_hdl_to_hdr(buffer)->next = NULL; + return buffer; } odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl) @@ -595,16 +594,18 @@ void odp_buffer_free_multi(const odp_buffer_t buf[], int num) } } -void odp_pool_print(odp_pool_t pool_hdl) +static void dpdk_pool_print(odp_pool_t pool_hdl) { uint32_t pool_id = pool_handle_to_index(pool_hdl); pool_entry_t *pool = get_pool_entry(pool_id); + rte_mempool_dump(stdout, pool->s.rte_mempool); } -int odp_pool_info(odp_pool_t pool_hdl, odp_pool_info_t *info) +static int dpdk_pool_info(odp_pool_t pool_hdl, odp_pool_info_t *info) { uint32_t pool_id = pool_handle_to_index(pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); if (pool == NULL || info == NULL) @@ -618,15 +619,15 @@ int odp_pool_info(odp_pool_t pool_hdl, odp_pool_info_t *info) /* * DPDK doesn't support pool destroy at the moment. Instead we should improve - * odp_pool_create() to try to reuse pools + * dpdk_pool_create() to try to reuse pools */ -int odp_pool_destroy(odp_pool_t pool_hdl) +static int dpdk_pool_destroy(odp_pool_t pool_hdl) { uint32_t pool_id = pool_handle_to_index(pool_hdl); pool_entry_t *pool = get_pool_entry(pool_id); - struct rte_mempool *mp; + struct rte_mempool *mp = rte_mempool_lookup(pool->s.name); - if ((mp = rte_mempool_lookup(pool->s.name)) == NULL) { + if (mp == NULL) { ODP_ERR("Can't find pool with this name!\n"); return -1; } @@ -637,18 +638,36 @@ int odp_pool_destroy(odp_pool_t pool_hdl) return 0; } -odp_pool_t odp_buffer_pool(odp_buffer_t buf) -{ - return buf_hdl_to_hdr(buf)->pool_hdl; -} - -void odp_pool_param_init(odp_pool_param_t *params) +static void dpdk_pool_param_init(odp_pool_param_t *params) { memset(params, 0, sizeof(odp_pool_param_t)); } -uint64_t odp_pool_to_u64(odp_pool_t hdl) +static uint64_t dpdk_pool_to_u64(odp_pool_t hdl) { return _odp_pri(hdl); } +pool_module_t dpdk_pool = { + .base = { + .name = "dpdk_pool", + .init_local = dpdk_pool_init_local, + .term_local = dpdk_pool_term_local, + .init_global = dpdk_pool_init_global, + .term_global = dpdk_pool_term_global, + }, + .capability = dpdk_pool_capability, + .create = dpdk_pool_create, + .destroy = dpdk_pool_destroy, + .lookup = dpdk_pool_lookup, + .info = dpdk_pool_info, + .print = dpdk_pool_print, + .to_u64 = dpdk_pool_to_u64, + .param_init = dpdk_pool_param_init, +}; + +ODP_MODULE_CONSTRUCTOR(dpdk_pool) +{ + odp_module_constructor(&dpdk_pool); + odp_subsystem_register_module(pool, &dpdk_pool); +}