"unprepared" packets could get to the wire in the retry loop.

Split packets freeing in two stages: one for preparation failure, and
one for transmission failure.
Adjust dropped counter update accordingly.

Fixes: 6b520d54ebfe ("app/testpmd: use Tx preparation in checksum engine")
Cc: sta...@dpdk.org

Signed-off-by: David Marchand <david.march...@redhat.com>
---
 app/test-pmd/csumonly.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index dc64754a05..700c79f122 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1164,10 +1164,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 
        nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
                        tx_pkts_burst, nb_rx);
-       if (nb_prep != nb_rx)
+       if (nb_prep != nb_rx) {
                fprintf(stderr,
                        "Preparing packet burst to transmit failed: %s\n",
                        rte_strerror(rte_errno));
+               fs->fwd_dropped += (nb_rx - nb_prep);
+               rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
+       }
 
        nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
                        nb_prep);
@@ -1175,12 +1178,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
        /*
         * Retry if necessary
         */
-       if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
+       if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
                retry = 0;
-               while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
+               while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
                        rte_delay_us(burst_tx_delay_time);
                        nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-                                       &tx_pkts_burst[nb_tx], nb_rx - nb_tx);
+                                       &tx_pkts_burst[nb_tx], nb_prep - nb_tx);
                }
        }
        fs->tx_packets += nb_tx;
@@ -1190,11 +1193,11 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
        fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
        inc_tx_burst_stats(fs, nb_tx);
-       if (unlikely(nb_tx < nb_rx)) {
-               fs->fwd_dropped += (nb_rx - nb_tx);
+       if (unlikely(nb_tx < nb_prep)) {
+               fs->fwd_dropped += (nb_prep - nb_tx);
                do {
                        rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
-               } while (++nb_tx < nb_rx);
+               } while (++nb_tx < nb_prep);
        }
 
        return true;
-- 
2.39.1

Reply via email to