From patchwork Thu Nov 16 09:00:05 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: 119022 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5336013qgn; Thu, 16 Nov 2017 01:00:33 -0800 (PST) X-Google-Smtp-Source: AGs4zMZphpt6HaSO+cdI2gXHb/16sz5m+oqn4iD3hfgXzMtQE9FZ32Pdd9UwEfX/1wjOVr9Qv7e5 X-Received: by 10.55.95.6 with SMTP id t6mr1310107qkb.47.1510822833803; Thu, 16 Nov 2017 01:00:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510822833; cv=none; d=google.com; s=arc-20160816; b=lJ0tKAm9il9B7eKJ/YRDKrMXZ3oCaM7Olj7CZXIpe2xa8uzcj9ufB96FErp9pUUAV3 q8hsBKb6fzdOGsxaWuJDwUSFAYcrbqPCI/U/urmlIQMRWD6E+pAio+/NgBewkqsE2d3T ktnRtl+++M6f0cX0qjTFOCzUhCuJiZYO7ZguHF8o0itCWJs6G8qrxIFPbKlj24kR29Ze Ej5/vkzuq2B4CNu1Ls5XseZ6ePa9Y8ov9lvqNx2how4FvINinos+pu/FUQso4F6SpQYH b9XD9Kwp71ZY+HsCQDFDDt24CKdc+hPCpS+oBTT5ckQHOQJFIcsqy3/RdBb05Bn3weRu dLJA== 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=Wsk4v5S4+zoYPGLilxRF4kwLPcg3YUrpthrkI64NmZE=; b=uG/0P+X3ZUF35fCtpDjME7pidR8+rA2y3N4vTjct4y43ZWs2eikKQGS0LYpFOiuUZn 2OP++W1PKdcFANFrvh/ubVtSWRZjRDDlC94OwCbZ4YmK9bh8OTk/m1Fcbf8+JdNUVxoE iarcbh0XJGkk/y6IUTGo/YQEoaYI0gbUCOmQIyQUX2JJ6lVRwIqB1eHQyxvp1yNSuU0g 8OHlMPu+R0KkMK0HIdCgbV7F5MlxTuxNfFXl5cP/1sOzRpdVLUFUge1osiN1HPO6IWIL cUHRqEusSw/peEtSBFd+2aFgZn9YAHxljJfFWNcB21zlyr6vN3a9DvRNwsYnTY3cUjym VBYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id v1si652679qkd.322.2017.11.16.01.00.32; Thu, 16 Nov 2017 01:00:33 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 76DF0607B2; Thu, 16 Nov 2017 09:00:32 +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 409676073F; Thu, 16 Nov 2017 09:00:23 +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 BCA6560749; Thu, 16 Nov 2017 09:00:12 +0000 (UTC) Received: from forward100j.mail.yandex.net (forward100j.mail.yandex.net [5.45.198.240]) by lists.linaro.org (Postfix) with ESMTPS id 5D6346068B for ; Thu, 16 Nov 2017 09:00:10 +0000 (UTC) Received: from mxback6j.mail.yandex.net (mxback6j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10f]) by forward100j.mail.yandex.net (Yandex) with ESMTP id CC1DA5D84B03 for ; Thu, 16 Nov 2017 12:00:08 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback6j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id mltmyWVJFm-08jOBSEe; Thu, 16 Nov 2017 12:00:08 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id uK4C5BL58q-08H85Tjm; Thu, 16 Nov 2017 12:00:08 +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: Thu, 16 Nov 2017 12:00:05 +0300 Message-Id: <1510822807-12483-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510822807-12483-1-git-send-email-odpbot@yandex.ru> References: <1510822807-12483-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 297 Subject: [lng-odp] [PATCH 2.0 v1 1/3] frameworks: modular: add static walk through function template 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: Bogdan Pricope SUBSYSTEM_FOREACH_TEMPLATE() generates static walk through functions to invoke subsystem's modules initialization or termination methods. Those functions may be used by a subsystem initialization or termination function if it needs to perform additional operations than subsystem's modules method invocation. Signed-off-by: Bogdan Pricope --- /** Email created from pull request 297 (bogdanPricope:2_0_ops_alloc_pr) ** https://github.com/Linaro/odp/pull/297 ** Patch: https://github.com/Linaro/odp/pull/297.patch ** Base sha: 6cd43041e55bd73a02ca202f835e590b3ad5c354 ** Merge commit sha: 9a2195f21322cf4bcf5f0b7b2fb827746597d8a1 **/ frameworks/modular/odp_module.h | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/frameworks/modular/odp_module.h b/frameworks/modular/odp_module.h index b20501eb2..0514bf5e1 100644 --- a/frameworks/modular/odp_module.h +++ b/frameworks/modular/odp_module.h @@ -202,16 +202,7 @@ struct odp_module_base { static void __attribute__((constructor(102))) \ odp_ ## name ## _module_constructor(void) -/* All subsystems' initialization and termination routines are - * the same, provide template to help generate similar routines - * automatically, examples: - * - * ODP_SUBSYSTEM_FOREACH_TEMPLATE(subsystem, init_global, DBG) - * will generate a function walk through all the modules of the - * subsystem and invoke init_global method for each. - */ -#define ODP_SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) \ -int odp_ ## subs ##_## method(bool continue_on_errors) \ +#define _SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) \ { \ int result = 0; \ ODP_MODULE_CLASS(subs) * mod = NULL; \ @@ -237,6 +228,32 @@ done: \ return result; \ } +/* ODP_SUBSYSTEM_FOREACH_TEMPLATE() generates subsystems + * initialization and termination routines automatically, + * examples: + * + * ODP_SUBSYSTEM_FOREACH_TEMPLATE(subsystem, init_global, DBG) + * will generate a function walk through all the modules of the + * subsystem and invoke init_global method for each. + */ + +#define ODP_SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) \ +int odp_ ## subs ##_## method(bool continue_on_errors) \ +_SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) + +/* SUBSYSTEM_FOREACH_TEMPLATE() generates static walk through + * functions to invoke subsystem's modules initialization or + * termination methods, examples: + * + * SUBSYSTEM_FOREACH_TEMPLATE(subsystem, init_global, DBG) + * will generate a function walk through all the modules of the + * subsystem and invoke init_global method for each. + */ + +#define SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) \ +static int subs ##_## method(bool continue_on_errors) \ +_SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) + /* Subsystem Modules Registration * * odp_subsystem_register_module() are called by all modules in their From patchwork Thu Nov 16 09:00:06 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: 119025 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5339494qgn; Thu, 16 Nov 2017 01:03:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMawp8sF/paLxgCX8GviAv8xHJCBymdjaxITb72VjCv+XzDVn/l3pdQ2XNRFr/RNBPblQ7qK X-Received: by 10.200.22.234 with SMTP id y39mr1267363qtk.59.1510823021166; Thu, 16 Nov 2017 01:03:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510823021; cv=none; d=google.com; s=arc-20160816; b=gKS0yf72OUtXlsBmH9Po4KRqczXWnYKtKCL49N5k1tG16o26e+vTIBX5c9hWrxbrpm IzRW8Rq79Oh7dTymm5wmweKEgj8QViZNRMqVPcu9ZwO7XK1ShVH89EXahmCx2i/N/Imc GIjC5IongEks8yRZG6H+W6WB9xs5HG9KqLnMSpZAQnkfn5t2Rdu08Xnx8GyE0pDtXnxP jlJVrP2Nn10FPhCYSafq0seVDXhVvRiWzVbDLqyj/hFpYd6NJoiM/Dis3uInp3hP35v3 ErA5YsW9Vp+Nqz7HDQEoBz4AAJAY3gzIZcELiv/swLDrS8H2vWrJUFiOohKFirJBuQOp nKWw== 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=u9w0cbw2UEjUNeYUM3AVkDoUcGrL/rrORWkkcI0PI8E=; b=IuIU+w01wl23V++m6T64uDfTaZI14YDEnncA6795Grpdx+nYeP9k56Gh8HGHZ9/bVN mAstn21e6aDo9yzxV5+nLY9YF+QEYxgrGeurAkDePdEYXJUnFBhsj9h12sUf0YhEBHEi mT0+Ht4a8NpSqERVPkJlHGEr3LlCGaM2+3X9wEbQHg8+UqUICYp8XnyrU1dKqa7w4KSf sNWGTbG41aywu058vUYViq7NfZiCjHCyFRKrtwE2QgdlmJ7FK+nIrXicP8OlGl1WoYip vNH8yaNF0IeAOyh8CcKRU5Rb1CwJoCufWu26Vu3GvOEPG+gcpNglgP2oENNXzVbQ+hZl ASRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id e64si648424qkc.65.2017.11.16.01.03.40; Thu, 16 Nov 2017 01:03:41 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 AFC236084B; Thu, 16 Nov 2017 09:03:40 +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=-5.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 DA518607A9; Thu, 16 Nov 2017 09:00:40 +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 AE62C60731; Thu, 16 Nov 2017 09:00:19 +0000 (UTC) Received: from forward100p.mail.yandex.net (forward100p.mail.yandex.net [77.88.28.100]) by lists.linaro.org (Postfix) with ESMTPS id B8F9D60746 for ; Thu, 16 Nov 2017 09:00:11 +0000 (UTC) Received: from mxback9j.mail.yandex.net (mxback9j.mail.yandex.net [IPv6:2a02:6b8:0:1619::112]) by forward100p.mail.yandex.net (Yandex) with ESMTP id 4A4C951027E1 for ; Thu, 16 Nov 2017 12:00:09 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback9j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Ovv8K1xSMp-09MmY4oe; Thu, 16 Nov 2017 12:00:09 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id uK4C5BL58q-08H4xnmJ; Thu, 16 Nov 2017 12:00:08 +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: Thu, 16 Nov 2017 12:00:06 +0300 Message-Id: <1510822807-12483-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510822807-12483-1-git-send-email-odpbot@yandex.ru> References: <1510822807-12483-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 297 Subject: [lng-odp] [PATCH 2.0 v1 2/3] linux-gen: pktio: add pktio ops_data pool 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: Bogdan Pricope Add memory pool for pktio entry private data. Signed-off-by: Bogdan Pricope --- /** Email created from pull request 297 (bogdanPricope:2_0_ops_alloc_pr) ** https://github.com/Linaro/odp/pull/297 ** Patch: https://github.com/Linaro/odp/pull/297.patch ** Base sha: 6cd43041e55bd73a02ca202f835e590b3ad5c354 ** Merge commit sha: 9a2195f21322cf4bcf5f0b7b2fb827746597d8a1 **/ .../include/odp_pktio_ops_subsystem.h | 31 ++++++++++++++ platform/linux-generic/pktio/subsystem.c | 50 +++++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index cb107fed2..110c113b4 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -16,6 +16,7 @@ extern "C" { #include #include +#include /* ODP packet IO operations subsystem declaration */ ODP_SUBSYSTEM_DECLARE(pktio_ops); @@ -88,10 +89,40 @@ typedef ODP_MODULE_CLASS(pktio_ops) { /* Maximum size of pktio specific ops data.*/ #define ODP_PKTIO_ODPS_DATA_MAX_SIZE 80000 +/* Pktio ops data pool */ +#define ODP_PKTIO_OPS_DATA_POOL_SIZE 160000 +#define ODP_PKTIO_OPS_DATA_POOL_NAME "ODP_PKTIO_OPS_DATA" + /* Extract pktio ops data from pktio entry structure */ #define odp_ops_data(_p, _mod) \ ((pktio_ops_ ## _mod ## _data_t *)(uintptr_t)_p->s.ops_data) +#define odp_ops_data_alloc(_p, _mod) \ +({ \ + odpdrv_shm_pool_t _pool = ODPDRV_SHM_POOL_INVALID; \ + uint64_t _size = sizeof(pktio_ops_ ## _mod ## _data_t); \ + \ + _p->s.ops_data = NULL; \ + _pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME); \ + if (_pool != ODPDRV_SHM_POOL_INVALID) \ + _p->s.ops_data = odpdrv_shm_pool_alloc(_pool, _size); \ + \ + ((pktio_ops_ ## _mod ## _data_t *)_p->s.ops_data); \ +}) + +#define odp_ops_data_free(_p) \ +({ \ + int _result = -1; \ + odpdrv_shm_pool_t _pool = ODPDRV_SHM_POOL_INVALID; \ + \ + _pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME); \ + if (_pool != ODPDRV_SHM_POOL_INVALID) { \ + odpdrv_shm_pool_free(_pool, _p->s.ops_data); \ + _result = 0; \ + } \ + _result; \ +}) + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/pktio/subsystem.c b/platform/linux-generic/pktio/subsystem.c index a3b36c144..abcec7253 100644 --- a/platform/linux-generic/pktio/subsystem.c +++ b/platform/linux-generic/pktio/subsystem.c @@ -15,9 +15,55 @@ ODP_SUBSYSTEM_DEFINE(pktio_ops, "packet IO operations", SUBSYSTEM_VERSION); /* Instantiate init and term functions */ -ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_global, ODP_ERR) +SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_global, ODP_ERR) +SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, term_global, ODP_ERR) ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_local, ODP_ERR) -ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, term_global, ODP_ABORT) + +int odp_pktio_ops_init_global(bool continue_on_errors) +{ + odpdrv_shm_pool_t pktio_ops_pool = ODPDRV_SHM_POOL_INVALID; + odpdrv_shm_pool_param_t pktio_ops_param; + + pktio_ops_param.pool_size = ODP_PKTIO_OPS_DATA_POOL_SIZE; + pktio_ops_param.min_alloc = 1; + pktio_ops_param.max_alloc = ODP_PKTIO_OPS_DATA_POOL_SIZE; + + pktio_ops_pool = odpdrv_shm_pool_create(ODP_PKTIO_OPS_DATA_POOL_NAME, + &pktio_ops_param); + if (pktio_ops_pool == ODPDRV_SHM_POOL_INVALID) { + ODP_ERR("error to pool_create pktio_ops pool\n"); + if (!continue_on_errors) + return -1; + } + + return pktio_ops_init_global(continue_on_errors); +} + +int odp_pktio_ops_term_global(bool continue_on_errors) +{ + int result = 0; + odpdrv_shm_pool_t pktio_ops_pool = ODPDRV_SHM_POOL_INVALID; + + result = pktio_ops_term_global(continue_on_errors); + if (result) { + ODP_ERR("error to pktio_ops_term_global\n"); + if (!continue_on_errors) + return -1; + } + + pktio_ops_pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME); + if (pktio_ops_pool != ODPDRV_SHM_POOL_INVALID) { + if (odpdrv_shm_pool_destroy(pktio_ops_pool)) { + ODP_ERR("error pool_destroy pktio_ops pool\n"); + result = -1; + } + } else { + ODP_ERR("error pool_lookup pktio_ops pool\n"); + result = -1; + } + + return result; +} /* Temporary variable to enable link modules, * will remove in Makefile scheme changes. From patchwork Thu Nov 16 09: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: 119024 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5337915qgn; Thu, 16 Nov 2017 01:02:12 -0800 (PST) X-Google-Smtp-Source: AGs4zMaV8Sh37N17a84g2BIJAU7wn6C69g0kuQzVWy0bVvg7ioFZKn1CChYf3usB1OGnHBoiag/f X-Received: by 10.55.189.135 with SMTP id n129mr1272706qkf.6.1510822932456; Thu, 16 Nov 2017 01:02:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510822932; cv=none; d=google.com; s=arc-20160816; b=TKReUDZIenOt0NpJkk2Bxu4gwKQFh14FCj1CxbXvivTbwtNdXFiSOmIrJl9cTSpSWQ 9dEDUHxwrRvvoaYQmnV+/Uy/OLzhW3SJkgQ58h6lmpJZOMBvAqKcdHUcY4RjvQz1KUZp qpscexLUDASFb33hD9bUpDzHgO8Kv1dM8blo/peBFhkHiDwUv2WSLkRw9CGLzBgeikjH 0p8TVfNB/dozJbHi9OlvERdRsqsBQ2Qs3sAdb8LjyP69Q2NFCBhp7U8TarN0YWd/Vg6v f0Qj6vE4a8S5009j1hXv+pLC7LDSkXuBauAvbJiiOj8ks5wkfs6xIFb+WUowEI37V0kt tSKQ== 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=0GbI9RrzuhTOi1V/LHw1SKMMy9xGcARILu2a7hBLOkk=; b=VOsw9QbssKFnBa7xnhq4+Cl1A5s5LwcMBw9rIYR06vOlG7PzO1lBvk7m11ugQFFKkB h0U9pRP8YPH5d6BfbSvEIwhl6e+tXxfHB3oZ7B6WBv8w7WLT2PS4SaWU0a4GpbjHDwLY pG8XCc4CMpGZhIjpzyQ4UmOIG6E7MC3oYvU0Hc4eQ4jaMLVt1uJCN96SsS9ly7hSbwsv oyiFUSG1c7DgciFggL1Km0Wi50xPubzc2n03hfpq9pTBefE+rbflEn3Ne/Lo6A0a6ouC zJ8LbBrp2kFkUgMwA2WMheHS8LlHlHX7rir/1q0pY7CdFdATQdg0wmg4vkHXdxlim+22 q4xQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id r22si652586qkr.149.2017.11.16.01.02.12; Thu, 16 Nov 2017 01:02:12 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 2A381607F6; Thu, 16 Nov 2017 09:02:12 +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 7EEDE6073F; Thu, 16 Nov 2017 09:00:34 +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 8D58E60731; Thu, 16 Nov 2017 09:00:16 +0000 (UTC) Received: from forward100j.mail.yandex.net (forward100j.mail.yandex.net [5.45.198.240]) by lists.linaro.org (Postfix) with ESMTPS id 366676073F for ; Thu, 16 Nov 2017 09:00:11 +0000 (UTC) Received: from mxback5j.mail.yandex.net (mxback5j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10e]) by forward100j.mail.yandex.net (Yandex) with ESMTP id 29D7E5D84AF0 for ; Thu, 16 Nov 2017 12:00:10 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback5j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id m2KdzKw8KX-0ABeY5gL; Thu, 16 Nov 2017 12:00:10 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id uK4C5BL58q-09HG260S; Thu, 16 Nov 2017 12:00:09 +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: Thu, 16 Nov 2017 12:00:07 +0300 Message-Id: <1510822807-12483-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510822807-12483-1-git-send-email-odpbot@yandex.ru> References: <1510822807-12483-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 297 Subject: [lng-odp] [PATCH 2.0 v1 3/3] linux-gen: pktio: use pktio ops_data pool to allocate pktio data 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: Bogdan Pricope Replace pktio ops_data array implementation with memory pool implementation. This will reduce the size of memory allocated for pktio entries. Signed-off-by: Bogdan Pricope --- /** Email created from pull request 297 (bogdanPricope:2_0_ops_alloc_pr) ** https://github.com/Linaro/odp/pull/297 ** Patch: https://github.com/Linaro/odp/pull/297.patch ** Base sha: 6cd43041e55bd73a02ca202f835e590b3ad5c354 ** Merge commit sha: 9a2195f21322cf4bcf5f0b7b2fb827746597d8a1 **/ platform/linux-dpdk/pktio/dpdk.c | 9 ++++--- .../linux-generic/include/odp_packet_io_internal.h | 4 ++-- .../include/odp_pktio_ops_subsystem.h | 5 +--- platform/linux-generic/pktio/dpdk.c | 10 +++++--- platform/linux-generic/pktio/ipc.c | 20 +++++++++++++--- platform/linux-generic/pktio/loopback.c | 24 +++++++++++++++---- platform/linux-generic/pktio/netmap.c | 22 +++++++++++++---- platform/linux-generic/pktio/pcap.c | 13 ++++++++-- platform/linux-generic/pktio/socket.c | 28 +++++++++++++++------- platform/linux-generic/pktio/socket_mmap.c | 28 +++++++++++++++------- platform/linux-generic/pktio/tap.c | 21 ++++++++++++---- 11 files changed, 138 insertions(+), 46 deletions(-) diff --git a/platform/linux-dpdk/pktio/dpdk.c b/platform/linux-dpdk/pktio/dpdk.c index a6e2573e5..588c68856 100644 --- a/platform/linux-dpdk/pktio/dpdk.c +++ b/platform/linux-dpdk/pktio/dpdk.c @@ -147,8 +147,7 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, { uint8_t portid = 0; struct rte_eth_dev_info dev_info; - pktio_ops_dpdk_data_t *pkt_dpdk = - odp_ops_data(pktio_entry, dpdk); + pktio_ops_dpdk_data_t *pkt_dpdk = NULL; int i; if (!_dpdk_netdev_is_valid(netdev)) { @@ -157,17 +156,21 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, return -1; } + pkt_dpdk = odp_ops_data_alloc(pktio_entry, dpdk); if (odp_unlikely(pkt_dpdk == NULL)) { ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct"); return -1; } + memset(pkt_dpdk, 0, sizeof(*pkt_dpdk)); + portid = atoi(netdev); pkt_dpdk->portid = portid; memset(&dev_info, 0, sizeof(struct rte_eth_dev_info)); rte_eth_dev_info_get(portid, &dev_info); if (dev_info.driver_name == NULL) { ODP_DBG("No driver found for interface: %s\n", netdev); + odp_ops_data_free(pktio_entry); return -1; } if (!strcmp(dev_info.driver_name, "rte_ixgbe_pmd")) @@ -197,7 +200,7 @@ static int close_pkt_dpdk(pktio_entry_t *pktio_entry) if (pktio_entry->s.state == PKTIO_STATE_STOPPED) rte_eth_dev_close(pkt_dpdk->portid); - return 0; + return odp_ops_data_free(pktio_entry); } static int start_pkt_dpdk(pktio_entry_t *pktio_entry) diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 7df11618e..6912b8519 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -43,8 +43,8 @@ typedef union pktio_entry_u pktio_entry_t; struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ - uint8_t ops_data[ODP_PKTIO_ODPS_DATA_MAX_SIZE]; /**< IO operation - specific data */ + void *ops_data; /**< IO operation specific data */ + /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 110c113b4..324178d52 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -86,16 +86,13 @@ typedef ODP_MODULE_CLASS(pktio_ops) { odp_api_proto(pktio_ops, print) print; } pktio_ops_module_t; -/* Maximum size of pktio specific ops data.*/ -#define ODP_PKTIO_ODPS_DATA_MAX_SIZE 80000 - /* Pktio ops data pool */ #define ODP_PKTIO_OPS_DATA_POOL_SIZE 160000 #define ODP_PKTIO_OPS_DATA_POOL_NAME "ODP_PKTIO_OPS_DATA" /* Extract pktio ops data from pktio entry structure */ #define odp_ops_data(_p, _mod) \ - ((pktio_ops_ ## _mod ## _data_t *)(uintptr_t)_p->s.ops_data) + ((pktio_ops_ ## _mod ## _data_t *)_p->s.ops_data) #define odp_ops_data_alloc(_p, _mod) \ ({ \ diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 4ef111c34..bc626ec7d 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -934,7 +934,7 @@ static int dpdk_close(pktio_entry_t *pktio_entry) rte_pktmbuf_free(pkt_dpdk->rx_cache[i].s.pkt[idx++]); } - return 0; + return odp_ops_data_free(pktio_entry); } static int dpdk_pktio_init(void) @@ -1208,8 +1208,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, const char *netdev, odp_pool_t pool) { - pktio_ops_dpdk_data_t *pkt_dpdk = - odp_ops_data(pktio_entry, dpdk); + pktio_ops_dpdk_data_t *pkt_dpdk = NULL; struct rte_eth_dev_info dev_info; struct rte_mempool *pkt_pool; char pool_name[RTE_MEMPOOL_NAMESIZE]; @@ -1223,6 +1222,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, if (pool == ODP_POOL_INVALID) return -1; + pool_entry = pool_entry_from_hdl(pool); if (!dpdk_netdev_is_valid(netdev)) { @@ -1237,6 +1237,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, dpdk_initialized = 1; } + pkt_dpdk = odp_ops_data_alloc(pktio_entry, dpdk); if (odp_unlikely(pkt_dpdk == NULL)) { ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct"); return -1; @@ -1250,6 +1251,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, if (rte_eth_dev_count() == 0) { ODP_ERR("No DPDK ports found\n"); + odp_ops_data_free(pktio_entry); return -1; } @@ -1258,6 +1260,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, mtu = dpdk_mtu_get(pktio_entry); if (mtu == 0) { ODP_ERR("Failed to read interface MTU\n"); + odp_ops_data_free(pktio_entry); return -1; } pkt_dpdk->mtu = mtu + _ODP_ETHHDR_LEN; @@ -1294,6 +1297,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, } if (pkt_pool == NULL) { ODP_ERR("Cannot init mbuf packet pool\n"); + odp_ops_data_free(pktio_entry); return -1; } diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 5ab957403..dd9632ab5 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -343,7 +343,7 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, char name[ODP_POOL_NAME_LEN + sizeof("_info")]; char tail[ODP_POOL_NAME_LEN]; odp_shm_t shm; - pktio_ops_ipc_data_t *pkt_ipc = odp_ops_data(pktio_entry, ipc); + pktio_ops_ipc_data_t *pkt_ipc; ODP_STATIC_ASSERT(ODP_POOL_NAME_LEN == _RING_NAMESIZE, "mismatch pool and ring name arrays"); @@ -351,6 +351,14 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, if (strncmp(dev, "ipc", 3)) return -1; + pkt_ipc = odp_ops_data_alloc(pktio_entry, ipc); + if (odp_unlikely(pkt_ipc == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_ipc_data_t struct"); + return -1; + } + + memset(pkt_ipc, 0, sizeof(*pkt_ipc)); + odp_atomic_init_u32(&pkt_ipc->ready, 0); pkt_ipc->rx.cache = _ring_create("ipc_rx_cache", @@ -364,12 +372,15 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, snprintf(name, sizeof(name), "ipc:%s_info", tail); IPC_ODP_DBG("lookup for name %s for pid %d\n", name, pid); shm = odp_shm_import(name, pid, name); - if (ODP_SHM_INVALID == shm) + if (ODP_SHM_INVALID == shm) { + odp_ops_data_free(pktio_entry); return -1; + } pinfo = odp_shm_addr(shm); if (!pinfo->master.init_done) { odp_shm_free(shm); + odp_ops_data_free(pktio_entry); return -1; } pkt_ipc->pinfo = pinfo; @@ -384,6 +395,7 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, _ODP_ISHM_EXPORT | _ODP_ISHM_LOCK); if (ODP_SHM_INVALID == shm) { ODP_ERR("can not create shm %s\n", name); + odp_ops_data_free(pktio_entry); return -1; } @@ -396,6 +408,8 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, ret = _ipc_init_master(pktio_entry, dev, pool); } + if (ret) + odp_ops_data_free(pktio_entry); return ret; } @@ -776,7 +790,7 @@ static int ipc_close(pktio_entry_t *pktio_entry) _ring_destroy(ipc_shm_name); _ring_destroy("ipc_rx_cache"); - return 0; + return odp_ops_data_free(pktio_entry); } static int ipc_pktio_init_global(void) diff --git a/platform/linux-generic/pktio/loopback.c b/platform/linux-generic/pktio/loopback.c index 60bee5913..34a785c1c 100644 --- a/platform/linux-generic/pktio/loopback.c +++ b/platform/linux-generic/pktio/loopback.c @@ -32,20 +32,29 @@ static int loopback_stats_reset(pktio_entry_t *pktio_entry); static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool ODP_UNUSED) { - pktio_ops_loopback_data_t *pkt_lbk = - odp_ops_data(pktio_entry, loopback); + pktio_ops_loopback_data_t *pkt_lbk = NULL; if (strcmp(devname, "loop")) return -1; + pkt_lbk = odp_ops_data_alloc(pktio_entry, loopback); + if (odp_unlikely(pkt_lbk == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_loopback_data_t struct"); + return -1; + } + + memset(pkt_lbk, 0, sizeof(*pkt_lbk)); + char loopq_name[ODP_QUEUE_NAME_LEN]; snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loopq", odp_pktio_to_u64(id)); pkt_lbk->loopq = odp_queue_create(loopq_name, NULL); - if (pkt_lbk->loopq == ODP_QUEUE_INVALID) + if (pkt_lbk->loopq == ODP_QUEUE_INVALID) { + odp_ops_data_free(pktio_entry); return -1; + } loopback_stats_reset(pktio_entry); @@ -54,10 +63,17 @@ static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, static int loopback_close(pktio_entry_t *pktio_entry) { + int result = 0; pktio_ops_loopback_data_t *pkt_lbk = odp_ops_data(pktio_entry, loopback); - return odp_queue_destroy(pkt_lbk->loopq); + if (odp_queue_destroy(pkt_lbk->loopq)) + result = -1; + + if (odp_ops_data_free(pktio_entry)) + result = -1; + + return result; } static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index 29c449e40..14163b42a 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -209,6 +209,7 @@ static inline void netmap_close_descriptors(pktio_entry_t *pktio_entry) static int netmap_close(pktio_entry_t *pktio_entry) { + int status = 0; pktio_ops_netmap_data_t *pkt_nm = odp_ops_data(pktio_entry, netmap); @@ -217,9 +218,17 @@ static int netmap_close(pktio_entry_t *pktio_entry) if (pkt_nm->sockfd != -1 && close(pkt_nm->sockfd) != 0) { __odp_errno = errno; ODP_ERR("close(sockfd): %s\n", strerror(errno)); - return -1; + + status = -1; } - return 0; + + if (odp_ops_data_free(pktio_entry)) { + ODP_ERR("ops_data_free(netmap) failed\n"); + + status = -1; + } + + return status; } static int netmap_link_status(pktio_entry_t *pktio_entry) @@ -343,8 +352,7 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *prefix; uint32_t mtu; uint32_t buf_size; - pktio_ops_netmap_data_t *pkt_nm = - odp_ops_data(pktio_entry, netmap); + pktio_ops_netmap_data_t *pkt_nm = NULL; struct nm_desc *desc; struct netmap_ring *ring; odp_pktin_hash_proto_t hash_proto; @@ -356,6 +364,11 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, if (pool == ODP_POOL_INVALID) return -1; + pkt_nm = odp_ops_data_alloc(pktio_entry, netmap); + if (odp_unlikely(pkt_nm == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_netmap_data_t struct"); + return -1; + } /* Init pktio entry */ memset(pkt_nm, 0, sizeof(*pkt_nm)); pkt_nm->sockfd = -1; @@ -471,6 +484,7 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, error: netmap_close(pktio_entry); + odp_ops_data_free(pktio_entry); return -1; } diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 5bfaeef0e..8ae98597d 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -140,9 +140,15 @@ static int _pcapif_init_tx(pktio_ops_pcap_data_t *pcap) static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool) { - pktio_ops_pcap_data_t *pcap = odp_ops_data(pktio_entry, pcap); + pktio_ops_pcap_data_t *pcap = NULL; int ret; + pcap = odp_ops_data_alloc(pktio_entry, pcap); + if (odp_unlikely(pcap == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_pcap_data_t struct"); + return -1; + } + memset(pcap, 0, sizeof(pktio_ops_pcap_data_t)); pcap->loop_cnt = 1; pcap->loops = 1; @@ -162,6 +168,9 @@ static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, (void)pcapif_stats_reset(pktio_entry); + if (ret) + odp_ops_data_free(pktio_entry); + return ret; } @@ -182,7 +191,7 @@ static int pcapif_close(pktio_entry_t *pktio_entry) free(pcap->fname_rx); free(pcap->fname_tx); - return 0; + return odp_ops_data_free(pktio_entry); } static int _pcapif_reopen(pktio_ops_pcap_data_t *pcap) diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index d9f85b29a..d4b135d32 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -110,16 +110,22 @@ int sendmmsg(int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags) */ static int sock_close(pktio_entry_t *pktio_entry) { + int result = 0; pktio_ops_socket_data_t *pkt_sock = odp_ops_data(pktio_entry, socket); if (pkt_sock->sockfd != -1 && close(pkt_sock->sockfd) != 0) { __odp_errno = errno; ODP_ERR("close(sockfd): %s\n", strerror(errno)); - return -1; + result = -1; } - return 0; + if (odp_ops_data_free(pktio_entry)) { + ODP_ERR("ops_data_free(socket) failed\n"); + result = -1; + } + + return result; } /* @@ -134,18 +140,24 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, struct ifreq ethreq; struct sockaddr_ll sa_ll; char shm_name[ODP_SHM_NAME_LEN]; - pktio_ops_socket_data_t *pkt_sock = - odp_ops_data(pktio_entry, socket); + pktio_ops_socket_data_t *pkt_sock = NULL; odp_pktio_stats_t cur_stats; + if (pool == ODP_POOL_INVALID) + return -1; + + pkt_sock = odp_ops_data_alloc(pktio_entry, socket); + if (odp_unlikely(pkt_sock == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_socket_data_t struct"); + return -1; + } + /* Init pktio entry */ memset(pkt_sock, 0, sizeof(*pkt_sock)); /* set sockfd to -1, because a valid socked might be initialized to 0 */ pkt_sock->sockfd = -1; - - if (pool == ODP_POOL_INVALID) - return -1; pkt_sock->pool = pool; + snprintf(shm_name, ODP_SHM_NAME_LEN, "%s-%s", "pktio", netdev); shm_name[ODP_SHM_NAME_LEN - 1] = '\0'; @@ -212,7 +224,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, error: sock_close(pktio_entry); - + odp_ops_data_free(pktio_entry); return -1; } diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index b5c27ef4b..e5013859b 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -497,20 +497,25 @@ static int sock_mmap_close(pktio_entry_t *entry) pktio_ops_socket_mmap_data_t *const pkt_sock = odp_ops_data(entry, socket_mmap); int ret; + int status = 0; ret = mmap_unmap_sock(pkt_sock); if (ret != 0) { ODP_ERR("mmap_unmap_sock() %s\n", strerror(errno)); - return -1; + status = -1; } if (pkt_sock->sockfd != -1 && close(pkt_sock->sockfd) != 0) { __odp_errno = errno; ODP_ERR("close(sockfd): %s\n", strerror(errno)); - return -1; + status = -1; } - return 0; + if (odp_ops_data_free(entry)) { + ODP_ERR("ops_data_free(sock_mmap) failed\n"); + status = -1; + } + return status; } static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, @@ -520,22 +525,26 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, int if_idx; int ret = 0; odp_pktio_stats_t cur_stats; + pktio_ops_socket_mmap_data_t *pkt_sock; + int fanout = 1; if (disable_pktio) return -1; - pktio_ops_socket_mmap_data_t - *const pkt_sock = odp_ops_data(pktio_entry, socket_mmap); - int fanout = 1; + if (pool == ODP_POOL_INVALID) + return -1; + + pkt_sock = odp_ops_data_alloc(pktio_entry, socket_mmap); + if (odp_unlikely(pkt_sock == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_socket_mmap_data_t struct"); + return -1; + } /* Init pktio entry */ memset(pkt_sock, 0, sizeof(*pkt_sock)); /* set sockfd to -1, because a valid socked might be initialized to 0 */ pkt_sock->sockfd = -1; - if (pool == ODP_POOL_INVALID) - return -1; - /* Store eth buffer offset for pkt buffers from this pool */ pkt_sock->frame_offset = 0; @@ -604,6 +613,7 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, error: sock_mmap_close(pktio_entry); + odp_ops_data_free(pktio_entry); return -1; } diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index 5bc7481d8..898f28e7f 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -92,23 +92,30 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, int fd, skfd, flags; uint32_t mtu; struct ifreq ifr; - pktio_ops_tap_data_t *tap = odp_ops_data(pktio_entry, tap); + pktio_ops_tap_data_t *tap = NULL; if (strncmp(devname, "tap:", 4) != 0) return -1; + if (pool == ODP_POOL_INVALID) + return -1; + + tap = odp_ops_data_alloc(pktio_entry, tap); + if (odp_unlikely(tap == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_tap_data_t struct"); + return -1; + } + /* Init pktio entry */ memset(tap, 0, sizeof(*tap)); tap->fd = -1; tap->skfd = -1; - if (pool == ODP_POOL_INVALID) - return -1; - fd = open("/dev/net/tun", O_RDWR); if (fd < 0) { __odp_errno = errno; ODP_ERR("failed to open /dev/net/tun: %s\n", strerror(errno)); + odp_ops_data_free(pktio_entry); return -1; } @@ -170,6 +177,7 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, tap_err: close(fd); ODP_ERR("Tap device alloc failed.\n"); + odp_ops_data_free(pktio_entry); return -1; } @@ -252,6 +260,11 @@ static int tap_pktio_close(pktio_entry_t *pktio_entry) ret = -1; } + if (odp_ops_data_free(pktio_entry)) { + ODP_ERR("ops_data_free(tap) failed\n"); + ret = -1; + } + return ret; }