From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by dpdk.org (Postfix) with ESMTP id C57205A6A for ; Sun, 9 Jul 2017 03:47:47 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id k67so93440376wrc.2 for ; Sat, 08 Jul 2017 18:47:47 -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=YTxjMe9IicIFD2rZic8ocjoPVY0vdOtTd2KWv2L302A=; b=LvHrs48dYYRFws6AtPHkpn7WUBdaFx2Hc6X2m+qbN0vsHY7VcrT8EwlXju4ZD8dxir sNDhb7fcy8WZeM8aherGUH8Mz0tpdtAqHjCEYxXeeTvSKCkA6ybJkkLusrOsB1txQyV1 h4jvXErT+F/hlj2ookSAtztpKII8/6VHjT0p0VvzFQKjPaE6j2d71JQvVT5jbb2FM2LV o2LMrFKRVwU08aI39YkmK2zapGTsz7fmVpJNP3lBRXZL6lHSoZXB55Yt9subEuBcVb8d +1AEIxQLqPRNXLMdFY8KnfGLzs+Gut9iEzn5SI/JhOmKTSeDcT76tLVKWtNsjI0VVbCp AXHw== 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=YTxjMe9IicIFD2rZic8ocjoPVY0vdOtTd2KWv2L302A=; b=A+ro6+KjGLZH3nZ9hwyMsoaFo++wR8xuDnhOdudtY+FiTKQHaWyRGyS4+1CCIkjtMp wFi/qNLoHXzTg7uyM4/Ck98ginj1zJDr0TZvBV3eS5GHYvy8CwQ0JJcrhBtHIhKZTYka mr3t3R0Ol3gZIpyV9ZU7QxBvnC5IxAtMRx8L/J0DHHRtiVi58qcaxzu0MNyTPqDKGbdf UudsEVilb6HFsCrj4h1LrenGYivucJz8yXrCHkE6mV3Zr8xc98UHSDvG9pJ44qrgbMWe 1bXMmi3/+DkHzJiMESDudyi8gfF3HfTRkhGOnkDowGpiFTMiGEVbEZS5Hu8D+Z9fnXiP sjHQ== X-Gm-Message-State: AIVw110yLF/PRWKAnv8a4Q+4pec5hf2HdjT9PqHndoV3v56QneFlsibH 1mYXX1I+4PTdKgXu2k0= X-Received: by 10.223.160.68 with SMTP id l4mr3689316wrl.90.1499564867235; Sat, 08 Jul 2017 18:47:47 -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 l186sm4278642wma.10.2017.07.08.18.47.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 08 Jul 2017 18:47:46 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Sun, 9 Jul 2017 03:47:23 +0200 Message-Id: <1b345dd1f441d0117421605db1e651cb17f1c897.1499564333.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 v7 02/11] 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: Sun, 09 Jul 2017 01:47:48 -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 69896e9..8f41a68 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 d894af6..d9a712a 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