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 5FBFB41CEC; Mon, 20 Feb 2023 17:42:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0BB89430D3; Mon, 20 Feb 2023 17:42:01 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id E24D4430CD for ; Mon, 20 Feb 2023 17:41:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676911319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lE441bsX29J96p+i3F/ri9/vtQP0Cp0NV9NZk3TM63Y=; b=HrZUBvk1vxf0aesGjGxX/1CLyolllfSjutp9hGrkiu6sSj8ocJjKMZYVGAWw/QXIorGcuO iTNboyog3ur0b+Pyx6GJXCocipfC3ZyB/yUGasAYnVYnKx6Aa9CCfFHwGEKaOh2Mzf/joy J0rsJpn3LGvPNXb5ajJex+rYyx1K+PA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-597-A6Kr1-jXMU6jtnbbFGwu6Q-1; Mon, 20 Feb 2023 11:41:56 -0500 X-MC-Unique: A6Kr1-jXMU6jtnbbFGwu6Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F00571C0433F; Mon, 20 Feb 2023 16:41:55 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5A2C1121314; Mon, 20 Feb 2023 16:41:54 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Ferruh Yigit , Aman Singh , Yuying Zhang , Robin Jarry Subject: [PATCH v2 8/9] app/testpmd: factorize fwd engine Rx Date: Mon, 20 Feb 2023 17:41:02 +0100 Message-Id: <20230220164103.3041538-9-david.marchand@redhat.com> In-Reply-To: <20230220164103.3041538-1-david.marchand@redhat.com> References: <20230124104742.1265439-1-david.marchand@redhat.com> <20230220164103.3041538-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 Reduce code duplication by introducing a helper that takes care of receiving packets and incrementing rx counter. inc_rx_burst_stats() is then unneeded and removed. Signed-off-by: David Marchand Reviewed-by: Ferruh Yigit --- Changes since v1: - updated shared_rxq fwd engine, - removed inc_rx_burst_stats helper, - removed likely() around rx stats update, --- app/test-pmd/5tswap.c | 5 +---- app/test-pmd/csumonly.c | 5 +---- app/test-pmd/flowgen.c | 5 +---- app/test-pmd/icmpecho.c | 5 +---- app/test-pmd/ieee1588fwd.c | 4 +--- app/test-pmd/iofwd.c | 5 +---- app/test-pmd/macfwd.c | 5 +---- app/test-pmd/macswap.c | 5 +---- app/test-pmd/noisy_vnf.c | 5 +---- app/test-pmd/rxonly.c | 5 +---- app/test-pmd/shared_rxq_fwd.c | 4 +--- app/test-pmd/testpmd.h | 10 ++++++++-- 12 files changed, 19 insertions(+), 44 deletions(-) diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c index 7b5f58f4d4..27da867d7f 100644 --- a/app/test-pmd/5tswap.c +++ b/app/test-pmd/5tswap.c @@ -108,13 +108,10 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs) /* * Receive a burst of packets and forward 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; - fs->rx_packets += nb_rx; txp = &ports[fs->tx_port]; ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads); vlan_qinq_set(pkts_burst, nb_rx, ol_flags, diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index f72e2d74c7..d758ae0ac6 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -860,13 +860,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) struct testpmd_offload_info info; /* receive a burst of packet */ - 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; - fs->rx_packets += nb_rx; rx_bad_ip_csum = 0; rx_bad_l4_csum = 0; rx_bad_outer_l4_csum = 0; diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c index 6f42019353..3705cc60c5 100644 --- a/app/test-pmd/flowgen.c +++ b/app/test-pmd/flowgen.c @@ -80,10 +80,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs) int next_flow = RTE_PER_LCORE(_next_flow); /* 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; + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); rte_pktmbuf_free_bulk(pkts_burst, nb_rx); diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c index eba8b99f1e..48f8fe0bf1 100644 --- a/app/test-pmd/icmpecho.c +++ b/app/test-pmd/icmpecho.c @@ -296,13 +296,10 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs) /* * First, receive a burst of packets. */ - 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; - fs->rx_packets += nb_rx; nb_replies = 0; for (i = 0; i < nb_rx; i++) { if (likely(i < nb_rx - 1)) diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c index fd8ba27b2f..1d51ebfe9d 100644 --- a/app/test-pmd/ieee1588fwd.c +++ b/app/test-pmd/ieee1588fwd.c @@ -102,11 +102,9 @@ ieee1588_packet_fwd(struct fwd_stream *fs) /* * Receive 1 packet at a time. */ - if (rte_eth_rx_burst(fs->rx_port, fs->rx_queue, &mb, 1) == 0) + if (common_fwd_stream_receive(fs, &mb, 1) == 0) return false; - fs->rx_packets += 1; - /* * Check that the received packet is a PTP packet that was detected * by the hardware. diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c index 12be06fa79..69b583cb5b 100644 --- a/app/test-pmd/iofwd.c +++ b/app/test-pmd/iofwd.c @@ -52,12 +52,9 @@ pkt_burst_io_forward(struct fwd_stream *fs) /* * Receive a burst of packets and forward 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; - fs->rx_packets += nb_rx; nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx); diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c index 953d9ea089..a72f5ccb75 100644 --- a/app/test-pmd/macfwd.c +++ b/app/test-pmd/macfwd.c @@ -58,13 +58,10 @@ pkt_burst_mac_forward(struct fwd_stream *fs) /* * Receive a burst of packets and forward 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; - fs->rx_packets += nb_rx; txp = &ports[fs->tx_port]; tx_offloads = txp->dev_conf.txmode.offloads; if (tx_offloads & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c index 062542dc53..ab37123404 100644 --- a/app/test-pmd/macswap.c +++ b/app/test-pmd/macswap.c @@ -59,13 +59,10 @@ pkt_burst_mac_swap(struct fwd_stream *fs) /* * Receive a burst of packets and forward 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; - fs->rx_packets += nb_rx; txp = &ports[fs->tx_port]; do_macswap(pkts_burst, nb_rx, txp); diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c index 7bcab84db3..e543adc865 100644 --- a/app/test-pmd/noisy_vnf.c +++ b/app/test-pmd/noisy_vnf.c @@ -150,12 +150,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs) bool needs_flush = false; uint64_t now; - 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) goto flush; - fs->rx_packets += nb_rx; if (!ncf->do_buffering) { sim_memory_lookups(ncf, nb_rx); diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c index d4bff9b5ea..315f9286cd 100644 --- a/app/test-pmd/rxonly.c +++ b/app/test-pmd/rxonly.c @@ -50,13 +50,10 @@ pkt_burst_receive(struct fwd_stream *fs) /* * Receive a burst of packets. */ - 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; - fs->rx_packets += nb_rx; rte_pktmbuf_free_bulk(pkts_burst, nb_rx); return true; diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c index 67e5494735..623d62da88 100644 --- a/app/test-pmd/shared_rxq_fwd.c +++ b/app/test-pmd/shared_rxq_fwd.c @@ -95,9 +95,7 @@ shared_rxq_fwd(struct fwd_stream *fs) struct rte_mbuf *pkts_burst[nb_pkt_per_burst]; uint16_t nb_rx; - 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); + nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return false; forward_shared_rxq(fs, nb_rx, pkts_burst); diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 4b28cd0d0d..6c82cbab45 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -839,11 +839,17 @@ mbuf_pool_find(unsigned int sock_id, uint16_t idx) return rte_mempool_lookup((const char *)pool_name); } -static inline void -inc_rx_burst_stats(struct fwd_stream *fs, uint16_t nb_rx) +static inline uint16_t +common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst, + unsigned int nb_pkts) { + uint16_t nb_rx; + + nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, burst, nb_pkts); if (record_burst_stats) fs->rx_burst_stats.pkt_burst_spread[nb_rx]++; + fs->rx_packets += nb_rx; + return nb_rx; } static inline void -- 2.39.2