diff mbox series

virtio_net: send notification coalescing command only if value changed

Message ID 20221221120618.652074-1-alvaro.karsz@solid-run.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series virtio_net: send notification coalescing command only if value changed | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Alvaro Karsz Dec. 21, 2022, 12:06 p.m. UTC
Don't send a VIRTIO_NET_CTRL_NOTF_COAL_TX_SET or
VIRTIO_NET_CTRL_NOTF_COAL_RX_SET command if the coalescing parameters
haven't changed.

Signed-off-by: Alvaro Karsz <alvaro.karsz@solid-run.com>
---
 drivers/net/virtio_net.c | 48 ++++++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

Comments

Michael S. Tsirkin Dec. 21, 2022, 12:33 p.m. UTC | #1
On Wed, Dec 21, 2022 at 02:06:18PM +0200, Alvaro Karsz wrote:
> Don't send a VIRTIO_NET_CTRL_NOTF_COAL_TX_SET or
> VIRTIO_NET_CTRL_NOTF_COAL_RX_SET command if the coalescing parameters
> haven't changed.
> 
> Signed-off-by: Alvaro Karsz <alvaro.karsz@solid-run.com>

Why do we bother? Resending needs more code and helps
reliability ...

> ---
>  drivers/net/virtio_net.c | 48 ++++++++++++++++++++++------------------
>  1 file changed, 27 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 7723b2a49d8..1d7118de62a 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2760,31 +2760,37 @@ static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi,
>  	struct virtio_net_ctrl_coal_tx coal_tx;
>  	struct virtio_net_ctrl_coal_rx coal_rx;
>  
> -	coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs);
> -	coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames);
> -	sg_init_one(&sgs_tx, &coal_tx, sizeof(coal_tx));
> -
> -	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
> -				  VIRTIO_NET_CTRL_NOTF_COAL_TX_SET,
> -				  &sgs_tx))
> -		return -EINVAL;
> +	if (ec->tx_coalesce_usecs != vi->tx_usecs ||
> +	    ec->tx_max_coalesced_frames != vi->tx_max_packets) {
> +		coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs);
> +		coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames);
> +		sg_init_one(&sgs_tx, &coal_tx, sizeof(coal_tx));
> +
> +		if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
> +					  VIRTIO_NET_CTRL_NOTF_COAL_TX_SET,
> +					  &sgs_tx))
> +			return -EINVAL;
>  
> -	/* Save parameters */
> -	vi->tx_usecs = ec->tx_coalesce_usecs;
> -	vi->tx_max_packets = ec->tx_max_coalesced_frames;
> +		/* Save parameters */
> +		vi->tx_usecs = ec->tx_coalesce_usecs;
> +		vi->tx_max_packets = ec->tx_max_coalesced_frames;
> +	}
>  
> -	coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs);
> -	coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames);
> -	sg_init_one(&sgs_rx, &coal_rx, sizeof(coal_rx));
> +	if (ec->rx_coalesce_usecs != vi->rx_usecs ||
> +	    ec->rx_max_coalesced_frames != vi->rx_max_packets) {
> +		coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs);
> +		coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames);
> +		sg_init_one(&sgs_rx, &coal_rx, sizeof(coal_rx));
>  
> -	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
> -				  VIRTIO_NET_CTRL_NOTF_COAL_RX_SET,
> -				  &sgs_rx))
> -		return -EINVAL;
> +		if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
> +					  VIRTIO_NET_CTRL_NOTF_COAL_RX_SET,
> +					  &sgs_rx))
> +			return -EINVAL;
>  
> -	/* Save parameters */
> -	vi->rx_usecs = ec->rx_coalesce_usecs;
> -	vi->rx_max_packets = ec->rx_max_coalesced_frames;
> +		/* Save parameters */
> +		vi->rx_usecs = ec->rx_coalesce_usecs;
> +		vi->rx_max_packets = ec->rx_max_coalesced_frames;
> +	}
>  
>  	return 0;
>  }
> -- 
> 2.32.0
Alvaro Karsz Dec. 21, 2022, 12:44 p.m. UTC | #2
> Why do we bother? Resending needs more code and helps
> reliability ...

It just seems unnecessary.
If a user changes just one parameter:
$ ethtool -C <iface> tx-usecs 30
It will trigger 2 commands, including
VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, even though no rx parameter changed.

If we'll add more ethtool coalescing parameters, changing one of the
new parameter will trigger meaningless
VIRTIO_NET_CTRL_NOTF_COAL_RX_SET and VIRTIO_NET_CTRL_NOTF_COAL_TX_SET
commands.

Alvaro
Michael S. Tsirkin Dec. 21, 2022, 1:01 p.m. UTC | #3
On Wed, Dec 21, 2022 at 02:44:21PM +0200, Alvaro Karsz wrote:
> > Why do we bother? Resending needs more code and helps
> > reliability ...
> 
> It just seems unnecessary.
> If a user changes just one parameter:
> $ ethtool -C <iface> tx-usecs 30
> It will trigger 2 commands, including
> VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, even though no rx parameter changed.
> 
> If we'll add more ethtool coalescing parameters, changing one of the
> new parameter will trigger meaningless
> VIRTIO_NET_CTRL_NOTF_COAL_RX_SET and VIRTIO_NET_CTRL_NOTF_COAL_TX_SET
> commands.
> 
> Alvaro

We'll always just do 2 commands, right?
I don't think we should bother at this point.
It might not be completely redundant.
E.g. if a card lost the config resending it might help fix things.
Alvaro Karsz Dec. 21, 2022, 1:10 p.m. UTC | #4
> We'll always just do 2 commands, right?

This is my point, we are sending 2 commands at the moment, even though
one of them may be unnecessary.

> E.g. if a card lost the config resending it might help fix things.

How can it lose the config?
We can  say the same about every command sent through the control vq.

> I don't think we should bother at this point.

Ok, I'll drop it.


Alvaro
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 7723b2a49d8..1d7118de62a 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2760,31 +2760,37 @@  static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi,
 	struct virtio_net_ctrl_coal_tx coal_tx;
 	struct virtio_net_ctrl_coal_rx coal_rx;
 
-	coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs);
-	coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames);
-	sg_init_one(&sgs_tx, &coal_tx, sizeof(coal_tx));
-
-	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
-				  VIRTIO_NET_CTRL_NOTF_COAL_TX_SET,
-				  &sgs_tx))
-		return -EINVAL;
+	if (ec->tx_coalesce_usecs != vi->tx_usecs ||
+	    ec->tx_max_coalesced_frames != vi->tx_max_packets) {
+		coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs);
+		coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames);
+		sg_init_one(&sgs_tx, &coal_tx, sizeof(coal_tx));
+
+		if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
+					  VIRTIO_NET_CTRL_NOTF_COAL_TX_SET,
+					  &sgs_tx))
+			return -EINVAL;
 
-	/* Save parameters */
-	vi->tx_usecs = ec->tx_coalesce_usecs;
-	vi->tx_max_packets = ec->tx_max_coalesced_frames;
+		/* Save parameters */
+		vi->tx_usecs = ec->tx_coalesce_usecs;
+		vi->tx_max_packets = ec->tx_max_coalesced_frames;
+	}
 
-	coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs);
-	coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames);
-	sg_init_one(&sgs_rx, &coal_rx, sizeof(coal_rx));
+	if (ec->rx_coalesce_usecs != vi->rx_usecs ||
+	    ec->rx_max_coalesced_frames != vi->rx_max_packets) {
+		coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs);
+		coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames);
+		sg_init_one(&sgs_rx, &coal_rx, sizeof(coal_rx));
 
-	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
-				  VIRTIO_NET_CTRL_NOTF_COAL_RX_SET,
-				  &sgs_rx))
-		return -EINVAL;
+		if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL,
+					  VIRTIO_NET_CTRL_NOTF_COAL_RX_SET,
+					  &sgs_rx))
+			return -EINVAL;
 
-	/* Save parameters */
-	vi->rx_usecs = ec->rx_coalesce_usecs;
-	vi->rx_max_packets = ec->rx_max_coalesced_frames;
+		/* Save parameters */
+		vi->rx_usecs = ec->rx_coalesce_usecs;
+		vi->rx_max_packets = ec->rx_max_coalesced_frames;
+	}
 
 	return 0;
 }