From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 67DA9B372 for ; Tue, 16 Sep 2014 14:08:07 +0200 (CEST) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by orsmga102.jf.intel.com with ESMTP; 16 Sep 2014 05:07:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,534,1406617200"; d="scan'208";a="477854469" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by azsmga001.ch.intel.com with ESMTP; 16 Sep 2014 05:13:40 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s8GCDZUr020138; Tue, 16 Sep 2014 13:13:36 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id s8GCDZZF016911; Tue, 16 Sep 2014 13:13:35 +0100 Received: (from reshmapa@localhost) by sivswdev02.ir.intel.com with id s8GCDZDJ016907; Tue, 16 Sep 2014 13:13:35 +0100 From: reshmapa To: dev@dpdk.org Date: Tue, 16 Sep 2014 13:13:26 +0100 Message-Id: <1410869607-16842-3-git-send-email-reshma.pattan@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1410869607-16842-1-git-send-email-reshma.pattan@intel.com> References: <1410869607-16842-1-git-send-email-reshma.pattan@intel.com> Subject: [dpdk-dev] [PATCH 2/3] distributor_app: code review comments implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Sep 2014 12:08:08 -0000 From: Reshma Pattan * 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 --- 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 #include #include +#include #include #include @@ -42,6 +43,7 @@ #include #include #include + #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