Skip to contentSkip to conversation

virtio_net: Avoid sending unnecessary vq coalescing commands

PATCH In review Heng Qi 5 participants 8 messages Jul 29, 2024 – Jul 31, 2024

Subsystems (4)
lore
Share & tools
lore

Heng Qi

author
#0 lore raw

PATCH 1/1 virtio_net: Avoid sending unnecessary vq coalescing commands

From the virtio spec:

The driver MUST have negotiated the VIRTIO_NET_F_VQ_NOTF_COAL feature when issuing commands VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET and VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET.

The driver must not send vq notification coalescing commands if VIRTIO_NET_F_VQ_NOTF_COAL is not negotiated. This limitation of course applies to vq resize.

Fixes f61fe5f081cf ("virtio-net: fix the vq coalescing setting for vq resize")
---
 drivers/net/virtio_net.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/net/virtio_net.c +17 -12
index 0383a3e136d6..eb115e807882 100644
@@ -3708,6 +3708,7 @@ static int virtnet_set_ringparam(struct net_device *dev,
 	u32 rx_pending, tx_pending;
 	struct receive_queue *rq;
 	struct send_queue *sq;
+	u32 pkts, usecs;
 	int i, err;
 
 	if (ring->rx_mini_pending || ring->rx_jumbo_pending)
@@ -3740,11 +3741,13 @@ static int virtnet_set_ringparam(struct net_device *dev,
 			 * through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver
 			 * did not set any TX coalescing parameters, to 0.
 			 */
-			err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i,
-							       vi->intr_coal_tx.max_usecs,
-							       vi->intr_coal_tx.max_packets);
-			if (err)
-				return err;
+			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+				usecs = vi->intr_coal_tx.max_usecs;
+				pkts = vi->intr_coal_tx.max_packets;
+				err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+				if (err)
+					return err;
+			}
 		}
 
 		if (ring->rx_pending != rx_pending) {
@@ -3753,13 +3756,15 @@ static int virtnet_set_ringparam(struct net_device *dev,
 				return err;
 
 			/* The reason is same as the transmit virtqueue reset */
-			mutex_lock(&vi->rq[i].dim_lock);
-			err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i,
-							       vi->intr_coal_rx.max_usecs,
-							       vi->intr_coal_rx.max_packets);
-			mutex_unlock(&vi->rq[i].dim_lock);
-			if (err)
-				return err;
+			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+				usecs = vi->intr_coal_rx.max_usecs;
+				pkts = vi->intr_coal_rx.max_packets;
+				mutex_lock(&vi->rq[i].dim_lock);
+				err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+				mutex_unlock(&vi->rq[i].dim_lock);
+				if (err)
+					return err;
+			}
 		}
 	}
 
Signature · 1 line
2.32.0.3.g01195cf9f
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Heng Qi

From the virtio spec:

The driver MUST have negotiated the VIRTIO_NET_F_VQ_NOTF_COAL feature when issuing commands VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET and VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET.

Quoted 6 lines

The driver must not send vq notification coalescing commands if VIRTIO_NET_F_VQ_NOTF_COAL is not negotiated. This limitation of course applies to vq resize.

Fixes f61fe5f081cf ("virtio-net: fix the vq coalescing setting for vq resize")
Quoted 61 lines
---
 drivers/net/virtio_net.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/net/virtio_net.c +17 -13
index 0383a3e136d6..eb115e807882 100644
@@ -3708,6 +3708,7 @@ static int virtnet_set_ringparam(struct net_device *dev,
 	u32 rx_pending, tx_pending;
 	struct receive_queue *rq;
 	struct send_queue *sq;
+	u32 pkts, usecs;
 	int i, err;
 
 	if (ring->rx_mini_pending || ring->rx_jumbo_pending)
@@ -3740,11 +3741,13 @@ static int virtnet_set_ringparam(struct net_device *dev,
 			 * through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver
 			 * did not set any TX coalescing parameters, to 0.
 			 */
-			err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i,
-							       vi->intr_coal_tx.max_usecs,
-							       vi->intr_coal_tx.max_packets);
-			if (err)
-				return err;
+			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+				usecs = vi->intr_coal_tx.max_usecs;
+				pkts = vi->intr_coal_tx.max_packets;
+				err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+				if (err)
+					return err;
+			}
 		}
 
 		if (ring->rx_pending != rx_pending) {
@@ -3753,13 +3756,15 @@ static int virtnet_set_ringparam(struct net_device *dev,
 				return err;
 
 			/* The reason is same as the transmit virtqueue reset */
-			mutex_lock(&vi->rq[i].dim_lock);
-			err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i,
-							       vi->intr_coal_rx.max_usecs,
-							       vi->intr_coal_rx.max_packets);
-			mutex_unlock(&vi->rq[i].dim_lock);
-			if (err)
-				return err;
+			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+				usecs = vi->intr_coal_rx.max_usecs;
+				pkts = vi->intr_coal_rx.max_packets;
+				mutex_lock(&vi->rq[i].dim_lock);
+				err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+				mutex_unlock(&vi->rq[i].dim_lock);
+				if (err)
+					return err;
+			}
 		}
 	}
 
--

2.32.0.3.g01195cf9f

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Heng Qi
Quoted 7 lines · Heng Qi

From the virtio spec:

The driver MUST have negotiated the VIRTIO_NET_F_VQ_NOTF_COAL feature when issuing commands VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET and VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET.

Quoted 5 lines

The driver must not send vq notification coalescing commands if VIRTIO_NET_F_VQ_NOTF_COAL is not negotiated. This limitation of course applies to vq resize.

Fixes f61fe5f081cf ("virtio-net: fix the vq coalescing setting for vq resize")
Quoted 62 lines
---
 drivers/net/virtio_net.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/net/virtio_net.c +17 -13
index 0383a3e136d6..eb115e807882 100644
@@ -3708,6 +3708,7 @@ static int virtnet_set_ringparam(struct net_device *dev,
        u32 rx_pending, tx_pending;
        struct receive_queue *rq;
        struct send_queue *sq;
+       u32 pkts, usecs;
        int i, err;
 
        if (ring->rx_mini_pending || ring->rx_jumbo_pending)
@@ -3740,11 +3741,13 @@ static int virtnet_set_ringparam(struct net_device *dev,
                         * through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver
                         * did not set any TX coalescing parameters, to 0.
                         */
-                       err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i,
-                                                              vi->intr_coal_tx.max_usecs,
-                                                              vi->intr_coal_tx.max_packets);
-                       if (err)
-                               return err;
+                       if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+                               usecs = vi->intr_coal_tx.max_usecs;
+                               pkts = vi->intr_coal_tx.max_packets;
+                               err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+                               if (err)
+                                       return err;
+                       }
                }
 
                if (ring->rx_pending != rx_pending) {
@@ -3753,13 +3756,15 @@ static int virtnet_set_ringparam(struct net_device *dev,
                                return err;
 
                        /* The reason is same as the transmit virtqueue reset */
-                       mutex_lock(&vi->rq[i].dim_lock);
-                       err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i,
-                                                              vi->intr_coal_rx.max_usecs,
-                                                              vi->intr_coal_rx.max_packets);
-                       mutex_unlock(&vi->rq[i].dim_lock);
-                       if (err)
-                               return err;
+                       if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+                               usecs = vi->intr_coal_rx.max_usecs;
+                               pkts = vi->intr_coal_rx.max_packets;
+                               mutex_lock(&vi->rq[i].dim_lock);
+                               err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+                               mutex_unlock(&vi->rq[i].dim_lock);
+                               if (err)
+                                       return err;
+                       }
                }
        }
 
--

2.32.0.3.g01195cf9f

maintainer
#3 lore raw
In reply to Heng Qi
Quoted 1 line · On Mon, 29 Jul 2024 20:47:55 +0800 Heng Qi wrote:

Subject: [PATCH net] virtio_net: Avoid sending unnecessary vq coalescing commands

subject currently reads like this is an optimization, could you rephrase?

Quoted 33 lines

From the virtio spec:

The driver MUST have negotiated the VIRTIO_NET_F_VQ_NOTF_COAL feature when issuing commands VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET and VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET.

The driver must not send vq notification coalescing commands if VIRTIO_NET_F_VQ_NOTF_COAL is not negotiated. This limitation of course applies to vq resize.

Fixes f61fe5f081cf ("virtio-net: fix the vq coalescing setting for vq resize")
---
 drivers/net/virtio_net.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/net/virtio_net.c +1 -1
index 0383a3e136d6..eb115e807882 100644
@@ -3708,6 +3708,7 @@ static int virtnet_set_ringparam(struct net_device *dev,
 	u32 rx_pending, tx_pending;
 	struct receive_queue *rq;
 	struct send_queue *sq;
+	u32 pkts, usecs;
 	int i, err;
 
 	if (ring->rx_mini_pending || ring->rx_jumbo_pending)
@@ -3740,11 +3741,13 @@ static int virtnet_set_ringparam(struct net_device *dev,
 			 * through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver
 			 * did not set any TX coalescing parameters, to 0.
 			 */
-			err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i,

drivers/net/virtio_net.c static int virtnet_set_ringparam(struct net_device *dev, · line 3749

Quoted 10 lines
drivers/net/virtio_net.c +6 -4
-							       vi->intr_coal_tx.max_usecs,
-							       vi->intr_coal_tx.max_packets);
-			if (err)
-				return err;
+			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+				usecs = vi->intr_coal_tx.max_usecs;
+				pkts = vi->intr_coal_tx.max_packets;
+				err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+				if (err)
+					return err;

Can you check the feature inside the
virtnet_send_.x_ctrl_coal_vq_cmd() helpers?
5 levels of indentation is a bit much

Signature · 1 line
pw-bot: cr
#4 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 1 line · On Mon, 29 Jul 2024 20:47:55 +0800 Heng Qi wrote:

Subject: [PATCH net] virtio_net: Avoid sending unnecessary vq coalescing commands

subject currently reads like this is an optimization, could you rephrase?

It might be "virtio-net: unbreak vq resizing when coalescing is not negotiated" ?

Thanks

author
#5 lore raw
Quoted 10 lines · Jason Wang
Quoted 6 lines · Jakub Kicinski
Quoted 1 line · On Mon, 29 Jul 2024 20:47:55 +0800 Heng Qi wrote:

Subject: [PATCH net] virtio_net: Avoid sending unnecessary vq coalescing commands

subject currently reads like this is an optimization, could you rephrase?

It might be "virtio-net: unbreak vq resizing when coalescing is not negotiated" ?

It's great.

Thanks.

Quoted 3 lines

Thanks

author
#6 lore raw
In reply to Jakub Kicinski
Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Mon, 29 Jul 2024 20:47:55 +0800 Heng Qi wrote:

Subject: [PATCH net] virtio_net: Avoid sending unnecessary vq coalescing commands

subject currently reads like this is an optimization, could you rephrase?

Jason's rephrase will be used.

Quoted 40 lines
Quoted 40 lines

From the virtio spec:

The driver MUST have negotiated the VIRTIO_NET_F_VQ_NOTF_COAL feature when issuing commands VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET and VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET.

The driver must not send vq notification coalescing commands if VIRTIO_NET_F_VQ_NOTF_COAL is not negotiated. This limitation of course applies to vq resize.

Fixes f61fe5f081cf ("virtio-net: fix the vq coalescing setting for vq resize")
---
 drivers/net/virtio_net.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/net/virtio_net.c +3 -5
index 0383a3e136d6..eb115e807882 100644
@@ -3708,6 +3708,7 @@ static int virtnet_set_ringparam(struct net_device *dev,
 	u32 rx_pending, tx_pending;
 	struct receive_queue *rq;
 	struct send_queue *sq;
+	u32 pkts, usecs;
 	int i, err;
 
 	if (ring->rx_mini_pending || ring->rx_jumbo_pending)
@@ -3740,11 +3741,13 @@ static int virtnet_set_ringparam(struct net_device *dev,
 			 * through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver
 			 * did not set any TX coalescing parameters, to 0.
 			 */
-			err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i,
-							       vi->intr_coal_tx.max_usecs,
-							       vi->intr_coal_tx.max_packets);
-			if (err)
-				return err;
+			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) {
+				usecs = vi->intr_coal_tx.max_usecs;
Quoted 8 lines

drivers/net/virtio_net.c static int virtnet_set_ringparam(struct net_device *dev, · line 3749

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+				pkts = vi->intr_coal_tx.max_packets;
+				err = virtnet_send_tx_ctrl_coal_vq_cmd(vi, i, usecs, pkts);
+				if (err)
+					return err;

Can you check the feature inside the
virtnet_send_.x_ctrl_coal_vq_cmd() helpers?
5 levels of indentation is a bit much

Makes sense. Will update in the next version.

Thanks.

Quoted 2 lines
Signature · 1 line
pw-bot: cr
Acked-by on v1 1/1
#7 lore raw
In reply to Heng Qi
Quoted 7 lines · Heng Qi

From the virtio spec:

The driver MUST have negotiated the VIRTIO_NET_F_VQ_NOTF_COAL feature when issuing commands VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET and VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET.

Quoted 7 lines

The driver must not send vq notification coalescing commands if VIRTIO_NET_F_VQ_NOTF_COAL is not negotiated. This limitation of course applies to vq resize.

Fixes f61fe5f081cf ("virtio-net: fix the vq coalescing setting for vq resize")

---

Thanks