From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id 45AEDDE3 for ; Tue, 26 Apr 2016 19:40:54 +0200 (CEST) Received: from hmsreliant.think-freely.org ([2001:470:8:a08:7aac:c0ff:fec2:933b] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1av6yd-0002mm-Go; Tue, 26 Apr 2016 13:40:51 -0400 From: Neil Horman To: dev@dpdk.org Cc: David Marchand , Stephen Hemminger , bruce.richardson@intel.com, Panu Matilainen , Thomas Monjalon , Neil Horman Date: Tue, 26 Apr 2016 13:39:51 -0400 Message-Id: <1461692391-30093-5-git-send-email-nhorman@tuxdriver.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1461692391-30093-1-git-send-email-nhorman@tuxdriver.com> References: <1461692391-30093-1-git-send-email-nhorman@tuxdriver.com> X-Spam-Score: -1.0 (-) X-Spam-Status: No Subject: [dpdk-dev] [RFC PATCH 4/4] pmdinfo: Add application to extract pmd driver info X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Apr 2016 17:40:54 -0000 This tool uses the prior infrastructure to provide human readable information to a user about the devices which a given pmd DSO supports. Usage: pmdinfo /path/to/driver/pmd pmdinfo dlopens the specified file, then iteratively looks up the this_pmd_driver symbol. For each found symbol in the DSO, it prints information found in the corresponding rte_driver struct Signed-off-by: Neil Horman CC: David Marchand CC: Stephen Hemminger CC: "Richardson, Bruce" CC: Panu Matilainen CC: Thomas Monjalon --- app/Makefile | 1 + app/pmdinfo/Makefile | 55 +++++++++++++++++++++++++++++ app/pmdinfo/pmdinfo.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 app/pmdinfo/Makefile create mode 100644 app/pmdinfo/pmdinfo.c diff --git a/app/Makefile b/app/Makefile index 1151e09..42ea130 100644 --- a/app/Makefile +++ b/app/Makefile @@ -37,5 +37,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += test-pipeline DIRS-$(CONFIG_RTE_TEST_PMD) += test-pmd DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_test DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += proc_info +DIRS-$(CONFIG_RTE_BUILD_SHARED_LIB) += pmdinfo include $(RTE_SDK)/mk/rte.subdir.mk diff --git a/app/pmdinfo/Makefile b/app/pmdinfo/Makefile new file mode 100644 index 0000000..eb38aab --- /dev/null +++ b/app/pmdinfo/Makefile @@ -0,0 +1,55 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2015 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include $(RTE_SDK)/mk/rte.vars.mk + +ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y) + +# +# library name +# +APP = pmdinfo + +CFLAGS += -Os -g +CFLAGS += $(WERROR_FLAGS) + +LDLIBS := -ldl + +DEPDIRS-y += lib + +# +# all source are stored in SRCS-y +# +SRCS-y := pmdinfo.c + +include $(RTE_SDK)/mk/rte.app.mk + +endif diff --git a/app/pmdinfo/pmdinfo.c b/app/pmdinfo/pmdinfo.c new file mode 100644 index 0000000..7db61b2 --- /dev/null +++ b/app/pmdinfo/pmdinfo.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include + + +static void dump_pci_table(struct rte_driver *driver) +{ + int i; + + if (!driver->pci_table) { + printf(" No PCI Table defined for this driver\n"); + return; + } + + printf("|====================PCI Table========================|\n"); + printf("| VENDOR ID | DEVICE ID | SUBVENDOR ID | SUBDEVICE ID |\n"); + printf("|-----------------------------------------------------|\n"); + for (i=0; driver->pci_table[i].vendor_id != 0; i++) { + printf("|%11x|%11x|%14x|%14x|\n", + driver->pci_table[i].vendor_id, driver->pci_table[i].device_id, + driver->pci_table[i].subsystem_vendor_id, + driver->pci_table[i].subsystem_device_id); + } + printf("|-----------------------------------------------------|\n"); +} + +static void dump_driver_info(int idx, struct rte_driver *driver) +{ + printf("PMD %d Information:\n", idx); + printf("Driver Name: %s\n", driver->name); + + switch (driver->type) { + case PMD_VDEV: + printf("Driver Type: Virtual\n"); + break; + case PMD_PDEV: + printf("Driver Type: PCI\n"); + dump_pci_table(driver); + break; + default: + printf("Driver Type: UNKNOWN (%d)\n", driver->type); + break; + } +} + +int main(int argc, char **argv) +{ + void *pmd; + struct rte_driver *driver; + int i = 0; + int rc = 0; + const char *basename = "this_pmd_driver"; + char symname[512]; + + if (argc <= 1) { + printf("You must specify a pmd to load\n"); + rc = 127; + goto out; + } + + pmd = dlopen(argv[1], RTLD_LAZY); + + + if (!pmd) { + printf("Unalbe to open dlopen library: %s\n", dlerror()); + rc = 128; + goto out; + } + + do { + memset(symname, 0, 512); + snprintf(symname, 512, "%s%d", basename, i); + driver = dlsym(pmd, symname); + + if (!driver) { + char *err = dlerror(); + if (err && !i) { + printf("%s\n", err); + rc = 129; + } + goto out_close; + } + dump_driver_info(i, driver); + i++; + } while(driver); + +out_close: + dlclose(pmd); +out: + exit(rc); +} + + + -- 2.5.5