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 1F5F5A0C4F; Mon, 9 Aug 2021 08:25:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0DA64068A; Mon, 9 Aug 2021 08:25:56 +0200 (CEST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 5633A4003C for ; Mon, 9 Aug 2021 08:25:55 +0200 (CEST) Received: by mail-pj1-f54.google.com with SMTP id lw7-20020a17090b1807b029017881cc80b7so6801205pjb.3 for ; Sun, 08 Aug 2021 23:25:54 -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:mime-version :content-transfer-encoding; bh=L0t+JeczdIhoksKoJF3L6a1vviBlmPbwO0+MdQCTAVM=; b=zXP64FQPN64/SouSDKRzaJ+IlZxQpuuKxNxHq+BEzmgx2+Y6LJKwml02JERnoXla6c X0pmC3mDa3Bilj8Ne6dgvDewmmbj3+HCmq8ktFr2E9TXm/U88w3lE1ceZhnxIuwicAc8 e9FiUk96LZF17P3uruic8ytq54iXcQzHJmSJ+0NFesCDOH05YPsf/zVVl7gAgltPTfr8 inp35CirPExbndXRa/As2u0nGBSkd+/IYN8xPvNS6aoN4oVybY4f90Y5iMCW4d+9FHlG jjVj7MIn6JkW3cPi1/tuWIqpz0IthUP7G0SHIeV23yN3P2Q54Q4NO5r/WpYVSPW4j21c CObQ== 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:mime-version :content-transfer-encoding; bh=L0t+JeczdIhoksKoJF3L6a1vviBlmPbwO0+MdQCTAVM=; b=e05PwlPKwbaYlEdKBDbNJsV/GUq1c9AOPHChgSpvCM/KwCIlq6GNKySLqSVd+8hzC5 8GqjGoOXGl7N7nXuCKSsPGk1B502Qkn3hWd9N4WR6LX7PAa1AJ5PLGZT6uMIxcIG1bbd V08XKF6n6c43Ks2fvtmQGN57irg7JAAmP7ofCJCbzSHr0JST0/+fybW1mOxErBfDb70y NQE0Ejp7yYGTegplF9Y5koo9xLq2kr2T9dZfbvxknnoqqR39izqGvH59EHEYlv8hcCND GffTmc+poH/AkErfnDEbieCuq5uq7xteZaPvLaqN9kWnjD0qZlUapWT7XZ+Mjt1SiaIl hBcg== X-Gm-Message-State: AOAM532bgh8MS9QfQaTgx0USG+wEN0fCqk6JZmH3FW5i7dgf7eWFGKbF FfxfUvzQb+nh3L4qyRt6iUZvOPWj/G0SWQ== X-Google-Smtp-Source: ABdhPJzgwAA+lcSE8TQ54wV2wE/6nacQb7lmHmG7awAIRVR0aGeaNggKsuQV51Ta+OdU/VujDfQHVg== X-Received: by 2002:aa7:860e:0:b029:3bd:7e49:7a14 with SMTP id p14-20020aa7860e0000b02903bd7e497a14mr22977181pfn.40.1628490353741; Sun, 08 Aug 2021 23:25:53 -0700 (PDT) Received: from C02D70YZMD6R.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id 198sm18618390pfu.32.2021.08.08.23.25.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Aug 2021 23:25:53 -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:25:48 +0800 Message-Id: <20210809062548.30187-1-wangzhihong.wzh@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] 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 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..5b389165bc 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)); + 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