From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6A003A0C4F; Mon, 9 Aug 2021 08:52:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E9C344069D; Mon, 9 Aug 2021 08:52:08 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 36A764068A for ; Mon, 9 Aug 2021 08:52:07 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id u16so15352422ple.2 for ; Sun, 08 Aug 2021 23:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MT7E92NPW2Crn6gTLjw9ZJ4e1slOqoSpKEuaMwoPZCM=; b=xpuZDzg4zlBU2w76S8vqKEIaweUS/Z5JHlHgY2ifA8vUiPPazttWYs+chPiD4wqORF fkEsmNb1tg4DnLbqr8Nm2S3qjHsNYrCbYP+emKSSlHn7j09Jvq1YFh6tXt3qJCfRhip1 xu+kwOmWfYye4XD15xIa/HdtGY8bbWFCXwS29dpnkaGpLqH2vhx4MQuyiZI3qtWEUr8I BmU/j9tjlJqF6UAFCmnGPi36JJrwsTA7ONGz9jwRL92zJfZBkBGuT+4630OKFz+4dQnI JUt4H+haMhYivI4dk6xQ82A1SkBmqd2zAJUDvw+ADof77U0cY7CYXVHjrcFgHUi0Ouge c3gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MT7E92NPW2Crn6gTLjw9ZJ4e1slOqoSpKEuaMwoPZCM=; b=o5I/feHTVQ8zQx3MM8p4cmAnAFhFaCl1+cimcWcnbUiRJUQFE/Sy/MsO8CjIbPiCQY AHyoGYVEVv0JO+v8+ocDyIqK9hDZpzXN7sdQ5YiAchokYMKyythGYdJQtese7hu001yv WhltxuACH90YULhzDNmHMIkTJ0YofxuySqcDuiG8vfdGCyHA3ETSPs7uxOddBBDX6GQv 27Cc37m8qcxcCzOXsngMI/2rcJfATSy6Lx/Mty54+/2/uTRltF0lSIqN6lhUHx4lRnck pm0YYZxyyKL9uHyRyidLzQG+FfqV38zLW1YgZxz0SmQaLCxzcPnvsRb5uizLARZ3qLic Tgng== X-Gm-Message-State: AOAM531BWzyTJDmw6s5IhpLsQtSEZjVkv0297b8JP/CD7exzZ9wI7yXR l9zwU/Tu8rWd44r3r++tzXwHUQrc66nSGw== X-Google-Smtp-Source: ABdhPJwWjuFA4Ci4yOlN+i5t02s1FjI3XSQjzGtPo/c94E0wBnkjvkiXnXPaIKkcF7peafgi3y2sDQ== X-Received: by 2002:a62:1c84:0:b029:39a:87b9:91e with SMTP id c126-20020a621c840000b029039a87b9091emr16840078pfc.7.1628491925876; Sun, 08 Aug 2021 23:52:05 -0700 (PDT) Received: from C02D70YZMD6R.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id q19sm21280278pgj.17.2021.08.08.23.52.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Aug 2021 23:52:05 -0700 (PDT) From: Zhihong Wang To: dev@dpdk.org, ferruh.yigit@intel.com, xiaoyun.li@intel.com Cc: Zhihong Wang Date: Mon, 9 Aug 2021 14:52:00 +0800 Message-Id: <20210809065200.31134-1-wangzhihong.wzh@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210809062548.30187-1-wangzhihong.wzh@bytedance.com> References: <20210809062548.30187-1-wangzhihong.wzh@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] app/testpmd: flowgen support ip and udp fields X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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