From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id C848023B for ; Thu, 8 Jun 2017 02:00:17 +0200 (CEST) Received: by mail-wm0-f52.google.com with SMTP id d73so20780962wma.0 for ; Wed, 07 Jun 2017 17:00:17 -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=V+Pd9Yma8IapaMZXql/ZvZoncFO6+oYXz9mNp8EtXGo=; b=h/Ti4PwLfKknu7ujpW3AmZnX0sEn5rpHXCRJqIzYM/PEEruPb9j7QR+6Y9uLs3LREf RZbC041T3x+YLKGxVn9If/0Lja//BneCZ53fmauUDqaIbJUAiyY6nyN+GOwNEbZJgyBC yKRMIQbKLN+2LxigXzUQPsZ5C1vMhb3qfsc7Bg6CZVQ+JQrfhd8xZppofNK6ny9QDmiO G3zT23dEImwwKqKwaBAp/vuoac+1L6vmIuSojSNJ+J+KG48+YO4obtTAYrbehAkSJqTh UGF6c+0fxC891sXPteELDWdHvQj+q9yM3+Vej5cRT2yVQx67/e8pHYb9bE3My4xXapTQ 6AFA== 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=V+Pd9Yma8IapaMZXql/ZvZoncFO6+oYXz9mNp8EtXGo=; b=dAIvbR3g5eDgD+JmOESJqv8enL2lwlRJkikfRaDZkBbDoIXVihmuPpl5Ug8d/DCIAc 7nlVPAv16q/iPltYGBYXa3DqUDPpT5WkbEZWcf3XvZzdh3twa+utjOu3vEhzdK0g3lqr 4uGfVtGYQyCHnSm+mvSvrHV81/uNFsX+G/NfNjr7lZrAAAfTrS13Z2n5G/iNsoXJvQvn qBpOQgBz5dt9shXEsFeMN9JKWrLcCdyxSEMqzji5Zvj5sqNi5Y4ktMmx85PGQ+vzh+w3 EWK1o4B97YurFHcc2j679fMhkC1v3yMYISxi1YwhKSfoCs7M+JAmceJjoo0MTQXGPZM7 rs1w== X-Gm-Message-State: AODbwcBbcXmm7nkNQtKmqXc4fArpqAfRb2RXbbzjTAl2jal2DERRe80b vMkxH98z/5X2LlY79Pc= X-Received: by 10.28.156.142 with SMTP id f136mr1489826wme.24.1496880017277; Wed, 07 Jun 2017 17:00:17 -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 s10sm4337785wmb.8.2017.06.07.17.00.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 17:00:16 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 8 Jun 2017 01:59:53 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v5 03/12] 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: Thu, 08 Jun 2017 00:00:18 -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 2729fc4..6977458 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -71,7 +71,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; @@ -206,7 +205,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; } @@ -279,7 +277,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; } @@ -304,7 +301,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 @@ -336,9 +341,6 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id) return -EINVAL; } - if (!nb_ports) - return -ENODEV; - *port_id = RTE_MAX_ETHPORTS; RTE_ETH_FOREACH_DEV(i) { if (!strncmp(name, diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index c09f88e..6786111 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1725,13 +1725,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