[dpdk-dev,RFC,4/4] pmdinfo: Add application to extract pmd driver info

Message ID 1461692391-30093-5-git-send-email-nhorman@tuxdriver.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Neil Horman April 26, 2016, 5:39 p.m. UTC
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<n> symbol.  For each found symbol in the DSO, it prints
information found in the corresponding rte_driver struct

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
CC: David Marchand <david.marchand@6wind.com>
CC: Stephen Hemminger <stephen@networkplumber.org>
CC: "Richardson, Bruce" <bruce.richardson@intel.com>
CC: Panu Matilainen <pmatilai@redhat.com>
CC: Thomas Monjalon <thomas.monjalon@6wind.com>
---
 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
  

Patch

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 <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <string.h>
+#include <rte_dev.h>
+
+
+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);
+}
+
+
+