netdevsim: implement peer queue flow control
Subsystems (3)
PATCH v3 1/1 netdevsim: implement peer queue flow control
Add flow control mechanism between paired netdevsim devices to stop the TX queue during high traffic scenarios. When a receive queue becomes congested (approaching NSIM_RING_SIZE limit), the corresponding transmit queue on the peer device is stopped using netif_subqueue_try_stop().
Once the receive queue has sufficient capacity again, the peer's transmit queue is resumed with netif_tx_wake_queue().
Key changes:
* Add nsim_stop_peer_tx_queue() to pause peer TX when RX queue is full
* Add nsim_start_peer_tx_queue() to resume peer TX when RX queue drains
* Implement queue mapping validation to ensure TX/RX queue count match
* Wake all queues during device unlinking to prevent stuck queues
* Use RCU protection when accessing peer device references
* wake the queues when changing the queue numbers
* Remove IFF_NO_QUEUE given it will enqueue packets now
The flow control only activates when devices have matching TX/RX queue counts to ensure proper queue mapping.
---
Changes in v3:
- Wake the queues if we need to in nsim_set_channels() (Jakub)
- Remove IFF_NO_QUEUE (Jakub)
- Improve function parameters (Jakub)
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Move the RCU locks inside the function (David)
- Use better helpers for waking up all the queues (Jakub)
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/net/netdevsim/bus.c | 3 ++ drivers/net/netdevsim/ethtool.c | 21 +++++++++++++ drivers/net/netdevsim/netdev.c | 68 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 85 insertions(+), 7 deletions(-)
drivers/net/netdevsim/bus.c +3 -0
@@ -366,6 +366,9 @@ static ssize_t unlink_device_store(const struct bus_type *bus, const char *buf, err =0 ;RCU_INIT_POINTER (nsim->peer,NULL );RCU_INIT_POINTER (peer->peer,NULL ); +synchronize_net (); +netif_tx_wake_all_queues (dev); +netif_tx_wake_all_queues (peer->netdev); out_put_netns:put_net (ns);
drivers/net/netdevsim/ethtool.c +21 -0
@@ -101,6 +101,22 @@ nsim_get_channels(struct net_device *dev, struct ethtool_channels *ch) ch->combined_count = ns->ethtool.channels; } +static void +nsim_wake_queues (struct net_device *dev) +{ +struct netdevsim *ns =netdev_priv (dev); +struct netdevsim *peer; + +synchronize_net (); +netif_tx_wake_all_queues (dev); + +rcu_read_lock (); + peer =rcu_dereference (ns->peer); +if (peer) +netif_tx_wake_all_queues (peer->netdev); +rcu_read_unlock (); +} +static int nsim_set_channels (struct net_device *dev,struct ethtool_channels *ch) {
@@ -113,6 +129,11 @@ nsim_set_channels(struct net_device *dev, struct ethtool_channels *ch)return err; ns->ethtool.channels = ch->combined_count; + +/* Only wake up queues if devices are linked */ +if (rcu_access_pointer (ns->peer)) +nsim_wake_queues (dev); +return 0 ; }
drivers/net/netdevsim/netdev.c +61 -7
104 lines not on this page · raw message
---
base-commit: 5fa1fa9184ef1af929ae49c715d4a25667e84df5
change-id: 20250630-netdev_flow_control-2b2d37965377
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Jakub Kicinski
maintainerdrivers/net/netdevsim/netdev.c MODULE_IMPORT_NS("NETDEV_INTERNAL"); · line 60
Quoted 1 line · On Fri, 11 Jul 2025 10:06:59 -0700 Breno Leitao wrote:
drivers/net/netdevsim/netdev.c +1
-0+if (!(netif_tx_queue_stopped (txq)))
Unnecessary parenthesis here, will drop when applying.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Fri, 11 Jul 2025 10:06:59 -0700 you wrote:
Add flow control mechanism between paired netdevsim devices to stop the TX queue during high traffic scenarios. When a receive queue becomes congested (approaching
NSIM_RING_SIZElimit), the corresponding transmit queue on the peer device is stopped usingnetif_subqueue_try_stop().Once the receive queue has sufficient capacity again, the peer's transmit queue is resumed with
netif_tx_wake_queue().[...]
Here is the summary with links:
- [net-next,v3] netdevsim: implement peer queue flow control
https://git.kernel.org/netdev/net-next/c/ff2ac4df58ad
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html