From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sclab-apps-2.localdomain (sc-fw1.tilera.com [12.218.212.162]) by dpdk.org (Postfix) with ESMTP id 9011AC94E for ; Fri, 19 Jun 2015 23:29:41 +0200 (CEST) X-CheckPoint: {558489C4-6-A3D4DA0C-C0000002} Received: by sclab-apps-2.localdomain (Postfix, from userid 1318) id 8A22E2202E6; Fri, 19 Jun 2015 14:29:40 -0700 (PDT) From: Cyril Chemparathy To: dev@dpdk.org Date: Fri, 19 Jun 2015 14:29:38 -0700 Message-Id: <1434749378-8578-2-git-send-email-cchemparathy@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1434749378-8578-1-git-send-email-cchemparathy@ezchip.com> References: <1434749378-8578-1-git-send-email-cchemparathy@ezchip.com> Subject: [dpdk-dev] [PATCH] examples/l2fwd: Add forward count limit. 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: Fri, 19 Jun 2015 21:29:52 -0000 This commit adds a forward count argument, which is used to terminate the test once a certain number of packets have been forwarded. Change-Id: Ia3e7ff5d41c3e947509b0653d53271b882fc04de Signed-off-by: Cyril Chemparathy --- examples/l2fwd/main.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index 720fd5a..20c1dd2 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -137,7 +137,9 @@ struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS]; /* A tsc-based timer responsible for triggering statistics printout */ #define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */ #define MAX_TIMER_PERIOD 86400 /* 1 day max */ +#define MAX_FORWARD_COUNT 1000000000 /* a cool billion :) */ static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */ +static int64_t forward_count; /* Print out statistics on packets dropped */ static void @@ -262,6 +264,7 @@ l2fwd_main_loop(void) unsigned i, j, portid, nb_rx; struct lcore_queue_conf *qconf; const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US; + uint64_t total_packets_tx; prev_tsc = 0; timer_tsc = 0; @@ -321,6 +324,17 @@ l2fwd_main_loop(void) } prev_tsc = cur_tsc; + + if (forward_count > 0) { + total_packets_tx = 0; + for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { + /* skip disabled ports */ + if ((l2fwd_enabled_port_mask & (1 << portid)) != 0) + total_packets_tx += port_statistics[portid].tx; + } + if (total_packets_tx >= forward_count) + break; + } } /* @@ -357,7 +371,8 @@ l2fwd_usage(const char *prgname) printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n" " -p PORTMASK: hexadecimal bitmask of ports to configure\n" " -q NQ: number of queue (=ports) per lcore (default is 1)\n" - " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n", + " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n" + " -C COUNT: exit after transmitting COUNT packets\n", prgname); } @@ -412,6 +427,22 @@ l2fwd_parse_timer_period(const char *q_arg) return n; } +static int +l2fwd_parse_forward_count(const char *q_arg) +{ + char *end = NULL; + int n; + + /* parse number string */ + n = strtol(q_arg, &end, 10); + if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) + return -1; + if (n >= MAX_FORWARD_COUNT) + return -1; + + return n; +} + /* Parse the argument given in the command line of the application */ static int l2fwd_parse_args(int argc, char **argv) @@ -426,7 +457,7 @@ l2fwd_parse_args(int argc, char **argv) argvopt = argv; - while ((opt = getopt_long(argc, argvopt, "p:q:T:", + while ((opt = getopt_long(argc, argvopt, "p:q:T:C:", lgopts, &option_index)) != EOF) { switch (opt) { @@ -460,6 +491,16 @@ l2fwd_parse_args(int argc, char **argv) } break; + /* forward count */ + case 'C': + forward_count = l2fwd_parse_forward_count(optarg); + if (forward_count < 0) { + printf("invalid forward count\n"); + l2fwd_usage(prgname); + return -1; + } + break; + /* long options */ case 0: l2fwd_usage(prgname); @@ -702,6 +743,7 @@ main(int argc, char **argv) if (rte_eal_wait_lcore(lcore_id) < 0) return -1; } + print_stats(); return 0; } -- 2.1.2