From patchwork Wed May 24 15:20:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 24526 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 [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id B63167D7F; Wed, 24 May 2017 17:20:30 +0200 (CEST) Received: from mail-wr0-f181.google.com (mail-wr0-f181.google.com [209.85.128.181]) by dpdk.org (Postfix) with ESMTP id BD89D7D34 for ; Wed, 24 May 2017 17:20:24 +0200 (CEST) Received: by mail-wr0-f181.google.com with SMTP id w50so57095634wrc.0 for ; Wed, 24 May 2017 08:20:24 -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=GNx0ouOZAI6FRE7P6Q9Mx842zbJwE6BDlpLBIe0vCYw=; b=J9ctf8Sia47cYA6Y3Zy/SA9YYil+2oMqxtq62K0bdVIqzKg5/X6K4ENUwrFo2fqLKc WY5Aquil7ynowT33PY/CwOjfSwkwKmoA9r73VmAPKx8sQ4sWiL8s/A/kFln/z0w4EURi TIWBC0eu+Kz1jFszRl+4biSz86JJRAsL96ZyAy3rhXHOBBE2i/b4lNtdct9iLPsR5UDL yvBnwJ+6XW5eNWVQwz3OzvS4UEPfRlPWOvouTf8Dzmj0+reBWPe+aO0VmIrSu3vMoQnf T3swAXUCpoOH2sIRORam5V7GIKyMa31rEXfscGmaI8lTS6K8hGEDzogM0FPe9h7NGxgJ 1Pmg== 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=GNx0ouOZAI6FRE7P6Q9Mx842zbJwE6BDlpLBIe0vCYw=; b=Xp0O7m16kWit9QnQgTwPHw4jWBbn7pMfMgFUdbM5CwcVCDfgU37jMtklDaq81dvQWn yfVYW5gXVnMgLZG8EeXWraGOOGk1rFTbcOL8tahzK6SvrC2mfS8XaizLHbCzh3Yn7KHh AI9ql5sOlSgQvQmHtZJBZdpNIo76i8SrfXYQOfCvqZ4wzsc1ARBUGjnlMp0D6+3mdZVh MoCHI3M1Sn4gZSz2SQ2oHnSA2UwBfPz6c89ppVic247X4XmIt15EiLwyMgnWr0yFmnD1 iVnklyqkppLiwybsiVPlAwPwY+RTRBdV/bWgBvw89qQDOyzF+G2NaZsUBi/xTLcrtQWh 8WsQ== X-Gm-Message-State: AODbwcArUTJgWWuvMOSopIQbyG7iDFAIiURG05++YlTiyCslQifga7yF 5hXyVXUSSZ4DrW4rxk4= X-Received: by 10.223.138.250 with SMTP id z55mr19845065wrz.50.1495639224178; Wed, 24 May 2017 08:20:24 -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 t85sm5444271wmt.23.2017.05.24.08.20.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:20:23 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 24 May 2017 17:20:01 +0200 Message-Id: <0c5992728a77ff88c2708b84c92088cdbae45501.1495634974.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 v3 03/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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 f592643..172c8ec 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; @@ -207,7 +206,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; } @@ -280,7 +278,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; } @@ -305,7 +302,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 @@ -337,9 +342,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 161b0ff..44f7e83 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1788,13 +1788,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.