net/virtio: Fix check of threshold for Tx freeing

Message ID 20250609072347.1748785-1-hengqi.chen@gmail.com (mailing list archive)
State New
Delegated to: Maxime Coquelin
Headers
Series net/virtio: Fix check of threshold for Tx freeing |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing warning Testing issues
ci/iol-abi-testing success Testing PASS
ci/aws-unit-testing success Unit Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/intel-Testing fail Testing issues
ci/iol-compile-arm64-testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Hengqi Chen June 9, 2025, 7:23 a.m. UTC
Like most dirvers, make the fast path of virtio_xmit_cleanup() behave as
described by the comments of rte_eth_txconf::tx_free_thresh ([0]):
    Start freeing Tx buffers if there are
    less free descriptors than this value.

The rationale behind this change is that:
  * vq->vq_nentries is set during device probe with the queue size specified
    by vhost backend, this value does not reflect the real nb_tx_desc
  * the real available tx desc is set to vq->vq_free_cnt via the nb_tx_desc
    param of rte_eth_tx_queue_setup() API
  * so `nb_used > vq->vq_nentries - vq->vq_free_thresh` could never be true
    if say nb_tx_desc=2048, vq->vq_nentries=4096, vq->vq_free_thresh=32,
    see bug report 1716 ([1]) for details.

Bugzilla ID: 1716

  [0]: https://github.com/DPDK/dpdk/commit/72514b5d5543
  [1]: https://bugs.dpdk.org/show_bug.cgi?id=1716

Signed-off-by: Baoyuan Li <updoing@sina.com>
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 drivers/net/virtio/virtio_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Maxime Coquelin June 12, 2025, 1:24 p.m. UTC | #1
On 6/9/25 9:23 AM, Hengqi Chen wrote:
> Like most dirvers, make the fast path of virtio_xmit_cleanup() behave as
> described by the comments of rte_eth_txconf::tx_free_thresh ([0]):
>      Start freeing Tx buffers if there are
>      less free descriptors than this value.
> 
> The rationale behind this change is that:
>    * vq->vq_nentries is set during device probe with the queue size specified
>      by vhost backend, this value does not reflect the real nb_tx_desc
>    * the real available tx desc is set to vq->vq_free_cnt via the nb_tx_desc
>      param of rte_eth_tx_queue_setup() API
>    * so `nb_used > vq->vq_nentries - vq->vq_free_thresh` could never be true
>      if say nb_tx_desc=2048, vq->vq_nentries=4096, vq->vq_free_thresh=32,
>      see bug report 1716 ([1]) for details.
> 
> Bugzilla ID: 1716
> 
>    [0]: https://github.com/DPDK/dpdk/commit/72514b5d5543
>    [1]: https://bugs.dpdk.org/show_bug.cgi?id=1716
> 
> Signed-off-by: Baoyuan Li <updoing@sina.com>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>   drivers/net/virtio/virtio_rxtx.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
> index edecd2011f..ab97f03d7d 100644
> --- a/drivers/net/virtio/virtio_rxtx.c
> +++ b/drivers/net/virtio/virtio_rxtx.c
> @@ -1873,7 +1873,7 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
>   
>   	nb_used = virtqueue_nused(vq);
>   
> -	if (likely(nb_used > vq->vq_nentries - vq->vq_free_thresh))
> +	if (likely(vq->vq_free_cnt < vq->vq_free_thresh))
>   		virtio_xmit_cleanup(vq, nb_used);
>   
>   	for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index edecd2011f..ab97f03d7d 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -1873,7 +1873,7 @@  virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 
 	nb_used = virtqueue_nused(vq);
 
-	if (likely(nb_used > vq->vq_nentries - vq->vq_free_thresh))
+	if (likely(vq->vq_free_cnt < vq->vq_free_thresh))
 		virtio_xmit_cleanup(vq, nb_used);
 
 	for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {