[v3,1/7] net/virtio: add Rx free threshold setting

Message ID 20200408085313.4487-2-yong.liu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series add packed ring vectorized datapath |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Marvin Liu April 8, 2020, 8:53 a.m. UTC
  Introduce free threshold setting in Rx queue, default value of it is 32.
Limiated threshold size to multiple of four as only vectorized packed Rx
function will utilize it. Virtio driver will rearm Rx queue when more
than rx_free_thresh descs were dequeued.

Signed-off-by: Marvin Liu <yong.liu@intel.com>
  

Comments

Xiaolong Ye April 8, 2020, 6:08 a.m. UTC | #1
On 04/08, Marvin Liu wrote:
>Introduce free threshold setting in Rx queue, default value of it is 32.
>Limiated threshold size to multiple of four as only vectorized packed Rx

s/Limiated/Limit

>function will utilize it. Virtio driver will rearm Rx queue when more
>than rx_free_thresh descs were dequeued.
>
>Signed-off-by: Marvin Liu <yong.liu@intel.com>
>
>diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
>index 752faa0f6..3a2dbc2e0 100644
>--- a/drivers/net/virtio/virtio_rxtx.c
>+++ b/drivers/net/virtio/virtio_rxtx.c
>@@ -936,6 +936,7 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
> 	struct virtio_hw *hw = dev->data->dev_private;
> 	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
> 	struct virtnet_rx *rxvq;
>+	uint16_t rx_free_thresh;
> 
> 	PMD_INIT_FUNC_TRACE();
> 
>@@ -944,6 +945,28 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
> 		return -EINVAL;
> 	}
> 
>+	rx_free_thresh = rx_conf->rx_free_thresh;
>+	if (rx_free_thresh == 0)
>+		rx_free_thresh =
>+			RTE_MIN(vq->vq_nentries / 4, DEFAULT_RX_FREE_THRESH);
>+
>+	if (rx_free_thresh & 0x3) {
>+		RTE_LOG(ERR, PMD, "rx_free_thresh must be multiples of four."
>+			" (rx_free_thresh=%u port=%u queue=%u)\n",
>+			rx_free_thresh, dev->data->port_id, queue_idx);
>+		return -EINVAL;
>+	}
>+
>+	if (rx_free_thresh >= vq->vq_nentries) {
>+		RTE_LOG(ERR, PMD, "rx_free_thresh must be less than the "
>+			"number of RX entries (%u)."
>+			" (rx_free_thresh=%u port=%u queue=%u)\n",
>+			vq->vq_nentries,
>+			rx_free_thresh, dev->data->port_id, queue_idx);
>+		return -EINVAL;
>+	}
>+	vq->vq_free_thresh = rx_free_thresh;
>+
> 	if (nb_desc == 0 || nb_desc > vq->vq_nentries)
> 		nb_desc = vq->vq_nentries;
> 	vq->vq_free_cnt = RTE_MIN(vq->vq_free_cnt, nb_desc);
>diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
>index 58ad7309a..6301c56b2 100644
>--- a/drivers/net/virtio/virtqueue.h
>+++ b/drivers/net/virtio/virtqueue.h
>@@ -18,6 +18,8 @@
> 
> struct rte_mbuf;
> 
>+#define DEFAULT_RX_FREE_THRESH 32

What about naming it VIRITO_DEFAULT_RX_FREE_THRESH?

Thanks,
Xiaolong


>+
> /*
>  * Per virtio_ring.h in Linux.
>  *     For virtio_pci on SMP, we don't need to order with respect to MMIO
>-- 
>2.17.1
>
  

Patch

diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 752faa0f6..3a2dbc2e0 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -936,6 +936,7 @@  virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 	struct virtio_hw *hw = dev->data->dev_private;
 	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
 	struct virtnet_rx *rxvq;
+	uint16_t rx_free_thresh;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -944,6 +945,28 @@  virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
+	rx_free_thresh = rx_conf->rx_free_thresh;
+	if (rx_free_thresh == 0)
+		rx_free_thresh =
+			RTE_MIN(vq->vq_nentries / 4, DEFAULT_RX_FREE_THRESH);
+
+	if (rx_free_thresh & 0x3) {
+		RTE_LOG(ERR, PMD, "rx_free_thresh must be multiples of four."
+			" (rx_free_thresh=%u port=%u queue=%u)\n",
+			rx_free_thresh, dev->data->port_id, queue_idx);
+		return -EINVAL;
+	}
+
+	if (rx_free_thresh >= vq->vq_nentries) {
+		RTE_LOG(ERR, PMD, "rx_free_thresh must be less than the "
+			"number of RX entries (%u)."
+			" (rx_free_thresh=%u port=%u queue=%u)\n",
+			vq->vq_nentries,
+			rx_free_thresh, dev->data->port_id, queue_idx);
+		return -EINVAL;
+	}
+	vq->vq_free_thresh = rx_free_thresh;
+
 	if (nb_desc == 0 || nb_desc > vq->vq_nentries)
 		nb_desc = vq->vq_nentries;
 	vq->vq_free_cnt = RTE_MIN(vq->vq_free_cnt, nb_desc);
diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index 58ad7309a..6301c56b2 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -18,6 +18,8 @@ 
 
 struct rte_mbuf;
 
+#define DEFAULT_RX_FREE_THRESH 32
+
 /*
  * Per virtio_ring.h in Linux.
  *     For virtio_pci on SMP, we don't need to order with respect to MMIO