From: David Marchand <david.marchand@6wind.com>
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
Subject: [dpdk-dev] [PATCH v3 13/13] app: introduce dpdk-obj-info tool
Date: Wed, 20 Apr 2016 14:43:56 +0200 [thread overview]
Message-ID: <1461156236-25349-14-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1461156236-25349-1-git-send-email-david.marchand@6wind.com>
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 <david.marchand@6wind.com>
---
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 <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <bfd.h>
+
+#include <rte_pci.h>
+
+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
next prev parent reply other threads:[~2016-04-20 12:44 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-05 19:37 [dpdk-dev] time to kill rte_pci_dev_ids.h Stephen Hemminger
2016-01-06 1:40 ` Thomas Monjalon
2016-01-08 13:20 ` David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 00/11] kill global pci device id list David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 01/11] e1000: move pci device ids to driver David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 02/11] ixgbe: " David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 03/11] i40e: " David Marchand
2016-01-10 20:02 ` Stephen Hemminger
2016-01-12 8:45 ` David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 04/11] fm10k: " David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 05/11] virtio: " David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 06/11] vmxnet3: " David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 07/11] enic: " David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 08/11] bnx2x: " David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 09/11] doc: refresh headers list David Marchand
2016-01-12 14:06 ` Mcnamara, John
2016-01-16 15:10 ` David Marchand
2016-01-18 9:47 ` Thomas Monjalon
2016-01-18 16:25 ` Mcnamara, John
2016-01-10 12:50 ` [dpdk-dev] [PATCH 10/11] pci: no need for global device ids list David Marchand
2016-01-10 12:50 ` [dpdk-dev] [PATCH 11/11] pci: place all uio pci device ids in a dedicated section David Marchand
2016-01-10 12:58 ` [dpdk-dev] [PATCH 00/11] kill global pci device id list David Marchand
2016-01-10 13:24 ` Thomas Monjalon
2016-01-10 13:26 ` David Marchand
2016-01-10 13:27 ` David Marchand
2016-01-10 15:53 ` Zhang, Helin
2016-01-16 15:02 ` David Marchand
2016-01-21 1:12 ` Zhang, Helin
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 00/10] " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 01/10] e1000: move pci device ids to driver David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 02/10] ixgbe: " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 03/10] i40e: " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 04/10] fm10k: " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 05/10] virtio: " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 06/10] vmxnet3: " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 07/10] enic: " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 08/10] bnx2x: " David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 09/10] pci: no need for global device ids list David Marchand
2016-01-18 12:30 ` [dpdk-dev] [PATCH v2 10/10] pci: place all uio pci device ids in a dedicated section David Marchand
2016-01-19 7:30 ` Thomas Monjalon
2016-01-19 14:29 ` Neil Horman
2016-01-19 16:10 ` Stephen Hemminger
2016-01-19 20:56 ` Neil Horman
2016-01-19 21:35 ` Stephen Hemminger
2016-01-20 15:40 ` Neil Horman
2016-02-24 11:37 ` Bruce Richardson
2016-02-24 11:50 ` Thomas Monjalon
2016-02-24 14:18 ` Neil Horman
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 00/13] kill global pci device id list David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 01/13] e1000: move pci device ids to driver David Marchand
2016-04-20 13:29 ` Neil Horman
2016-04-20 13:39 ` David Marchand
2016-04-20 18:15 ` Neil Horman
2016-04-21 7:27 ` David Marchand
2016-04-21 12:08 ` Neil Horman
2016-04-21 12:41 ` Thomas Monjalon
2016-04-22 12:13 ` Neil Horman
2016-04-22 13:22 ` Thomas Monjalon
2016-07-08 13:31 ` Thomas Monjalon
2016-07-11 5:33 ` Yuanhan Liu
2016-07-11 5:56 ` Thomas Monjalon
2016-07-11 6:05 ` Yuanhan Liu
2016-07-11 11:35 ` David Marchand
2016-07-11 12:05 ` Yuanhan Liu
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 02/13] ixgbe: " David Marchand
2016-04-29 1:34 ` Wu, Jingjing
2016-05-04 8:26 ` David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 03/13] i40e: " David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 04/13] fm10k: " David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 05/13] virtio: " David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 06/13] vmxnet3: " David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 07/13] enic: " David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 08/13] bnx2x: " David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 09/13] ena: remove unneeded pci macro David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 10/13] pci: no need for global device ids list David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 11/13] drivers: constify pci id tables David Marchand
2016-04-20 12:43 ` [dpdk-dev] [PATCH v3 12/13] drivers: export pci drivers David Marchand
2016-04-20 12:43 ` David Marchand [this message]
2016-04-21 8:07 ` [dpdk-dev] [PATCH v3 00/13] kill global pci device id list David Marchand
2016-04-21 12:13 ` Neil Horman
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 00/10] kill global pci device id list (almost) David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 01/10] eal: remove PCI device ids header from doxygen David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 02/10] net/e1000: move em PCI device ids to the driver David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 03/10] net/i40e: move " David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 04/10] net/fm10k: " David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 05/10] net/virtio: " David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 06/10] net/vmxnet3: " David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 07/10] net/enic: " David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 08/10] net/bnx2x: " David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 09/10] net/bnxt: " David Marchand
2016-07-11 14:40 ` [dpdk-dev] [PATCH v4 10/10] net/ena: remove unneeded PCI macro David Marchand
2016-07-11 16:27 ` [dpdk-dev] [PATCH v4 00/10] kill global pci device id list (almost) Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461156236-25349-14-git-send-email-david.marchand@6wind.com \
--to=david.marchand@6wind.com \
--cc=bruce.richardson@intel.com \
--cc=christian.ehrhardt@canonical.com \
--cc=dev@dpdk.org \
--cc=nhorman@tuxdriver.com \
--cc=pmatilai@redhat.com \
--cc=stephen@networkplumber.org \
--cc=thomas.monjalon@6wind.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).