virtio-net: Fix and update interrupt moderation
Subsystems (3)
v3 cover virtio-net: Fix and update interrupt moderation
The setting of virtio coalescing parameters involves all-queues and per queue, so we must be careful to synchronize the two.
Regarding napi_tx switching, this patch set is not only compatible with the previous way of using tx-frames to switch napi_tx, but also improves the user experience when setting interrupt parameters.
This patch set has been tested and was part of the previous netdim patch set[1] and is now being split to be rolled out in steps.
[1] https://lore.kernel.org/all/[email protected]/
---v2->v3:
1. Fix a tiny comment.
v1->v2:
1. Fix some minor comments and add ack tags.
Heng Qi (6):
virtio-net: initially change the value of tx-frames
virtio-net: fix mismatch of getting tx-frames
virtio-net: consistently save parameters for per-queue
virtio-net: fix per queue coalescing parameter setting
virtio-net: fix the vq coalescing setting for vq resize
virtio-net: a tiny comment update
drivers/net/virtio_net.c | 104 ++++++++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 29 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b
PATCH v3 1/6 virtio-net: initially change the value of tx-frames
Background:
1. Commit 0c465be183c7 ("virtio_net: ethtool tx napi configuration") uses tx-frames to toggle napi_tx (0 off and 1 on) if notification coalescing is not supported.
2. Commit 31c03aef9bc2 ("virtio_net: enable napi_tx by default") enables napi_tx for all txqs by default.
Status:
When virtio-net supports notification coalescing, after initialization, tx-frames is 0 and napi_tx is true.
Problem:
When the user only wants to set rx coalescing params using
ethtool -C eth0 rx-usecs 10, or
ethtool -Q eth0 queue_mask 0x1 -C rx-usecs 10,
these cmds will carry tx-frames as 0, causing the napi_tx switching condition is satisfied. Then the user gets:
netlink error: Device or resource busy.
The same happens when trying to set rx-frames, adaptive_rx, adaptive_tx...
How to fix:
When notification coalescing feature is negotiated, initially make the value of tx-frames to be consistent with napi_tx.
For compatibility with the past, it is still supported to use tx-frames to toggle napi_tx.
--- drivers/net/virtio_net.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/net/virtio_net.c +21 -7
@@ -4442,13 +4442,6 @@ static int virtnet_probe(struct virtio_device *vdev) dev->xdp_features |=NETDEV_XDP_ACT_RX_SG ; } -if (virtio_has_feature (vi->vdev,VIRTIO_NET_F_NOTF_COAL )) { - vi->intr_coal_rx.max_usecs =0 ; - vi->intr_coal_tx.max_usecs =0 ; - vi->intr_coal_tx.max_packets =0 ; - vi->intr_coal_rx.max_packets =0 ; - } -if (virtio_has_feature (vdev,VIRTIO_NET_F_HASH_REPORT )) vi->has_rss_hash_report = true;
@@ -4523,6 +4516,27 @@ static int virtnet_probe(struct virtio_device *vdev)if (err) goto free; +if (virtio_has_feature (vi->vdev,VIRTIO_NET_F_NOTF_COAL )) { + vi->intr_coal_rx.max_usecs =0 ; + vi->intr_coal_tx.max_usecs =0 ; + vi->intr_coal_rx.max_packets =0 ; + +/* Keep the default values of the coalescing parameters +* aligned with the default napi_tx state. +*/ +if (vi->sq[0 ].napi.weight) + vi->intr_coal_tx.max_packets =1 ; +else + vi->intr_coal_tx.max_packets =0 ; + } + +if (virtio_has_feature (vi->vdev,VIRTIO_NET_F_VQ_NOTF_COAL )) { +/* The reason is the same as VIRTIO_NET_F_NOTF_COAL. */ +for (i =0 ; i < vi->max_queue_pairs; i++) +if (vi->sq[i].napi.weight) + vi->sq[i].intr_coal.max_packets =1 ; + } +#ifdef CONFIG_SYSFS if (vi->mergeable_rx_bufs) dev->sysfs_rx_queue_group = &virtio_net_mrg_rx_group;
Signature · 1 line
2.19.1.6.gb485710b
PATCH v3 2/6 virtio-net: fix mismatch of getting tx-frames
In reply to Heng QiSince virtio-net allows switching napi_tx for per txq, we have to get the specific txq's result now.
--- drivers/net/virtio_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
@@ -3453,7 +3453,7 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, }else { ec->rx_max_coalesced_frames =1 ; -if (vi->sq[0 ].napi.weight) +if (vi->sq[queue].napi.weight) ec->tx_max_coalesced_frames =1 ; }
Signature · 1 line
2.19.1.6.gb485710b
PATCH v3 3/6 virtio-net: consistently save parameters for per-queue
In reply to Heng QiWhen using .set_coalesce interface to set all queue coalescing parameters, we need to update both per-queue and global save values.
--- drivers/net/virtio_net.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/virtio_net.c +9 -0
@@ -3233,6 +3233,7 @@ static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec) {struct scatterlist sgs_tx, sgs_rx; +int i; vi->ctrl->coal_tx.tx_usecs =cpu_to_le32 (ec->tx_coalesce_usecs); vi->ctrl->coal_tx.tx_max_packets =cpu_to_le32 (ec->tx_max_coalesced_frames);
@@ -3246,6 +3247,10 @@ static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi,/* Save parameters */ vi->intr_coal_tx.max_usecs = ec->tx_coalesce_usecs; vi->intr_coal_tx.max_packets = ec->tx_max_coalesced_frames; +for (i =0 ; i < vi->max_queue_pairs; i++) { + vi->sq[i].intr_coal.max_usecs = ec->tx_coalesce_usecs; + vi->sq[i].intr_coal.max_packets = ec->tx_max_coalesced_frames; + } vi->ctrl->coal_rx.rx_usecs =cpu_to_le32 (ec->rx_coalesce_usecs); vi->ctrl->coal_rx.rx_max_packets =cpu_to_le32 (ec->rx_max_coalesced_frames);
@@ -3259,6 +3264,10 @@ static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi,/* Save parameters */ vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; +for (i =0 ; i < vi->max_queue_pairs; i++) { + vi->rq[i].intr_coal.max_usecs = ec->rx_coalesce_usecs; + vi->rq[i].intr_coal.max_packets = ec->rx_max_coalesced_frames; + }return 0 ; }
Signature · 1 line
2.19.1.6.gb485710b
PATCH v3 4/6 virtio-net: fix per queue coalescing parameter setting
In reply to Heng QiWhen the user sets a non-zero coalescing parameter to 0 for a specific virtqueue, it does not work as expected, so let's fix this.
---v2->v3:
1. Add the ack tag.
v1->v2:
1. Remove useless comments.
drivers/net/virtio_net.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-)
drivers/net/virtio_net.c +16 -20
@@ -3296,27 +3296,23 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, {int err; -if (ec->rx_coalesce_usecs || ec->rx_max_coalesced_frames) { - err =virtnet_send_ctrl_coal_vq_cmd (vi,rxq2vq (queue), - ec->rx_coalesce_usecs, - ec->rx_max_coalesced_frames); -if (err) -return err; -/* Save parameters */ - vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs; - vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames; - } + err =virtnet_send_ctrl_coal_vq_cmd (vi,rxq2vq (queue), + ec->rx_coalesce_usecs, + ec->rx_max_coalesced_frames); +if (err) +return err; -if (ec->tx_coalesce_usecs || ec->tx_max_coalesced_frames) { - err =virtnet_send_ctrl_coal_vq_cmd (vi,txq2vq (queue), - ec->tx_coalesce_usecs, - ec->tx_max_coalesced_frames); -if (err) -return err; -/* Save parameters */ - vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs; - vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames; - } + vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs; + vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames; + + err =virtnet_send_ctrl_coal_vq_cmd (vi,txq2vq (queue), + ec->tx_coalesce_usecs, + ec->tx_max_coalesced_frames); +if (err) +return err; + + vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs; + vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames;return 0 ; }
Signature · 1 line
2.19.1.6.gb485710b
PATCH v3 5/6 virtio-net: fix the vq coalescing setting for vq resize
In reply to Heng QiAccording to the definition of virtqueue coalescing spec[1]:
Upon disabling and re-enabling a transmit virtqueue, the device MUST set the coalescing parameters of the virtqueue to those configured through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET command, or, if the driver did not set any TX coalescing parameters, to 0.
Upon disabling and re-enabling a receive virtqueue, the device MUST set the coalescing parameters of the virtqueue to those configured through the VIRTIO_NET_CTRL_NOTF_COAL_RX_SET command, or, if the driver did not set any RX coalescing parameters, to 0.
We need to add this setting for vq resize (ethtool -G) where vq_reset happens.
[1] https://lists.oasis-open.org/archives/virtio-dev/202303/msg00415.html
---v2->v3:
1. Remove a useless comment and add the ack tag.
drivers/net/virtio_net.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/net/virtio_net.c +27 -0
@@ -2855,6 +2855,9 @@ static void virtnet_get_ringparam(struct net_device *dev, ring->tx_pending =virtqueue_get_vring_size (vi->sq[0 ].vq); } +static int virtnet_send_ctrl_coal_vq_cmd (struct virtnet_info *vi, +u16 vqn,u32 max_usecs,u32 max_packets); + static int virtnet_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring, struct kernel_ethtool_ringparam *kernel_ring,
@@ -2890,12 +2893,36 @@ static int virtnet_set_ringparam(struct net_device *dev, err =virtnet_tx_resize (vi, sq, ring->tx_pending);if (err)return err; + +/* Upon disabling and re-enabling a transmit virtqueue, the device must +* set the coalescing parameters of the virtqueue to those configured +* 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_ctrl_coal_vq_cmd (vi,txq2vq (i), + vi->intr_coal_tx.max_usecs, + vi->intr_coal_tx.max_packets); +if (err) +return err; + + vi->sq[i].intr_coal.max_usecs = vi->intr_coal_tx.max_usecs; + vi->sq[i].intr_coal.max_packets = vi->intr_coal_tx.max_packets; }if (ring->rx_pending != rx_pending) { err =virtnet_rx_resize (vi, rq, ring->rx_pending);if (err)return err; + +/* The reason is same as the transmit virtqueue reset */ + err =virtnet_send_ctrl_coal_vq_cmd (vi,rxq2vq (i), + vi->intr_coal_rx.max_usecs, + vi->intr_coal_rx.max_packets); +if (err) +return err; + + vi->rq[i].intr_coal.max_usecs = vi->intr_coal_rx.max_usecs; + vi->rq[i].intr_coal.max_packets = vi->intr_coal_rx.max_packets; } }
Signature · 1 line
2.19.1.6.gb485710b
PATCH v3 6/6 virtio-net: a tiny comment update
In reply to Heng QiUpdate a comment because virtio-net now supports both VIRTIO_NET_F_NOTF_COAL and VIRTIO_NET_F_VQ_NOTF_COAL.
--- drivers/net/virtio_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
@@ -3347,7 +3347,7 @@ static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi,static int virtnet_coal_params_supported (struct ethtool_coalesce *ec) {/* usecs coalescing is supported only if VIRTIO_NET_F_NOTF_COAL -* feature is negotiated. +* or VIRTIO_NET_F_VQ_NOTF_COAL feature is negotiated. */ if (ec->rx_coalesce_usecs || ec->tx_coalesce_usecs)return -EOPNOTSUPP ;
Signature · 1 line
2.19.1.6.gb485710b
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 8 lines · On Sun, 8 Oct 2023 14:27:38 +0800 you wrote:
The setting of virtio coalescing parameters involves all-queues and per queue, so we must be careful to synchronize the two.
Regarding
napi_txswitching, this patch set is not only compatible with the previous way of using tx-frames to switchnapi_tx, but also improves the user experience when setting interrupt parameters.[...]
Here is the summary with links:
- [v3,1/6] virtio-net: initially change the value of tx-frames
https://git.kernel.org/netdev/net-next/c/3014a0d54820 - [v3,2/6] virtio-net: fix mismatch of getting tx-frames https://git.kernel.org/netdev/net-next/c/134674c1877b - [v3,3/6] virtio-net: consistently save parameters for per-queue https://git.kernel.org/netdev/net-next/c/e9420838ab4f - [v3,4/6] virtio-net: fix per queue coalescing parameter setting https://git.kernel.org/netdev/net-next/c/bfb2b3609162 - [v3,5/6] virtio-net: fix the vq coalescing setting for vq resize https://git.kernel.org/netdev/net-next/c/f61fe5f081cf - [v3,6/6] virtio-net: a tiny comment update https://git.kernel.org/netdev/net-next/c/c4e33cf2611b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html