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 6A00742476; Tue, 24 Jan 2023 11:48:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AD98842D48; Tue, 24 Jan 2023 11:48:34 +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 DEBC142D47 for ; Tue, 24 Jan 2023 11:48:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674557312; 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=M4QJnlAgz9bPPZs4/akwcerhuZaHNlyrn2rs6MMLOmU=; b=bs0tB5fWMcrRLBea8gbsA7RZ8OdGFPMFD5WKtK7CGVoAH+mCEFZkLsmeC8t47O3cnJUd/x vyAWbduP7KL0LJdaXsxn3iH2FXZb1XxtxNyki/7lzfnI7lE9KGFrMkSFpZnXwk5ja39sqm kkh4Ex/7Kbk6RgxZgmkqv1eNowZDjQI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-217-ZlpH0SrQMH22b3gQNArjeQ-1; Tue, 24 Jan 2023 05:48:30 -0500 X-MC-Unique: ZlpH0SrQMH22b3gQNArjeQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6F68985A588; Tue, 24 Jan 2023 10:48:30 +0000 (UTC) Received: from dmarchan.redhat.com (ovpn-192-67.brq.redhat.com [10.40.192.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BBD340444C5; Tue, 24 Jan 2023 10:48:29 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Ferruh Yigit , Aman Singh , Yuying Zhang , Robin Jarry Subject: [PATCH 5/6] app/testpmd: factorize fwd engine Rx Date: Tue, 24 Jan 2023 11:47:41 +0100 Message-Id: <20230124104742.1265439-6-david.marchand@redhat.com> In-Reply-To: <20230124104742.1265439-1-david.marchand@redhat.com> References: <20230124104742.1265439-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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. Signed-off-by: David Marchand --- 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/testpmd.h | 12 ++++++++++++ 11 files changed, 22 insertions(+), 39 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 db7009c678..e8bfd7d940 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 be35023444..937d5a1d7d 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 ad4597cf9a..de3ddcf9a5 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/testpmd.h b/app/test-pmd/testpmd.h index 5d1a5cde7d..e6b28b4748 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -857,6 +857,18 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx) if (record_burst_stats) fs->tx_burst_stats.pkt_burst_spread[nb_tx]++; } +static inline uint16_t +common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst, + unsigned int count) +{ + uint16_t nb_rx; + + nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, burst, count); + inc_rx_burst_stats(fs, nb_rx); + if (likely(nb_rx != 0)) + fs->rx_packets += nb_rx; + return nb_rx; +} /* Prototypes */ unsigned int parse_item_list(const char *str, const char *item_name, -- 2.39.1