Reduce code duplication by introducing a helper that takes care of receiving packets and incrementing rx counter.
Signed-off-by: David Marchand <david.march...@redhat.com> --- 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