From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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: , X-List-Received-Date: Wed, 17 Apr 2019 23:00:28 -0000 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; } -- 2.21.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 39834A00E6 for ; Thu, 18 Apr 2019 01:00:30 +0200 (CEST) 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 Content-Transfer-Encoding: 8bit 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190417225927.UvbwjxCOFBTG7YkQb-6-YQyAFhWAuQA_WsyYZaZ7WNo@z> 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; } -- 2.21.0