From patchwork Wed Apr 17 22:59:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 52889 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2128E1B8FC; Thu, 18 Apr 2019 01:00:29 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 89DE01B8FA for ; Thu, 18 Apr 2019 01:00:28 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 064AE21E97; Wed, 17 Apr 2019 19:00:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Apr 2019 19:00:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=mesmtp; bh=OLeLlezfS2lTEz1KRe3KvmQ f3/jfZJ4odCFf3+bx9Sc=; b=HjhA8PRL1obSYasHhgWUscRkvNAJd5WKJrHCC43 1Ud0vEhyEPDF9VJx3D33M7FO/N8gkziEjs5IIYjxosqsxTxoYs3Gxqtq3ISqyfyR RLOPGJ9kiPdYHA3QXAmZ8iB0x+zRpm5dWFJ7zNbBN+3YnBngk6l7sNa/5NyZsrko 1rIE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=OLeLlezfS2lTEz1KR e3KvmQf3/jfZJ4odCFf3+bx9Sc=; b=WII+5Q1SPQuiz0ZQIukgB2fMUVLwg07a+ jnRrWOVqEDDiTy2v3JuGJgrEXrh/3KmKgDWLZy2g2ubtV2N6P7UwlKey6fDHZNDr DK49hSiXcjzs3jA+18IOjikwsCRv/T8/cAIsKnbNalKDljU29ebjZpnRF37DvqZm JBDp804GifdIm3hfyY4EBE1kkKvnekC6xVI3wHWAkKzjNKo92Eh/W8yEHndiFv8Y /Qg1P7UKaJ2byYTrHERlRTQj75fkK/L9fz5VBxSiT53mGWw8+LArP4MrzEyiCWxg i8MB4ZYvihgJK5VgwB/ITXL+kQwsGsCyudkZdt+V0lqcWjqM/YUwQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrfeeggddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghsucfo ohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucfkphepje ejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgr shesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 10577E44A1; Wed, 17 Apr 2019 19:00:25 -0400 (EDT) From: Thomas Monjalon To: Shahaf Shuler , Yongseok Koh , Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org Date: Thu, 18 Apr 2019 00:59:27 +0200 Message-Id: <20190417225928.8962-1-thomas@monjalon.net> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/2] ethdev: avoid explicit check of valid port state X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Some port iterations are manually checking against RTE_ETH_DEV_UNUSED instead of using the iterators based on rte_eth_find_next(). A new macro RTE_ETH_FOREACH_VALID_DEV() is introduced, but kept private because there should be no need of iterating over all devices in the API. The public iterators have additional filters for ownership, parent device or sibling ports. Signed-off-by: Thomas Monjalon --- drivers/net/mlx5/mlx5.c | 9 ++------- lib/librte_ethdev/rte_ethdev.c | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 9ff50dfbe..4deaada5c 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1964,14 +1964,9 @@ static int mlx5_pci_remove(struct rte_pci_device *pci_dev) { uint16_t port_id; - struct rte_eth_dev *port; - for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) { - port = &rte_eth_devices[port_id]; - if (port->state != RTE_ETH_DEV_UNUSED && - port->device == &pci_dev->device) - rte_eth_dev_close(port_id); - } + RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device) + rte_eth_dev_close(port_id); return 0; } diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 243beb4dd..cca15efca 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -339,6 +339,11 @@ rte_eth_find_next(uint16_t port_id) return port_id; } +#define RTE_ETH_FOREACH_VALID_DEV(port_id) \ + for (port_id = rte_eth_find_next(0); \ + port_id < RTE_MAX_ETHPORTS; \ + port_id = rte_eth_find_next(port_id + 1)) + uint16_t rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent) { @@ -584,13 +589,10 @@ rte_eth_is_valid_owner_id(uint64_t owner_id) uint64_t rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id) { + port_id = rte_eth_find_next(port_id); while (port_id < RTE_MAX_ETHPORTS && - (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED || - rte_eth_devices[port_id].data->owner.id != owner_id)) - port_id++; - - if (port_id >= RTE_MAX_ETHPORTS) - return RTE_MAX_ETHPORTS; + rte_eth_devices[port_id].data->owner.id != owner_id) + port_id = rte_eth_find_next(port_id + 1); return port_id; } @@ -768,9 +770,8 @@ rte_eth_dev_count_total(void) { uint16_t port, count = 0; - for (port = 0; port < RTE_MAX_ETHPORTS; port++) - if (rte_eth_devices[port].state != RTE_ETH_DEV_UNUSED) - count++; + RTE_ETH_FOREACH_VALID_DEV(port) + count++; return count; } @@ -804,13 +805,11 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) return -EINVAL; } - for (pid = 0; pid < RTE_MAX_ETHPORTS; pid++) { - if (rte_eth_devices[pid].state != RTE_ETH_DEV_UNUSED && - !strcmp(name, rte_eth_dev_shared_data->data[pid].name)) { + RTE_ETH_FOREACH_VALID_DEV(pid) + if (!strcmp(name, rte_eth_dev_shared_data->data[pid].name)) { *port_id = pid; return 0; } - } return -ENODEV; } From patchwork Wed Apr 17 22:59:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 52890 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E6F8B1B906; Thu, 18 Apr 2019 01:00:40 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id ACDC91B8FA for ; Thu, 18 Apr 2019 01:00:38 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5B21220F02; Wed, 17 Apr 2019 19:00:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Apr 2019 19:00:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=jLyNSl0Ak3 LjZgmX2SqZnWiLHeDslYwff6b8MPKPBSo=; b=jc1A676W5sbVEtm0T6o4nJzzIs IqsZI2EntKU0jMIwTdILn++25g2ghnP7++BnF+OnxjN+Md2UCUea3IUgHbLCdfrr Q3I7qSwL3V6MgcTaqDLT1/jZL8RjIoPePT63rEwHnohqQRDvnRa7lzySGWGORwOq 2VUkOVJMmTcCbIz9A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=jLyNSl0Ak3LjZgmX2SqZnWiLHeDslYwff6b8MPKPBSo=; b=adL8Xp2/ rcwlkG1hSL6sICKcsSBJy5BYNCnMbNvLBfNujTSoFGaDCcygcnT9R32lVIaOpM2i 5dPoPkMJP/jJspo/ebuFXE0gImmCF/Nuda62FhBdV4YFpwX8QttAgTtytARvh6jW lH+zKwCNvT0caxoMgO2qto3EyS/Q6DfLH6BerRZQl2OXZMx2VdCWk/0ugf9hxFUE zKpnZ9g2jB9zECAS0xPL03wV+ZuQ07JHm/4pSIEnv9eXSSSdZnsHjO5XTA24O6BD Hc9VPjwvEnpWN5rVUHHv/vDGeHCMZjdnRXB8QQW3ExY1gzSuP8pYHyhem/dAszf5 KYx7JI46RLDtqQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrfeeggddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghs ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucfkph epjeejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhho mhgrshesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 4D30EE44B4; Wed, 17 Apr 2019 19:00:37 -0400 (EDT) From: Thomas Monjalon To: Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org Date: Thu, 18 Apr 2019 00:59:28 +0200 Message-Id: <20190417225928.8962-2-thomas@monjalon.net> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190417225928.8962-1-thomas@monjalon.net> References: <20190417225928.8962-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 2/2] ethdev: promote function for port count as stable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The function rte_eth_dev_count_total() was introduced one year ago in the release 18.05. It can be declared non experimental in 19.05. Signed-off-by: Thomas Monjalon Acked-by: Ferruh Yigit Acked-by: Andrew Rybchenko --- lib/librte_ethdev/rte_ethdev.c | 2 +- lib/librte_ethdev/rte_ethdev.h | 2 +- lib/librte_ethdev/rte_ethdev_version.map | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index cca15efca..4d99186e8 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -765,7 +765,7 @@ rte_eth_dev_count_avail(void) return count; } -uint16_t __rte_experimental +uint16_t rte_eth_dev_count_total(void) { uint16_t port, count = 0; diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index 40a068fe8..aafc503db 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -1560,7 +1560,7 @@ uint16_t rte_eth_dev_count_avail(void); * @return * The total count of Ethernet devices. */ -uint16_t __rte_experimental rte_eth_dev_count_total(void); +uint16_t rte_eth_dev_count_total(void); /** * Convert a numerical speed in Mbps to a bitmap flag that can be used in diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index b37a4167d..afcd25599 100644 --- a/lib/librte_ethdev/rte_ethdev_version.map +++ b/lib/librte_ethdev/rte_ethdev_version.map @@ -229,11 +229,17 @@ DPDK_18.11 { } DPDK_18.08; +DPDK_19.05 { + global: + + rte_eth_dev_count_total; + +} DPDK_18.11; + EXPERIMENTAL { global: rte_eth_devargs_parse; - rte_eth_dev_count_total; rte_eth_dev_create; rte_eth_dev_destroy; rte_eth_dev_get_module_eeprom;