From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by dpdk.org (Postfix) with ESMTP id 96EF9569A for ; Wed, 20 Apr 2016 14:44:17 +0200 (CEST) Received: by mail-wm0-f43.google.com with SMTP id n3so79805650wmn.0 for ; Wed, 20 Apr 2016 05:44:17 -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=84IIs5Nr9Hfucab4TxS62g4YtSJn1J0Dx+gH8YHEMYk=; b=nZjjckmrCrHcGwuA7jnKiTxDqdrHOMHeRcK+ep+8EdV8WZms0neyu6hzJKpDmUbt+M pwbB3wcWwRnrJJl3MaWeE+vLe4eLACK5dW5FRgRh9SOaa7V0ANittYP5roRcyUpO2HNV yWy9Fl5VbpBr2IrgDqF6FODKUsOuZng9S5e/zpZZAN2Fy2f94HIt+FvO9KSzd4vgpVYW Tu1OnmnBKprK8SfAjXGqgOEleUyRZ8rHlvuQe/R/RaklogtfpUZ6Jsn5aI6VjBcisGkW Aj2VI4bl0POyRsWvPhRz4vJS/HDU/AOOPGOuqh2E/v027tUTndIsueg/VOnTgCwD0iMv x7Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=84IIs5Nr9Hfucab4TxS62g4YtSJn1J0Dx+gH8YHEMYk=; b=cIqrqmdQr8YfFj5re6rOil2oybNwzoheXVNj8KC8PUHPyy7nyUK6TvT9FwrQw6IlfJ MzHG/yurWeOBZBXGdRwiT7eja3tFQkyQUEVa8VVCnYHcq+QxT1qjddpKDKTZ8VwAJ15M MK49SAPL89lFr1gCAPlikF1Xah1DGaO2TgaEjBR0n1rP+cwDRm7ecrU40xC1Exc8BzqX hy9INt8Oazm9IGWMq25KaCX5taKYH0doxYninw4F525FFnV6/dXjFg0+qormcqxsM/jN VkBxntdLHFouTLVerCvUOh7DsbtmCR20uuadftJszlSVdar0j3FmSgED3YTDGTrl0sxI Ak2Q== X-Gm-Message-State: AOPr4FXrr4dt/i8PH3g0tJvIj9FLZ3AVFfQjFnLdHwWSWDUQ7QrEn3gCUMszz6ybTZrlLjcs X-Received: by 10.194.57.100 with SMTP id h4mr8697158wjq.18.1461156257409; Wed, 20 Apr 2016 05:44:17 -0700 (PDT) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id j10sm5428135wjb.46.2016.04.20.05.44.16 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Apr 2016 05:44:16 -0700 (PDT) From: David Marchand To: dev@dpdk.org Cc: thomas.monjalon@6wind.com, stephen@networkplumber.org, bruce.richardson@intel.com, nhorman@tuxdriver.com, pmatilai@redhat.com, christian.ehrhardt@canonical.com Date: Wed, 20 Apr 2016 14:43:56 +0200 Message-Id: <1461156236-25349-14-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461156236-25349-1-git-send-email-david.marchand@6wind.com> References: <1453120248-28274-1-git-send-email-david.marchand@6wind.com> <1461156236-25349-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH v3 13/13] app: introduce dpdk-obj-info tool 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: Wed, 20 Apr 2016 12:44:17 -0000 Export some useful information for startup scripts and debug. For now, only pci drivers are handled. Example for a static binary: marchand@gloops:~/git/dpdk$ ./build/app/dpdk-obj-info ./build/app/testpmd pci:driver=cxgbe,flags=needmapping,lsc pci:driver=cxgbe,id=vendor=1425,device=5400,subvendor=ffff,subdevice=ffff pci:driver=cxgbe,id=vendor=1425,device=5401,subvendor=ffff,subdevice=ffff pci:driver=cxgbe,id=vendor=1425,device=5402,subvendor=ffff,subdevice=ffff Example for a dso: marchand@gloops:~/git/dpdk$ ./build/app/dpdk-obj-info ./build/lib/librte_pmd_ixgbe.so pci:driver=ixgbe,flags=needmapping,lsc,detachable pci:driver=ixgbe,id=vendor=8086,device=10b6,subvendor=ffff,subdevice=ffff pci:driver=ixgbe,id=vendor=8086,device=1508,subvendor=ffff,subdevice=ffff pci:driver=ixgbe,id=vendor=8086,device=10c6,subvendor=ffff,subdevice=ffff Signed-off-by: David Marchand --- app/Makefile | 1 + app/dpdk-obj-info/Makefile | 45 +++++++++ app/dpdk-obj-info/dpdk-obj-info.c | 188 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 app/dpdk-obj-info/Makefile create mode 100644 app/dpdk-obj-info/dpdk-obj-info.c diff --git a/app/Makefile b/app/Makefile index 1151e09..0461a35 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-y += dpdk-obj-info include $(RTE_SDK)/mk/rte.subdir.mk diff --git a/app/dpdk-obj-info/Makefile b/app/dpdk-obj-info/Makefile new file mode 100644 index 0000000..b0f4bc7 --- /dev/null +++ b/app/dpdk-obj-info/Makefile @@ -0,0 +1,45 @@ +# BSD LICENSE +# +# Copyright 2016 6WIND S.A. +# +# 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 6WIND S.A. 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 + + +APP = dpdk-obj-info + +SRCS-y += dpdk-obj-info.c + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) + +LDLIBS += -lbfd --as-needed + +DEPDIRS-y += lib + +include $(RTE_SDK)/mk/rte.app.mk diff --git a/app/dpdk-obj-info/dpdk-obj-info.c b/app/dpdk-obj-info/dpdk-obj-info.c new file mode 100644 index 0000000..23c183d --- /dev/null +++ b/app/dpdk-obj-info/dpdk-obj-info.c @@ -0,0 +1,188 @@ +/*- + * BSD LICENSE + * + * Copyright 2016 6WIND S.A. + * + * 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 6WIND S.A. 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static char * +dump_flags(uint32_t flags) +{ + static char buffer[sizeof("needmapping,lsc,detachable,")]; + int written = 0; + + buffer[0] = '\0'; + + if (flags & RTE_PCI_DRV_NEED_MAPPING) + written += snprintf(&buffer[written], sizeof(buffer) - written, + "%s,", "needmapping"); + if (flags & RTE_PCI_DRV_INTR_LSC) + written += snprintf(&buffer[written], sizeof(buffer) - written, + "%s,", "lsc"); + if (flags & RTE_PCI_DRV_DETACHABLE) + written += snprintf(&buffer[written], sizeof(buffer) - written, + "%s,", "detachable"); + if (written) + buffer[written-1] = '\0'; + + return buffer; +} + +static bfd *cur_bfd; +static void *bin_start; +static asymbol **sym_table; +static long sym_number; + +static asymbol * +find_symbol(const uintptr_t p) +{ + int i; + + for (i = 0; i < sym_number; i++) { + asymbol *sym = sym_table[i]; + + if (bfd_asymbol_value(sym) == p) + return sym; + } + + return NULL; +} + +static off_t +get_sec_vma_offset(const asection *sec) +{ + return (uintptr_t) bin_start + sec->filepos + - bfd_get_section_vma(cur_bfd, sec); +} + +static uintptr_t +get_value(const asymbol *sym) +{ + asection *sec = bfd_get_section(sym); + off_t sec_vma_offset = get_sec_vma_offset(sec); + return bfd_asymbol_value(sym) + sec_vma_offset; +} + +int main(int argc, char *argv[]) +{ + int fd; + struct stat st; + long sym_table_size; + long i; + const char *filename; + const char *filter = NULL; + + /* for now, handle one file, and an optional driver name */ + if (argc < 2 || argc > 3) + return -1; + + filename = argv[1]; + if (argc > 2) + filter = argv[2]; + + fd = open(filename, O_RDONLY); + if (fd < 0) + return -1; + if (fstat(fd, &st) < 0) + return -1; + + bin_start = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (bin_start == MAP_FAILED) + return -1; + + bfd_init(); + + cur_bfd = bfd_fdopenr(filename, NULL, fd); + if (!cur_bfd) { + printf("could not init bfd: %s\n", strerror(errno)); + return -1; + } + + if (!bfd_check_format(cur_bfd, bfd_object)) + return -1; + + sym_table_size = bfd_get_symtab_upper_bound(cur_bfd); + if (sym_table_size <= 0) + return -1; + + sym_table = malloc(sym_table_size); + if (!sym_table) + return -1; + + sym_number = bfd_canonicalize_symtab(cur_bfd, sym_table); + if (sym_number < 0) + return -1; + + for (i = 0; i < sym_number; i++) { + asymbol *sym = sym_table[i]; + const struct rte_pci_driver *dr; + asymbol *symid; + const struct rte_pci_id *id; + const char *name; + + if (strncmp(sym->name, RTE_EAL_PCI_DRIVER_PREFIX, + strlen(RTE_EAL_PCI_DRIVER_PREFIX))) + continue; + + name = sym->name + strlen(RTE_EAL_PCI_DRIVER_PREFIX); + if (filter && strcmp(name, filter)) + continue; + + /* pcidriver_* symbols are pointers to real symbol */ + dr = (typeof(dr))get_value(find_symbol(*(uintptr_t *)get_value(sym))); + symid = find_symbol((uintptr_t)dr->id_table); + id = (typeof(id))get_value(symid); + + printf("pci:driver=%s,", name); + printf("flags=%s\n", dump_flags(dr->drv_flags)); + + while (id->vendor_id) { + printf("pci:driver=%s,", name); + printf("id="); + printf("vendor=%4.4x,", id->vendor_id); + printf("device=%4.4x,", id->device_id); + printf("subvendor=%4.4x,", id->subsystem_vendor_id); + printf("subdevice=%4.4x\n", id->subsystem_device_id); + id++; + } + } + + return 0; +} -- 1.9.1