[dpdk-dev,v1,18/18] app/testpmd: add show device command

Message ID 5dc4c501bf56cfc5645acdd2e195afff2139daec.1521124599.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Gaëtan Rivet March 15, 2018, 5:49 p.m. UTC
  A new interactive command is offered:

   show device <device description>

This commands lists all rte_device element matching the device
description. e.g.:

   show device bus=pci
   show device bus=vdev
   show device bus=vdev,class=eth
   show device bus=vdev,class=eth,name=net_ring0

These devices may not be otherwise useful, some buses will spawn devices
to keep track of their assets without having a driver to use them.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 app/test-pmd/cmdline.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
  

Comments

Gaëtan Rivet March 19, 2018, 11:33 a.m. UTC | #1
On Thu, Mar 15, 2018 at 06:49:48PM +0100, Gaetan Rivet wrote:
> A new interactive command is offered:
> 
>    show device <device description>
> 
> This commands lists all rte_device element matching the device
> description. e.g.:
> 
>    show device bus=pci
>    show device bus=vdev
>    show device bus=vdev,class=eth
>    show device bus=vdev,class=eth,name=net_ring0

Silly mistake, it should read instead:

     show device bus=pci
     show device bus=vdev
     show device bus=vdev/class=eth
     show device bus=vdev/class=eth,name=net_ring0

> 
> These devices may not be otherwise useful, some buses will spawn devices
> to keep track of their assets without having a driver to use them.
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  app/test-pmd/cmdline.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 40b31ad7e..8ac5fb3ca 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -6701,6 +6701,57 @@ cmdline_parse_inst_t cmd_showportall = {
>  	},
>  };
>  
> +/* *** SHOW DEVICE INFO *** */
> +struct cmd_showdevice_result {
> +	cmdline_fixed_string_t show;
> +	cmdline_fixed_string_t device;
> +	cmdline_fixed_string_t filter;
> +};
> +
> +static void
> +cmd_showdevice_dump_device(const struct rte_device *dev)
> +{
> +	const struct rte_driver *drv = dev->driver;
> +
> +	printf("0x%p: %s:%s\n", (const void *)dev, dev->name,
> +		drv ? drv->name : "<nil>");
> +}
> +
> +static void cmd_showdevice_parsed(void *parsed_result,
> +				__attribute__((unused)) struct cmdline *cl,
> +				__attribute__((unused)) void *data)
> +{
> +	struct cmd_showdevice_result *res = parsed_result;
> +	struct rte_dev_iterator it;
> +	const struct rte_device *dev;
> +
> +	RTE_DEV_FOREACH(dev, res->filter, &it)
> +		cmd_showdevice_dump_device(dev);
> +}
> +
> +cmdline_parse_token_string_t cmd_showdevice_show =
> +	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
> +				show, "show");
> +cmdline_parse_token_string_t cmd_showdevice_device =
> +	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
> +				device, "device");
> +cmdline_parse_token_string_t cmd_showdevice_filter =
> +	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
> +			filter, NULL);
> +
> +cmdline_parse_inst_t cmd_showdevice = {
> +	.f = cmd_showdevice_parsed,
> +	.data = NULL,
> +	.help_str = "show device "
> +		"<device string>",
> +	.tokens = {
> +		(void *)&cmd_showdevice_show,
> +		(void *)&cmd_showdevice_device,
> +		(void *)&cmd_showdevice_filter,
> +		NULL,
> +	},
> +};
> +
>  /* *** SHOW PORT INFO *** */
>  struct cmd_showport_result {
>  	cmdline_fixed_string_t show;
> @@ -16038,6 +16089,7 @@ cmdline_parse_ctx_t main_ctx[] = {
>  	(cmdline_parse_inst_t *)&cmd_help_long,
>  	(cmdline_parse_inst_t *)&cmd_quit,
>  	(cmdline_parse_inst_t *)&cmd_load_from_file,
> +	(cmdline_parse_inst_t *)&cmd_showdevice,
>  	(cmdline_parse_inst_t *)&cmd_showport,
>  	(cmdline_parse_inst_t *)&cmd_showqueue,
>  	(cmdline_parse_inst_t *)&cmd_showportall,
> -- 
> 2.11.0
>
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 40b31ad7e..8ac5fb3ca 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -6701,6 +6701,57 @@  cmdline_parse_inst_t cmd_showportall = {
 	},
 };
 
+/* *** SHOW DEVICE INFO *** */
+struct cmd_showdevice_result {
+	cmdline_fixed_string_t show;
+	cmdline_fixed_string_t device;
+	cmdline_fixed_string_t filter;
+};
+
+static void
+cmd_showdevice_dump_device(const struct rte_device *dev)
+{
+	const struct rte_driver *drv = dev->driver;
+
+	printf("0x%p: %s:%s\n", (const void *)dev, dev->name,
+		drv ? drv->name : "<nil>");
+}
+
+static void cmd_showdevice_parsed(void *parsed_result,
+				__attribute__((unused)) struct cmdline *cl,
+				__attribute__((unused)) void *data)
+{
+	struct cmd_showdevice_result *res = parsed_result;
+	struct rte_dev_iterator it;
+	const struct rte_device *dev;
+
+	RTE_DEV_FOREACH(dev, res->filter, &it)
+		cmd_showdevice_dump_device(dev);
+}
+
+cmdline_parse_token_string_t cmd_showdevice_show =
+	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
+				show, "show");
+cmdline_parse_token_string_t cmd_showdevice_device =
+	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
+				device, "device");
+cmdline_parse_token_string_t cmd_showdevice_filter =
+	TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
+			filter, NULL);
+
+cmdline_parse_inst_t cmd_showdevice = {
+	.f = cmd_showdevice_parsed,
+	.data = NULL,
+	.help_str = "show device "
+		"<device string>",
+	.tokens = {
+		(void *)&cmd_showdevice_show,
+		(void *)&cmd_showdevice_device,
+		(void *)&cmd_showdevice_filter,
+		NULL,
+	},
+};
+
 /* *** SHOW PORT INFO *** */
 struct cmd_showport_result {
 	cmdline_fixed_string_t show;
@@ -16038,6 +16089,7 @@  cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_help_long,
 	(cmdline_parse_inst_t *)&cmd_quit,
 	(cmdline_parse_inst_t *)&cmd_load_from_file,
+	(cmdline_parse_inst_t *)&cmd_showdevice,
 	(cmdline_parse_inst_t *)&cmd_showport,
 	(cmdline_parse_inst_t *)&cmd_showqueue,
 	(cmdline_parse_inst_t *)&cmd_showportall,