DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dharmik Thakkar <dharmik.thakkar@arm.com>
To: Wenzhuo Lu <wenzhuo.lu@intel.com>,
	Beilei Xing <beilei.xing@intel.com>,
	Bernard Iremonger <bernard.iremonger@intel.com>
Cc: dev@dpdk.org, nd@arm.com, Dharmik Thakkar <dharmik.thakkar@arm.com>
Subject: [dpdk-dev] [PATCH 1/6] app/testpmd: add record-core-cycles runtime config
Date: Tue, 14 Jul 2020 16:51:03 -0500	[thread overview]
Message-ID: <20200714215108.22437-2-dharmik.thakkar@arm.com> (raw)
In-Reply-To: <20200714215108.22437-1-dharmik.thakkar@arm.com>

Convert CONFIG_RTE_TEST_PMD_RECORD_CORE_CYCLES to a
runtime configuration.

Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
Tested-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
 app/test-pmd/5tswap.c     | 16 +++-----------
 app/test-pmd/cmdline.c    | 46 +++++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c     |  6 +++++
 app/test-pmd/csumonly.c   | 16 +++-----------
 app/test-pmd/flowgen.c    | 17 ++++-----------
 app/test-pmd/icmpecho.c   | 16 +++-----------
 app/test-pmd/iofwd.c      | 18 ++++-----------
 app/test-pmd/macfwd.c     | 17 ++++-----------
 app/test-pmd/macswap.c    | 16 +++-----------
 app/test-pmd/parameters.c |  6 ++++-
 app/test-pmd/rxonly.c     | 15 +++----------
 app/test-pmd/testpmd.c    | 44 ++++++++++++++++++-------------------
 app/test-pmd/testpmd.h    | 18 +++++++++++++--
 app/test-pmd/txonly.c     | 16 +++-----------
 14 files changed, 125 insertions(+), 142 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 972f6b93b31d..04f035bb450f 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -105,15 +105,9 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		uint8_t *byte;
 	} h;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -193,11 +187,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 			rte_pktmbuf_free(pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine five_tuple_swap_fwd_engine = {
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 39a1e772ed7c..1f30a9021500 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -529,6 +529,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set the option to hide the zero values"
 			" for xstats display.\n"
 
+			"set record-core-cycles on|off\n"
+			"    Set the option to enable measurement of CPU cycles.\n"
+
 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
 
@@ -8335,6 +8338,48 @@ cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
 	},
 };
 
+/* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
+struct cmd_set_record_core_cycles_result {
+	cmdline_fixed_string_t keyword;
+	cmdline_fixed_string_t name;
+	cmdline_fixed_string_t on_off;
+};
+
+static void
+cmd_set_record_core_cycles_parsed(void *parsed_result,
+			__rte_unused struct cmdline *cl,
+			__rte_unused void *data)
+{
+	struct cmd_set_record_core_cycles_result *res;
+	uint16_t on_off = 0;
+
+	res = parsed_result;
+	on_off = !strcmp(res->on_off, "on") ? 1 : 0;
+	set_record_core_cycles(on_off);
+}
+
+cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
+				 keyword, "set");
+cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
+				 name, "record-core-cycles");
+cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
+				 on_off, "on#off");
+
+cmdline_parse_inst_t cmd_set_record_core_cycles = {
+	.f = cmd_set_record_core_cycles_parsed,
+	.data = NULL,
+	.help_str = "set record-core-cycles on|off",
+	.tokens = {
+		(void *)&cmd_set_record_core_cycles_keyword,
+		(void *)&cmd_set_record_core_cycles_name,
+		(void *)&cmd_set_record_core_cycles_on_off,
+		NULL,
+	},
+};
+
 /* *** CONFIGURE UNICAST HASH TABLE *** */
 struct cmd_set_uc_hash_table {
 	cmdline_fixed_string_t set;
@@ -19487,6 +19532,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
 	(cmdline_parse_inst_t *)&cmd_set_qmap,
 	(cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
+	(cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
 	(cmdline_parse_inst_t *)&cmd_operate_port,
 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index fcbe6b6f7440..d93699b34e3a 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -3679,6 +3679,12 @@ set_xstats_hide_zero(uint8_t on_off)
 	xstats_hide_zero = on_off;
 }
 
+void
+set_record_core_cycles(uint8_t on_off)
+{
+	record_core_cycles = on_off;
+}
+
 static inline void
 print_fdir_mask(struct rte_eth_fdir_masks *mask)
 {
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 0a96b24eb27b..836bafa0f6df 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -789,15 +789,9 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint16_t nb_segments = 0;
 	int ret;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/* receive a burst of packet */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
@@ -1098,11 +1092,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 		} while (++nb_tx < nb_rx);
 	}
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine csum_fwd_engine = {
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 4bd351e6754a..e92a0eeca254 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -97,16 +97,10 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t i;
 	uint32_t retry;
 	uint64_t tx_offloads;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
+	uint64_t start_tsc = 0;
 	static int next_flow = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/* Receive a burst of packets and discard them. */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
@@ -207,11 +201,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 			rte_pktmbuf_free(pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_pkt);
 	}
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine flow_gen_engine = {
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 78e3adf2c106..3f27e8c29d33 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -293,15 +293,9 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	uint32_t cksum;
 	uint8_t  i;
 	int l2_len;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/*
 	 * First, receive a burst of packets.
@@ -520,11 +514,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		}
 	}
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine icmp_echo_engine = {
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 22b59bbdaf5a..456f7b5925ed 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -50,16 +50,9 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
-
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -96,11 +89,8 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 			rte_pktmbuf_free(pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine io_fwd_engine = {
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 0a89d94befe5..6a77568c7e60 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -56,15 +56,9 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	uint16_t i;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -126,11 +120,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 			rte_pktmbuf_free(pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine mac_fwd_engine = {
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index fbe8cb39e5d2..aaef5b0047b1 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -57,15 +57,9 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -105,11 +99,7 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 			rte_pktmbuf_free(pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine mac_swap_engine = {
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 7cb0e3d6ec0a..76072ae81b93 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -70,7 +70,7 @@ usage(char* progname)
 	       "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
 	       "--txpt= | --txht= | --txwt= | --txfreet= | "
 	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
-	       "--vxlan-gpe-port= ]\n",
+	       "--vxlan-gpe-port= | --record-core-cycles]\n",
 	       progname);
 #ifdef RTE_LIBRTE_CMDLINE
 	printf("  --interactive: run in interactive mode.\n");
@@ -216,6 +216,7 @@ usage(char* progname)
 	       "valid only with --mp-alloc=anon\n");
 	printf("  --rx-mq-mode=0xX: hexadecimal bitmask of RX mq mode can be "
 	       "enabled\n");
+	printf("  --record-core-cycles: enable measurement of CPU cycles.\n");
 }
 
 #ifdef RTE_LIBRTE_CMDLINE
@@ -677,6 +678,7 @@ launch_args_parse(int argc, char** argv)
 		{ "noisy-lkup-num-reads-writes", 1, 0, 0 },
 		{ "no-iova-contig",             0, 0, 0 },
 		{ "rx-mq-mode",                 1, 0, 0 },
+		{ "record-core-cycles",         0, 0, 0 },
 		{ 0, 0, 0, 0 },
 	};
 
@@ -1381,6 +1383,8 @@ launch_args_parse(int argc, char** argv)
 						 "rx-mq-mode must be >= 0 and <= %d\n",
 						 ETH_MQ_RX_VMDQ_DCB_RSS);
 			}
+			if (!strcmp(lgopts[opt_idx].name, "record-core-cycles"))
+				record_core_cycles = 1;
 			break;
 		case 'h':
 			usage(argv[0]);
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index 18d59a68d652..b6c8b8c7d5db 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -49,14 +49,9 @@ pkt_burst_receive(struct fwd_stream *fs)
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
 	uint16_t i;
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets.
@@ -73,11 +68,7 @@ pkt_burst_receive(struct fwd_stream *fs)
 	for (i = 0; i < nb_rx; i++)
 		rte_pktmbuf_free(pkts_burst[i]);
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+	get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine rx_only_engine = {
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 7842c3b78120..f327b16604d2 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -475,6 +475,11 @@ uint16_t nb_rx_queue_stats_mappings = 0;
  */
 uint8_t xstats_hide_zero;
 
+/*
+ * Measure of CPU cycles disabled by default
+ */
+uint8_t record_core_cycles;
+
 unsigned int num_sockets = 0;
 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
 
@@ -1800,9 +1805,7 @@ fwd_stats_display(void)
 	uint64_t total_tx_dropped = 0;
 	uint64_t total_rx_nombuf = 0;
 	struct rte_eth_stats stats;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
 	uint64_t fwd_cycles = 0;
-#endif
 	uint64_t total_recv = 0;
 	uint64_t total_xmit = 0;
 	struct rte_port *port;
@@ -1830,9 +1833,8 @@ fwd_stats_display(void)
 		ports_stats[fs->rx_port].rx_bad_outer_l4_csum +=
 				fs->rx_bad_outer_l4_csum;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-		fwd_cycles += fs->core_cycles;
-#endif
+		if (record_core_cycles)
+			fwd_cycles += fs->core_cycles;
 	}
 	for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
 		uint8_t j;
@@ -1961,24 +1963,24 @@ fwd_stats_display(void)
 	printf("  %s++++++++++++++++++++++++++++++++++++++++++++++"
 	       "%s\n",
 	       acc_stats_border, acc_stats_border);
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
+	if (record_core_cycles) {
 #define CYC_PER_MHZ 1E6
-	if (total_recv > 0 || total_xmit > 0) {
-		uint64_t total_pkts = 0;
-		if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 ||
-		    strcmp(cur_fwd_eng->fwd_mode_name, "flowgen") == 0)
-			total_pkts = total_xmit;
-		else
-			total_pkts = total_recv;
+		if (total_recv > 0 || total_xmit > 0) {
+			uint64_t total_pkts = 0;
+			if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 ||
+			    strcmp(cur_fwd_eng->fwd_mode_name, "flowgen") == 0)
+				total_pkts = total_xmit;
+			else
+				total_pkts = total_recv;
 
-		printf("\n  CPU cycles/packet=%.2F (total cycles="
-		       "%"PRIu64" / total %s packets=%"PRIu64") at %"PRIu64
-		       " MHz Clock\n",
-		       (double) fwd_cycles / total_pkts,
-		       fwd_cycles, cur_fwd_eng->fwd_mode_name, total_pkts,
-		       (uint64_t)(rte_get_tsc_hz() / CYC_PER_MHZ));
+			printf("\n  CPU cycles/packet=%.2F (total cycles="
+			       "%"PRIu64" / total %s packets=%"PRIu64") at %"PRIu64
+			       " MHz Clock\n",
+			       (double) fwd_cycles / total_pkts,
+			       fwd_cycles, cur_fwd_eng->fwd_mode_name, total_pkts,
+			       (uint64_t)(rte_get_tsc_hz() / CYC_PER_MHZ));
+		}
 	}
-#endif
 }
 
 void
@@ -2006,9 +2008,7 @@ fwd_stats_reset(void)
 		memset(&fs->rx_burst_stats, 0, sizeof(fs->rx_burst_stats));
 		memset(&fs->tx_burst_stats, 0, sizeof(fs->tx_burst_stats));
 #endif
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
 		fs->core_cycles = 0;
-#endif
 	}
 }
 
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 25a12b14f29d..dcc37be02d59 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -129,9 +129,7 @@ struct fwd_stream {
 	uint64_t rx_bad_outer_l4_csum;
 	/**< received packets has bad outer l4 checksum */
 	unsigned int gro_times;	/**< GRO operation times */
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
 	uint64_t     core_cycles; /**< used for RX and TX processing */
-#endif
 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
 	struct pkt_burst_stats rx_burst_stats;
 	struct pkt_burst_stats tx_burst_stats;
@@ -301,6 +299,7 @@ extern uint16_t nb_rx_queue_stats_mappings;
 extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */
 
 /* globals used for configuration */
+extern uint8_t record_core_cycles; /**< Enables measurement of CPU cycles */
 extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */
 extern int testpmd_logtype; /**< Log type for testpmd logs */
 extern uint8_t  interactive;
@@ -681,6 +680,20 @@ port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
 #define port_id_pci_reg_write(pt_id, reg_off, reg_value) \
 	port_pci_reg_write(&ports[(pt_id)], (reg_off), (reg_value))
 
+static inline void
+get_start_cycles(uint64_t *start_tsc)
+{
+	if (record_core_cycles)
+		*start_tsc = rte_rdtsc();
+}
+
+static inline void
+get_end_cycles(struct fwd_stream *fs, uint64_t start_tsc)
+{
+	if (record_core_cycles)
+		fs->core_cycles += rte_rdtsc() - start_tsc;
+}
+
 /* Prototypes */
 unsigned int parse_item_list(char* str, const char* item_name,
 			unsigned int max_items,
@@ -772,6 +785,7 @@ void set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_va
 
 void set_xstats_hide_zero(uint8_t on_off);
 
+void set_record_core_cycles(uint8_t on_off);
 void set_verbose_level(uint16_t vb_level);
 void set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs);
 void show_tx_pkt_segments(void);
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 97f4a452da12..00a3a6f90c7a 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -294,15 +294,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	uint32_t retry;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	uint64_t start_tsc;
-	uint64_t end_tsc;
-	uint64_t core_cycles;
-#endif
+	uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	start_tsc = rte_rdtsc();
-#endif
+	get_start_cycles(&start_tsc);
 
 	mbp = current_fwd_lcore()->mbp;
 	txp = &ports[fs->tx_port];
@@ -391,11 +385,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 		} while (++nb_tx < nb_pkt);
 	}
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-	end_tsc = rte_rdtsc();
-	core_cycles = (end_tsc - start_tsc);
-	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+	get_end_cycles(fs, start_tsc);
 }
 
 static void
-- 
2.17.1


  reply	other threads:[~2020-07-14 21:52 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200506215939eucas1p1fd98a671dda83adf884c30d7bf9b77c4@eucas1p1.samsung.com>
2020-05-06 21:58 ` [dpdk-dev] [PATCH 1/5] app/testpmd: print clock with CPU cycles per pkt Dharmik Thakkar
2020-05-06 21:58   ` [dpdk-dev] [PATCH 2/5] app/testpmd: print fractional part in CPU cycles Dharmik Thakkar
2020-05-07  9:50     ` Ananyev, Konstantin
2020-05-07 22:16       ` Dharmik Thakkar
2020-05-08 17:17         ` Ananyev, Konstantin
2020-05-08 17:36           ` Dharmik Thakkar
2020-05-08 18:08             ` Ananyev, Konstantin
2020-05-06 21:58   ` [dpdk-dev] [PATCH 3/5] doc: add cycles per packet in testpmd user guide Dharmik Thakkar
2020-05-07  5:24     ` Jerin Jacob
2020-05-07 22:27       ` Dharmik Thakkar
2020-05-07 14:30     ` Iremonger, Bernard
2020-05-06 21:58   ` [dpdk-dev] [PATCH 4/5] doc: include config options " Dharmik Thakkar
2020-05-07 14:42     ` Iremonger, Bernard
2020-05-06 21:58   ` [dpdk-dev] [PATCH 5/5] doc: add aarch64 generic counter section Dharmik Thakkar
2020-05-07  5:17     ` Jerin Jacob
2020-05-06 22:48   ` [dpdk-dev] [PATCH 1/5] app/testpmd: print clock with CPU cycles per pkt Lukasz Wojciechowski
2020-05-07 13:38   ` Iremonger, Bernard
2020-05-08 22:38   ` [dpdk-dev] [PATCH v2 " Dharmik Thakkar
2020-05-08 22:38     ` [dpdk-dev] [PATCH v2 2/5] app/testpmd: print fractional part in CPU cycles Dharmik Thakkar
2020-05-12 10:19       ` Iremonger, Bernard
2020-05-08 22:38     ` [dpdk-dev] [PATCH v2 3/5] doc: add cycles per packet in testpmd user guide Dharmik Thakkar
2020-05-12 10:20       ` Iremonger, Bernard
2020-05-15 12:15       ` Ferruh Yigit
2020-05-15 20:33         ` Dharmik Thakkar
2020-05-18  9:47           ` Ferruh Yigit
2020-05-18 21:49             ` Dharmik Thakkar
2020-05-19  8:27               ` Ferruh Yigit
2020-05-20  3:20       ` [dpdk-dev] [PATCH v3 1/2] " Dharmik Thakkar
2020-05-20  3:20         ` [dpdk-dev] [PATCH v3 2/2] doc: include config options " Dharmik Thakkar
2020-06-17 18:21           ` Ferruh Yigit
2020-06-17 19:48             ` Thomas Monjalon
2020-06-19 15:38               ` Dharmik Thakkar
2020-06-19 15:43                 ` Thomas Monjalon
2020-06-19 16:13                   ` Dharmik Thakkar
2020-06-22 15:26                     ` Thomas Monjalon
2020-06-29 14:25                       ` Dharmik Thakkar
2020-07-14 21:51           ` [dpdk-dev] [PATCH 0/6] app/testpmd: add runtime config Dharmik Thakkar
2020-07-14 21:51             ` Dharmik Thakkar [this message]
2020-07-14 21:51             ` [dpdk-dev] [PATCH 2/6] doc: add record-core-cycles to testpmd funcs doc Dharmik Thakkar
2020-07-14 21:51             ` [dpdk-dev] [PATCH 3/6] app/testpmd: add record-burst-stats runtime config Dharmik Thakkar
2020-07-14 21:51             ` [dpdk-dev] [PATCH 4/6] doc: add record-burst-stats to testpmd funcs doc Dharmik Thakkar
2020-07-14 21:51             ` [dpdk-dev] [PATCH 5/6] app/testpmd: enable burst stats for noisy vnf mode Dharmik Thakkar
2020-07-14 21:51             ` [dpdk-dev] [PATCH 6/6] app/testpmd: enable empty polls in 5tswap Dharmik Thakkar
2020-07-15  4:29               ` Phil Yang
2020-08-26 16:33             ` [dpdk-dev] [PATCH 0/6] app/testpmd: add runtime config Ferruh Yigit
2020-08-26 16:41               ` Bruce Richardson
2020-08-26 17:07                 ` Dharmik Thakkar
2020-08-26 22:06                   ` Ferruh Yigit
2020-09-10 15:06                     ` Ferruh Yigit
2020-08-26 21:24                 ` Ferruh Yigit
2020-05-20 14:49         ` [dpdk-dev] [PATCH v3 1/2] doc: add cycles per packet in testpmd user guide Ferruh Yigit
2020-05-21 17:41           ` Ferruh Yigit
2020-05-08 22:38     ` [dpdk-dev] [PATCH v2 4/5] doc: include config options " Dharmik Thakkar
2020-05-12 10:20       ` Iremonger, Bernard
2020-05-19  7:42         ` Thomas Monjalon
2020-05-19 22:58           ` Dharmik Thakkar
2020-05-20  7:53             ` Thomas Monjalon
2020-05-20 22:39               ` Dharmik Thakkar
2020-05-19  7:45       ` Thomas Monjalon
2020-05-08 22:38     ` [dpdk-dev] [PATCH v2 5/5] doc: add aarch64 generic counter section Dharmik Thakkar
2020-05-12 10:18     ` [dpdk-dev] [PATCH v2 1/5] app/testpmd: print clock with CPU cycles per pkt Iremonger, Bernard
2020-05-15 12:23     ` Ferruh Yigit

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=20200714215108.22437-2-dharmik.thakkar@arm.com \
    --to=dharmik.thakkar@arm.com \
    --cc=beilei.xing@intel.com \
    --cc=bernard.iremonger@intel.com \
    --cc=dev@dpdk.org \
    --cc=nd@arm.com \
    --cc=wenzhuo.lu@intel.com \
    /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).