From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 45775B385 for ; Mon, 25 Aug 2014 08:09:42 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 24 Aug 2014 23:13:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,395,1406617200"; d="scan'208";a="562947739" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga001.jf.intel.com with ESMTP; 24 Aug 2014 23:13:34 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id s7P6DWbH012203; Mon, 25 Aug 2014 14:13:32 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s7P6DTAo011389; Mon, 25 Aug 2014 14:13:31 +0800 Received: (from cliang18@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s7P6DSqI011385; Mon, 25 Aug 2014 14:13:28 +0800 From: Cunming Liang To: dev@dpdk.org Date: Mon, 25 Aug 2014 14:12:51 +0800 Message-Id: <1408947174-11323-3-git-send-email-cunming.liang@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1408947174-11323-1-git-send-email-cunming.liang@intel.com> References: <1408947174-11323-1-git-send-email-cunming.liang@intel.com> Subject: [dpdk-dev] [PATCH 2/5] app/test: measure standalone rx or tx cycles/packet 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: Mon, 25 Aug 2014 06:09:43 -0000 Signed-off-by: Cunming Liang Acked-by: Bruce Richardson --- app/test/commands.c | 38 ++++++++++ app/test/test.h | 1 + app/test/test_pmd_perf.c | 175 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 185 insertions(+), 29 deletions(-) diff --git a/app/test/commands.c b/app/test/commands.c index d0e583e..8721e25 100644 --- a/app/test/commands.c +++ b/app/test/commands.c @@ -490,6 +490,43 @@ cmdline_parse_inst_t cmd_set_rxtx = { /****************/ +/****************/ + +struct cmd_set_rxtx_anchor { + cmdline_fixed_string_t set; + cmdline_fixed_string_t type; +}; + +static void +cmd_set_rxtx_anchor_parsed(void *parsed_result, + struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_rxtx_anchor *res = parsed_result; + if (test_set_rxtx_anchor(res->type) < 0) + cmdline_printf(cl, "Cannot find such anchor\n"); +} + +cmdline_parse_token_string_t cmd_set_rxtx_anchor_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, set, + "set_rxtx_anchor"); + +cmdline_parse_token_string_t cmd_set_rxtx_anchor_type = + TOKEN_STRING_INITIALIZER(struct cmd_set_rxtx_anchor, type, NULL); + +cmdline_parse_inst_t cmd_set_rxtx_anchor = { + .f = cmd_set_rxtx_anchor_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = "set rxtx anchor: " + "set_rxtx_anchor ", + .tokens = { /* token list, NULL terminated */ + (void *)&cmd_set_rxtx_anchor_set, + (void *)&cmd_set_rxtx_anchor_type, + NULL, + }, +}; + +/****************/ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_autotest, @@ -498,6 +535,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_ring, (cmdline_parse_inst_t *)&cmd_quit, (cmdline_parse_inst_t *)&cmd_set_rxtx, + (cmdline_parse_inst_t *)&cmd_set_rxtx_anchor, NULL, }; diff --git a/app/test/test.h b/app/test/test.h index ad01eec..c24ce9f 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -185,6 +185,7 @@ int test_devargs(void); int test_link_bonding(void); int test_pmd_perf(void); int test_set_rxtx_conf(cmdline_fixed_string_t mode); +int test_set_rxtx_anchor(cmdline_fixed_string_t type); int test_pci_run; diff --git a/app/test/test_pmd_perf.c b/app/test/test_pmd_perf.c index ee527d3..5d02fac 100644 --- a/app/test/test_pmd_perf.c +++ b/app/test/test_pmd_perf.c @@ -364,6 +364,125 @@ signal_handler(int signum) #define MAX_TRAFIC_BURST (4096) struct rte_mbuf *tx_burst[MAX_TRAFIC_BURST]; +uint64_t (*do_measure)(struct lcore_conf *conf, + struct rte_mbuf *pkts_burst[], + uint64_t total_pkts); + +static uint64_t +measure_rxtx(struct lcore_conf *conf, + struct rte_mbuf *pkts_burst[], + uint64_t total_pkts) +{ + unsigned i, portid, nb_rx, nb_tx; + uint64_t prev_tsc, cur_tsc; + + prev_tsc = rte_rdtsc(); + + while (likely(!stop)) { + for (i = 0; i < conf->nb_ports; i++) { + portid = conf->portlist[i]; + nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, + pkts_burst, MAX_PKT_BURST); + if (unlikely(nb_rx == 0)) { + idle++; + continue; + } + + count += nb_rx; + nb_tx = rte_eth_tx_burst(portid, 0, pkts_burst, nb_rx); + if (unlikely(nb_tx < nb_rx)) { + drop += (nb_rx - nb_tx); + do { + rte_pktmbuf_free(pkts_burst[nb_tx]); + } while (++nb_tx < nb_rx); + } + } + if (unlikely(count >= total_pkts)) + break; + } + + cur_tsc = rte_rdtsc(); + + return cur_tsc - prev_tsc; +} + +static uint64_t +measure_rxonly(struct lcore_conf *conf, + struct rte_mbuf *pkts_burst[], + uint64_t total_pkts) +{ + unsigned i, portid, nb_rx, nb_tx; + uint64_t diff_tsc, cur_tsc; + + diff_tsc = 0; + while (likely(!stop)) { + for (i = 0; i < conf->nb_ports; i++) { + portid = conf->portlist[i]; + + cur_tsc = rte_rdtsc(); + nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, + pkts_burst, MAX_PKT_BURST); + if (unlikely(nb_rx == 0)) { + idle++; + continue; + } + diff_tsc += rte_rdtsc() - cur_tsc; + + count += nb_rx; + nb_tx = rte_eth_tx_burst(portid, 0, pkts_burst, nb_rx); + if (unlikely(nb_tx < nb_rx)) { + drop += (nb_rx - nb_tx); + do { + rte_pktmbuf_free(pkts_burst[nb_tx]); + } while (++nb_tx < nb_rx); + } + } + if (unlikely(count >= total_pkts)) + break; + } + + return diff_tsc; +} + +static uint64_t +measure_txonly(struct lcore_conf *conf, + struct rte_mbuf *pkts_burst[], + uint64_t total_pkts) +{ + unsigned i, portid, nb_rx, nb_tx; + uint64_t diff_tsc, cur_tsc; + + printf("do tx measure\n"); + diff_tsc = 0; + while (likely(!stop)) { + for (i = 0; i < conf->nb_ports; i++) { + portid = conf->portlist[i]; + nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, + pkts_burst, MAX_PKT_BURST); + if (unlikely(nb_rx == 0)) { + idle++; + continue; + } + + count += nb_rx; + + cur_tsc = rte_rdtsc(); + nb_tx = rte_eth_tx_burst(portid, 0, pkts_burst, nb_rx); + if (unlikely(nb_tx < nb_rx)) { + drop += (nb_rx - nb_tx); + do { + rte_pktmbuf_free(pkts_burst[nb_tx]); + } while (++nb_tx < nb_rx); + } + diff_tsc += rte_rdtsc() - cur_tsc; + } + if (unlikely(count >= total_pkts)) + break; + } + + return diff_tsc; +} + /* main processing loop */ static int main_loop(__rte_unused void *args) @@ -375,8 +494,8 @@ main_loop(__rte_unused void *args) unsigned lcore_id; unsigned i, portid, nb_rx = 0, nb_tx = 0; struct lcore_conf *conf; - uint64_t prev_tsc, cur_tsc; int pkt_per_port; + uint64_t diff_tsc; uint64_t packets_per_second, total_packets; lcore_id = rte_lcore_id(); @@ -410,32 +529,7 @@ main_loop(__rte_unused void *args) printf("Test will stop after at least %"PRIu64" packets received\n", + total_packets); - prev_tsc = rte_rdtsc(); - - while (likely(!stop)) { - for (i = 0; i < conf->nb_ports; i++) { - portid = conf->portlist[i]; - nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, - pkts_burst, MAX_PKT_BURST); - if (unlikely(nb_rx == 0)) { - idle++; - continue; - } - - count += nb_rx; - nb_tx = rte_eth_tx_burst(portid, 0, pkts_burst, nb_rx); - if (unlikely(nb_tx < nb_rx)) { - drop += (nb_rx - nb_tx); - do { - rte_pktmbuf_free(pkts_burst[nb_tx]); - } while (++nb_tx < nb_rx); - } - } - if (unlikely(count >= total_packets)) - break; - } - - cur_tsc = rte_rdtsc(); + diff_tsc = do_measure(conf, pkts_burst, total_packets); for (i = 0; i < conf->nb_ports; i++) { portid = conf->portlist[i]; @@ -455,7 +549,7 @@ main_loop(__rte_unused void *args) return -1; printf("%lu packet, %lu drop, %lu idle\n", count, drop, idle); - printf("Result: %ld cycles per packet\n", (cur_tsc - prev_tsc) / count); + printf("Result: %ld cycles per packet\n", diff_tsc / count); return 0; } @@ -559,6 +653,10 @@ test_pmd_perf(void) init_traffic(mbufpool[socketid], tx_burst, MAX_TRAFIC_BURST); + /* do both rxtx by default */ + if (NULL == do_measure) + do_measure = measure_rxtx; + rte_eal_remote_launch(main_loop, NULL, slave_id); if (rte_eal_wait_lcore(slave_id) < 0) return -1; @@ -577,7 +675,7 @@ test_pmd_perf(void) int test_set_rxtx_conf(cmdline_fixed_string_t mode) { - printf("mode is %s\n", mode); + printf("mode switch to %s\n", mode); if (!strcmp(mode, "vector")) { /* vector rx, tx */ @@ -618,3 +716,22 @@ test_set_rxtx_conf(cmdline_fixed_string_t mode) return -1; } + +int +test_set_rxtx_anchor(cmdline_fixed_string_t type) +{ + printf("type switch to %s\n", type); + + if (!strcmp(type, "rxtx")) { + do_measure = measure_rxtx; + return 0; + } else if (!strcmp(type, "rxonly")) { + do_measure = measure_rxonly; + return 0; + } else if (!strcmp(type, "txonly")) { + do_measure = measure_txonly; + return 0; + } + + return -1; +} -- 1.8.1.4