From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com [209.85.128.173]) by dpdk.org (Postfix) with ESMTP id 813537CA9 for ; Fri, 7 Jul 2017 02:10:14 +0200 (CEST) Received: by mail-wr0-f173.google.com with SMTP id c11so24293415wrc.3 for ; Thu, 06 Jul 2017 17:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=iLXW7hJ0IvGs4dYIY6/kK8tSaCZw1z2oqpHKc3sr7is=; b=Og5qKonU1H2dFUYgG41YPqffJxMXNkAUToj3RExywHs4NviX7r6x3bszdDWUWfayAG vB2aY3u1Bs7MWSRyJlOFpIYt50y2A1M4mVi43hdHD1wCiTx5kKJ25jIisTajL5aAVq0B AF2MbdTrj98YrS+hbkazbVewPqpIglYc/Cc8Rp8pooZhepwzyUHVpnCXnbX4GLTLWS4h 5ohPpc5qwjE0UclrdQQ+NzL8X0cG+Q3EXPIVdVJ7a5n86gwqN4XRJJ2khs6wuA4Y55BD ghoODnu43gS9Hz90bTOMQM+SLplEryR4WSnbqTvFnTrkRJ2zuv8qevPZSAm3v6xTHddu Su4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=iLXW7hJ0IvGs4dYIY6/kK8tSaCZw1z2oqpHKc3sr7is=; b=UfAbx4kGbUlpg0v89NU0pDsyQMzHtXi0LP1RJJ/SD3GsRJz7ph1kCUtXu8UYa6gV2M wRnkegmLhwhzIYdrKeDYxsj1TdLMy0jkMCajY7WBCVD2FUHptq8n/LexWYHzGwOa640y GcZ8OC8192/RGLZRdNZ9DZNMo1tNRiHyVD3mqhOtoqSBQ38YCqqKRZLiuoAJzcQo88ig g8lY5fOwj6ReoAb/UFBB8k3G2mHMJ/jrxL3qL7MzHUNB8IEe8igy+fQcKHC6ZtzlRwS5 xU3w2Icj/G51eysiIaFfA5IV8IkO82PFbCDBqe1gG3zGoFIbwCvIeOYk8JRhCJRtFPm2 wbIA== X-Gm-Message-State: AIVw112Gj7Tgk4Hmv5ujj1WQ9R0gt1a6aebfxsmfoY7sQSrMR5mYWVeU Auozzo0eWwR7WJDXZtg= X-Received: by 10.28.154.19 with SMTP id c19mr288194wme.87.1499386213950; Thu, 06 Jul 2017 17:10:13 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id f45sm2391166wrf.2.2017.07.06.17.10.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Jul 2017 17:10:12 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Fri, 7 Jul 2017 02:09:24 +0200 Message-Id: <9ae7b227197f41f73ac8597d979701ba53309661.1499384906.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v6 14/23] ethdev: count devices consistently 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: Fri, 07 Jul 2017 00:10:14 -0000 Make the rte_eth_dev_count() return the number of available devices even after some are detached by the hotplug API or put in a deferred state. Signed-off-by: Gaetan Rivet --- lib/librte_ether/rte_ethdev.c | 16 +++++++++------- lib/librte_ether/rte_ethdev.h | 13 ++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 0377b97..012950a 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -72,7 +72,6 @@ static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data"; struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS]; static struct rte_eth_dev_data *rte_eth_dev_data; static uint8_t eth_dev_last_created_port; -static uint8_t nb_ports; /* spinlock for eth device callbacks */ static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER; @@ -210,7 +209,6 @@ eth_dev_get(uint8_t port_id) TAILQ_INIT(&(eth_dev->link_intr_cbs)); eth_dev_last_created_port = port_id; - nb_ports++; return eth_dev; } @@ -283,7 +281,6 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) return -EINVAL; eth_dev->state = RTE_ETH_DEV_UNUSED; - nb_ports--; return 0; } @@ -308,7 +305,15 @@ rte_eth_dev_socket_id(uint8_t port_id) uint8_t rte_eth_dev_count(void) { - return nb_ports; + uint8_t p; + uint8_t count; + + count = 0; + + RTE_ETH_FOREACH_DEV(p) + count++; + + return count; } int @@ -341,9 +346,6 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id) return -EINVAL; } - if (!nb_ports) - return -ENODEV; - RTE_ETH_FOREACH_DEV(i) { if (!rte_eth_devices[i].device) continue; diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 4b485f7..abac320 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1724,13 +1724,12 @@ uint8_t rte_eth_find_next(uint8_t port_id); /** * Get the total number of Ethernet devices that have been successfully - * initialized by the [matching] Ethernet driver during the PCI probing phase. - * All devices whose port identifier is in the range - * [0, rte_eth_dev_count() - 1] can be operated on by network applications - * immediately after invoking rte_eal_init(). - * If the application unplugs a port using hotplug function, The enabled port - * numbers may be noncontiguous. In the case, the applications need to manage - * enabled port by using the ``RTE_ETH_FOREACH_DEV()`` macro. + * initialized by the matching Ethernet driver during the PCI probing phase + * and that are available for applications to use. These devices must be + * accessed by using the ``RTE_ETH_FOREACH_DEV()`` macro to deal with + * non-contiguous ranges of devices. + * These non-contiguous ranges can be created by calls to hotplug functions or + * by some PMDs. * * @return * - The total number of usable Ethernet devices. -- 2.1.4