DPDK patches and discussions
 help / color / mirror / Atom feed
From: reshmapa <reshma.pattan@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 2/3] distributor_app: code review comments implementation
Date: Tue, 16 Sep 2014 13:13:26 +0100	[thread overview]
Message-ID: <1410869607-16842-3-git-send-email-reshma.pattan@intel.com> (raw)
In-Reply-To: <1410869607-16842-1-git-send-email-reshma.pattan@intel.com>

From: Reshma Pattan <reshma.pattan@intel.com>

    * support provided for command-line option portmask.
    * removed -g option in make file
    * spacing adjustment in header files inclusion in main.c
    * removal of const +3 in delcarration of rte_mbuf inside
      output_buffer structure declaration

    Changes in V2:

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 examples/distributor_app/Makefile |   2 +-
 examples/distributor_app/main.c   | 137 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 133 insertions(+), 6 deletions(-)

diff --git a/examples/distributor_app/Makefile b/examples/distributor_app/Makefile
index d46746e..394785d 100644
--- a/examples/distributor_app/Makefile
+++ b/examples/distributor_app/Makefile
@@ -52,6 +52,6 @@ ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
 CFLAGS_main.o += -Wno-return-type
 endif
 
-EXTRA_CFLAGS += -O3 -g -Wfatal-errors
+EXTRA_CFLAGS += -O3 -Wfatal-errors
 
 include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/distributor_app/main.c b/examples/distributor_app/main.c
index 45d5bc1..fab8199 100644
--- a/examples/distributor_app/main.c
+++ b/examples/distributor_app/main.c
@@ -35,6 +35,7 @@
 #include <inttypes.h>
 #include <unistd.h>
 #include <signal.h>
+#include <getopt.h>
 
 #include <rte_eal.h>
 #include <rte_ethdev.h>
@@ -42,6 +43,7 @@
 #include <rte_malloc.h>
 #include <rte_debug.h>
 #include <rte_distributor.h>
+
 #include "main.h"
 
 #define RX_RING_SIZE 256
@@ -66,6 +68,9 @@
 #define BURST_SIZE 32
 #define RTE_RING_SZ 1024
 
+/* mask of enabled ports */
+static uint32_t enabled_port_mask = 0;
+
 static volatile struct app_stats {
 	struct {
 		uint64_t rx_pkts;
@@ -127,7 +132,7 @@ static const struct rte_eth_txconf tx_conf_default = {
 
 struct output_buffer {
 	unsigned count;
-	struct rte_mbuf *mbufs[BURST_SIZE + 3];
+	struct rte_mbuf *mbufs[BURST_SIZE];
 };
 
 /*
@@ -210,16 +215,27 @@ lcore_rx(struct lcore_params *p)
 	const int socket_id = rte_socket_id();
 	uint8_t port;
 
-	for (port = 0; port < nb_ports; port++)
+	for (port = 0; port < nb_ports; port++){
+		/* skip ports that are not enabled */
+		if ((enabled_port_mask & (1 << port)) == 0){
+			continue;
+		}
 		if (rte_eth_dev_socket_id(port) > 0 &&
 				rte_eth_dev_socket_id(port) != socket_id)
 			printf("WARNING, port %u is on remote NUMA node to "
 					"RX thread.\n\tPerformance will not "
 					"be optimal.\n", port);
+	}
 
 	printf("\nCore %u doing packet RX.\n", rte_lcore_id());
 	port = 0;
 	for (;;) {
+		/* skip ports that are not enabled */ 
+		if ((enabled_port_mask & (1 << port)) == 0){
+			if (++port == nb_ports)
+				port = 0;
+			continue;
+		}
 		struct rte_mbuf *bufs[BURST_SIZE*2];
 		const uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs,
 				BURST_SIZE);
@@ -265,6 +281,11 @@ flush_all_ports(struct output_buffer *tx_buffers, uint8_t nb_ports)
 {
 	uint8_t outp;
 	for (outp = 0; outp < nb_ports; outp++) {
+		/* skip ports that are not enabled */
+		if ((enabled_port_mask & (1 << outp)) == 0){
+			continue; 
+		}
+
 		if (tx_buffers[outp].count == 0)
 			continue;
 
@@ -280,16 +301,25 @@ lcore_tx(struct rte_ring *in_r)
 	const int socket_id = rte_socket_id();
 	uint8_t port;
 
-	for (port = 0; port < nb_ports; port++)
+	for (port = 0; port < nb_ports; port++){
+		/* skip ports that are not enabled */ 
+		if ((enabled_port_mask & (1 << port)) == 0){
+			continue;
+		}
 		if (rte_eth_dev_socket_id(port) > 0 &&
 				rte_eth_dev_socket_id(port) != socket_id)
 			printf("WARNING, port %u is on remote NUMA node to "
 					"TX thread.\n\tPerformance will not "
 					"be optimal.\n", port);
+	}
 
 	printf("\nCore %u doing packet TX.\n", rte_lcore_id());
 	for (;;) {
 		for (port = 0; port < nb_ports; port++) {
+			/* skip ports that are not enabled */ 
+			if ((enabled_port_mask & (1 << port)) == 0){
+				continue;
+			}
 			struct rte_mbuf *bufs[BURST_SIZE];
 			const uint16_t nb_rx = rte_ring_dequeue_burst(in_r,
 					(void *)bufs, BURST_SIZE);
@@ -313,6 +343,10 @@ lcore_tx(struct rte_ring *in_r)
 				/* workers should update in_port to hold the
 				 * output port value */
 				outp = bufs[i]->pkt.in_port;
+				/* skip ports that are not enabled */
+				if ((enabled_port_mask & (1 << outp)) == 0){
+					continue;
+				}
 				outbuf = &tx_buffers[outp];
 				outbuf->mbufs[outbuf->count++] = bufs[i];
 				if (outbuf->count == BURST_SIZE)
@@ -370,6 +404,77 @@ int_handler(int sig_num)
 	exit(0);
 }
 
+/* display usage */
+static void
+print_usage(const char *prgname)
+{
+        printf("%s [EAL options] -- -p PORTMASK\n"
+               "  -p PORTMASK: hexadecimal bitmask of ports to configure\n",
+               prgname);
+}
+
+static int
+parse_portmask(const char *portmask)
+{
+        char *end = NULL;
+        unsigned long pm;
+
+        /* parse hexadecimal string */
+        pm = strtoul(portmask, &end, 16);
+        if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
+                return -1;
+
+        if (pm == 0)
+                return -1;
+
+        return pm;
+}
+
+/* Parse the argument given in the command line of the application */
+static int 
+parse_args(int argc, char **argv)
+{
+        int opt;
+        char **argvopt;
+        int option_index;
+        char *prgname = argv[0];
+        static struct option lgopts[] = { 
+                {NULL, 0, 0, 0}
+        };  
+
+        argvopt = argv;
+
+        while ((opt = getopt_long(argc, argvopt, "p:",
+                                  lgopts, &option_index)) != EOF) {
+
+                switch (opt) {
+                /* portmask */
+                case 'p':
+                        enabled_port_mask = parse_portmask(optarg);
+                        if (enabled_port_mask == 0) {
+                                printf("invalid portmask\n");
+                                print_usage(prgname);
+                                return -1; 
+                        }   
+                        break;
+		
+		default:
+			print_usage(prgname);
+			return -1;
+		}
+        }
+	
+	if (optind <= 1) {
+		print_usage(prgname);
+		return -1;
+	}
+
+	argv[optind-1] = prgname;
+
+        optind = 0; /* reset getopt lib */
+        return 0;
+}
+
 /* Main function, does initialization and calls the per-lcore functions */
 int
 MAIN(int argc, char *argv[])
@@ -380,6 +485,7 @@ MAIN(int argc, char *argv[])
 	unsigned lcore_id, worker_id = 0;
 	unsigned nb_ports;
 	uint8_t portid;
+	uint8_t nb_ports_available;
 
 	/* catch ctrl-c so we can print on exit */
 	signal(SIGINT, int_handler);
@@ -391,6 +497,11 @@ MAIN(int argc, char *argv[])
 	argc -= ret;
 	argv += ret;
 
+        /* parse application arguments (after the EAL ones) */
+        ret = parse_args(argc, argv);
+        if (ret < 0) 
+                rte_exit(EXIT_FAILURE, "Invalid distributor parameters\n");
+
 	if (rte_lcore_count() < 3)
 		rte_exit(EXIT_FAILURE, "Error, This application needs at "
 				"least 3 logical cores to run:\n"
@@ -417,11 +528,28 @@ MAIN(int argc, char *argv[])
 	if (mbuf_pool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
 
+	nb_ports_available = nb_ports;
+
 	/* initialize all ports */
-	for (portid = 0; portid < nb_ports; portid++)
+	for (portid = 0; portid < nb_ports; portid++){
+		/* skip ports that are not enabled */
+		if ((enabled_port_mask & (1 << portid)) == 0){
+			printf("\nSkipping disabled port %d\n", portid);
+			nb_ports_available--;
+			continue;
+		}
+		/* init port */
+                printf("Initializing port %u... done\n", (unsigned) portid);
+
 		if (port_init(portid, mbuf_pool) != 0)
 			rte_exit(EXIT_FAILURE, "Cannot initialize port %"PRIu8"\n",
 					portid);
+	}
+
+        if (!nb_ports_available) {
+                rte_exit(EXIT_FAILURE,
+                        "All available ports are disabled. Please set portmask.\n");
+        }   
 
 	d = rte_distributor_create("PKT_DIST", rte_socket_id(),
 			rte_lcore_count() - 2);
@@ -456,4 +584,3 @@ MAIN(int argc, char *argv[])
 	lcore_rx(&p);
 	return 0;
 }
-
-- 
1.8.3.1

  parent reply	other threads:[~2014-09-16 12:08 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-16 12:13 [dpdk-dev] [PATCH 0/3] distributor_app: new sample application for distributor library reshmapa
2014-09-16 12:13 ` [dpdk-dev] [PATCH 1/3] distributor_app: new sample app reshmapa
2014-09-16 12:13 ` reshmapa [this message]
2014-09-16 12:13 ` [dpdk-dev] [PATCH 3/3] distributor_app: removed extra spaces reshmapa
2014-09-23 12:55 ` [dpdk-dev] [PATCH 0/3] distributor_app: new sample application for distributor library Bruce Richardson
2014-09-24 14:16 ` [dpdk-dev] [PATCH v2] distributor_app: new sample app reshmapa
2014-09-26 15:11   ` De Lara Guarch, Pablo
2014-09-26 15:51     ` Ananyev, Konstantin
2014-09-29 12:39       ` Pattan, Reshma
2014-09-29 13:06         ` Ananyev, Konstantin
2014-09-29 13:35           ` De Lara Guarch, Pablo
2014-09-29 14:35             ` Neil Horman
2014-09-30  8:02             ` Pattan, Reshma
2014-09-30  9:21               ` Ananyev, Konstantin
2014-09-30 10:39   ` [dpdk-dev] [PATCH v3] " reshmapa
2014-09-30 11:34     ` Neil Horman
2014-09-30 12:18       ` Bruce Richardson
2014-09-30 13:39         ` Neil Horman
2014-10-01 14:47           ` Pattan, Reshma
2014-10-01 14:56             ` Neil Horman
2014-10-01 15:37               ` Bruce Richardson
2014-10-01 16:07                 ` Neil Horman
2014-10-06 14:16                   ` Pattan, Reshma
2014-10-06 14:44                     ` Neil Horman
2014-10-06 17:34                       ` Pattan, Reshma
2014-10-06 19:02                         ` Neil Horman
2014-10-02  9:04                 ` Ananyev, Konstantin
2014-10-01 13:33     ` [dpdk-dev] [PATCH v4] distributor_app: gracefull shutdown of tx/rx threads on SIGINT reshmapa
2014-10-01 13:46       ` Pattan, Reshma
2014-10-01 13:49       ` Thomas Monjalon
2014-10-01 14:33       ` [dpdk-dev] [PATCH v5] distributor_app: new sample app reshmapa
2014-10-17 13:59         ` [dpdk-dev] [PATCH v6] " Reshma Pattan
2014-11-02 20:08           ` De Lara Guarch, Pablo
2014-11-03 15:49           ` [dpdk-dev] [PATCH v7] " Reshma Pattan
2014-11-03 16:03             ` De Lara Guarch, Pablo
2014-11-13 21:30               ` Thomas Monjalon
2014-11-14  8:44                 ` Pattan, Reshma
2014-11-16 21:59                   ` 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=1410869607-16842-3-git-send-email-reshma.pattan@intel.com \
    --to=reshma.pattan@intel.com \
    --cc=dev@dpdk.org \
    /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).