[dpdk-dev] [PATCH v5 4/4] app/testpmd: use per-core variable in flowgen

Zhihong Wang wangzhihong.wzh at bytedance.com
Fri Aug 13 10:05:48 CEST 2021


Use per-core variable for flow indexing to solve cache contention in
multi-core scenarios.

Signed-off-by: Zhihong Wang <wangzhihong.wzh at bytedance.com>
Acked-by: Xiaoyun Li <xiaoyun.li at intel.com>
---
v5: replace modulo operation to improve performance
v4: use loop local variable to improve performance

 app/test-pmd/flowgen.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 229794ee9c..9348618d0f 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -53,6 +53,8 @@ static struct rte_ether_addr cfg_ether_dst =
 
 #define IP_DEFTTL  64   /* from RFC 1340. */
 
+RTE_DEFINE_PER_LCORE(int, _next_flow);
+
 /*
  * Multi-flow generation mode.
  *
@@ -80,7 +82,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint32_t retry;
 	uint64_t tx_offloads;
 	uint64_t start_tsc = 0;
-	static int next_flow = 0;
+	int next_flow = RTE_PER_LCORE(_next_flow);
 
 	get_start_cycles(&start_tsc);
 
@@ -163,7 +165,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 		}
 		pkts_burst[nb_pkt] = pkt;
 
-		next_flow = (next_flow + 1) % cfg_n_flows;
+		if (++next_flow >= (int)cfg_n_flows)
+			next_flow = 0;
 	}
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
@@ -193,6 +196,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 		} while (++nb_tx < nb_pkt);
 	}
 
+	RTE_PER_LCORE(_next_flow) = next_flow;
+
 	get_end_cycles(fs, start_tsc);
 }
 
-- 
2.11.0



More information about the dev mailing list