From: Cyril Chemparathy <cchemparathy@ezchip.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] examples/l2fwd: Add forward count limit.
Date: Fri, 19 Jun 2015 14:29:38 -0700 [thread overview]
Message-ID: <1434749378-8578-2-git-send-email-cchemparathy@ezchip.com> (raw)
In-Reply-To: <1434749378-8578-1-git-send-email-cchemparathy@ezchip.com>
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 <cchemparathy@ezchip.com>
---
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
next prev parent reply other threads:[~2015-06-19 21:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-19 21:29 [dpdk-dev] [PATCH] mk: add support for gdb debug info generation Cyril Chemparathy
2015-06-19 21:29 ` Cyril Chemparathy [this message]
2015-07-10 14:20 ` [dpdk-dev] [PATCH] examples/l2fwd: Add forward count limit Thomas Monjalon
2015-06-22 7:44 ` [dpdk-dev] [PATCH] mk: add support for gdb debug info generation Gonzalez Monroy, Sergio
2015-06-22 7:56 ` Simon Kågström
2015-06-23 7:39 ` Gonzalez Monroy, Sergio
2015-06-23 7:47 ` Thomas Monjalon
2015-06-23 10:08 ` Simon Kågström
2015-06-22 16:41 ` Cyril Chemparathy
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=1434749378-8578-2-git-send-email-cchemparathy@ezchip.com \
--to=cchemparathy@ezchip.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).