From patchwork Fri Nov 17 17: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: 119190 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp758799qgn; Fri, 17 Nov 2017 09:01:05 -0800 (PST) X-Google-Smtp-Source: AGs4zMbg4A1uZal3D8A6DSHCuI2EOZf04bRs4qqg+zgxJA76raSsJ2lWWFfZlCGLhfOYVCWBbJm8 X-Received: by 10.55.78.72 with SMTP id c69mr9250808qkb.105.1510938065182; Fri, 17 Nov 2017 09:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510938065; cv=none; d=google.com; s=arc-20160816; b=MFNCzz0/FWDaghJ54nINvfGmbnRLSoFkRTSB8KwqAK5rWMFE3s8E+/HPsUwGk8uZ15 mWswCcjIMcTLPHVRAH59zElWw8hyTONG5vyGDonyYydq2ysNsIqpVcLjdg8u41yCAB7R +veamPFoCn05y06BJ/jEUDwCcy5SzmdETSPxgbmxTZIfj3mrfLNs2MXaugZ5Mg6HNWmO onSv92KkWm9ypDSqnDGBM460566XPaZMeVc1+XcWKbr5vUaOZ8rotbh9Mxf7/zrXlkSb zXR3WW8mWFCeRY/dqqnvdXMKjaNmr3nz522zY5fkvgxB1ymwfBGZCV5G917qt4RinEaG tvww== 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=Mre7kV8RAwsiYdrTfN8uKDo9i2w38r3ec2P+M7zWcY8=; b=sPGIW+elwIsztoLD6Deo2qNPFpbSKDcBfxD/dK9EPzSaZeAhS4EaLMVxw2RL/fIvMM Po9B5WNT7bsj21b7bKpOSeGNMoALEcdpQXtOtifyz55AFsfK6zD62ThQKcJO7QBrq6hr U52FWhXLZbdOqq3wR8Xzxz+tmIRb/fLy+aI43wcCDjWGoOg7VxrYFRWiU/j14S8frpXD 10zNnu0D8Tabl99lrfY6JHRk13C7jNdOEd2nEfNNUokd2NkIEhxyE8RfXflEM4CwxDnx OF9kf1MUTsjW/6SrPCRe5HxGWQL/czm2+yNAse/aJfpreTTllAoMaXF1CFlegZPT+GJ0 0DMw== 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 x38si3365620qtj.432.2017.11.17.09.01.04; Fri, 17 Nov 2017 09:01:05 -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 C73C260856; Fri, 17 Nov 2017 17:01:04 +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,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 91B7D607F1; Fri, 17 Nov 2017 17:00:29 +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 2B28E607F1; Fri, 17 Nov 2017 17:00:18 +0000 (UTC) Received: from forward105j.mail.yandex.net (forward105j.mail.yandex.net [5.45.198.248]) by lists.linaro.org (Postfix) with ESMTPS id DC76C604A1 for ; Fri, 17 Nov 2017 17:00:15 +0000 (UTC) Received: from mxback4o.mail.yandex.net (mxback4o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1e]) by forward105j.mail.yandex.net (Yandex) with ESMTP id 448181849C7 for ; Fri, 17 Nov 2017 20:00:11 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback4o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id WrMC9kDHSN-0Bv8kVZx; Fri, 17 Nov 2017 20:00:11 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id fMGIr6c0ch-0A4Ofsap; Fri, 17 Nov 2017 20:00:10 +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, 17 Nov 2017 20:00:07 +0300 Message-Id: <1510938009-12495-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510938009-12495-1-git-send-email-odpbot@yandex.ru> References: <1510938009-12495-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 297 Subject: [lng-odp] [PATCH 2.0 v2 1/3] linux-gen: pktio: add IO interface operation 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 Pktio implementations will allocate pktio entries operations data from this pool. 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: c785d2a3749494734a049a6e261df1b741ea22e0 **/ include/odp/api/spec/packet_io.h | 5 ++ platform/linux-dpdk/Makefile.am | 2 + platform/linux-generic/Makefile.am | 2 + .../linux-generic/include/odp_packet_io_pool.h | 27 +++++++++++ platform/linux-generic/odp_packet_io.c | 9 ++++ platform/linux-generic/odp_packet_io_pool.c | 54 ++++++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 platform/linux-generic/include/odp_packet_io_pool.h create mode 100644 platform/linux-generic/odp_packet_io_pool.c diff --git a/include/odp/api/spec/packet_io.h b/include/odp/api/spec/packet_io.h index 52af646a6..70dacd3c9 100644 --- a/include/odp/api/spec/packet_io.h +++ b/include/odp/api/spec/packet_io.h @@ -1188,6 +1188,11 @@ uint64_t odp_pktin_ts_res(odp_pktio_t pktio); */ odp_time_t odp_pktin_ts_from_ns(odp_pktio_t pktio, uint64_t ns); +/** + * Packet IO operations data pool name + */ +#define ODP_PKTIO_OPS_DATA_POOL_NAME "ODP_PKTIO_OPS_DATA" + /** * @} */ diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index f27d2b50c..9efd7fa5b 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -206,6 +206,7 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ring_internal.h \ + ${top_srcdir}/platform/linux-generic/include/odp_packet_io_pool.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 \ @@ -260,6 +261,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/pktio/subsystem.c \ odp_packet_flags.c \ ../linux-generic/odp_packet_io.c \ + ../linux-generic/odp_packet_io_pool.c \ ../linux-generic/pktio/loopback.c \ ../linux-generic/odp_pkt_queue.c \ pool/dpdk.c \ diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 56ef03c6f..769edcf90 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -175,6 +175,7 @@ noinst_HEADERS = \ include/odp_name_table_internal.h \ include/odp_packet_internal.h \ include/odp_packet_io_internal.h \ + include/odp_packet_io_pool.h \ include/odp_packet_io_ring_internal.h \ pktio/ethtool.h \ pktio/common.h \ @@ -244,6 +245,7 @@ __LIB__libodp_linux_la_SOURCES = \ odp_packet.c \ odp_packet_flags.c \ odp_packet_io.c \ + odp_packet_io_pool.c \ pktio/ethtool.c \ pktio/subsystem.c \ pktio/ipc.c \ diff --git a/platform/linux-generic/include/odp_packet_io_pool.h b/platform/linux-generic/include/odp_packet_io_pool.h new file mode 100644 index 000000000..59f6e41c1 --- /dev/null +++ b/platform/linux-generic/include/odp_packet_io_pool.h @@ -0,0 +1,27 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP packet IO pool + */ + +#ifndef ODP_PACKET_IO_POOL_H_ +#define ODP_PACKET_IO_POOL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int odp_packet_io_pool_create(void); +int odp_packet_io_pool_destroy(void); + +#ifdef __cplusplus +} +#endif + +#endif /* ODP_PACKET_IO_POOL_H_*/ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index a1c708616..432fcf7eb 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -76,6 +77,10 @@ int odp_pktio_init_global(void) pktio_entry_ptr[i] = pktio_entry; } + if (odp_packet_io_pool_create()) { + odp_shm_free(shm); + return -1; + } return odp_pktio_ops_init_global(true); } @@ -1122,6 +1127,10 @@ int odp_pktio_term_global(void) ret = odp_pktio_ops_term_global(false); + ret = odp_packet_io_pool_destroy(); + if (ret) + ODP_ERR("unable to destroy pktio pool\n"); + ret = odp_shm_free(odp_shm_lookup("odp_pktio_entries")); if (ret != 0) ODP_ERR("shm free failed for odp_pktio_entries"); diff --git a/platform/linux-generic/odp_packet_io_pool.c b/platform/linux-generic/odp_packet_io_pool.c new file mode 100644 index 000000000..edfa2ced9 --- /dev/null +++ b/platform/linux-generic/odp_packet_io_pool.c @@ -0,0 +1,54 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "config.h" + +#include +#include +#include +#include +#include "odp_packet_io_pool.h" +#include "odp_debug_internal.h" + +#define ODP_PKTIO_OPS_DATA_POOL_SIZE 160000 + +int odp_packet_io_pool_create(void) +{ + odpdrv_shm_pool_t pktio_ops_pool; + odpdrv_shm_pool_param_t pktio_ops_param; + + odp_memset(&pktio_ops_param, 0, sizeof(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"); + return -1; + } + + return 0; +} + +int odp_packet_io_pool_destroy(void) +{ + odpdrv_shm_pool_t pktio_ops_pool; + + pktio_ops_pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME); + if (pktio_ops_pool == ODPDRV_SHM_POOL_INVALID) { + ODP_ERR("error pool_lookup pktio_ops pool\n"); + return -1; + } + + if (odpdrv_shm_pool_destroy(pktio_ops_pool)) { + ODP_ERR("error pool_destroy pktio_ops pool\n"); + return -1; + } + + return 0; +} From patchwork Fri Nov 17 17:00:08 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: 119191 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp759897qgn; Fri, 17 Nov 2017 09:01:51 -0800 (PST) X-Google-Smtp-Source: AGs4zMbGWxfllV7SU3AdBmNBYxCH1FvdC5jBtcVGQe2RJzH6mZQ/o29cLtLMXeC9cE8Bk6kDNY4/ X-Received: by 10.200.24.80 with SMTP id n16mr9385689qtk.193.1510938110664; Fri, 17 Nov 2017 09:01:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510938110; cv=none; d=google.com; s=arc-20160816; b=zqWHoS7yQwDYlwqCbyDO+URio9VAIQDI0fiqYp6EigDDI/6rQ+LkrxSphx+0cKBZoS uz+MWofqxJ5vu/OihWGpmGl1ZYc0zjqek23M3r3yQ+EFp06NJNlAKaOOElJDA/aQb/pz PMhI6RgzLv4kDFA8zYkqer5C8vF9qvfqCipm2+rnbm3MdFj3MH+ng5umfG6WX+4gap1l komdNjvayhW+OQu93jf0P18lrMZ2biJuGyr33UViBKn6rExy8F1VNNFn6l36mRmhEuVm FjhRe7EM20/AoAPq/fExL9X4isVNHzxq9d5Ce8hR96vKThVz0mtCpetsd/OsMJSiW3iT SJ3A== 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=dpR+jeNCiQimGXifs92oJZBLIajAK0TPXl92nFclMJE=; b=oV6wGcKZStp3lVwy4lnOCqC/EFWGG6EzkIi2d/aM3veAYdryuko+4Pk0eExPgSIVhH hKXzzTx7qGGrjptQNqVPpUMUfaUgm8ihk2PhX30K0ejfAYkp9qX2zeod9H5RawD9NMwm KZ5tkonwcv1gDkpZzUb7tOT/J6lP2QD7aWq0ztWme/nky6FZ5ARZjFv22CHD/JAmgnQm QI8z6SDvdgw5DPnup0FaIK344pzUcgQTb16Iio87mcF9NvCnWIO7ih+FjoBzMZonKD6e hkqlhblkgWHk1WfD2AR8SG6nA5lOKuxnlbKOYLUeXTVJh+Ug14w3n0M4Aw/hV3TrVll1 j2zA== 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 u21si3216279qkl.34.2017.11.17.09.01.50; Fri, 17 Nov 2017 09:01:50 -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 398196088C; Fri, 17 Nov 2017 17:01:50 +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 57E26607E5; Fri, 17 Nov 2017 17: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 9F382607F6; Fri, 17 Nov 2017 17:00:20 +0000 (UTC) Received: from forward101p.mail.yandex.net (forward101p.mail.yandex.net [77.88.28.101]) by lists.linaro.org (Postfix) with ESMTPS id 0B259607BA for ; Fri, 17 Nov 2017 17:00:13 +0000 (UTC) Received: from mxback1j.mail.yandex.net (mxback1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10a]) by forward101p.mail.yandex.net (Yandex) with ESMTP id 03A966A85365 for ; Fri, 17 Nov 2017 20:00:12 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback1j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id MsXwFhR1Aw-0BrWqxCh; Fri, 17 Nov 2017 20:00:11 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id fMGIr6c0ch-0B4uZxot; Fri, 17 Nov 2017 20: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, 17 Nov 2017 20:00:08 +0300 Message-Id: <1510938009-12495-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510938009-12495-1-git-send-email-odpbot@yandex.ru> References: <1510938009-12495-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 297 Subject: [lng-odp] [PATCH 2.0 v2 2/3] linux-gen: pktio: add IO interface operations data allocate/free API 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 Pktios may use added macros to alloc/free operation data buffers 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: c785d2a3749494734a049a6e261df1b741ea22e0 **/ .../include/odp_pktio_ops_subsystem.h | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index cb107fed2..42cb6d2c5 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -15,7 +15,9 @@ extern "C" { #endif #include +#include #include +#include /* ODP packet IO operations subsystem declaration */ ODP_SUBSYSTEM_DECLARE(pktio_ops); @@ -92,6 +94,32 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #define odp_ops_data(_p, _mod) \ ((pktio_ops_ ## _mod ## _data_t *)(uintptr_t)_p->s.ops_data) +#define odp_ops_data_alloc(_p, _size) \ +({ \ + odpdrv_shm_pool_t _pool; \ + \ + _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, \ + ROUNDUP_CACHE_LINE(_size)); \ + \ + _p->s.ops_data; \ +}) + +#define odp_ops_data_free(_p) \ +({ \ + odpdrv_shm_pool_t _pool; \ + int _result = -1; \ + \ + _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 From patchwork Fri Nov 17 17: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: 119192 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp761017qgn; Fri, 17 Nov 2017 09:02:36 -0800 (PST) X-Google-Smtp-Source: AGs4zMa6C6qq05l6TgDMXieVYTZxLSyM0pGV9xz79dJjwvAApmVEIdoQAQ2GV74BZ8geD6cex7vJ X-Received: by 10.200.2.160 with SMTP id p32mr9424930qtg.172.1510938155920; Fri, 17 Nov 2017 09:02:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510938155; cv=none; d=google.com; s=arc-20160816; b=SmCmTZE6svaRUAp4K73oAoee6OLUv7t5IFPo4pAhr59RseQon9O/2zKXF4W0x3kTcs CCd57yZMSmnlO9SZ9kk8XvWYTCUzkPhraWjnMBL7EVxwGXq6RbMi+jaQei/WmAkMqycR XnCSSRyebMAjlrytczXjozhiwyC4RBWtZoG7aoqErFjH+NVaAysrwXPE4qsTlygVSFI+ nY7hmgk3rIw7AMflFWBbt/UKtn+J97B7dnKoCpXTN4iqKMEu/KPvSkDKthbBdfDxbVwJ 1QkBX0qz/pTUXV+hLs8k6VQquz1srRWVgVL15Q8IvF06PPL97eiS9y2L4EHFnzv6dlpF 0nIQ== 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=0mG6zGR8YORhFIKOzdo98HTcYXMEOxaxZdrXAXgmjdI=; b=vk9IQDadPkJAXOX1OvV55d30dOHm0oP5fQ6q/ZmfOqzgpu67pio6efIyrhHVBoQtqo BK1wL9EA+xqLNRE4duPlp3w1vhuafeEEc3AJB7fXm9bY7Oa52P/RdsXujekuSv3TQg2A rXaAAMmCkXjffvfEtTH1eOLzIYTIXDFE0998046tg4ubOXONdKGOcaXp6o7hYGHzMEha 0KvAyYILINxTibL/qCw2E7zfHvzqGsD6zBynDso5O02t86vEUQgQ+IwFK96Rt7fAmHFE p4gUIdXWanPMhzThXj2l+ZJNJgxbecCGbmtEiSDofoIHjZCHX1/uNkmdqXa38sjNqSJs ZNxw== 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 q1si3895292qkl.299.2017.11.17.09.02.35; Fri, 17 Nov 2017 09:02:35 -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 7C954608A8; Fri, 17 Nov 2017 17:02:35 +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,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 904E66082E; Fri, 17 Nov 2017 17:00:42 +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 2B1186068B; Fri, 17 Nov 2017 17:00:23 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id CD8596074A for ; Fri, 17 Nov 2017 17:00:14 +0000 (UTC) Received: from mxback20j.mail.yandex.net (mxback20j.mail.yandex.net [IPv6:2a02:6b8:0:1619::114]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 5ABF2781990 for ; Fri, 17 Nov 2017 20:00:13 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback20j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id iGYM6EcTdg-0D6addUo; Fri, 17 Nov 2017 20:00:13 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id fMGIr6c0ch-0C4KAEvK; Fri, 17 Nov 2017 20:00:12 +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, 17 Nov 2017 20:00:09 +0300 Message-Id: <1510938009-12495-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510938009-12495-1-git-send-email-odpbot@yandex.ru> References: <1510938009-12495-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 297 Subject: [lng-odp] [PATCH 2.0 v2 3/3] linux-gen: pktio: use IO operation 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: c785d2a3749494734a049a6e261df1b741ea22e0 **/ platform/linux-dpdk/pktio/dpdk.c | 9 +++++--- .../linux-generic/include/odp_packet_io_internal.h | 4 ++-- .../include/odp_pktio_ops_subsystem.h | 6 +---- 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 | 21 +++++++++++++---- platform/linux-generic/pktio/pcap.c | 15 +++++++++--- platform/linux-generic/pktio/socket.c | 27 +++++++++++++++------- platform/linux-generic/pktio/socket_mmap.c | 27 ++++++++++++++-------- platform/linux-generic/pktio/tap.c | 21 +++++++++++++---- 11 files changed, 136 insertions(+), 48 deletions(-) diff --git a/platform/linux-dpdk/pktio/dpdk.c b/platform/linux-dpdk/pktio/dpdk.c index a6e2573e5..99851c3f5 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, sizeof(*pkt_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 42cb6d2c5..31ce9a655 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -87,12 +87,8 @@ 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 - /* 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(_p, _mod) _p->s.ops_data #define odp_ops_data_alloc(_p, _size) \ ({ \ diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 4ef111c34..7501784cb 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, sizeof(*pkt_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..9e134c533 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, sizeof(*pkt_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..ce36cb319 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, sizeof(*pkt_lbk)); + 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..69e484162 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, sizeof(*pkt_nm)); + 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; diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 5bfaeef0e..fecd3a133 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -140,10 +140,16 @@ 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; - memset(pcap, 0, sizeof(pktio_ops_pcap_data_t)); + pcap = odp_ops_data_alloc(pktio_entry, sizeof(*pcap)); + if (odp_unlikely(pcap == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_pcap_data_t struct"); + return -1; + } + + memset(pcap, 0, sizeof(*pcap)); pcap->loop_cnt = 1; pcap->loops = 1; pcap->pool = pool; @@ -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..ccbe465e9 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, sizeof(*pkt_sock)); + 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,6 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, error: sock_close(pktio_entry); - return -1; } diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index b5c27ef4b..f752c3ffd 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, sizeof(*pkt_sock)); + 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; diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index 5bc7481d8..d4edee7c5 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, sizeof(*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; }