virtio_net: ethtool tx napi configuration
Subsystems (3)
PATCH 1/1 virtio_net: ethtool tx napi configuration
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
--- drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
drivers/net/virtio_net.c +52 -0
@@ -66,6 +66,8 @@ DECLARE_EWMA(pkt_len, 0, 64)#define VIRTNET_DRIVER_VERSION "1.0.0" +static const u32 ethtool_coalesce_napi_mask = (1UL <<10 ); +static const unsigned long guest_offloads[] = {VIRTIO_NET_F_GUEST_TSO4 ,VIRTIO_NET_F_GUEST_TSO6 ,
@@ -2181,6 +2183,54 @@ static int virtnet_get_link_ksettings(struct net_device *dev,return 0 ; } +static int virtnet_set_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_SCOALESCE , + .rx_max_coalesced_frames =1 , + .tx_max_coalesced_frames =1 , + }; +struct virtnet_info *vi =netdev_priv (dev); +int i, napi_weight =0 ; + +if (ec->tx_max_coalesced_frames & ethtool_coalesce_napi_mask) { + ec->tx_max_coalesced_frames &= ~ethtool_coalesce_napi_mask; + napi_weight =NAPI_POLL_WEIGHT ; + } + +/* disallow changes to fields not explicitly tested above */ +if (memcmp (ec, &ec_default,sizeof (ec_default))) +return -EINVAL ; + +if (napi_weight ^ vi->sq[0 ].napi.weight) { +if (dev->flags &IFF_UP ) +return -EBUSY ; +for (i =0 ; i < vi->max_queue_pairs; i++) + vi->sq[i].napi.weight = napi_weight; + } + +return 0 ; +} + +static int virtnet_get_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_GCOALESCE , + .rx_max_coalesced_frames =1 , + .tx_max_coalesced_frames =1 , + }; +struct virtnet_info *vi =netdev_priv (dev); + +memcpy (ec, &ec_default,sizeof (ec_default)); + +if (vi->sq[0 ].napi.weight) + ec->tx_max_coalesced_frames |= ethtool_coalesce_napi_mask; + +return 0 ; +} +static void virtnet_init_settings (struct net_device *dev) {struct virtnet_info *vi =netdev_priv (dev);
@@ -2219,6 +2269,8 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_ts_info = ethtool_op_get_ts_info, .get_link_ksettings = virtnet_get_link_ksettings, .set_link_ksettings = virtnet_set_link_ksettings, + .set_coalesce = virtnet_set_coalesce, + .get_coalesce = virtnet_get_coalesce, };static void virtnet_freeze_down (struct virtio_device *vdev)
Signature · 1 line
2.19.0.rc2.392.g5ba43deb5a-goog
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
I cook a fixup, and it looks works in my setup:
drivers/net/virtio_net.c +0 -0
@@ -2204,10 +2204,17 @@ static int virtnet_set_coalesce(struct net_device *dev,
return -EINVAL;
if (napi_weight ^ vi->sq[0].napi.weight) {
- if (dev->flags & IFF_UP)
- return -EBUSY;
- for (i = 0; i < vi->max_queue_pairs; i++) + for (i = 0; i < vi->max_queue_pairs; i++) { + struct netdev_queue *txq =
+ netdev_get_tx_queue(vi->dev, i); +
+ virtnet_napi_tx_disable(&vi->sq[i].napi);
+ __netif_tx_lock_bh(txq); vi->sq[i].napi.weight = napi_weight; + __netif_tx_unlock_bh(txq);
+ virtnet_napi_tx_enable(vi, vi->sq[i].vq,
+ &vi->sq[i].napi);
+ }
}
return 0;
The only left case is the speculative tx polling in RX NAPI. I think we don't need to care in this case since it was not a must for correctness.
Quoted 22 lines
Suggested-by Jason Wang <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>--- drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)drivers/net/virtio_net.c +2
-0@@ -66,6 +66,8 @@ DECLARE_EWMA(pkt_len, 0, 64)#define VIRTNET_DRIVER_VERSION "1.0.0" +static const u32 ethtool_coalesce_napi_mask = (1UL <<10 ); +static const unsigned long guest_offloads[] = {VIRTIO_NET_F_GUEST_TSO4 ,VIRTIO_NET_F_GUEST_TSO6 ,
drivers/net/virtio_net.c static int virtnet_get_link_ksettings(struct net_device *dev, · line 2191
Quoted 9 lines
drivers/net/virtio_net.c +6
-0@@ -2181,6 +2183,54 @@ static int virtnet_get_link_ksettings(struct net_device *dev,return 0 ; } +static int virtnet_set_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_SCOALESCE , + .rx_max_coalesced_frames =1 ,
I think rx part is no necessary.
Thanks
Quoted 54 lines
drivers/net/virtio_net.c +44
-0+ .tx_max_coalesced_frames = 1, + }; +struct virtnet_info *vi =netdev_priv (dev); +int i, napi_weight =0 ; + +if (ec->tx_max_coalesced_frames & ethtool_coalesce_napi_mask) { + ec->tx_max_coalesced_frames &= ~ethtool_coalesce_napi_mask; + napi_weight =NAPI_POLL_WEIGHT ; + } + +/* disallow changes to fields not explicitly tested above */ +if (memcmp (ec, &ec_default,sizeof (ec_default))) +return -EINVAL ; + +if (napi_weight ^ vi->sq[0 ].napi.weight) { +if (dev->flags &IFF_UP ) +return -EBUSY ; +for (i =0 ; i < vi->max_queue_pairs; i++) + vi->sq[i].napi.weight = napi_weight; + } + +return 0 ; +} + +static int virtnet_get_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_GCOALESCE , + .rx_max_coalesced_frames =1 , + .tx_max_coalesced_frames =1 , + }; +struct virtnet_info *vi =netdev_priv (dev); + +memcpy (ec, &ec_default,sizeof (ec_default)); + +if (vi->sq[0 ].napi.weight) + ec->tx_max_coalesced_frames |= ethtool_coalesce_napi_mask; + +return 0 ; +} +static void virtnet_init_settings (struct net_device *dev) {struct virtnet_info *vi =netdev_priv (dev);@@ -2219,6 +2269,8 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_ts_info = ethtool_op_get_ts_info, .get_link_ksettings = virtnet_get_link_ksettings, .set_link_ksettings = virtnet_set_link_ksettings, + .set_coalesce = virtnet_set_coalesce, + .get_coalesce = virtnet_get_coalesce, };static void virtnet_freeze_down (struct virtio_device *vdev)
Quoted 45 lines · Jason Wang
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
I cook a fixup, and it looks works in my setup:
drivers/net/virtio_net.c +10
-3@@ -2204,10 +2204,17 @@ static int virtnet_set_coalesce(struct net_device *dev, return -EINVAL ;if (napi_weight ^ vi->sq[0 ].napi.weight) { -if (dev->flags &IFF_UP ) -return -EBUSY ; -for (i =0 ; i < vi->max_queue_pairs; i++) +for (i =0 ; i < vi->max_queue_pairs; i++) { +struct netdev_queue *txq = +netdev_get_tx_queue (vi->dev, i); + +virtnet_napi_tx_disable (&vi->sq[i].napi); +__netif_tx_lock_bh (txq); vi->sq[i].napi.weight = napi_weight; +__netif_tx_unlock_bh (txq); +virtnet_napi_tx_enable (vi, vi->sq[i].vq, + &vi->sq[i].napi); + } }
Quoted 1 line
return 0;
Thanks! It passes my simple stress test, too. Which consists of two concurrent loops, one toggling the ethtool option, another running TCP_RR.
Quoted 2 lines
The only left case is the speculative tx polling in RX NAPI. I think we don't need to care in this case since it was not a must for correctness.
As long as the txq lock is held that will be a noop, anyway. The other concurrent action is skb_xmit_done. It looks correct to me, but need to think about it a bit. The tricky transition is coming out of napi without having >= 2 + MAX_SKB_FRAGS clean descriptors. If the queue is stopped it may deadlock transmission in no-napi mode.
Quoted 25 lines
Quoted 25 lines
Suggested-by Jason Wang <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>--- drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)drivers/net/virtio_net.c +2
-0@@ -66,6 +66,8 @@ DECLARE_EWMA(pkt_len, 0, 64)#define VIRTNET_DRIVER_VERSION "1.0.0" +static const u32 ethtool_coalesce_napi_mask = (1UL <<10 ); +static const unsigned long guest_offloads[] = {VIRTIO_NET_F_GUEST_TSO4 ,VIRTIO_NET_F_GUEST_TSO6 ,@@ -2181,6 +2183,54 @@ static int virtnet_get_link_ksettings(struct net_device *dev,return 0 ; }
Quoted 8 lines
drivers/net/virtio_net.c static int virtnet_get_link_ksettings(struct net_device *dev, · line 2191
Quoted 6 lines
drivers/net/virtio_net.c +6
-0+static int virtnet_set_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_SCOALESCE , + .rx_max_coalesced_frames =1 ,I think rx part is no necessary.
The definition of ethtool_coalesce has:
"* It is illegal to set both usecs and max_frames to zero as this
* would cause interrupts to never be generated. To disable
* coalescing, set usecs = 0 and max_frames = 1."
I'd rather not diverge from this prescribed behavior unless there's a strong reason.
On the related point in the other thread:
Quoted 4 lines
Rethink about this, how about something like:
-
UINT_MAX: no tx interrupt
- other value: tx interrupt with possible interrupt moderation
Okay, that will be simpler to configure.
Quoted 49 lines · Willem de Bruijn
Quoted 43 lines · Jason Wang
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
I cook a fixup, and it looks works in my setup:
drivers/net/virtio_net.c +10
-3@@ -2204,10 +2204,17 @@ static int virtnet_set_coalesce(struct net_device *dev, return -EINVAL ;if (napi_weight ^ vi->sq[0 ].napi.weight) { -if (dev->flags &IFF_UP ) -return -EBUSY ; -for (i =0 ; i < vi->max_queue_pairs; i++) +for (i =0 ; i < vi->max_queue_pairs; i++) { +struct netdev_queue *txq = +netdev_get_tx_queue (vi->dev, i); + +virtnet_napi_tx_disable (&vi->sq[i].napi); +__netif_tx_lock_bh (txq); vi->sq[i].napi.weight = napi_weight; +__netif_tx_unlock_bh (txq); +virtnet_napi_tx_enable (vi, vi->sq[i].vq, + &vi->sq[i].napi); + } }Quoted 1 line
return 0;Thanks! It passes my simple stress test, too. Which consists of two concurrent loops, one toggling the ethtool option, another running
TCP_RR.
Quoted 7 lines
Quoted 2 lines
The only left case is the speculative tx polling in RX NAPI. I think we don't need to care in this case since it was not a must for correctness.
As long as the txq lock is held that will be a noop, anyway. The other concurrent action is
skb_xmit_done. It looks correct to me, but need to think about it a bit. The tricky transition is coming out of napi without having >= 2 +MAX_SKB_FRAGSclean descriptors. If the queue is stopped it may deadlock transmission in no-napi mode.
Yes, maybe we can enable tx queue when napi weight is zero in virtnet_poll_tx(). Let me do more stress test on this.
Quoted 32 lines
Quoted 25 lines
Quoted 25 lines
Suggested-by Jason Wang <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>--- drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)drivers/net/virtio_net.c +2
-0@@ -66,6 +66,8 @@ DECLARE_EWMA(pkt_len, 0, 64)#define VIRTNET_DRIVER_VERSION "1.0.0" +static const u32 ethtool_coalesce_napi_mask = (1UL <<10 ); +static const unsigned long guest_offloads[] = {VIRTIO_NET_F_GUEST_TSO4 ,VIRTIO_NET_F_GUEST_TSO6 ,@@ -2181,6 +2183,54 @@ static int virtnet_get_link_ksettings(struct net_device *dev,return 0 ; }Quoted 7 lines
drivers/net/virtio_net.c static int virtnet_get_link_ksettings(struct net_device *dev, · line 2191
Quoted 6 lines
drivers/net/virtio_net.c +6
-0+static int virtnet_set_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_SCOALESCE , + .rx_max_coalesced_frames =1 ,I think rx part is no necessary.
Quoted 8 lines
The definition of
ethtool_coalescehas:"* It is illegal to set both usecs and
max_framesto zero as this
* would cause interrupts to never be generated. To disable
* coalescing, set usecs = 0 andmax_frames= 1."I'd rather not diverge from this prescribed behavior unless there's a strong reason.
I get this.
Quoted 8 lines
On the related point in the other thread:
Quoted 4 lines
Rethink about this, how about something like:
-
UINT_MAX: no tx interrupt
- other value: tx interrupt with possible interrupt moderationOkay, that will be simpler to configure.
I wonder maybe we can use ethtool_coalesce definition. E.g usecs = 0 && max_frame = 0 means no interrupt? Just a thought, I'm ok with either.
Thanks
Quoted 34 lines
Quoted 34 lines
Quoted 27 lines
I cook a fixup, and it looks works in my setup:
drivers/net/virtio_net.c +10
-3@@ -2204,10 +2204,17 @@ static int virtnet_set_coalesce(struct net_device *dev, return -EINVAL ;if (napi_weight ^ vi->sq[0 ].napi.weight) { -if (dev->flags &IFF_UP ) -return -EBUSY ; -for (i =0 ; i < vi->max_queue_pairs; i++) +for (i =0 ; i < vi->max_queue_pairs; i++) { +struct netdev_queue *txq = +netdev_get_tx_queue (vi->dev, i); + +virtnet_napi_tx_disable (&vi->sq[i].napi); +__netif_tx_lock_bh (txq); vi->sq[i].napi.weight = napi_weight; +__netif_tx_unlock_bh (txq); +virtnet_napi_tx_enable (vi, vi->sq[i].vq, + &vi->sq[i].napi); + } }Quoted 1 line
return 0;Thanks! It passes my simple stress test, too. Which consists of two concurrent loops, one toggling the ethtool option, another running
TCP_RR.Quoted 2 lines
The only left case is the speculative tx polling in RX NAPI. I think we don't need to care in this case since it was not a must for correctness.
Quoted 8 lines
Quoted 5 lines
As long as the txq lock is held that will be a noop, anyway. The other concurrent action is
skb_xmit_done. It looks correct to me, but need to think about it a bit. The tricky transition is coming out of napi without having >= 2 +MAX_SKB_FRAGSclean descriptors. If the queue is stopped it may deadlock transmission in no-napi mode.Yes, maybe we can enable tx queue when napi weight is zero in
virtnet_poll_tx().
Yes, that precaution should resolve that edge case.
Quoted 48 lines
Let me do more stress test on this.
Quoted 32 lines
Quoted 25 lines
Quoted 25 lines
Suggested-by Jason Wang <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>--- drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)drivers/net/virtio_net.c +2
-0@@ -66,6 +66,8 @@ DECLARE_EWMA(pkt_len, 0, 64)#define VIRTNET_DRIVER_VERSION "1.0.0" +static const u32 ethtool_coalesce_napi_mask = (1UL <<10 ); +static const unsigned long guest_offloads[] = {VIRTIO_NET_F_GUEST_TSO4 ,VIRTIO_NET_F_GUEST_TSO6 ,@@ -2181,6 +2183,54 @@ static int virtnet_get_link_ksettings(struct net_device *dev,return 0 ; }Quoted 7 lines
drivers/net/virtio_net.c static int virtnet_get_link_ksettings(struct net_device *dev, · line 2191
Quoted 6 lines
drivers/net/virtio_net.c +6
-0+static int virtnet_set_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_SCOALESCE , + .rx_max_coalesced_frames =1 ,I think rx part is no necessary.
Quoted 8 lines
The definition of
ethtool_coalescehas:"* It is illegal to set both usecs and
max_framesto zero as this
* would cause interrupts to never be generated. To disable
* coalescing, set usecs = 0 andmax_frames= 1."I'd rather not diverge from this prescribed behavior unless there's a strong reason.
I get this.
Quoted 3 lines
On the related point in the other thread:
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Rethink about this, how about something like:
-
UINT_MAX: no tx interrupt
- other value: tx interrupt with possible interrupt moderationOkay, that will be simpler to configure.
I wonder maybe we can use
ethtool_coalescedefinition. E.g usecs = 0 &&max_frame= 0 means no interrupt? Just a thought, I'm ok with either.
Come to think of it, max_frames 0 is no worse than max_frames UINT_MAX. Sure, let's do that.
Quoted 34 lines · Willem de Bruijn
Quoted 34 lines
Quoted 34 lines
Quoted 27 lines
I cook a fixup, and it looks works in my setup:
drivers/net/virtio_net.c +10
-3@@ -2204,10 +2204,17 @@ static int virtnet_set_coalesce(struct net_device *dev, return -EINVAL ;if (napi_weight ^ vi->sq[0 ].napi.weight) { -if (dev->flags &IFF_UP ) -return -EBUSY ; -for (i =0 ; i < vi->max_queue_pairs; i++) +for (i =0 ; i < vi->max_queue_pairs; i++) { +struct netdev_queue *txq = +netdev_get_tx_queue (vi->dev, i); + +virtnet_napi_tx_disable (&vi->sq[i].napi); +__netif_tx_lock_bh (txq); vi->sq[i].napi.weight = napi_weight; +__netif_tx_unlock_bh (txq); +virtnet_napi_tx_enable (vi, vi->sq[i].vq, + &vi->sq[i].napi); + } }Quoted 1 line
return 0;Thanks! It passes my simple stress test, too. Which consists of two concurrent loops, one toggling the ethtool option, another running
TCP_RR.Quoted 2 lines
The only left case is the speculative tx polling in RX NAPI. I think we don't need to care in this case since it was not a must for correctness.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
As long as the txq lock is held that will be a noop, anyway. The other concurrent action is
skb_xmit_done. It looks correct to me, but need to think about it a bit. The tricky transition is coming out of napi without having >= 2 +MAX_SKB_FRAGSclean descriptors. If the queue is stopped it may deadlock transmission in no-napi mode.Yes, maybe we can enable tx queue when napi weight is zero in
virtnet_poll_tx().Yes, that precaution should resolve that edge case.
I've done a stress test and it passes. The test contains:
- vm with 2 queues
- a bash script to enable and disable tx napi
- two netperf UDP_STREAM sessions to send small packets
Thanks
Quoted 45 lines · Jason Wang
Quoted 41 lines · Willem de Bruijn
Quoted 41 lines
Quoted 32 lines
Quoted 27 lines
I cook a fixup, and it looks works in my setup:
drivers/net/virtio_net.c +10
-3@@ -2204,10 +2204,17 @@ static int virtnet_set_coalesce(struct net_device *dev, return -EINVAL ;if (napi_weight ^ vi->sq[0 ].napi.weight) { -if (dev->flags &IFF_UP ) -return -EBUSY ; -for (i =0 ; i < vi->max_queue_pairs; i++) +for (i =0 ; i < vi->max_queue_pairs; i++) { +struct netdev_queue *txq = +netdev_get_tx_queue (vi->dev, i); + +virtnet_napi_tx_disable (&vi->sq[i].napi); +__netif_tx_lock_bh (txq); vi->sq[i].napi.weight = napi_weight; +__netif_tx_unlock_bh (txq); +virtnet_napi_tx_enable (vi, vi->sq[i].vq, + &vi->sq[i].napi); + } }Quoted 1 line
return 0;Thanks! It passes my simple stress test, too. Which consists of two concurrent loops, one toggling the ethtool option, another running
TCP_RR.Quoted 7 lines
Quoted 2 lines
The only left case is the speculative tx polling in RX NAPI. I think we don't need to care in this case since it was not a must for correctness.
As long as the txq lock is held that will be a noop, anyway. The other concurrent action is
skb_xmit_done. It looks correct to me, but need to think about it a bit. The tricky transition is coming out of napi without having >= 2 +MAX_SKB_FRAGSclean descriptors. If the queue is stopped it may deadlock transmission in no-napi mode.Yes, maybe we can enable tx queue when napi weight is zero in
virtnet_poll_tx().
Quoted 8 lines
Quoted 2 lines
Yes, that precaution should resolve that edge case.
I've done a stress test and it passes. The test contains:
- vm with 2 queues
- a bash script to enable and disable tx napi
- two netperfUDP_STREAMsessions to send small packets
Great. That matches my results. Do you want to send the v2?
Quoted 45 lines · Willem de Bruijn
Quoted 44 lines · Jason Wang
Quoted 41 lines · Willem de Bruijn
Quoted 41 lines
Quoted 32 lines
Quoted 27 lines
I cook a fixup, and it looks works in my setup:
drivers/net/virtio_net.c +10
-3@@ -2204,10 +2204,17 @@ static int virtnet_set_coalesce(struct net_device *dev, return -EINVAL ;if (napi_weight ^ vi->sq[0 ].napi.weight) { -if (dev->flags &IFF_UP ) -return -EBUSY ; -for (i =0 ; i < vi->max_queue_pairs; i++) +for (i =0 ; i < vi->max_queue_pairs; i++) { +struct netdev_queue *txq = +netdev_get_tx_queue (vi->dev, i); + +virtnet_napi_tx_disable (&vi->sq[i].napi); +__netif_tx_lock_bh (txq); vi->sq[i].napi.weight = napi_weight; +__netif_tx_unlock_bh (txq); +virtnet_napi_tx_enable (vi, vi->sq[i].vq, + &vi->sq[i].napi); + } }Quoted 1 line
return 0;Thanks! It passes my simple stress test, too. Which consists of two concurrent loops, one toggling the ethtool option, another running
TCP_RR.Quoted 7 lines
Quoted 2 lines
The only left case is the speculative tx polling in RX NAPI. I think we don't need to care in this case since it was not a must for correctness.
As long as the txq lock is held that will be a noop, anyway. The other concurrent action is
skb_xmit_done. It looks correct to me, but need to think about it a bit. The tricky transition is coming out of napi without having >= 2 +MAX_SKB_FRAGSclean descriptors. If the queue is stopped it may deadlock transmission in no-napi mode.Yes, maybe we can enable tx queue when napi weight is zero in
virtnet_poll_tx().
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Yes, that precaution should resolve that edge case.
I've done a stress test and it passes. The test contains:
- vm with 2 queues
- a bash script to enable and disable tx napi
- two netperfUDP_STREAMsessions to send small packetsGreat. That matches my results. Do you want to send the v2?
Some mails were blocked so I do not receive some replies in time. So I post a V2 (but as you've pointed out, it's buggy).
Thanks
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 86 lines
Suggested-by Jason Wang <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>--- drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)drivers/net/virtio_net.c +52
-0@@ -66,6 +66,8 @@ DECLARE_EWMA(pkt_len, 0, 64)#define VIRTNET_DRIVER_VERSION "1.0.0" +static const u32 ethtool_coalesce_napi_mask = (1UL <<10 ); +static const unsigned long guest_offloads[] = {VIRTIO_NET_F_GUEST_TSO4 ,VIRTIO_NET_F_GUEST_TSO6 ,@@ -2181,6 +2183,54 @@ static int virtnet_get_link_ksettings(struct net_device *dev,return 0 ; } +static int virtnet_set_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_SCOALESCE , + .rx_max_coalesced_frames =1 , + .tx_max_coalesced_frames =1 , + }; +struct virtnet_info *vi =netdev_priv (dev); +int i, napi_weight =0 ; + +if (ec->tx_max_coalesced_frames & ethtool_coalesce_napi_mask) { + ec->tx_max_coalesced_frames &= ~ethtool_coalesce_napi_mask; + napi_weight =NAPI_POLL_WEIGHT ; + } + +/* disallow changes to fields not explicitly tested above */ +if (memcmp (ec, &ec_default,sizeof (ec_default))) +return -EINVAL ; + +if (napi_weight ^ vi->sq[0 ].napi.weight) { +if (dev->flags &IFF_UP ) +return -EBUSY ; +for (i =0 ; i < vi->max_queue_pairs; i++) + vi->sq[i].napi.weight = napi_weight; + } + +return 0 ; +} + +static int virtnet_get_coalesce (struct net_device *dev, +struct ethtool_coalesce *ec) +{ +const struct ethtool_coalesce ec_default = { + .cmd =ETHTOOL_GCOALESCE , + .rx_max_coalesced_frames =1 , + .tx_max_coalesced_frames =1 , + }; +struct virtnet_info *vi =netdev_priv (dev); + +memcpy (ec, &ec_default,sizeof (ec_default)); + +if (vi->sq[0 ].napi.weight) + ec->tx_max_coalesced_frames |= ethtool_coalesce_napi_mask; + +return 0 ; +} +static void virtnet_init_settings (struct net_device *dev) {struct virtnet_info *vi =netdev_priv (dev);@@ -2219,6 +2269,8 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_ts_info = ethtool_op_get_ts_info, .get_link_ksettings = virtnet_get_link_ksettings, .set_link_ksettings = virtnet_set_link_ksettings, + .set_coalesce = virtnet_set_coalesce, + .get_coalesce = virtnet_get_coalesce, };static void virtnet_freeze_down (struct virtio_device *vdev)
Signature · 1 line
Florian
Quoted 14 lines · Florian Fainelli
Quoted 10 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Quoted 6 lines
Quoted 3 lines
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
Configurable napi-tx is not a common feature across devices. We really want virtio-net to also just convert to napi-tx as default, but need a way to gradually convert with application opt-out if some workloads see regressions. There is prior art in interpreting coalesce values as more than a direct mapping to usec. The e1000 is one example.
Quoted 19 lines · Willem de Bruijn
Quoted 18 lines · Florian Fainelli
Quoted 13 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Quoted 5 lines
Quoted 2 lines
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using ethtool_drvinfo::n_priv_flags, ETH_SS_PRIV_FLAGS and then ETHTOOL_GFPFLAGS and ETHTOOL_SPFLAGS to control the toggling of that private flag. mlx5 has a number of privates flags for instance.
Quoted 5 lines
Configurable napi-tx is not a common feature across devices. We really want virtio-net to also just convert to napi-tx as default, but need a way to gradually convert with application opt-out if some workloads see regressions.
The rationale makes sense, no questions about it.
Quoted 3 lines
There is prior art in interpreting coalesce values as more than a direct mapping to usec. The e1000 is one example.
Looked at both e1000 and e1000e and they both have a similar programming of the HW's interrupt target rate register, which is relevant to interrupt coalescing, what part of these drivers do you see as doing something not quite coalescing related?
Signature · 1 line
Florian
Quoted 26 lines · Florian Fainelli
Quoted 22 lines · Willem de Bruijn
Quoted 20 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 6 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.
Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Quoted 7 lines
Quoted 4 lines
Configurable napi-tx is not a common feature across devices. We really want virtio-net to also just convert to napi-tx as default, but need a way to gradually convert with application opt-out if some workloads see regressions.
The rationale makes sense, no questions about it.
Quoted 8 lines
Quoted 3 lines
There is prior art in interpreting coalesce values as more than a direct mapping to usec. The e1000 is one example.
Looked at both e1000 and e1000e and they both have a similar programming of the HW's interrupt target rate register, which is relevant to interrupt coalescing, what part of these drivers do you see as doing something not quite coalescing related?
It's all coalescing related, for sure. e1000_set_coalesce just does not translate the tx-usecs values into microsecond latency directly.
It modifies both the interrupt throttle rate adapter->itr and interrupt mode adapter->itr_setting, which are initially set in e1000_check_options from module param InterruptThrottleRate.
Value 0 disables interrupt moderation. 1 and 3 program a dynamic mode. 2 is an illegal value as is 5..9. 10..10000 converts from usec to interrupt rate/sec.
I took tx-napi to be a similar interrupt related option as, say, dynamic conservative mode interrupt moderation.
Quoted 31 lines · Willem de Bruijn
Quoted 29 lines · Florian Fainelli
Quoted 24 lines · Willem de Bruijn
Quoted 14 lines · Florian Fainelli
Quoted 10 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Quoted 6 lines
Quoted 3 lines
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
Quoted 6 lines
Quoted 3 lines
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at include/linux/netdevice.h:515
BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
Quoted 32 lines · Willem de Bruijn
Quoted 23 lines · Willem de Bruijn
Quoted 22 lines · Florian Fainelli
Quoted 19 lines · Willem de Bruijn
Quoted 18 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Quoted 7 lines
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at
include/linux/netdevice.h:515BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
This reminds me that we need to check netif_running() before trying to enable and disable tx napi in ethtool_set_coalesce().
Thanks
Quoted 39 lines · Jason Wang
Quoted 35 lines · Willem de Bruijn
Quoted 23 lines · Willem de Bruijn
Quoted 22 lines · Florian Fainelli
Quoted 19 lines · Willem de Bruijn
Quoted 18 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
Quoted 7 lines
Quoted 4 lines
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at
include/linux/netdevice.h:515BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));This reminds me that we need to check
netif_running()before trying to enable and disable tx napi inethtool_set_coalesce().
The first iteration of my patch checked IFF_UP and effectively only allowed the change when not running. What do you mean by need to check?
And to respond to the other follow-up notes at once:
Quoted 5 lines
Consider we may have interrupt moderation in the future, I tend to use
set_coalesce. Otherwise we may need two steps to enable moderation:- tx-napi on
-set_coalesce
FWIW, I don't care strongly whether we do this through coalesce or priv_flags.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!napi_weight) + virtqueue_enable_cb(vi->sq[i].vq);I don't get why we need to disable enable cb here.
To avoid entering no-napi mode with too few descriptors to make progress and no way to get out of that state. This is a pretty crude attempt at handling that, admittedly.
Quoted 40 lines · Willem de Bruijn
Quoted 39 lines · Jason Wang
Quoted 36 lines · Willem de Bruijn
Quoted 21 lines · Willem de Bruijn
Quoted 20 lines · Florian Fainelli
Quoted 18 lines · Willem de Bruijn
Quoted 17 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at
include/linux/netdevice.h:515
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));This reminds me that we need to check
netif_running()before trying to enable and disable tx napi inethtool_set_coalesce().The first iteration of my patch checked
IFF_UPand effectively only allowed the change when not running. What do you mean by need to check?
I mean if device is not up, there's no need to toggle napi state and tx lock.
Quoted 9 lines
And to respond to the other follow-up notes at once:
Quoted 5 lines
Consider we may have interrupt moderation in the future, I tend to use
set_coalesce. Otherwise we may need two steps to enable moderation:- tx-napi on
-set_coalesceFWIW, I don't care strongly whether we do this through coalesce or
priv_flags.
Ok.
Quoted 6 lines
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!napi_weight) + virtqueue_enable_cb(vi->sq[i].vq);I don't get why we need to disable enable cb here.
To avoid entering no-napi mode with too few descriptors to make progress and no way to get out of that state. This is a pretty crude attempt at handling that, admittedly.
But in this case, we will call enable_cb_delayed() and we will finally get a interrupt?
Thanks
Quoted 57 lines · Jason Wang
Quoted 40 lines · Willem de Bruijn
Quoted 39 lines · Jason Wang
Quoted 36 lines · Willem de Bruijn
Quoted 21 lines · Willem de Bruijn
Quoted 20 lines · Florian Fainelli
Quoted 18 lines · Willem de Bruijn
Quoted 17 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at
include/linux/netdevice.h:515Quoted 6 lines
Quoted 3 lines
Quoted 1 line
BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));This reminds me that we need to check
netif_running()before trying to enable and disable tx napi inethtool_set_coalesce().The first iteration of my patch checked
IFF_UPand effectively only allowed the change when not running. What do you mean by need to check?I mean if device is not up, there's no need to toggle napi state and tx lock.
Quoted 3 lines
And to respond to the other follow-up notes at once:
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Consider we may have interrupt moderation in the future, I tend to use
set_coalesce. Otherwise we may need two steps to enable moderation:- tx-napi on
-set_coalesceFWIW, I don't care strongly whether we do this through coalesce or
priv_flags.Ok.
Since you prefer coalesce, let's go with that (and a revision of your latest patch).
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ if (!napi_weight) + virtqueue_enable_cb(vi->sq[i].vq);I don't get why we need to disable enable cb here.
To avoid entering no-napi mode with too few descriptors to make progress and no way to get out of that state. This is a pretty crude attempt at handling that, admittedly.
But in this case, we will call
enable_cb_delayed()and we will finally get a interrupt?
Right. It's a bit of a roundabout way to ensure that netif_tx_wake_queue and thus eventually free_old_xmit_skbs are called. It might make more sense to just wake the device without going through an interrupt.
Quoted 55 lines · Willem de Bruijn
Quoted 54 lines · Jason Wang
Quoted 37 lines · Willem de Bruijn
Quoted 36 lines · Jason Wang
Quoted 34 lines · Willem de Bruijn
Quoted 19 lines · Willem de Bruijn
Quoted 18 lines · Florian Fainelli
Quoted 17 lines · Willem de Bruijn
Quoted 16 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at
include/linux/netdevice.h:515Quoted 6 lines
Quoted 3 lines
Quoted 1 line
BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));This reminds me that we need to check
netif_running()before trying to enable and disable tx napi inethtool_set_coalesce().The first iteration of my patch checked
IFF_UPand effectively only allowed the change when not running. What do you mean by need to check?I mean if device is not up, there's no need to toggle napi state and tx lock.
Quoted 5 lines
And to respond to the other follow-up notes at once:
Quoted 3 lines
Consider we may have interrupt moderation in the future, I tend to use
set_coalesce. Otherwise we may need two steps to enable moderation:
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
- tx-napi on
-set_coalesceFWIW, I don't care strongly whether we do this through coalesce or
priv_flags.Ok.
Since you prefer coalesce, let's go with that (and a revision of your latest patch).
Good to know this.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!napi_weight) + virtqueue_enable_cb(vi->sq[i].vq);I don't get why we need to disable enable cb here.
To avoid entering no-napi mode with too few descriptors to make progress and no way to get out of that state. This is a pretty crude attempt at handling that, admittedly.
Quoted 6 lines
Quoted 2 lines
But in this case, we will call
enable_cb_delayed()and we will finally get a interrupt?Right. It's a bit of a roundabout way to ensure that
netif_tx_wake_queueand thus eventuallyfree_old_xmit_skbsare called. It might make more sense to just wake the device without going through an interrupt.
I'm not sure I get this. If we don't enable tx napi, we tend to delay TX interrupt if we found the ring is about to full to avoid interrupt storm, so we're probably ok in this case.
Thanks
Quoted 76 lines · Jason Wang
Quoted 55 lines · Willem de Bruijn
Quoted 54 lines · Jason Wang
Quoted 37 lines · Willem de Bruijn
Quoted 36 lines · Jason Wang
Quoted 34 lines · Willem de Bruijn
Quoted 19 lines · Willem de Bruijn
Quoted 18 lines · Florian Fainelli
Quoted 17 lines · Willem de Bruijn
Quoted 16 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at
include/linux/netdevice.h:515Quoted 6 lines
Quoted 3 lines
Quoted 1 line
BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));This reminds me that we need to check
netif_running()before trying to enable and disable tx napi inethtool_set_coalesce().The first iteration of my patch checked
IFF_UPand effectively only allowed the change when not running. What do you mean by need to check?I mean if device is not up, there's no need to toggle napi state and tx lock.
Quoted 5 lines
And to respond to the other follow-up notes at once:
Quoted 3 lines
Consider we may have interrupt moderation in the future, I tend to use
set_coalesce. Otherwise we may need two steps to enable moderation:Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
- tx-napi on
-set_coalesceFWIW, I don't care strongly whether we do this through coalesce or
priv_flags.Ok.
Since you prefer coalesce, let's go with that (and a revision of your latest patch).
Good to know this.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!napi_weight) + virtqueue_enable_cb(vi->sq[i].vq);I don't get why we need to disable enable cb here.
To avoid entering no-napi mode with too few descriptors to make progress and no way to get out of that state. This is a pretty crude attempt at handling that, admittedly.
But in this case, we will call
enable_cb_delayed()and we will finally get a interrupt?
Quoted 8 lines
Quoted 4 lines
Right. It's a bit of a roundabout way to ensure that
netif_tx_wake_queueand thus eventuallyfree_old_xmit_skbsare called. It might make more sense to just wake the device without going through an interrupt.I'm not sure I get this. If we don't enable tx napi, we tend to delay TX interrupt if we found the ring is about to full to avoid interrupt storm, so we're probably ok in this case.
I'm only concerned about the transition state when converting from napi to no-napi when the queue is stopped and tx interrupt disabled.
With napi mode the interrupt is only disabled if napi is scheduled, in which case it will eventually reenable the interrupt. But when switching to no-napi mode in this state no progress will be made.
But it seems this cannot happen. When converting to no-napi mode, set_coalesce waits for napi to complete in napi_disable. So the interrupt should always start enabled when transitioning into no-napi mode.
Quoted 83 lines · Willem de Bruijn
Quoted 72 lines · Jason Wang
Quoted 53 lines · Willem de Bruijn
Quoted 52 lines · Jason Wang
Quoted 36 lines · Willem de Bruijn
Quoted 35 lines · Jason Wang
Quoted 34 lines · Willem de Bruijn
Quoted 19 lines · Willem de Bruijn
Quoted 18 lines · Florian Fainelli
Quoted 17 lines · Willem de Bruijn
Quoted 16 lines · Florian Fainelli
Quoted 6 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Quoted 7 lines
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Okay, I made that change. That is indeed much cleaner, thanks. Let me send the patch, initially as RFC.
I've observed one issue where if we toggle the flag before bringing up the device, it hits a kernel BUG at
include/linux/netdevice.h:515Quoted 6 lines
Quoted 3 lines
Quoted 1 line
BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));This reminds me that we need to check
netif_running()before trying to enable and disable tx napi inethtool_set_coalesce().The first iteration of my patch checked
IFF_UPand effectively only allowed the change when not running. What do you mean by need to check?I mean if device is not up, there's no need to toggle napi state and tx lock.
Quoted 5 lines
And to respond to the other follow-up notes at once:
Quoted 3 lines
Consider we may have interrupt moderation in the future, I tend to use
set_coalesce. Otherwise we may need two steps to enable moderation:Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
- tx-napi on
-set_coalesceFWIW, I don't care strongly whether we do this through coalesce or
priv_flags.Ok.
Since you prefer coalesce, let's go with that (and a revision of your latest patch).
Good to know this.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!napi_weight) + virtqueue_enable_cb(vi->sq[i].vq);I don't get why we need to disable enable cb here.
To avoid entering no-napi mode with too few descriptors to make progress and no way to get out of that state. This is a pretty crude attempt at handling that, admittedly.
But in this case, we will call
enable_cb_delayed()and we will finally get a interrupt?Quoted 7 lines
Quoted 4 lines
Right. It's a bit of a roundabout way to ensure that
netif_tx_wake_queueand thus eventuallyfree_old_xmit_skbsare called. It might make more sense to just wake the device without going through an interrupt.I'm not sure I get this. If we don't enable tx napi, we tend to delay TX interrupt if we found the ring is about to full to avoid interrupt storm, so we're probably ok in this case.
I'm only concerned about the transition state when converting from napi to no-napi when the queue is stopped and tx interrupt disabled.
Quoted 8 lines
With napi mode the interrupt is only disabled if napi is scheduled, in which case it will eventually reenable the interrupt. But when switching to no-napi mode in this state no progress will be made.
But it seems this cannot happen. When converting to no-napi mode,
set_coalescewaits for napi to complete innapi_disable. So the interrupt should always start enabled when transitioning into no-napi mode.
Yes, I see.
Thanks
Quoted 6 lines · Willem de Bruijn
Quoted 3 lines
I'm not sure I get this. If we don't enable tx napi, we tend to delay TX interrupt if we found the ring is about to full to avoid interrupt storm, so we're probably ok in this case.
I'm only concerned about the transition state when converting from napi to no-napi when the queue is stopped and tx interrupt disabled.
Quoted 8 lines
With napi mode the interrupt is only disabled if napi is scheduled, in which case it will eventually reenable the interrupt. But when switching to no-napi mode in this state no progress will be made.
But it seems this cannot happen. When converting to no-napi mode,
set_coalescewaits for napi to complete innapi_disable. So the interrupt should always start enabled when transitioning into no-napi mode.
An update, I meet a hang in napi_disalbe(). But it's hard to be reproduced. I tend to choose a easy way like V1 that only allow the switching when device is down.
I will post the patch after a vacation. (or you can post if it was urgent for you).
Thanks
Quoted 14 lines · Jason Wang
Quoted 10 lines · Willem de Bruijn
Quoted 3 lines
I'm not sure I get this. If we don't enable tx napi, we tend to delay TX interrupt if we found the ring is about to full to avoid interrupt storm, so we're probably ok in this case.
I'm only concerned about the transition state when converting from napi to no-napi when the queue is stopped and tx interrupt disabled.
With napi mode the interrupt is only disabled if napi is scheduled, in which case it will eventually reenable the interrupt. But when switching to no-napi mode in this state no progress will be made.
Quoted 8 lines
Quoted 4 lines
But it seems this cannot happen. When converting to no-napi mode,
set_coalescewaits for napi to complete innapi_disable. So the interrupt should always start enabled when transitioning into no-napi mode.An update, I meet a hang in
napi_disalbe(). But it's hard to be reproduced. I tend to choose a easy way like V1 that only allow the switching when device is down.
I agree.
Quoted 2 lines
I will post the patch after a vacation. (or you can post if it was urgent for you).
If you have time to review and add your signed-off-by, I can post it. It's a pretty small diff at this point.
But no rush, we can also wait until after your vacation.
I also need to look at a patch to toggle LRO using ethtool, btw.
Quoted 21 lines · Willem de Bruijn
Quoted 13 lines · Jason Wang
Quoted 10 lines · Willem de Bruijn
Quoted 3 lines
I'm not sure I get this. If we don't enable tx napi, we tend to delay TX interrupt if we found the ring is about to full to avoid interrupt storm, so we're probably ok in this case.
I'm only concerned about the transition state when converting from napi to no-napi when the queue is stopped and tx interrupt disabled.
With napi mode the interrupt is only disabled if napi is scheduled, in which case it will eventually reenable the interrupt. But when switching to no-napi mode in this state no progress will be made.
Quoted 7 lines
Quoted 4 lines
But it seems this cannot happen. When converting to no-napi mode,
set_coalescewaits for napi to complete innapi_disable. So the interrupt should always start enabled when transitioning into no-napi mode.An update, I meet a hang in
napi_disalbe(). But it's hard to be reproduced. I tend to choose a easy way like V1 that only allow the switching when device is down.
Quoted 8 lines
I agree.
Quoted 2 lines
I will post the patch after a vacation. (or you can post if it was urgent for you).
If you have time to review and add your signed-off-by, I can post it. It's a pretty small diff at this point.
But no rush, we can also wait until after your vacation.
Then let me post it after the vacation.
Quoted 2 lines
I also need to look at a patch to toggle LRO using ethtool, btw.
Interesting, we've already did something similar during XDP. The GUEST_TSO_XXX part may need some private flags I believe.
Thanks
Quoted 51 lines · Willem de Bruijn
Quoted 20 lines · Florian Fainelli
Quoted 17 lines · Willem de Bruijn
Quoted 16 lines · Florian Fainelli
Quoted 13 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Implement ethtool .set_coalesce (-C) and .get_coalesce (-c) handlers. Interrupt moderation is currently not supported, so these accept and display the default settings of 0 usec and 1 frame.
Toggle tx napi through a bit in tx-frames. So as to not interfere with possible future interrupt moderation, use bit 10, well outside the reasonable range of real interrupt moderation values.
Changes are not atomic. The tx IRQ, napi BH and transmit path must be quiesced when switching modes. Only allow changing this setting when the device is down.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Humm, would not a private ethtool flag to switch TX NAPI on/off be more appropriate rather than use the coalescing configuration API here?
What do you mean by private ethtool flag? A new field in ethtool --features (-k)?
I meant using
ethtool_drvinfo::n_priv_flags,ETH_SS_PRIV_FLAGSand thenETHTOOL_GFPFLAGSandETHTOOL_SPFLAGSto control the toggling of that private flag. mlx5 has a number of privates flags for instance.Interesting, thanks! I was not at all aware of those ethtool flags. Am having a look. It definitely looks promising.
Quoted 6 lines
Quoted 4 lines
Configurable napi-tx is not a common feature across devices. We really want virtio-net to also just convert to napi-tx as default, but need a way to gradually convert with application opt-out if some workloads see regressions.
The rationale makes sense, no questions about it.
Quoted 7 lines
Quoted 3 lines
There is prior art in interpreting coalesce values as more than a direct mapping to usec. The e1000 is one example.
Looked at both e1000 and e1000e and they both have a similar programming of the HW's interrupt target rate register, which is relevant to interrupt coalescing, what part of these drivers do you see as doing something not quite coalescing related?
It's all coalescing related, for sure.
e1000_set_coalescejust does not translate the tx-usecs values into microsecond latency directly.It modifies both the interrupt throttle rate
adapter->itrand interrupt modeadapter->itr_setting, which are initially set ine1000_check_optionsfrom module param InterruptThrottleRate.
Quoted 6 lines
Value 0 disables interrupt moderation. 1 and 3 program a dynamic mode. 2 is an illegal value as is 5..9. 10..10000 converts from usec to interrupt rate/sec.
I took tx-napi to be a similar interrupt related option as, say, dynamic conservative mode interrupt moderation.
Consider we may have interrupt moderation in the future, I tend to use set_coalesce. Otherwise we may need two steps to enable moderation:
- tx-napi on
- set_coalesce
Thanks