From patchwork Thu Jul 5 11:48:19 2018 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: 42347 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 885611BF4B; Thu, 5 Jul 2018 13:49:35 +0200 (CEST) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id E9C9F1BED9 for ; Thu, 5 Jul 2018 13:49:12 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id n17-v6so10381943wmh.2 for ; Thu, 05 Jul 2018 04:49:12 -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; bh=rgl50crsTMdz8uMA9l9eRovWUssSsKezern0x9vWcy0=; b=NZ4cPeTqOlJXodHD/PdiGgl4IuX4vLNOJJtXQ1TEfZmr6xSvawuzptY3WRzaeB7IPu 7cnxfqLeLaNT3hfjdIyY+e/f8K2rCLeEH/b7CxmXSxjLMnZ8SsFJsC5MgM6/zE171rnY UWWK4mm90ubTAPQXrWKy181FCNn2GC5EuqyUshO6oCUu7SXNdkvTJoFEFQqyqov/qyuU rHiZL+IFI198YqKU8gGKMrrvyEx0BtoREccuPCD2SU7upZizyhWWcBFRkNQHYKADEHne fRQNXsXr70hcnDCsc4qrMaobB41jcFPqwp1VlvL77KCiQkGchD95a3EkfvDIQdedlvCu 9lcg== 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; bh=rgl50crsTMdz8uMA9l9eRovWUssSsKezern0x9vWcy0=; b=EnknH8VVglcxdQWV5qauhIKRyMyGcyCGxv1DZB6WnAwS0wLWzzwQLbfYp1ko+iyei+ 3IN2d9JVkXpy3GzQFI8x6PILYC3aGnLd8kzIXwLso7prOZh6fscv4kM60nunU0fzQPF/ 8FMfWqdWtcZTbKbVeHSART9BQi8EJwQHDkQFc97fCvIJ+PYNhk91lfjaqgfL7A+IhYKe pKBBgVbdkwweJ0v0A1nn8EdHEGUAol1/B4BFsdDfjP70MllHuQfqZftIFKN7nzKyOTBW SnO7xqMDl8ho+KwXPPL2bGBowTPxP09iFMzJLd8ULxO4pH8UitHxpN2vPQvtYFnuH71y ODXg== X-Gm-Message-State: APt69E00m9y9sXZlPtgjrC1IrMx2BjbI8mLI96IFuazhT3aVwaWwlcHx eNiKRfA3UhpJBq8ll7HFRbeTFMTT X-Google-Smtp-Source: AAOMgpcOfMkAalTWy8dM0VwTmI3ClkiTB3t0SRLuoi980Fszz98gsNevsDPH4GxTYIh879EqG6wh/Q== X-Received: by 2002:a1c:8893:: with SMTP id k141-v6mr4039172wmd.36.1530791352298; Thu, 05 Jul 2018 04:49:12 -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 o42-v6sm15809183wrc.50.2018.07.05.04.49.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 04:49:11 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 5 Jul 2018 13:48:19 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v10 12/27] eal/dev: implement device iteration initialization 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" Parse a device description. Split this description in their relevant part for each layers. No dynamic allocation is performed. Signed-off-by: Gaetan Rivet --- lib/Makefile | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_dev.c | 55 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 24 +++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/rte_eal_version.map | 1 + 6 files changed, 83 insertions(+) diff --git a/lib/Makefile b/lib/Makefile index 8a65525cd..afa604e20 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -7,6 +7,7 @@ DIRS-y += librte_compat DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs DEPDIRS-librte_kvargs := librte_compat DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal +DEPDIRS-librte_eal := librte_kvargs DIRS-$(CONFIG_RTE_LIBRTE_PCI) += librte_pci DEPDIRS-librte_pci := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile index b0a1c880a..67b10ae0d 100644 --- a/lib/librte_eal/bsdapp/eal/Makefile +++ b/lib/librte_eal/bsdapp/eal/Makefile @@ -18,6 +18,7 @@ CFLAGS += $(WERROR_FLAGS) -O3 LDLIBS += -lexecinfo LDLIBS += -lpthread LDLIBS += -lgcc_s +LDLIBS += -lrte_kvargs EXPORT_MAP := ../../rte_eal_version.map diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index ce4b51469..5b7956d17 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -10,9 +10,12 @@ #include #include +#include #include #include #include +#include +#include #include #include #include @@ -343,3 +346,55 @@ dev_callback_process(char *device_name, enum rte_dev_event_type event) } rte_spinlock_unlock(&dev_event_lock); } + +__rte_experimental +int +rte_dev_iterator_init(struct rte_dev_iterator *it, + const char *devstr) +{ + struct rte_devargs da; + struct rte_class *cls = NULL; + struct rte_bus *bus = NULL; + + /* Having both busstr and clsstr NULL is illegal, + * marking this iterator as invalid unless + * everything goes well. + */ + it->busstr = NULL; + it->clsstr = NULL; + + da.data = devstr; + if (rte_devargs_layers_parse(&da, devstr)) + goto get_out; + + bus = da.bus; + cls = da.cls; + /* The string should have at least + * one layer specified. + */ + if (bus == NULL && cls == NULL) { + RTE_LOG(ERR, EAL, + "Either bus or class must be specified.\n"); + rte_errno = EINVAL; + goto get_out; + } + if (bus != NULL && bus->dev_iterate == NULL) { + RTE_LOG(ERR, EAL, "Bus %s not supported\n", bus->name); + rte_errno = ENOTSUP; + goto get_out; + } + if (cls != NULL && cls->dev_iterate == NULL) { + RTE_LOG(ERR, EAL, "Class %s not supported\n", cls->name); + rte_errno = ENOTSUP; + goto get_out; + } + it->busstr = da.busstr; + it->clsstr = da.clsstr; + it->devstr = devstr; + it->bus = bus; + it->cls = cls; + it->device = NULL; + it->class_device = NULL; +get_out: + return -rte_errno; +} diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 120df729f..7b7bd83bc 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -332,6 +332,30 @@ typedef void *(*rte_dev_iterate_t)(const void *start, const char *devstr, const struct rte_dev_iterator *it); +/** + * Initializes a device iterator. + * + * This iterator allows accessing a list of devices matching a criteria. + * The device matching is made among all buses and classes currently registered, + * filtered by the device description given as parameter. + * + * This function will not allocate any memory. It is safe to stop the + * iteration at any moment and let the iterator go out of context. + * + * @param it + * Device iterator handle. + * + * @param str + * Device description string. + * + * @return + * 0 on successful initialization. + * <0 on error. + */ +__rte_experimental +int +rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index babc8617a..885c48110 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -27,6 +27,7 @@ LDLIBS += -lrt ifeq ($(CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES),y) LDLIBS += -lnuma endif +LDLIBS += -lrte_kvargs # specific to linuxapp exec-env SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 19d36b4c7..ac04120d6 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -251,6 +251,7 @@ EXPERIMENTAL { rte_dev_event_callback_unregister; rte_dev_event_monitor_start; rte_dev_event_monitor_stop; + rte_dev_iterator_init; rte_devargs_add; rte_devargs_dump; rte_devargs_insert;