[v4,2/2] app/pdump: enhance to support multi-core capture

Message ID 20190402043318.20382-3-vipin.varghese@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series app/pdump: enhance to support unique cores |

Checks

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

Commit Message

Varghese, Vipin April 2, 2019, 4:33 a.m. UTC
  Add option --multi, to enhance the pdump application to allow capture
on unique cores for each --pdump option. If option --multi is ignored
the default capture occurs on a single core for all --pdump options.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
---
 app/pdump/main.c           | 76 ++++++++++++++++++++++++++++++++------
 doc/guides/tools/pdump.rst |  8 +++-
 2 files changed, 72 insertions(+), 12 deletions(-)
  

Comments

David Marchand April 2, 2019, 7:05 a.m. UTC | #1
On Tue, Apr 2, 2019 at 6:33 AM Vipin Varghese <vipin.varghese@intel.com>
wrote:

> Add option --multi, to enhance the pdump application to allow capture
> on unique cores for each --pdump option. If option --multi is ignored
> the default capture occurs on a single core for all --pdump options.
>
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> ---
>  app/pdump/main.c           | 76 ++++++++++++++++++++++++++++++++------
>  doc/guides/tools/pdump.rst |  8 +++-
>  2 files changed, 72 insertions(+), 12 deletions(-)
>
> diff --git a/app/pdump/main.c b/app/pdump/main.c
> index c1db2eb8d..997c8942f 100644
> --- a/app/pdump/main.c
> +++ b/app/pdump/main.c
> @@ -28,6 +28,7 @@
>  #include <rte_pdump.h>
>
>  #define CMD_LINE_OPT_PDUMP "pdump"
> +#define CMD_LINE_OPT_MULTI "multi"
>  #define PDUMP_PORT_ARG "port"
>  #define PDUMP_PCI_ARG "device_id"
>  #define PDUMP_QUEUE_ARG "queue"
> @@ -139,12 +140,14 @@ struct parse_val {
>  static int num_tuples;
>  static struct rte_eth_conf port_conf_default;
>  static volatile uint8_t quit_signal;
> +static uint8_t multiple_core_capture;
>
>  /**< display usage */
>  static void
>  pdump_usage(const char *prgname)
>  {
> -       printf("usage: %s [EAL options] -- --pdump "
> +       printf("usage: %s [EAL options] -- [--multi] "
> +                       "--pdump "
>                         "'(port=<port id> | device_id=<pci id or vdev
> name>),"
>                         "(queue=<queue_id>),"
>                         "(rx-dev=<iface or pcap file> |"
>

Rather than hardcode the usage, reuse the macro you introduced:
CMD_LINE_OPT_MULTI.


@@ -376,6 +379,7 @@ launch_args_parse(int argc, char **argv, char *prgname)
>         int option_index;
>         static struct option long_option[] = {
>                 {"pdump", 1, 0, 0},
> +               {"multi", 0, 0, 0},
>                 {NULL, 0, 0, 0}
>         };
>
>
Idem reuse the macro.

Besides look at lib/librte_eal/common/eal_options.h and
lib/librte_eal/common/eal_common_options.c.
Define an enum for long only options and map "multi" to an integer that has
no printable character associated.

This way, you can avoid (see below)...

@@ -395,6 +399,10 @@ launch_args_parse(int argc, char **argv, char *prgname)
>                                         pdump_usage(prgname);
>                                         return -1;
>                                 }
> +                       } else if (!strncmp(long_option[option_index].name,
> +                                       CMD_LINE_OPT_MULTI,
> +                                       sizeof(CMD_LINE_OPT_MULTI))) {
> +                               multiple_core_capture = 1;
>                         }
>                         break;
>                 default:
>

... this strncmp.
getopt_long already matched the input option for you.
  
Varghese, Vipin April 2, 2019, 8:06 a.m. UTC | #2
Hi David,

Thanks for the inputs, these are useful. Let me work on these and share v5 ASAP.

Thanks
Vipin Varghese

From: David Marchand <david.marchand@redhat.com>
Sent: Tuesday, April 2, 2019 12:35 PM
To: Varghese, Vipin <vipin.varghese@intel.com>
Cc: dev <dev@dpdk.org>; Kovacevic, Marko <marko.kovacevic@intel.com>; Pattan, Reshma <reshma.pattan@intel.com>; Wiles, Keith <keith.wiles@intel.com>; Mcnamara, John <john.mcnamara@intel.com>; Byrne, Stephen1 <stephen1.byrne@intel.com>; Tamboli, Amit S <amit.tamboli@intel.com>; Padubidri, Sanjay A <sanjay.padubidri@intel.com>; Patel, Amol <amol.patel@intel.com>
Subject: Re: [dpdk-dev] [PATCH v4 2/2] app/pdump: enhance to support multi-core capture


On Tue, Apr 2, 2019 at 6:33 AM Vipin Varghese <vipin.varghese@intel.com<mailto:vipin.varghese@intel.com>> wrote:
Add option --multi, to enhance the pdump application to allow capture
on unique cores for each --pdump option. If option --multi is ignored
the default capture occurs on a single core for all --pdump options.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com<mailto:vipin.varghese@intel.com>>
---
 app/pdump/main.c           | 76 ++++++++++++++++++++++++++++++++------
 doc/guides/tools/pdump.rst |  8 +++-
 2 files changed, 72 insertions(+), 12 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index c1db2eb8d..997c8942f 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -28,6 +28,7 @@
 #include <rte_pdump.h>

 #define CMD_LINE_OPT_PDUMP "pdump"
+#define CMD_LINE_OPT_MULTI "multi"
 #define PDUMP_PORT_ARG "port"
 #define PDUMP_PCI_ARG "device_id"
 #define PDUMP_QUEUE_ARG "queue"
@@ -139,12 +140,14 @@ struct parse_val {
 static int num_tuples;
 static struct rte_eth_conf port_conf_default;
 static volatile uint8_t quit_signal;
+static uint8_t multiple_core_capture;

 /**< display usage */
 static void
 pdump_usage(const char *prgname)
 {
-       printf("usage: %s [EAL options] -- --pdump "
+       printf("usage: %s [EAL options] -- [--multi] "
+                       "--pdump "
                        "'(port=<port id> | device_id=<pci id or vdev name>),"
                        "(queue=<queue_id>),"
                        "(rx-dev=<iface or pcap file> |"

Rather than hardcode the usage, reuse the macro you introduced: CMD_LINE_OPT_MULTI.


@@ -376,6 +379,7 @@ launch_args_parse(int argc, char **argv, char *prgname)
        int option_index;
        static struct option long_option[] = {
                {"pdump", 1, 0, 0},
+               {"multi", 0, 0, 0},
                {NULL, 0, 0, 0}
        };

Idem reuse the macro.

Besides look at lib/librte_eal/common/eal_options.h and lib/librte_eal/common/eal_common_options.c.
Define an enum for long only options and map "multi" to an integer that has no printable character associated.

This way, you can avoid (see below)...

@@ -395,6 +399,10 @@ launch_args_parse(int argc, char **argv, char *prgname)
                                        pdump_usage(prgname);
                                        return -1;
                                }
+                       } else if (!strncmp(long_option[option_index].name,
+                                       CMD_LINE_OPT_MULTI,
+                                       sizeof(CMD_LINE_OPT_MULTI))) {
+                               multiple_core_capture = 1;
                        }
                        break;
                default:

... this strncmp.
getopt_long already matched the input option for you.


--
David Marchand
  

Patch

diff --git a/app/pdump/main.c b/app/pdump/main.c
index c1db2eb8d..997c8942f 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -28,6 +28,7 @@ 
 #include <rte_pdump.h>
 
 #define CMD_LINE_OPT_PDUMP "pdump"
+#define CMD_LINE_OPT_MULTI "multi"
 #define PDUMP_PORT_ARG "port"
 #define PDUMP_PCI_ARG "device_id"
 #define PDUMP_QUEUE_ARG "queue"
@@ -139,12 +140,14 @@  struct parse_val {
 static int num_tuples;
 static struct rte_eth_conf port_conf_default;
 static volatile uint8_t quit_signal;
+static uint8_t multiple_core_capture;
 
 /**< display usage */
 static void
 pdump_usage(const char *prgname)
 {
-	printf("usage: %s [EAL options] -- --pdump "
+	printf("usage: %s [EAL options] -- [--multi] "
+			"--pdump "
 			"'(port=<port id> | device_id=<pci id or vdev name>),"
 			"(queue=<queue_id>),"
 			"(rx-dev=<iface or pcap file> |"
@@ -376,6 +379,7 @@  launch_args_parse(int argc, char **argv, char *prgname)
 	int option_index;
 	static struct option long_option[] = {
 		{"pdump", 1, 0, 0},
+		{"multi", 0, 0, 0},
 		{NULL, 0, 0, 0}
 	};
 
@@ -395,6 +399,10 @@  launch_args_parse(int argc, char **argv, char *prgname)
 					pdump_usage(prgname);
 					return -1;
 				}
+			} else if (!strncmp(long_option[option_index].name,
+					CMD_LINE_OPT_MULTI,
+					sizeof(CMD_LINE_OPT_MULTI))) {
+				multiple_core_capture = 1;
 			}
 			break;
 		default:
@@ -834,23 +842,69 @@  enable_pdump(void)
 	}
 }
 
+static inline void
+pdump_packets(struct pdump_tuples *pt)
+{
+	if (pt->dir & RTE_PDUMP_FLAG_RX)
+		pdump_rxtx(pt->rx_ring, pt->rx_vdev_id, &pt->stats);
+	if (pt->dir & RTE_PDUMP_FLAG_TX)
+		pdump_rxtx(pt->tx_ring, pt->tx_vdev_id, &pt->stats);
+}
+
+static int
+dump_packets_core(void *arg)
+{
+	struct pdump_tuples *pt = (struct pdump_tuples *) arg;
+
+	printf(" core (%u); port %u device (%s) queue %u\n",
+			rte_lcore_id(), pt->port, pt->device_id, pt->queue);
+	fflush(stdout);
+
+	while (!quit_signal)
+		pdump_packets(pt);
+
+	return 0;
+}
+
 static inline void
 dump_packets(void)
 {
 	int i;
-	struct pdump_tuples *pt;
+	uint32_t lcore_id = 0;
+
+	if (!multiple_core_capture) {
+		printf(" core (%u), capture for (%d) tuples\n",
+				rte_lcore_id(), num_tuples);
+		fflush(stdout);
 
-	while (!quit_signal) {
-		for (i = 0; i < num_tuples; i++) {
-			pt = &pdump_t[i];
-			if (pt->dir & RTE_PDUMP_FLAG_RX)
-				pdump_rxtx(pt->rx_ring, pt->rx_vdev_id,
-					&pt->stats);
-			if (pt->dir & RTE_PDUMP_FLAG_TX)
-				pdump_rxtx(pt->tx_ring, pt->tx_vdev_id,
-					&pt->stats);
+		while (!quit_signal) {
+			for (i = 0; i < num_tuples; i++)
+				pdump_packets(&pdump_t[i]);
 		}
+
+		return;
 	}
+
+	/* check if there enough core */
+	if ((uint32_t)num_tuples >= rte_lcore_count()) {
+		printf("Insufficient cores to run parallel!\n");
+		return;
+	}
+
+	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+
+	for (i = 0; i < num_tuples; i++) {
+		rte_eal_remote_launch(dump_packets_core,
+				&pdump_t[i], lcore_id);
+		lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+
+		if (rte_eal_wait_lcore(lcore_id) < 0)
+			rte_exit(EXIT_FAILURE, "failed to wait\n");
+	}
+
+	/* master core */
+	while (!quit_signal)
+		;
 }
 
 int
diff --git a/doc/guides/tools/pdump.rst b/doc/guides/tools/pdump.rst
index 7c2b73e72..dd60cb812 100644
--- a/doc/guides/tools/pdump.rst
+++ b/doc/guides/tools/pdump.rst
@@ -35,6 +35,7 @@  The tool has a number of command line options:
 .. code-block:: console
 
    ./build/app/dpdk-pdump --
+                          [--multi]
                           --pdump '(port=<port id> | device_id=<pci id or vdev name>),
                                    (queue=<queue_id>),
                                    (rx-dev=<iface or pcap file> |
@@ -43,6 +44,10 @@  The tool has a number of command line options:
                                    [mbuf-size=<mbuf data size>],
                                    [total-num-mbufs=<number of mbufs>]'
 
+The ``--multi`` command line option is optional argument. If passed, capture
+will be running on unqiue cores for all ``--pdump`` options. If ignored,
+capture will be running on single core for all ``--pdump`` options.
+
 The ``--pdump`` command line option is mandatory and it takes various sub arguments which are described in
 below section.
 
@@ -112,4 +117,5 @@  Example
 
 .. code-block:: console
 
-   $ sudo ./build/app/dpdk-pdump -- --pdump 'port=0,queue=*,rx-dev=/tmp/rx.pcap'
+   $ sudo ./build/app/dpdk-pdump -l 3 -- --pdump 'port=0,queue=*,rx-dev=/tmp/rx.pcap'
+   $ sudo ./build/app/dpdk-pdump -l 3,4,5 -- --multi --pdump 'port=0,queue=*,rx-dev=/tmp/rx-1.pcap' --pdump 'port=1,queue=*,rx-dev=/tmp/rx-2.pcap'