From patchwork Tue Jul 18 12:48:13 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: 27022 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 BA2E058F6; Tue, 18 Jul 2017 14:48:51 +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 316A32FDD for ; Tue, 18 Jul 2017 14:48:40 +0200 (CEST) Received: by mail-wr0-f181.google.com with SMTP id w4so27377275wrb.2 for ; Tue, 18 Jul 2017 05:48:40 -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=/70BXAVFOXI77776Yu8C5QHzQ14aJBBFQpd5XxNw+Lw=; b=X0ssQYHUOcAlXyfFp4b8c+qBR54Ws4kOYi0miM/EuOEappNO9ryK3pIlSTdhZD0QUk rN/2efSlGpiEVZnY7DhjP14pIU4oauH+EwiD1FgkWp0HLZ7BukuG5LVniRmwqyjuS8bd XgqmtXn2aQ2XQIgeuMZCdMDAQROK06kZLuVaMWE3wCgVF1oCPmIn0MJu8BiwHrStvwLE 3JphGKGHz1FGRiQNeVq6DaqXZtSfcV0nTcsGqrAIkwDK//nW+4hXl7XzdDOj2vq4Q2in IQIXSWjp96KBGuePQnldvxM1qPftF1WkC1ILetWAwD0wGxYAyouRTN60OVTryFOcAv3T XpOA== 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=/70BXAVFOXI77776Yu8C5QHzQ14aJBBFQpd5XxNw+Lw=; b=NueUJO+22UsS3Z2pXRAwqtkSfiGaI95Mi1cAG5jJvSV+IxMYp8BURmKaX3iLnSNCCD 9NiiIUJQZh0rn1ccI326UzPGijxneYokIJc0cZaMW5MJzEtkMJgy/tow5bnkVVwiMB01 OscuPgVRNctuKZfAvx/02LPWHDt3j3WsqyFygNKoTLDg1jh5DrJvCST6Vqb162yy32HG htWbZ1RIIEyhka22Z8RyujXsof2CmSUIUUM+1OcD5yaow5V4p+Ultrcmz167bSDrLvTT Bfv3XESdGk8qoaJHXH1ohgEddNtOBkaaW5HWXVFr++z0eE2FmQ5QMj9dB3aqYSN6ftgQ czsw== X-Gm-Message-State: AIVw110pTF9PkXQHXWnQJfRawNVeJ0Zl38fnIYA3e0jEaM2YNyYOSZY9 jY3HMPVSkpMxXRebbLI= X-Received: by 10.28.213.75 with SMTP id m72mr1689989wmg.41.1500382120302; Tue, 18 Jul 2017 05:48:40 -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 j8sm1033960wrj.10.2017.07.18.05.48.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 05:48:39 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 18 Jul 2017 14:48:13 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v11 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 Acked-by: Thomas Monjalon --- 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 7b69ddf..45aae74 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1746,13 +1746,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.