From: Zhihong Wang <wangzhihong.wzh@bytedance.com>
To: dev@dpdk.org, ferruh.yigit@intel.com, xiaoyun.li@intel.com
Cc: Zhihong Wang <wangzhihong.wzh@bytedance.com>
Subject: [dpdk-dev] [PATCH v2] app/testpmd: flowgen support ip and udp fields
Date: Mon, 9 Aug 2021 14:52:00 +0800 [thread overview]
Message-ID: <20210809065200.31134-1-wangzhihong.wzh@bytedance.com> (raw)
In-Reply-To: <20210809062548.30187-1-wangzhihong.wzh@bytedance.com>
This patch aims to:
1. Add flexibility by supporting IP & UDP src/dst fields
2. Improve multi-core performance by using per-core vars
v2: fix assigning ip header cksum
Signed-off-by: Zhihong Wang <wangzhihong.wzh@bytedance.com>
---
app/test-pmd/flowgen.c | 137 +++++++++++++++++++++++++++++++------------------
1 file changed, 86 insertions(+), 51 deletions(-)
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 3bf6e1ce97..333c3b2cd2 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -40,41 +40,37 @@
#include "testpmd.h"
-/* hardcoded configuration (for now) */
-static unsigned cfg_n_flows = 1024;
-static uint32_t cfg_ip_src = RTE_IPV4(10, 254, 0, 0);
-static uint32_t cfg_ip_dst = RTE_IPV4(10, 253, 0, 0);
-static uint16_t cfg_udp_src = 1000;
-static uint16_t cfg_udp_dst = 1001;
+/*
+ * Hardcoded range for flow generation.
+ *
+ * Total number of flows =
+ * cfg_n_ip_src * cfg_n_ip_dst * cfg_n_udp_src * cfg_n_udp_dst
+ */
+static uint32_t cfg_n_ip_src = 100;
+static uint32_t cfg_n_ip_dst = 100;
+static uint32_t cfg_n_udp_src = 10;
+static uint32_t cfg_n_udp_dst = 10;
+
+/* Base ip and port for flow generation. */
+static uint32_t cfg_ip_src_base = RTE_IPV4(10, 254, 0, 0);
+static uint32_t cfg_ip_dst_base = RTE_IPV4(10, 253, 0, 0);
+static uint16_t cfg_udp_src_base = 1000;
+static uint16_t cfg_udp_dst_base = 1001;
static struct rte_ether_addr cfg_ether_src =
{{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x00 }};
static struct rte_ether_addr cfg_ether_dst =
{{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x01 }};
+RTE_DEFINE_PER_LCORE(uint32_t, _next_ip_src);
+RTE_DEFINE_PER_LCORE(uint32_t, _next_ip_dst);
+RTE_DEFINE_PER_LCORE(uint32_t, _next_udp_src);
+RTE_DEFINE_PER_LCORE(uint32_t, _next_udp_dst);
+
#define IP_DEFTTL 64 /* from RFC 1340. */
/* Use this type to inform GCC that ip_sum violates aliasing rules. */
typedef unaligned_uint16_t alias_int16_t __attribute__((__may_alias__));
-static inline uint16_t
-ip_sum(const alias_int16_t *hdr, int hdr_len)
-{
- uint32_t sum = 0;
-
- while (hdr_len > 1)
- {
- sum += *hdr++;
- if (sum & 0x80000000)
- sum = (sum & 0xFFFF) + (sum >> 16);
- hdr_len -= 2;
- }
-
- while (sum >> 16)
- sum = (sum & 0xFFFF) + (sum >> 16);
-
- return ~sum;
-}
-
/*
* Multi-flow generation mode.
*
@@ -85,7 +81,7 @@ ip_sum(const alias_int16_t *hdr, int hdr_len)
static void
pkt_burst_flow_gen(struct fwd_stream *fs)
{
- unsigned pkt_size = tx_pkt_length - 4; /* Adjust FCS */
+ uint32_t pkt_size = tx_pkt_length - 4; /* Adjust FCS */
struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
struct rte_mempool *mbp;
struct rte_mbuf *pkt = NULL;
@@ -102,15 +98,18 @@ 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;
+ uint32_t next_ip_src = RTE_PER_LCORE(_next_ip_src);
+ uint32_t next_ip_dst = RTE_PER_LCORE(_next_ip_dst);
+ uint32_t next_udp_src = RTE_PER_LCORE(_next_udp_src);
+ uint32_t next_udp_dst = RTE_PER_LCORE(_next_udp_dst);
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,
nb_pkt_per_burst);
+ inc_rx_burst_stats(fs, nb_rx);
fs->rx_packets += nb_rx;
-
for (i = 0; i < nb_rx; i++)
rte_pktmbuf_free(pkts_burst[i]);
@@ -144,7 +143,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
rte_ether_addr_copy(&cfg_ether_dst, ð_hdr->d_addr);
rte_ether_addr_copy(&cfg_ether_src, ð_hdr->s_addr);
- eth_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
+ eth_hdr->ether_type =
+ rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
/* Initialize IP header. */
ip_hdr = (struct rte_ipv4_hdr *)(eth_hdr + 1);
@@ -155,22 +155,30 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
ip_hdr->time_to_live = IP_DEFTTL;
ip_hdr->next_proto_id = IPPROTO_UDP;
ip_hdr->packet_id = 0;
- ip_hdr->src_addr = rte_cpu_to_be_32(cfg_ip_src);
- ip_hdr->dst_addr = rte_cpu_to_be_32(cfg_ip_dst +
- next_flow);
- ip_hdr->total_length = RTE_CPU_TO_BE_16(pkt_size -
- sizeof(*eth_hdr));
- ip_hdr->hdr_checksum = ip_sum((const alias_int16_t *)ip_hdr,
- sizeof(*ip_hdr));
+ ip_hdr->src_addr =
+ rte_cpu_to_be_32(cfg_ip_src_base
+ + next_ip_src);
+ ip_hdr->dst_addr =
+ rte_cpu_to_be_32(cfg_ip_dst_base
+ + next_ip_dst);
+ ip_hdr->total_length =
+ RTE_CPU_TO_BE_16(pkt_size
+ - sizeof(*eth_hdr));
+ ip_hdr->hdr_checksum = rte_ipv4_cksum(ip_hdr);
/* Initialize UDP header. */
udp_hdr = (struct rte_udp_hdr *)(ip_hdr + 1);
- udp_hdr->src_port = rte_cpu_to_be_16(cfg_udp_src);
- udp_hdr->dst_port = rte_cpu_to_be_16(cfg_udp_dst);
+ udp_hdr->src_port =
+ rte_cpu_to_be_16(cfg_udp_src_base
+ + next_udp_src);
+ udp_hdr->dst_port =
+ rte_cpu_to_be_16(cfg_udp_dst_base
+ + next_udp_dst);
+ udp_hdr->dgram_len =
+ RTE_CPU_TO_BE_16(pkt_size
+ - sizeof(*eth_hdr)
+ - sizeof(*ip_hdr));
udp_hdr->dgram_cksum = 0; /* No UDP checksum. */
- udp_hdr->dgram_len = RTE_CPU_TO_BE_16(pkt_size -
- sizeof(*eth_hdr) -
- sizeof(*ip_hdr));
pkt->nb_segs = 1;
pkt->pkt_len = pkt_size;
pkt->ol_flags &= EXT_ATTACHED_MBUF;
@@ -185,30 +193,57 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
}
pkts_burst[nb_pkt] = pkt;
- next_flow = (next_flow + 1) % cfg_n_flows;
+ if (++next_udp_dst < cfg_n_udp_dst)
+ continue;
+ next_udp_dst = 0;
+ if (++next_udp_src < cfg_n_udp_src)
+ continue;
+ next_udp_src = 0;
+ if (++next_ip_dst < cfg_n_ip_dst)
+ continue;
+ next_ip_dst = 0;
+ if (++next_ip_src < cfg_n_ip_src)
+ continue;
+ next_ip_src = 0;
}
nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
/*
* Retry if necessary
*/
- if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
+ if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
retry = 0;
- while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
+ while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
rte_delay_us(burst_tx_delay_time);
nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
- &pkts_burst[nb_tx], nb_rx - nb_tx);
+ &pkts_burst[nb_tx], nb_pkt - nb_tx);
}
}
- fs->tx_packets += nb_tx;
inc_tx_burst_stats(fs, nb_tx);
- if (unlikely(nb_tx < nb_pkt)) {
- /* Back out the flow counter. */
- next_flow -= (nb_pkt - nb_tx);
- while (next_flow < 0)
- next_flow += cfg_n_flows;
+ fs->tx_packets += nb_tx;
+ /* Catch up flow idx by actual sent. */
+ for (i = 0; i < nb_tx; ++i) {
+ RTE_PER_LCORE(_next_udp_dst) = RTE_PER_LCORE(_next_udp_dst) + 1;
+ if (RTE_PER_LCORE(_next_udp_dst) < cfg_n_udp_dst)
+ continue;
+ RTE_PER_LCORE(_next_udp_dst) = 0;
+ RTE_PER_LCORE(_next_udp_src) = RTE_PER_LCORE(_next_udp_src) + 1;
+ if (RTE_PER_LCORE(_next_udp_src) < cfg_n_udp_src)
+ continue;
+ RTE_PER_LCORE(_next_udp_src) = 0;
+ RTE_PER_LCORE(_next_ip_dst) = RTE_PER_LCORE(_next_ip_dst) + 1;
+ if (RTE_PER_LCORE(_next_ip_dst) < cfg_n_ip_dst)
+ continue;
+ RTE_PER_LCORE(_next_ip_dst) = 0;
+ RTE_PER_LCORE(_next_ip_src) = RTE_PER_LCORE(_next_ip_src) + 1;
+ if (RTE_PER_LCORE(_next_ip_src) < cfg_n_ip_src)
+ continue;
+ RTE_PER_LCORE(_next_ip_src) = 0;
+ }
+ if (unlikely(nb_tx < nb_pkt)) {
+ fs->fwd_dropped += nb_pkt - nb_tx;
do {
rte_pktmbuf_free(pkts_burst[nb_tx]);
} while (++nb_tx < nb_pkt);
--
2.11.0
next prev parent reply other threads:[~2021-08-09 6:52 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 6:25 [dpdk-dev] [PATCH] " Zhihong Wang
2021-08-09 6:52 ` Zhihong Wang [this message]
2021-08-09 12:21 ` [dpdk-dev] [PATCH v2] " Singh, Aman Deep
2021-08-10 7:30 ` [dpdk-dev] [External] " 王志宏
2021-08-09 15:18 ` [dpdk-dev] " Ferruh Yigit
2021-08-10 7:57 ` [dpdk-dev] [External] " 王志宏
2021-08-10 9:12 ` Ferruh Yigit
2021-08-11 2:48 ` 王志宏
2021-08-11 10:31 ` Ferruh Yigit
2021-08-12 9:32 ` 王志宏
2021-08-12 11:11 ` [dpdk-dev] [PATCH v3 0/4] app/testpmd: flowgen fixes and improvements Zhihong Wang
2021-08-12 11:11 ` [dpdk-dev] [PATCH v3 1/4] app/testpmd: fix tx retry in flowgen Zhihong Wang
2021-08-12 11:11 ` [dpdk-dev] [PATCH v3 2/4] app/testpmd: use rte_ipv4_cksum " Zhihong Wang
2021-08-12 11:11 ` [dpdk-dev] [PATCH v3 3/4] app/testpmd: record rx_burst and fwd_dropped " Zhihong Wang
2021-08-12 11:11 ` [dpdk-dev] [PATCH v3 4/4] app/testpmd: use per-core variable " Zhihong Wang
2021-08-12 13:18 ` [dpdk-dev] [PATCH v4 0/4] app/testpmd: flowgen fixes and improvements Zhihong Wang
2021-08-12 13:18 ` [dpdk-dev] [PATCH v4 1/4] app/testpmd: fix tx retry in flowgen Zhihong Wang
2021-08-13 1:33 ` Li, Xiaoyun
2021-08-13 2:27 ` [dpdk-dev] [External] " 王志宏
2021-08-12 13:18 ` [dpdk-dev] [PATCH v4 2/4] app/testpmd: use rte_ipv4_cksum " Zhihong Wang
2021-08-13 1:37 ` Li, Xiaoyun
2021-08-12 13:19 ` [dpdk-dev] [PATCH v4 3/4] app/testpmd: record rx_burst and fwd_dropped " Zhihong Wang
2021-08-13 1:44 ` Li, Xiaoyun
2021-08-12 13:19 ` [dpdk-dev] [PATCH v4 4/4] app/testpmd: use per-core variable " Zhihong Wang
2021-08-13 1:56 ` Li, Xiaoyun
2021-08-13 2:35 ` [dpdk-dev] [External] " 王志宏
2021-08-13 8:05 ` [dpdk-dev] [PATCH v5 0/4] app/testpmd: flowgen fixes and improvements Zhihong Wang
2021-08-13 8:05 ` [dpdk-dev] [PATCH v5 1/4] app/testpmd: fix tx retry in flowgen Zhihong Wang
2021-08-13 8:05 ` [dpdk-dev] [PATCH v5 2/4] app/testpmd: use rte_ipv4_cksum " Zhihong Wang
2021-08-13 8:05 ` [dpdk-dev] [PATCH v5 3/4] app/testpmd: record rx_burst and fwd_dropped " Zhihong Wang
2021-08-13 8:05 ` [dpdk-dev] [PATCH v5 4/4] app/testpmd: use per-core variable " Zhihong Wang
2021-08-24 17:21 ` [dpdk-dev] [PATCH v5 0/4] app/testpmd: flowgen fixes and improvements 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=20210809065200.31134-1-wangzhihong.wzh@bytedance.com \
--to=wangzhihong.wzh@bytedance.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=xiaoyun.li@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).