From patchwork Sat Jul 15 17:57:31 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: 26954 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 569147CBA; Sat, 15 Jul 2017 19:58:05 +0200 (CEST) Received: from mail-wr0-f174.google.com (mail-wr0-f174.google.com [209.85.128.174]) by dpdk.org (Postfix) with ESMTP id 41BA57CC9 for ; Sat, 15 Jul 2017 19:57:56 +0200 (CEST) Received: by mail-wr0-f174.google.com with SMTP id w4so5267185wrb.2 for ; Sat, 15 Jul 2017 10:57:56 -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=ZWsRUMSfSizmdkS6Cz4u2aRmSFYDv5xVRGTh60y55fI=; b=bh/++A/7QTx47y8SGLpq5xwqLt9/InfS4c44KJqB+fKlH6tTImbckLk+Jw/DXikXlp VZGjEqoGuV+Z0GaVDiTE6kM5E0tIZQOgytc6WBoWprINQUcI0ZkbfhRu2C8zB4iwii0A QzmLCm1iReQ7qquemfH0olYkKzWN77CMGchKKh/59Uz4sc5/rkiAj72YsGEzZwHyjleN oKZ9gC0p+zT/JB/vvsjHk4Uhz+5OAUCsulsj2IvDBj2WgQHGZsRUiWqbDK0KXDdpM0X1 oxLBBmOcPNbzXCQax4Da26REzUglInUw0aJsGMWzbN947gLsTjYblCG5ibf67EMByp6i g7Og== 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=ZWsRUMSfSizmdkS6Cz4u2aRmSFYDv5xVRGTh60y55fI=; b=DF4EacbeqvjhuQTMNsXi3a+5xSKYbo7ygVtTaMdIkyRUwIO6PjsbAoRCC/i8VuBma2 4tqwnh8x3qAYlmkp/FuQ92Qwb5LnRHfSq32toaHjRvVAOALqUy5fsCfIdXZGaWXAHzRK eM2jwp+s+D0NeE9AXqC/7sfPCkOTPT0DLzjB5y5TqNhYr+tkHKBAwLWusPQ3UKUHwryV oZQUid3l+SUVbE5LZFVqbVViRmKLnHbzyW5WqN7QY+exJ0zo0X3q4U4TSEy6fAuf9TIN ZHwFXpir6VNKaMUAzTEe1mTDpvZX7HmGLrlLrDWqV8Pn9RN83lr1IrdGm4MTsMEm41M1 G0Kw== X-Gm-Message-State: AIVw112S5wG3yJH+BT6b2Hk1M9tOIgjJsI6/42TddkNYptRlm/TBYxkW 7aJ+825JuTFVew3/eSE= X-Received: by 10.223.180.67 with SMTP id v3mr8830052wrd.0.1500141475595; Sat, 15 Jul 2017 10:57:55 -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 g82sm6342745wmg.8.2017.07.15.10.57.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 15 Jul 2017 10:57:54 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Sat, 15 Jul 2017 19:57:31 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v10 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: , 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 81b398d..d4ebb1b 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 774408c..3ee20a8 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1748,13 +1748,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.