Add support for per-NAPI config via netlink
Subsystems (10)
v5 cover Add support for per-NAPI config via netlink
Greetings:
Welcome to v5, the first non-RFC version of this code! See the changelog below for more details on changes between revisions.
A few important call outs for reviewers:
1. This revision seems to work (see below for a full walk through). I think this is the behavior we talked about, but please let me know if a use case is missing.
2. Re a previous point made by Stanislav regarding "taking over a NAPI ID" when the channel count changes: mlx5 seems to call napi_disable followed by netif_napi_del for the old queues and then calls napi_enable for the new ones. In this RFC, the NAPI ID generation is deferred to napi_enable. This means we won't end up with two of the same NAPI IDs added to the hash at the same time.
Can we assume all drivers will napi_disable the old queues before napi_enable the new ones?
- If yes: we might not need to worry about a NAPI ID takeover function.
- If no: I'll need to make a change so that the NAPI ID generation is deferred only for drivers which have opted into the config space via calls to netif_napi_add_config
3. I made the decision to remove the WARN_ON_ONCE that (I think?) Jakub previously suggested in alloc_netdev_mqs (WARN_ON_ONCE(txqs != rxqs);) because this was triggering on every kernel boot with my mlx5 NIC.
4. I left the "maxqs = max(txqs, rxqs);" in alloc_netdev_mqs despite thinking this is a bit strange. I think it's strange that we might be short some number of NAPI configs, but it seems like most people are in favor of this approach, so I've left it.
I'd appreciate thoughts from reviewers on the above items, if at all possible.
Now, on to the implementation.
Firstly, this implementation moves certain settings to napi_struct so that they are "per-NAPI", while taking care to respect existing sysfs parameters which are interface wide and affect all NAPIs:
- NAPI ID
- gro_flush_timeout
- defer_hard_irqs
Furthermore:
- NAPI ID generation and addition to the hash is now deferred to napi_enable, instead of during netif_napi_add
- NAPIs are removed from the hash during napi_disable, instead of netif_napi_del.
- An array of "struct napi_config" is allocated in net_device.
IMPORTANT: The above changes affect all network drivers.
Optionally, drivers may opt-in to using their config space by calling netif_napi_add_config instead of netif_napi_add.
If a driver does this, the NAPI being added is linked with an allocated "struct napi_config" and the per-NAPI settings (including NAPI ID) are persisted even as hardware queues are destroyed and recreated.
To help illustrate how this would end up working, I've added patches for 3 drivers, of which I have access to only 1:
- mlx5 which is the basis of the examples below
- mlx4 which has TX only NAPIs, just to highlight that case. I have only compile tested this patch; I don't have this hardware.
- bnxt which I have only compiled tested. I don't have this hardware.
NOTE: I only tested this on mlx5; I have no access to the other hardware for which I provided patches. Hopefully other folks can help test :)
Here's how it works when I test it on my mlx5 system:
# start with 2 queues
$ ethtool -l eth4 | grep Combined | tail -1 Combined: 2
First, output the current NAPI settings:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'
[{'defer-hard-irqs': 0,
'gro-flush-timeout': 0,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 0,
'gro-flush-timeout': 0,
'id': 344,
'ifindex': 7,
'irq': 327}]Now, set the global sysfs parameters:
$ sudo bash -c 'echo 20000 >/sys/class/net/eth4/gro_flush_timeout' $ sudo bash -c 'echo 100 >/sys/class/net/eth4/napi_defer_hard_irqs'
Output current NAPI settings again:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'
[{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]Now set NAPI ID 345, via its NAPI ID to specific values:
$ sudo ./tools/net/ynl/cli.py \
--spec Documentation/netlink/specs/netdev.yaml \
--do napi-set \
--json='{"id": 345,
"defer-hard-irqs": 111,
"gro-flush-timeout": 11111}'
NoneNow output current NAPI settings again to ensure only NAPI ID 345 changed:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'[{'defer-hard-irqs': 111,
'gro-flush-timeout': 11111,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]
Now, increase gro-flush-timeout only:
$ sudo ./tools/net/ynl/cli.py \
--spec Documentation/netlink/specs/netdev.yaml \
--do napi-set --json='{"id": 345,
"gro-flush-timeout": 44444}'
NoneNow output the current NAPI settings once more:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'
[{'defer-hard-irqs': 111,
'gro-flush-timeout': 44444,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]Now set NAPI ID 345 to have gro_flush_timeout of 0:
$ sudo ./tools/net/ynl/cli.py \
--spec Documentation/netlink/specs/netdev.yaml \
--do napi-set --json='{"id": 345,
"gro-flush-timeout": 0}'
NoneCheck that NAPI ID 345 has a value of 0:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'[{'defer-hard-irqs': 111,
'gro-flush-timeout': 0,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]
Change the queue count, ensuring that NAPI ID 345 retains its settings:
$ sudo ethtool -L eth4 combined 4
Check that the new queues have the system wide settings but that NAPI ID 345 remains unchanged:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'[{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 347,
'ifindex': 7,
'irq': 529},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 346,
'ifindex': 7,
'irq': 528},
{'defer-hard-irqs': 111,
'gro-flush-timeout': 0,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]
Now reduce the queue count below where NAPI ID 345 is indexed:
$ sudo ethtool -L eth4 combined 1
Check the output:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'
[{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]Re-increase the queue count to ensure NAPI ID 345 is re-assigned the same values:
$ sudo ethtool -L eth4 combined 2
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'
[{'defer-hard-irqs': 111,
'gro-flush-timeout': 0,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]Create new queues to ensure the sysfs globals are used for the new NAPIs but that NAPI ID 345 is unchanged:
$ sudo ethtool -L eth4 combined 8
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'
[...]
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 346,
'ifindex': 7,
'irq': 528},
{'defer-hard-irqs': 111,
'gro-flush-timeout': 0,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 100,
'gro-flush-timeout': 20000,
'id': 344,
'ifindex': 7,
'irq': 327}]Last, but not least, let's try writing the sysfs parameters to ensure all NAPIs are rewritten:
$ sudo bash -c 'echo 33333 >/sys/class/net/eth4/gro_flush_timeout' $ sudo bash -c 'echo 222 >/sys/class/net/eth4/napi_defer_hard_irqs'
Check that worked:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--dump napi-get --json='{"ifindex": 7}'[...]
{'defer-hard-irqs': 222,
'gro-flush-timeout': 33333,
'id': 346,
'ifindex': 7,
'irq': 528},
{'defer-hard-irqs': 222,
'gro-flush-timeout': 33333,
'id': 345,
'ifindex': 7,
'irq': 527},
{'defer-hard-irqs': 222,
'gro-flush-timeout': 33333,
'id': 344,
'ifindex': 7,
'irq': 327}]
Thanks,
Joe
v5:
- Converted from an RFC to a PATCH
- Moved defer_hard_irqs above control-fields comment in napi_struct in patch 1
- Moved gro_flush_timeout above control-fields comment in napi_struct in patch 3
- Removed unnecessary idpf changes from patch 3
- Removed unnecessary kdoc in patch 5 for a parameter removed in an earlier revision
- Removed unnecessary NULL check in patch 5
- Used tooling to autogenerate code for patch 6, which fixed the type and range of NETDEV_A_NAPI_DEFER_HARD_IRQ.
rfcv4:
- Updated commit messages of most patches
- Renamed netif_napi_add_storage to netif_napi_add_config in patch 5
- Added a NULL check in netdev_set_defer_hard_irqs and
netdev_set_gro_flush_timeout for netdev->napi_config in patch 5
- Removed the WARN_ON_ONCE suggested in an earlier revision in alloc_netdev_mqs from patch 5; it triggers every time on my mlx5 machine at boot and needlessly spams the log
- Added a locking adjustment suggested by Stanislav to patch 6 to protect napi_id in patch 5
- Removed napi_hash_del from netif_napi_del in patch 5. netif_napi_del calls __netif_napi_del which itself calls napi_hash_del. The original code thus resulted in two napi_hash_del calls, which is incorrect.
- Removed the napi_hash_add from netif_napi_add_weight in patch 5. NAPIs are added to the hash when napi_enable is called, instead.
- Moved the napi_restore_config to the top of napi_enable in patch 5.
- Simplified the logic in __netif_napi_del and removed napi_hash_del. NAPIs are removed in napi_disable.
- Fixed merge conflicts in patch 6 so it applies cleanly
rfcv3:
- Renamed napi_storage to napi_config
- Reordered patches
- Added defer_hard_irqs and gro_flush_timeout to napi_struct
- Attempt to save and restore settings on napi_disable/napi_enable
- Removed weight as a parameter to netif_napi_add_storage
- Updated driver patches to no longer pass in weight
rfcv2:
- Almost total rewrite from v1
Joe Damato (9):
net: napi: Make napi_defer_hard_irqs per-NAPI
netdev-genl: Dump napi_defer_hard_irqs
net: napi: Make gro_flush_timeout per-NAPI
netdev-genl: Dump gro_flush_timeout
net: napi: Add napi_config
netdev-genl: Support setting per-NAPI config values
bnxt: Add support for persistent NAPI config
mlx5: Add support for persistent NAPI config
mlx4: Add support for persistent NAPI config to RX CQs
Documentation/netlink/specs/netdev.yaml | 25 +++++ .../networking/net_cachelines/net_device.rst | 5 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 3 +- drivers/net/ethernet/mellanox/mlx4/en_cq.c | 3 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 2 +- include/linux/netdevice.h | 42 +++++++- include/uapi/linux/netdev.h | 3 + net/core/dev.c | 95 ++++++++++++++++--- net/core/dev.h | 88 +++++++++++++++++ net/core/net-sysfs.c | 4 +- net/core/netdev-genl-gen.c | 18 ++++ net/core/netdev-genl-gen.h | 1 + net/core/netdev-genl.c | 57 +++++++++++ tools/include/uapi/linux/netdev.h | 3 + 14 files changed, 322 insertions(+), 27 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/9 net: napi: Make napi_defer_hard_irqs per-NAPI
Add defer_hard_irqs to napi_struct in preparation for per-NAPI settings.
The existing sysfs parameter is respected; writes to sysfs will write to all NAPI structs for the device and the net_device defer_hard_irq field. Reads from sysfs show the net_device field.
The ability to set defer_hard_irqs on specific NAPI instances will be added in a later commit, via netdev-genl.
--- .../networking/net_cachelines/net_device.rst | 2 +- include/linux/netdevice.h | 3 +- net/core/dev.c | 10 +++--- net/core/dev.h | 36 +++++++++++++++++++ net/core/net-sysfs.c | 2 +- 5 files changed, 45 insertions(+), 8 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -1
@@ -100,7 +100,6 @@ unsigned_int num_rx_queues unsigned_int real_num_rx_queues - read_mostly get_rps_cpu struct_bpf_prog* xdp_prog - read_mostly netif_elide_gro() unsigned_long gro_flush_timeout - read_mostly napi_complete_done -u32 napi_defer_hard_irqs - read_mostly napi_complete_done unsigned_int gro_max_size - read_mostly skb_gro_receive unsigned_int gro_ipv4_max_size - read_mostly skb_gro_receive rx_handler_func_t* rx_handler read_mostly - __netif_receive_skb_core
@@ -185,3 +184,4 @@ struct_dpll_pin* dpll_pin struct hlist_head page_pools struct dim_irq_moder* irq_moder u64 max_pacing_offload_horizon +u32 napi_defer_hard_irqs
include/linux/netdevice.h +2 -1
@@ -373,6 +373,7 @@ struct napi_struct {unsigned int napi_id;struct hrtimer timer;struct task_struct *thread; +u32 defer_hard_irqs;/* control-path-only fields follow */ struct list_head dev_list;struct hlist_node napi_hash_node;
@@ -2077,7 +2078,6 @@ struct net_device {unsigned int real_num_rx_queues;struct netdev_rx_queue *_rx;unsigned long gro_flush_timeout; -u32 napi_defer_hard_irqs;unsigned int gro_max_size;unsigned int gro_ipv4_max_size;rx_handler_func_t __rcu *rx_handler;
@@ -2405,6 +2405,7 @@ struct net_device {struct dim_irq_moder *irq_moder;u64 max_pacing_offload_horizon; +u32 napi_defer_hard_irqs; u8 priv[] ____cacheline_aligned__counted_by (priv_len );
net/core/dev.c +5 -5
@@ -6231,7 +6231,7 @@ bool napi_complete_done(struct napi_struct *n, int work_done)if (work_done) {if (n->gro_bitmask) timeout =READ_ONCE (n->dev->gro_flush_timeout); - n->defer_hard_irqs_count =READ_ONCE (n->dev->napi_defer_hard_irqs); + n->defer_hard_irqs_count =napi_get_defer_hard_irqs (n); }if (n->defer_hard_irqs_count >0 ) { n->defer_hard_irqs_count--;
@@ -6369,7 +6369,7 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bpf_net_ctx =bpf_net_ctx_set (&__bpf_net_ctx);if (flags &NAPI_F_PREFER_BUSY_POLL ) { - napi->defer_hard_irqs_count =READ_ONCE (napi->dev->napi_defer_hard_irqs); + napi->defer_hard_irqs_count =napi_get_defer_hard_irqs (napi); timeout =READ_ONCE (napi->dev->gro_flush_timeout);if (napi->defer_hard_irqs_count && timeout) {hrtimer_start (&napi->timer,ns_to_ktime (timeout),HRTIMER_MODE_REL_PINNED );
@@ -6651,6 +6651,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,INIT_HLIST_NODE (&napi->napi_hash_node);hrtimer_init (&napi->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_PINNED ); napi->timer.function = napi_watchdog; +napi_set_defer_hard_irqs (napi,READ_ONCE (dev->napi_defer_hard_irqs));init_gro_hash (napi); napi->skb =NULL ;INIT_LIST_HEAD (&napi->rx_list);
@@ -11057,7 +11058,7 @@ void netdev_sw_irq_coalesce_default_on(struct net_device *dev)if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { dev->gro_flush_timeout =20000 ; - dev->napi_defer_hard_irqs =1 ; +netdev_set_defer_hard_irqs (dev,1 ); } }EXPORT_SYMBOL_GPL (netdev_sw_irq_coalesce_default_on);
@@ -11995,7 +11996,6 @@ static void __init net_dev_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, real_num_rx_queues); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, _rx); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_flush_timeout); - CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, napi_defer_hard_irqs); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_max_size); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_ipv4_max_size); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, rx_handler);
@@ -12007,7 +12007,7 @@ static void __init net_dev_struct_check(void)#ifdef CONFIG_NET_XGRESS CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, tcx_ingress);#endif - CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 104); + CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 100); }/*
net/core/dev.h +36 -0
@@ -138,6 +138,42 @@ static inline void netif_set_gro_ipv4_max_size(struct net_device *dev,WRITE_ONCE (dev->gro_ipv4_max_size, size); } +/** +* napi_get_defer_hard_irqs - get the NAPI's defer_hard_irqs +* @n: napi struct to get the defer_hard_irqs field from +* +* Return: the per-NAPI value of the defar_hard_irqs field. +*/ +static inline u32 napi_get_defer_hard_irqs (const struct napi_struct *n) +{ +return READ_ONCE (n->defer_hard_irqs); +} + +/** +* napi_set_defer_hard_irqs - set the defer_hard_irqs for a napi +* @n: napi_struct to set the defer_hard_irqs field +* @defer: the value the field should be set to +*/ +static inline void napi_set_defer_hard_irqs (struct napi_struct *n,u32 defer) +{ +WRITE_ONCE (n->defer_hard_irqs, defer); +} + +/** +* netdev_set_defer_hard_irqs - set defer_hard_irqs for all NAPIs of a netdev +* @netdev: the net_device for which all NAPIs will have defer_hard_irqs set +* @defer: the defer_hard_irqs value to set +*/ +static inline void netdev_set_defer_hard_irqs (struct net_device *netdev, +u32 defer) +{ +struct napi_struct *napi; + +WRITE_ONCE (netdev->napi_defer_hard_irqs, defer); +list_for_each_entry (napi, &netdev->napi_list, dev_list) +napi_set_defer_hard_irqs (napi, defer); +} +int rps_cpumask_housekeeping (struct cpumask *mask);#if defined(CONFIG_DEBUG_NET ) && defined(CONFIG_BPF_SYSCALL )
net/core/net-sysfs.c +1 -1
@@ -429,7 +429,7 @@ static int change_napi_defer_hard_irqs(struct net_device *dev, unsigned long valif (val >S32_MAX )return -ERANGE ; -WRITE_ONCE (dev->napi_defer_hard_irqs, val); +netdev_set_defer_hard_irqs (dev, (u32 )val);return 0 ; }
Signature · 1 line
2.34.1
Re: [net-next v5 1/9] net: napi: Make napi_defer_hard_irqs per-NAPI
Quoted 4 lines · Joe Damato
Add
defer_hard_irqstonapi_structin preparation for per-NAPI settings.
Quoted 8 lines
The existing sysfs parameter is respected; writes to sysfs will write to all NAPI structs for the device and the
net_devicedefer_hard_irqfield. Reads from sysfs show thenet_devicefield.The ability to set
defer_hard_irqson specific NAPI instances will be added in a later commit, via netdev-genl.Signed-off-by Joe Damato <[email protected]>
PATCH v5 2/9 netdev-genl: Dump napi_defer_hard_irqs
In reply to Joe DamatoSupport dumping defer_hard_irqs for a NAPI ID.
--- Documentation/netlink/specs/netdev.yaml | 8 ++++++++ include/uapi/linux/netdev.h | 1 + net/core/netdev-genl.c | 6 ++++++ tools/include/uapi/linux/netdev.h | 1 + 4 files changed, 16 insertions(+)
Documentation/netlink/specs/netdev.yaml +8 -0
@@ -248,6 +248,13 @@ attribute-sets: threaded mode. If NAPI is not in threaded mode (i.e. uses normal softirq context), the attribute will be absent. type: u32 + - + name: defer-hard-irqs + doc: The number of consecutive empty polls before IRQ deferral ends + and hardware IRQs are re-enabled. + type: u32 + checks: + max: s32-max - name: queue attributes:
@@ -636,6 +643,7 @@ operations: - ifindex - irq - pid + - defer-hard-irqs dump: request: attributes:
include/uapi/linux/netdev.h +1 -0
@@ -122,6 +122,7 @@ enum {NETDEV_A_NAPI_ID ,NETDEV_A_NAPI_IRQ ,NETDEV_A_NAPI_PID , +NETDEV_A_NAPI_DEFER_HARD_IRQS , __NETDEV_A_NAPI_MAX,NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX -1 )
net/core/netdev-genl.c +6 -0
@@ -161,6 +161,7 @@ static int netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, const struct genl_info *info) { + u32 napi_defer_hard_irqs;void *hdr;pid_t pid;
@@ -189,6 +190,11 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, goto nla_put_failure; } + napi_defer_hard_irqs =napi_get_defer_hard_irqs (napi); +if (nla_put_s32 (rsp,NETDEV_A_NAPI_DEFER_HARD_IRQS , + napi_defer_hard_irqs)) + goto nla_put_failure; +genlmsg_end (rsp, hdr);return 0 ;
tools/include/uapi/linux/netdev.h +1 -0
@@ -122,6 +122,7 @@ enum {NETDEV_A_NAPI_ID ,NETDEV_A_NAPI_IRQ ,NETDEV_A_NAPI_PID , +NETDEV_A_NAPI_DEFER_HARD_IRQS , __NETDEV_A_NAPI_MAX,NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX -1 )
Signature · 1 line
2.34.1
Re: [net-next v5 2/9] netdev-genl: Dump napi_defer_hard_irqs
Quoted 5 lines · Joe Damato
Support dumping
defer_hard_irqsfor a NAPI ID.Signed-off-by Joe Damato <[email protected]>---
PATCH v5 3/9 net: napi: Make gro_flush_timeout per-NAPI
In reply to Joe DamatoAllow per-NAPI gro_flush_timeout setting.
The existing sysfs parameter is respected; writes to sysfs will write to all NAPI structs for the device and the net_device gro_flush_timeout field. Reads from sysfs will read from the net_device field.
The ability to set gro_flush_timeout on specific NAPI instances will be added in a later commit, via netdev-genl.
--- .../networking/net_cachelines/net_device.rst | 2 +- include/linux/netdevice.h | 3 +- net/core/dev.c | 12 +++--- net/core/dev.h | 40 +++++++++++++++++++ net/core/net-sysfs.c | 2 +- 5 files changed, 50 insertions(+), 9 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -1
@@ -99,7 +99,6 @@ struct_netdev_queue* _rx read_mostly unsigned_int num_rx_queues unsigned_int real_num_rx_queues - read_mostly get_rps_cpu struct_bpf_prog* xdp_prog - read_mostly netif_elide_gro() -unsigned_long gro_flush_timeout - read_mostly napi_complete_done unsigned_int gro_max_size - read_mostly skb_gro_receive unsigned_int gro_ipv4_max_size - read_mostly skb_gro_receive rx_handler_func_t* rx_handler read_mostly - __netif_receive_skb_core
@@ -184,4 +183,5 @@ struct_dpll_pin* dpll_pin struct hlist_head page_pools struct dim_irq_moder* irq_moder u64 max_pacing_offload_horizon +unsigned_long gro_flush_timeout u32 napi_defer_hard_irqs
include/linux/netdevice.h +2 -1
@@ -373,6 +373,7 @@ struct napi_struct {unsigned int napi_id;struct hrtimer timer;struct task_struct *thread; +unsigned long gro_flush_timeout;u32 defer_hard_irqs;/* control-path-only fields follow */ struct list_head dev_list;
@@ -2077,7 +2078,6 @@ struct net_device {int ifindex;unsigned int real_num_rx_queues;struct netdev_rx_queue *_rx; -unsigned long gro_flush_timeout;unsigned int gro_max_size;unsigned int gro_ipv4_max_size;rx_handler_func_t __rcu *rx_handler;
@@ -2405,6 +2405,7 @@ struct net_device {struct dim_irq_moder *irq_moder;u64 max_pacing_offload_horizon; +unsigned long gro_flush_timeout;u32 napi_defer_hard_irqs;u8 priv[]____cacheline_aligned
net/core/dev.c +6 -6
@@ -6230,12 +6230,12 @@ bool napi_complete_done(struct napi_struct *n, int work_done)if (work_done) {if (n->gro_bitmask) - timeout =READ_ONCE (n->dev->gro_flush_timeout); + timeout =napi_get_gro_flush_timeout (n); n->defer_hard_irqs_count =napi_get_defer_hard_irqs (n); }if (n->defer_hard_irqs_count >0 ) { n->defer_hard_irqs_count--; - timeout =READ_ONCE (n->dev->gro_flush_timeout); + timeout =napi_get_gro_flush_timeout (n);if (timeout) ret = false; }
@@ -6370,7 +6370,7 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock,if (flags &NAPI_F_PREFER_BUSY_POLL ) { napi->defer_hard_irqs_count =napi_get_defer_hard_irqs (napi); - timeout =READ_ONCE (napi->dev->gro_flush_timeout); + timeout =napi_get_gro_flush_timeout (napi);if (napi->defer_hard_irqs_count && timeout) {hrtimer_start (&napi->timer,ns_to_ktime (timeout),HRTIMER_MODE_REL_PINNED ); skip_schedule = true;
@@ -6652,6 +6652,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,hrtimer_init (&napi->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_PINNED ); napi->timer.function = napi_watchdog;napi_set_defer_hard_irqs (napi,READ_ONCE (dev->napi_defer_hard_irqs)); +napi_set_gro_flush_timeout (napi,READ_ONCE (dev->gro_flush_timeout));init_gro_hash (napi); napi->skb =NULL ;INIT_LIST_HEAD (&napi->rx_list);
@@ -11057,7 +11058,7 @@ void netdev_sw_irq_coalesce_default_on(struct net_device *dev)WARN_ON (dev->reg_state ==NETREG_REGISTERED );if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { - dev->gro_flush_timeout =20000 ; +netdev_set_gro_flush_timeout (dev,20000 );netdev_set_defer_hard_irqs (dev,1 ); } }
@@ -11995,7 +11996,6 @@ static void __init net_dev_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, ifindex); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, real_num_rx_queues); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, _rx); - CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_flush_timeout); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_max_size); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_ipv4_max_size); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, rx_handler);
@@ -12007,7 +12007,7 @@ static void __init net_dev_struct_check(void)#ifdef CONFIG_NET_XGRESS CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, tcx_ingress);#endif - CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 100); + CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 92); }/*
net/core/dev.h +40 -0
@@ -174,6 +174,46 @@ static inline void netdev_set_defer_hard_irqs(struct net_device *netdev,napi_set_defer_hard_irqs (napi, defer); } +/** +* napi_get_gro_flush_timeout - get the gro_flush_timeout +* @n: napi struct to get the gro_flush_timeout from +* +* Return: the per-NAPI value of the gro_flush_timeout field. +*/ +static inline unsigned long +napi_get_gro_flush_timeout (const struct napi_struct *n) +{ +return READ_ONCE (n->gro_flush_timeout); +} + +/** +* napi_set_gro_flush_timeout - set the gro_flush_timeout for a napi +* @n: napi struct to set the gro_flush_timeout +* @timeout: timeout value to set +* +* napi_set_gro_flush_timeout sets the per-NAPI gro_flush_timeout +*/ +static inline void napi_set_gro_flush_timeout (struct napi_struct *n, +unsigned long timeout) +{ +WRITE_ONCE (n->gro_flush_timeout, timeout); +} + +/** +* netdev_set_gro_flush_timeout - set gro_flush_timeout of a netdev's NAPIs +* @netdev: the net_device for which all NAPIs will have gro_flush_timeout set +* @timeout: the timeout value to set +*/ +static inline void netdev_set_gro_flush_timeout (struct net_device *netdev, +unsigned long timeout) +{ +struct napi_struct *napi; + +WRITE_ONCE (netdev->gro_flush_timeout, timeout); +list_for_each_entry (napi, &netdev->napi_list, dev_list) +napi_set_gro_flush_timeout (napi, timeout); +} +int rps_cpumask_housekeeping (struct cpumask *mask);#if defined(CONFIG_DEBUG_NET ) && defined(CONFIG_BPF_SYSCALL )
net/core/net-sysfs.c +1 -1
@@ -409,7 +409,7 @@ NETDEVICE_SHOW_RW(tx_queue_len, fmt_dec);static int change_gro_flush_timeout (struct net_device *dev,unsigned long val) { -WRITE_ONCE (dev->gro_flush_timeout, val); +netdev_set_gro_flush_timeout (dev, val);return 0 ; }
Signature · 1 line
2.34.1
Re: [net-next v5 3/9] net: napi: Make gro_flush_timeout per-NAPI
Quoted 11 lines · Joe Damato
Allow per-NAPI
gro_flush_timeoutsetting.The existing sysfs parameter is respected; writes to sysfs will write to all NAPI structs for the device and the
net_devicegro_flush_timeoutfield. Reads from sysfs will read from thenet_devicefield.The ability to set
gro_flush_timeouton specific NAPI instances will be added in a later commit, via netdev-genl.Signed-off-by Joe Damato <[email protected]>
PATCH v5 4/9 netdev-genl: Dump gro_flush_timeout
In reply to Joe DamatoSupport dumping gro_flush_timeout for a NAPI ID.
--- Documentation/netlink/specs/netdev.yaml | 6 ++++++ include/uapi/linux/netdev.h | 1 + net/core/netdev-genl.c | 6 ++++++ tools/include/uapi/linux/netdev.h | 1 + 4 files changed, 14 insertions(+)
Documentation/netlink/specs/netdev.yaml +6 -0
@@ -255,6 +255,11 @@ attribute-sets: type: u32 checks: max: s32-max + - + name: gro-flush-timeout + doc: The timeout, in nanoseconds, of when to trigger the NAPI + watchdog timer and schedule NAPI processing. + type: uint - name: queue attributes:
@@ -644,6 +649,7 @@ operations: - irq - pid - defer-hard-irqs + - gro-flush-timeout dump: request: attributes:
include/uapi/linux/netdev.h +1 -0
@@ -123,6 +123,7 @@ enum {NETDEV_A_NAPI_IRQ ,NETDEV_A_NAPI_PID ,NETDEV_A_NAPI_DEFER_HARD_IRQS , +NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT , __NETDEV_A_NAPI_MAX,NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX -1 )
net/core/netdev-genl.c +6 -0
@@ -161,6 +161,7 @@ static int netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, const struct genl_info *info) { + unsigned long gro_flush_timeout;u32 napi_defer_hard_irqs;void *hdr;pid_t pid;
@@ -195,6 +196,11 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, napi_defer_hard_irqs)) goto nla_put_failure; + gro_flush_timeout =napi_get_gro_flush_timeout (napi); +if (nla_put_uint (rsp,NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT , + gro_flush_timeout)) + goto nla_put_failure; +genlmsg_end (rsp, hdr);return 0 ;
tools/include/uapi/linux/netdev.h +1 -0
@@ -123,6 +123,7 @@ enum {NETDEV_A_NAPI_IRQ ,NETDEV_A_NAPI_PID ,NETDEV_A_NAPI_DEFER_HARD_IRQS , +NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT , __NETDEV_A_NAPI_MAX,NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX -1 )
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerRe: [net-next v5 4/9] netdev-genl: Dump gro_flush_timeout
Documentation/netlink/specs/netdev.yaml attribute-sets: · line 261
Quoted 3 lines · On Wed, 9 Oct 2024 00:54:58 +0000 Joe Damato wrote:
Documentation/netlink/specs/netdev.yaml +3
-0+ name: gro-flush-timeout + doc: The timeout, in nanoseconds, of when to trigger the NAPI + watchdog timer and schedule NAPI processing.
You gotta respin because we reformatted the cacheline info.
So while at it perhaps throw in a sentence here about the GRO effects? The initial use of GRO flush timeout was to hold incomplete GRO super-frames in the GRO engine across NAPI cycles.
Re: [net-next v5 4/9] netdev-genl: Dump gro_flush_timeout
Quoted 6 lines · Jakub Kicinski
Documentation/netlink/specs/netdev.yaml attribute-sets: · line 261
Quoted 3 lines · On Wed, 9 Oct 2024 00:54:58 +0000 Joe Damato wrote:
Documentation/netlink/specs/netdev.yaml +3
-0+ name: gro-flush-timeout + doc: The timeout, in nanoseconds, of when to trigger the NAPI + watchdog timer and schedule NAPI processing.You gotta respin because we reformatted the cacheline info.
Yea, I figured I'd be racing with that change and would need a respin.
I'm not sure how the queue works exactly, but it looks like I might also be racing with another change [1], I think.
I think I'm just over 24hr and could respin and resend now, but should I wait longer in case [1] is merged before you see my respin?
Just trying to figure out how to get the fewest number of respins possible ;)
Quoted 3 lines
So while at it perhaps throw in a sentence here about the GRO effects? The initial use of GRO flush timeout was to hold incomplete GRO super-frames in the GRO engine across NAPI cycles.
From my reading of the code, if the timeout is non-zero, then napi_gro_flush will flush only "old" super-frames in napi_complete_done.
If that's accurate (and maybe I missed something?), then how about:
doc: The timeout, in nanoseconds, of when to trigger the NAPI
watchdog timer which schedules NAPI processing. Additionally, a non-zero value will also prevent GRO from flushing recent super-frames at the end of a NAPI cycle. This may add receive latency in exchange for reducing the number of frames processed by the network stack.
LMK if that's accurate and sounds OK or if it's wrong / too verbose?
[1]: https://lore.kernel.org/netdev/[email protected]/T/#m3f11aae53b3244037ac641ef36985c5e85e2ed5e
Re: [net-next v5 4/9] netdev-genl: Dump gro_flush_timeout
Quoted 12 lines · Joe Damato
Quoted 6 lines · Jakub Kicinski
Documentation/netlink/specs/netdev.yaml attribute-sets: · line 261
Quoted 3 lines · On Wed, 9 Oct 2024 00:54:58 +0000 Joe Damato wrote:
Documentation/netlink/specs/netdev.yaml +3
-0+ name: gro-flush-timeout + doc: The timeout, in nanoseconds, of when to trigger the NAPI + watchdog timer and schedule NAPI processing.You gotta respin because we reformatted the cacheline info.
Yea, I figured I'd be racing with that change and would need a respin.
Quoted 6 lines
I'm not sure how the queue works exactly, but it looks like I might also be racing with another change [1], I think.
I think I'm just over 24hr and could respin and resend now, but should I wait longer in case [1] is merged before you see my respin?
I would avoid the rtnl_lock() addition in "netdev-genl: Support setting per-NAPI config values"
before re-sending ?
Quoted 12 lines
Just trying to figure out how to get the fewest number of respins possible ;)
Quoted 3 lines
So while at it perhaps throw in a sentence here about the GRO effects? The initial use of GRO flush timeout was to hold incomplete GRO super-frames in the GRO engine across NAPI cycles.
From my reading of the code, if the timeout is non-zero, then
napi_gro_flushwill flush only "old" super-frames innapi_complete_done.
Quoted 8 lines
If that's accurate (and maybe I missed something?), then how about:
doc: The timeout, in nanoseconds, of when to trigger the NAPI
watchdog timer which schedules NAPI processing. Additionally, a non-zero value will also prevent GRO from flushing recent super-frames at the end of a NAPI cycle. This may add receive latency in exchange for reducing the number of frames processed by the network stack.
Note that linux TCP always has a PSH flag at the end of each TSO packet, so the latency increase is only possible in presence of tail drop, if the last MSS (with the PSH) was dropped.
Quoted 2 lines
LMK if that's accurate and sounds OK or if it's wrong / too verbose?
I do not think it is too verbose.
Re: [net-next v5 4/9] netdev-genl: Dump gro_flush_timeout
Quoted 16 lines · Eric Dumazet
Quoted 15 lines · Joe Damato
Quoted 6 lines · Jakub Kicinski
Documentation/netlink/specs/netdev.yaml attribute-sets: · line 261
Quoted 3 lines · On Wed, 9 Oct 2024 00:54:58 +0000 Joe Damato wrote:
Documentation/netlink/specs/netdev.yaml +3
-0+ name: gro-flush-timeout + doc: The timeout, in nanoseconds, of when to trigger the NAPI + watchdog timer and schedule NAPI processing.You gotta respin because we reformatted the cacheline info.
Yea, I figured I'd be racing with that change and would need a respin.
I'm not sure how the queue works exactly, but it looks like I might also be racing with another change [1], I think.
Quoted 7 lines
Quoted 3 lines
I think I'm just over 24hr and could respin and resend now, but should I wait longer in case [1] is merged before you see my respin?
I would avoid the
rtnl_lock()addition in "netdev-genl: Support setting per-NAPI config values"
before re-sending ?
OK.
Quoted 21 lines
Quoted 12 lines
Just trying to figure out how to get the fewest number of respins possible ;)
Quoted 3 lines
So while at it perhaps throw in a sentence here about the GRO effects? The initial use of GRO flush timeout was to hold incomplete GRO super-frames in the GRO engine across NAPI cycles.
From my reading of the code, if the timeout is non-zero, then
napi_gro_flushwill flush only "old" super-frames innapi_complete_done.Quoted 8 lines
If that's accurate (and maybe I missed something?), then how about:
doc: The timeout, in nanoseconds, of when to trigger the NAPI
watchdog timer which schedules NAPI processing. Additionally, a non-zero value will also prevent GRO from flushing recent super-frames at the end of a NAPI cycle. This may add receive latency in exchange for reducing the number of frames processed by the network stack.
Quoted 3 lines
Note that linux TCP always has a PSH flag at the end of each TSO packet, so the latency increase is only possible in presence of tail drop, if the last MSS (with the PSH) was dropped.
Would you like me to note that in the doc, as well?
PATCH v5 5/9 net: napi: Add napi_config
In reply to Joe DamatoAdd a persistent NAPI config area for NAPI configuration to the core. Drivers opt-in to setting the persistent config for a NAPI by passing an index when calling netif_napi_add_config.
napi_config is allocated in alloc_netdev_mqs, freed in free_netdev (after the NAPIs are deleted).
Drivers which call netif_napi_add_config will have persistent per-NAPI
settings: NAPI IDs, gro_flush_timeout, and defer_hard_irq settings.
Per-NAPI settings are saved in napi_disable and restored in napi_enable.
--- .../networking/net_cachelines/net_device.rst | 1 + include/linux/netdevice.h | 36 ++++++++- net/core/dev.c | 79 +++++++++++++++++-- net/core/dev.h | 12 +++ 4 files changed, 118 insertions(+), 10 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -0
@@ -183,5 +183,6 @@ struct_dpll_pin* dpll_pin struct hlist_head page_pools struct dim_irq_moder* irq_moder u64 max_pacing_offload_horizon +struct_napi_config* napi_config unsigned_long gro_flush_timeout u32 napi_defer_hard_irqs
include/linux/netdevice.h +33 -3
@@ -342,6 +342,15 @@ struct gro_list {*/ #define GRO_HASH_BUCKETS 8 +/* +* Structure for per-NAPI config +*/ +struct napi_config { +u64 gro_flush_timeout; +u32 defer_hard_irqs; +unsigned int napi_id; +}; +/* * Structure for NAPI scheduling similar to tasklet but with weighting */
@@ -379,6 +388,8 @@ struct napi_struct {struct list_head dev_list;struct hlist_node napi_hash_node;int irq; +int index; +struct napi_config *config; };enum {
@@ -1860,9 +1871,6 @@ enum netdev_reg_state {* allocated at register_netdev() time * @real_num_rx_queues: Number of RX queues currently active in device * @xdp_prog: XDP sockets filter program pointer -* @gro_flush_timeout: timeout for GRO layer in NAPI -* @napi_defer_hard_irqs: If not zero, provides a counter that would -* allow to avoid NIC hard IRQ, on busy queues. * * @rx_handler: handler for received packets * @rx_handler_data: XXX: need comments on this one
@@ -2012,6 +2020,11 @@ enum netdev_reg_state {* where the clock is recovered. * * @max_pacing_offload_horizon: max EDT offload horizon in nsec. +* @napi_config: An array of napi_config structures containing per-NAPI +* settings. +* @gro_flush_timeout: timeout for GRO layer in NAPI +* @napi_defer_hard_irqs: If not zero, provides a counter that would +* allow to avoid NIC hard IRQ, on busy queues. * * FIXME: cleanup struct net_device such that network protocol info * moves out.
@@ -2405,6 +2418,7 @@ struct net_device {struct dim_irq_moder *irq_moder;u64 max_pacing_offload_horizon; +struct napi_config *napi_config;unsigned long gro_flush_timeout;u32 napi_defer_hard_irqs;
@@ -2657,6 +2671,22 @@ netif_napi_add_tx_weight(struct net_device *dev,netif_napi_add_weight (dev, napi, poll, weight); } +/** +* netif_napi_add_config - initialize a NAPI context with persistent config +* @dev: network device +* @napi: NAPI context +* @poll: polling function +* @index: the NAPI index +*/ +static inline void +netif_napi_add_config (struct net_device *dev,struct napi_struct *napi, +int (*poll)(struct napi_struct *,int ),int index) +{ + napi->index = index; + napi->config = &dev->napi_config[index]; +netif_napi_add_weight (dev, napi, poll,NAPI_POLL_WEIGHT ); +} +/** * netif_napi_add_tx() - initialize a NAPI context to be used for Tx only * @dev: network device
net/core/dev.c +72 -7
152 lines not on this page · raw message
net/core/dev.h +12 -0
@@ -167,11 +167,17 @@ static inline void napi_set_defer_hard_irqs(struct napi_struct *n, u32 defer)static inline void netdev_set_defer_hard_irqs (struct net_device *netdev,u32 defer) { +unsigned int count =max (netdev->num_rx_queues, + netdev->num_tx_queues);struct napi_struct *napi; +int i;WRITE_ONCE (netdev->napi_defer_hard_irqs, defer);list_for_each_entry (napi, &netdev->napi_list, dev_list)napi_set_defer_hard_irqs (napi, defer); + +for (i =0 ; i < count; i++) + netdev->napi_config[i].defer_hard_irqs = defer; }/**
@@ -207,11 +213,17 @@ static inline void napi_set_gro_flush_timeout(struct napi_struct *n,static inline void netdev_set_gro_flush_timeout (struct net_device *netdev,unsigned long timeout) { +unsigned int count =max (netdev->num_rx_queues, + netdev->num_tx_queues);struct napi_struct *napi; +int i;WRITE_ONCE (netdev->gro_flush_timeout, timeout);list_for_each_entry (napi, &netdev->napi_list, dev_list)napi_set_gro_flush_timeout (napi, timeout); + +for (i =0 ; i < count; i++) + netdev->napi_config[i].gro_flush_timeout = timeout; }int rps_cpumask_housekeeping (struct cpumask *mask);
Signature · 1 line
2.34.1
Re: [net-next v5 5/9] net: napi: Add napi_config
Quoted 127 lines · Joe Damato
Add a persistent NAPI config area for NAPI configuration to the core. Drivers opt-in to setting the persistent config for a NAPI by passing an index when calling
netif_napi_add_config.
napi_configis allocated inalloc_netdev_mqs, freed infree_netdev(after the NAPIs are deleted).Drivers which call
netif_napi_add_configwill have persistent per-NAPI
settings: NAPI IDs,gro_flush_timeout, anddefer_hard_irqsettings.Per-NAPI settings are saved in
napi_disableand restored innapi_enable.Co-developed-by Martin Karsten <[email protected]>Signed-off-by Martin Karsten <[email protected]>Signed-off-by Joe Damato <[email protected]>--- .../networking/net_cachelines/net_device.rst | 1 + include/linux/netdevice.h | 36 ++++++++- net/core/dev.c | 79 +++++++++++++++++-- net/core/dev.h | 12 +++ 4 files changed, 118 insertions(+), 10 deletions(-)Documentation/networking/net_cachelines/net_device.rst +1
-0@@ -183,5 +183,6 @@ struct_dpll_pin* dpll_pin struct hlist_head page_pools struct dim_irq_moder* irq_moder u64 max_pacing_offload_horizon +struct_napi_config* napi_config unsigned_long gro_flush_timeout u32 napi_defer_hard_irqsinclude/linux/netdevice.h +33
-3@@ -342,6 +342,15 @@ struct gro_list {*/ #define GRO_HASH_BUCKETS 8 +/* +* Structure for per-NAPI config +*/ +struct napi_config { +u64 gro_flush_timeout; +u32 defer_hard_irqs; +unsigned int napi_id; +}; +/* * Structure for NAPI scheduling similar to tasklet but with weighting */ @@ -379,6 +388,8 @@ struct napi_struct {struct list_head dev_list;struct hlist_node napi_hash_node;int irq; +int index; +struct napi_config *config; };enum {@@ -1860,9 +1871,6 @@ enum netdev_reg_state {* allocated at register_netdev() time * @real_num_rx_queues: Number of RX queues currently active in device * @xdp_prog: XDP sockets filter program pointer -* @gro_flush_timeout: timeout for GRO layer in NAPI -* @napi_defer_hard_irqs: If not zero, provides a counter that would -* allow to avoid NIC hard IRQ, on busy queues. * * @rx_handler: handler for received packets * @rx_handler_data: XXX: need comments on this one @@ -2012,6 +2020,11 @@ enum netdev_reg_state {* where the clock is recovered. * * @max_pacing_offload_horizon: max EDT offload horizon in nsec. +* @napi_config: An array of napi_config structures containing per-NAPI +* settings. +* @gro_flush_timeout: timeout for GRO layer in NAPI +* @napi_defer_hard_irqs: If not zero, provides a counter that would +* allow to avoid NIC hard IRQ, on busy queues. * * FIXME: cleanup struct net_device such that network protocol info * moves out. @@ -2405,6 +2418,7 @@ struct net_device {struct dim_irq_moder *irq_moder;u64 max_pacing_offload_horizon; +struct napi_config *napi_config;unsigned long gro_flush_timeout;u32 napi_defer_hard_irqs;@@ -2657,6 +2671,22 @@ netif_napi_add_tx_weight(struct net_device *dev,netif_napi_add_weight (dev, napi, poll, weight); } +/** +* netif_napi_add_config - initialize a NAPI context with persistent config +* @dev: network device +* @napi: NAPI context +* @poll: polling function +* @index: the NAPI index +*/ +static inline void +netif_napi_add_config (struct net_device *dev,struct napi_struct *napi, +int (*poll)(struct napi_struct *,int ),int index) +{ + napi->index = index; + napi->config = &dev->napi_config[index]; +netif_napi_add_weight (dev, napi, poll,NAPI_POLL_WEIGHT ); +} +/** * netif_napi_add_tx() - initialize a NAPI context to be used for Tx only * @dev: network device net/core/dev.c +3
-0@@ -6503,6 +6503,22 @@ EXPORT_SYMBOL(napi_busy_loop);#endif /* CONFIG_NET_RX_BUSY_POLL */ +static void __napi_hash_add_with_id (struct napi_struct *napi, +unsigned int napi_id) +{
net/core/dev.c EXPORT_SYMBOL(napi_busy_loop); · line 6518
Quoted 10 lines
net/core/dev.c +10
-0+ napi->napi_id = napi_id; +hlist_add_head_rcu (&napi->napi_hash_node, + &napi_hash[napi->napi_id %HASH_SIZE (napi_hash)]); +} + +static void napi_hash_add_with_id (struct napi_struct *napi, +unsigned int napi_id) +{ +spin_lock (&napi_hash_lock); +__napi_hash_add_with_id (napi, napi_id);
Hmmm... there is no check if 'napi_id' is already used and hashed.
I would add
WARN_ON_ONCE(napi_by_id(napi_id));
Quoted 19 lines
net/core/dev.c +4
-3+spin_unlock (&napi_hash_lock); +} +static void napi_hash_add (struct napi_struct *napi) {if (test_bit (NAPI_STATE_NO_BUSY_POLL , &napi->state))@@ -6515,10 +6531,8 @@ static void napi_hash_add(struct napi_struct *napi)if (unlikely (++napi_gen_id <MIN_NAPI_ID )) napi_gen_id =MIN_NAPI_ID ; }while (napi_by_id (napi_gen_id)); - napi->napi_id = napi_gen_id; -hlist_add_head_rcu (&napi->napi_hash_node, - &napi_hash[napi->napi_id %HASH_SIZE (napi_hash)]); +__napi_hash_add_with_id (napi, napi_gen_id);spin_unlock (&napi_hash_lock); }
Re: [net-next v5 5/9] net: napi: Add napi_config
Quoted 1 line · Eric Dumazet
On Wed, Oct 9, 2024 at 2:56 AM Joe Damato <[email protected]> wrote:
[...]
Quoted 9 lines
net/core/dev.c EXPORT_SYMBOL(napi_busy_loop); · line 6518
Quoted 6 lines
net/core/dev.c +6
-0+ +static void napi_hash_add_with_id (struct napi_struct *napi, +unsigned int napi_id) +{ +spin_lock (&napi_hash_lock); +__napi_hash_add_with_id (napi, napi_id);Hmmm... there is no check if '
napi_id' is already used and hashed.
Quoted 3 lines
I would add
WARN_ON_ONCE(napi_by_id(napi_id));
Thanks for the careful review, Eric.
I agree that adding this is a good idea and I will do so for the v6.
Jakub: I hope that it's OK if I retain your Reviewed-by tag as the change Eric suggested is a minor one?
If you'd prefer I drop your Reviewed-by from this one, please let me know.
Jakub Kicinski
maintainerRe: [net-next v5 5/9] net: napi: Add napi_config
Quoted 2 lines · On Thu, 10 Oct 2024 08:59:29 -0700 Joe Damato wrote:
Jakub: I hope that it's OK if I retain your Reviewed-by tag as the change Eric suggested is a minor one?
Yes
PATCH v5 6/9 netdev-genl: Support setting per-NAPI config values
In reply to Joe DamatoAdd support to set per-NAPI defer_hard_irqs and gro_flush_timeout.
--- Documentation/netlink/specs/netdev.yaml | 11 ++++++ include/uapi/linux/netdev.h | 1 + net/core/netdev-genl-gen.c | 18 ++++++++++ net/core/netdev-genl-gen.h | 1 + net/core/netdev-genl.c | 45 +++++++++++++++++++++++++ tools/include/uapi/linux/netdev.h | 1 + 6 files changed, 77 insertions(+)
Documentation/netlink/specs/netdev.yaml +11 -0
@@ -690,6 +690,17 @@ operations: reply: attributes: - id + - + name: napi-set + doc: Set configurable NAPI instance settings. + attribute-set: napi + flags: [ admin-perm ] + do: + request: + attributes: + - id + - defer-hard-irqs + - gro-flush-timeout kernel-family: headers: [ "linux/list.h"]
include/uapi/linux/netdev.h +1 -0
@@ -201,6 +201,7 @@ enum {NETDEV_CMD_NAPI_GET ,NETDEV_CMD_QSTATS_GET ,NETDEV_CMD_BIND_RX , +NETDEV_CMD_NAPI_SET , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 )
net/core/netdev-genl-gen.c +18 -0
@@ -22,6 +22,10 @@ static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = .max = 2147483647ULL, }; +static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { + .max =2147483647ULL , +}; +/* Common nested types */ const struct nla_policy netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFINDEX +1 ] = { [NETDEV_A_PAGE_POOL_ID ] =NLA_POLICY_FULL_RANGE (NLA_UINT , &netdev_a_page_pool_id_range),
@@ -87,6 +91,13 @@ static const struct nla_policy netdev_bind_rx_nl_policy[NETDEV_A_DMABUF_FD + 1] [NETDEV_A_DMABUF_QUEUES] = NLA_POLICY_NESTED(netdev_queue_id_nl_policy), }; +/* NETDEV_CMD_NAPI_SET - do */ +static const struct nla_policy netdev_napi_set_nl_policy[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT +1 ] = { + [NETDEV_A_NAPI_ID ] = { .type =NLA_U32 , }, + [NETDEV_A_NAPI_DEFER_HARD_IRQS ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &netdev_a_napi_defer_hard_irqs_range), + [NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT ] = { .type =NLA_UINT , }, +}; +/* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { {
@@ -171,6 +182,13 @@ static const struct genl_split_ops netdev_nl_ops[] = { .maxattr = NETDEV_A_DMABUF_FD, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, + { + .cmd = NETDEV_CMD_NAPI_SET, + .doit = netdev_nl_napi_set_doit, + .policy = netdev_napi_set_nl_policy, + .maxattr = NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, };static const struct genl_multicast_group netdev_nl_mcgrps[] = {
net/core/netdev-genl-gen.h +1 -0
@@ -33,6 +33,7 @@ int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);int netdev_nl_qstats_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int netdev_nl_bind_rx_doit (struct sk_buff *skb,struct genl_info *info); +int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info);enum {NETDEV_NLGRP_MGMT ,
net/core/netdev-genl.c +45 -0
51 lines not on this page · raw message
tools/include/uapi/linux/netdev.h +1 -0
@@ -201,6 +201,7 @@ enum {NETDEV_CMD_NAPI_GET ,NETDEV_CMD_QSTATS_GET ,NETDEV_CMD_BIND_RX , +NETDEV_CMD_NAPI_SET , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 )
Signature · 1 line
2.34.1
Re: [net-next v5 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 52 lines · Joe Damato
Add support to set per-NAPI
defer_hard_irqsandgro_flush_timeout.Signed-off-by Joe Damato <[email protected]>--- Documentation/netlink/specs/netdev.yaml | 11 ++++++ include/uapi/linux/netdev.h | 1 + net/core/netdev-genl-gen.c | 18 ++++++++++ net/core/netdev-genl-gen.h | 1 + net/core/netdev-genl.c | 45 +++++++++++++++++++++++++ tools/include/uapi/linux/netdev.h | 1 + 6 files changed, 77 insertions(+)Documentation/netlink/specs/netdev.yaml +11
-0@@ -690,6 +690,17 @@ operations: reply: attributes: - id + - + name: napi-set + doc: Set configurable NAPI instance settings. + attribute-set: napi + flags: [ admin-perm ] + do: + request: + attributes: + - id + - defer-hard-irqs + - gro-flush-timeout kernel-family: headers: [ "linux/list.h"]include/uapi/linux/netdev.h +1
-0@@ -201,6 +201,7 @@ enum {NETDEV_CMD_NAPI_GET ,NETDEV_CMD_QSTATS_GET ,NETDEV_CMD_BIND_RX , +NETDEV_CMD_NAPI_SET , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 )net/core/netdev-genl-gen.c +0
-0
net/core/netdev-genl-gen.c static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = · line 26
Quoted 5 lines
net/core/netdev-genl-gen.c +2
-0@@ -22,6 +22,10 @@ static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = .max = 2147483647ULL, }; +static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { + .max =2147483647ULL ,
Would (u64)INT_MAX work ?
Quoted 74 lines
net/core/netdev-genl-gen.c +16
-0+}; +/* Common nested types */ const struct nla_policy netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFINDEX +1 ] = { [NETDEV_A_PAGE_POOL_ID ] =NLA_POLICY_FULL_RANGE (NLA_UINT , &netdev_a_page_pool_id_range),@@ -87,6 +91,13 @@ static const struct nla_policy netdev_bind_rx_nl_policy[NETDEV_A_DMABUF_FD + 1] [NETDEV_A_DMABUF_QUEUES] = NLA_POLICY_NESTED(netdev_queue_id_nl_policy), }; +/* NETDEV_CMD_NAPI_SET - do */ +static const struct nla_policy netdev_napi_set_nl_policy[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT +1 ] = { + [NETDEV_A_NAPI_ID ] = { .type =NLA_U32 , }, + [NETDEV_A_NAPI_DEFER_HARD_IRQS ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &netdev_a_napi_defer_hard_irqs_range), + [NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT ] = { .type =NLA_UINT , }, +}; +/* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { {@@ -171,6 +182,13 @@ static const struct genl_split_ops netdev_nl_ops[] = { .maxattr = NETDEV_A_DMABUF_FD, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, + { + .cmd = NETDEV_CMD_NAPI_SET, + .doit = netdev_nl_napi_set_doit, + .policy = netdev_napi_set_nl_policy, + .maxattr = NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, };static const struct genl_multicast_group netdev_nl_mcgrps[] = {net/core/netdev-genl-gen.h +1
-0@@ -33,6 +33,7 @@ int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);int netdev_nl_qstats_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int netdev_nl_bind_rx_doit (struct sk_buff *skb,struct genl_info *info); +int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info);enum {NETDEV_NLGRP_MGMT ,net/core/netdev-genl.c +21
-0@@ -303,6 +303,51 @@ int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)return err; } +static int +netdev_nl_napi_set_config (struct napi_struct *napi,struct genl_info *info) +{ +u64 gro_flush_timeout =0 ; +u32 defer =0 ; + +if (info->attrs[NETDEV_A_NAPI_DEFER_HARD_IRQS ]) { + defer =nla_get_u32 (info->attrs[NETDEV_A_NAPI_DEFER_HARD_IRQS ]); +napi_set_defer_hard_irqs (napi, defer); + } + +if (info->attrs[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT ]) { + gro_flush_timeout =nla_get_uint (info->attrs[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT ]); +napi_set_gro_flush_timeout (napi, gro_flush_timeout); + } + +return 0 ; +} + +int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info) +{
net/core/netdev-genl.c int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 336
Quoted 10 lines
net/core/netdev-genl.c +10
-0+struct napi_struct *napi; +unsigned int napi_id; +int err; + +if (GENL_REQ_ATTR_CHECK (info,NETDEV_A_NAPI_ID )) +return -EINVAL ; + + napi_id =nla_get_u32 (info->attrs[NETDEV_A_NAPI_ID ]); + +rtnl_lock ();
Hmm.... please see my patch there :
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Lets not add another rtnl_lock() :/
Quoted 32 lines
net/core/netdev-genl.c +14
-0+ + napi =napi_by_id (napi_id); +if (napi) { + err =netdev_nl_napi_set_config (napi, info); + }else { +NL_SET_BAD_ATTR (info->extack, info->attrs[NETDEV_A_NAPI_ID ]); + err = -ENOENT ; + } + +rtnl_unlock (); + +return err; +} +static int netdev_nl_queue_fill_one (struct sk_buff *rsp,struct net_device *netdev,u32 q_idx,u32 q_type,const struct genl_info *info)tools/include/uapi/linux/netdev.h +1
-1@@ -201,6 +201,7 @@ enum {NETDEV_CMD_NAPI_GET ,NETDEV_CMD_QSTATS_GET ,NETDEV_CMD_BIND_RX , +NETDEV_CMD_NAPI_SET , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 ) --2.34.1
Jakub Kicinski
maintainerRe: [net-next v5 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 4 lines · On Thu, 10 Oct 2024 06:24:54 +0200 Eric Dumazet wrote:
net/core/netdev-genl-gen.c static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = · line 26
Quoted 2 lines
net/core/netdev-genl-gen.c +2
-0+static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { + .max =2147483647ULL ,Would (u64)INT_MAX work ?
I sent a codegen change for this. The codegen is a bit of a mess.
Quoted 15 lines
net/core/netdev-genl.c int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 336
Quoted 12 lines
net/core/netdev-genl.c +12
-0+int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct napi_struct *napi; +unsigned int napi_id; +int err; + +if (GENL_REQ_ATTR_CHECK (info,NETDEV_A_NAPI_ID )) +return -EINVAL ; + + napi_id =nla_get_u32 (info->attrs[NETDEV_A_NAPI_ID ]); + +rtnl_lock ();Hmm.... please see my patch there :
Quoted 3 lines
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Lets not add another
rtnl_lock():/
It's not as easy since NAPIs can come and go at driver's whim. I'm quietly hoping we can convert all netdev-nl NAPI accesses to use the netdev->lock protection I strong-armed Paolo into adding in his shaper series. But perhaps we can do that after this series? NAPI GET already takes RTNL lock.
Re: [net-next v5 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 26 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 10 Oct 2024 06:24:54 +0200 Eric Dumazet wrote:
net/core/netdev-genl-gen.c static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = · line 26
Quoted 2 lines
net/core/netdev-genl-gen.c +2
-0+static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { + .max =2147483647ULL ,Would (u64)INT_MAX work ?
I sent a codegen change for this. The codegen is a bit of a mess.
Quoted 17 lines
net/core/netdev-genl.c int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 336
Quoted 12 lines
net/core/netdev-genl.c +12
-0+int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct napi_struct *napi; +unsigned int napi_id; +int err; + +if (GENL_REQ_ATTR_CHECK (info,NETDEV_A_NAPI_ID )) +return -EINVAL ; + + napi_id =nla_get_u32 (info->attrs[NETDEV_A_NAPI_ID ]); + +rtnl_lock ();Hmm.... please see my patch there :
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 7 lines
Quoted 1 line
Lets not add another
rtnl_lock():/It's not as easy since NAPIs can come and go at driver's whim. I'm quietly hoping we can convert all netdev-nl NAPI accesses to use the
netdev->lockprotection I strong-armed Paolo into adding in his shaper series. But perhaps we can do that after this series? NAPI GET already takes RTNL lock.
napi_by_id() is protected by rcu and its own spinlock ( napi_hash_lock ) I do not see why rtnl is needed.
This will also be a big issue with per netns-RTNL anyway.
Re: [net-next v5 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 36 lines · Eric Dumazet
Quoted 26 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 10 Oct 2024 06:24:54 +0200 Eric Dumazet wrote:
net/core/netdev-genl-gen.c static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = · line 26
Quoted 2 lines
net/core/netdev-genl-gen.c +2
-0+static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { + .max =2147483647ULL ,Would (u64)INT_MAX work ?
I sent a codegen change for this. The codegen is a bit of a mess.
Quoted 17 lines
net/core/netdev-genl.c int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 336
Quoted 12 lines
net/core/netdev-genl.c +12
-0+int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct napi_struct *napi; +unsigned int napi_id; +int err; + +if (GENL_REQ_ATTR_CHECK (info,NETDEV_A_NAPI_ID )) +return -EINVAL ; + + napi_id =nla_get_u32 (info->attrs[NETDEV_A_NAPI_ID ]); + +rtnl_lock ();Hmm.... please see my patch there :
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 7 lines
Quoted 1 line
Lets not add another
rtnl_lock():/It's not as easy since NAPIs can come and go at driver's whim. I'm quietly hoping we can convert all netdev-nl NAPI accesses to use the
netdev->lockprotection I strong-armed Paolo into adding in his shaper series. But perhaps we can do that after this series? NAPI GET already takes RTNL lock.
Quoted 3 lines
napi_by_id()is protected by rcu and its own spinlock (napi_hash_lock) I do not see why rtnl is needed.
This will also be a big issue with per netns-RTNL anyway.
I deeply appreciate and respect both of your thoughts on this; I will hold off on sending a v6 until a decision is made on this particular issue.
Thank you both for your careful review and analysis.
Re: [net-next v5 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 38 lines · Joe Damato
Quoted 36 lines · Eric Dumazet
Quoted 33 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 10 Oct 2024 06:24:54 +0200 Eric Dumazet wrote:
net/core/netdev-genl-gen.c static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = · line 26
Quoted 2 lines
net/core/netdev-genl-gen.c +2
-0+static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { + .max =2147483647ULL ,Would (u64)INT_MAX work ?
I sent a codegen change for this. The codegen is a bit of a mess.
Quoted 15 lines
net/core/netdev-genl.c int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 336
Quoted 12 lines
net/core/netdev-genl.c +12
-0+int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct napi_struct *napi; +unsigned int napi_id; +int err; + +if (GENL_REQ_ATTR_CHECK (info,NETDEV_A_NAPI_ID )) +return -EINVAL ; + + napi_id =nla_get_u32 (info->attrs[NETDEV_A_NAPI_ID ]); + +rtnl_lock ();Hmm.... please see my patch there :
Quoted 3 lines
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Lets not add another
rtnl_lock():/It's not as easy since NAPIs can come and go at driver's whim. I'm quietly hoping we can convert all netdev-nl NAPI accesses to use the
netdev->lockprotection I strong-armed Paolo into adding in his shaper series. But perhaps we can do that after this series? NAPI GET already takes RTNL lock.
Quoted 8 lines
Quoted 3 lines
napi_by_id()is protected by rcu and its own spinlock (napi_hash_lock) I do not see why rtnl is needed.
This will also be a big issue with per netns-RTNL anyway.I deeply appreciate and respect both of your thoughts on this; I will hold off on sending a v6 until a decision is made on this particular issue.
I do not want to block your series.
Whatever is needed later, I can handle.
Re: [net-next v5 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 43 lines · Eric Dumazet
Quoted 42 lines · Joe Damato
Quoted 39 lines · Eric Dumazet
Quoted 26 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 10 Oct 2024 06:24:54 +0200 Eric Dumazet wrote:
net/core/netdev-genl-gen.c static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = · line 26
Quoted 2 lines
net/core/netdev-genl-gen.c +2
-0+static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { + .max =2147483647ULL ,Would (u64)INT_MAX work ?
I sent a codegen change for this. The codegen is a bit of a mess.
Quoted 17 lines
net/core/netdev-genl.c int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 336
Quoted 12 lines
net/core/netdev-genl.c +12
-0+int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct napi_struct *napi; +unsigned int napi_id; +int err; + +if (GENL_REQ_ATTR_CHECK (info,NETDEV_A_NAPI_ID )) +return -EINVAL ; + + napi_id =nla_get_u32 (info->attrs[NETDEV_A_NAPI_ID ]); + +rtnl_lock ();Hmm.... please see my patch there :
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 7 lines
Quoted 1 line
Lets not add another
rtnl_lock():/It's not as easy since NAPIs can come and go at driver's whim. I'm quietly hoping we can convert all netdev-nl NAPI accesses to use the
netdev->lockprotection I strong-armed Paolo into adding in his shaper series. But perhaps we can do that after this series? NAPI GET already takes RTNL lock.
napi_by_id()is protected by rcu and its own spinlock (napi_hash_lock) I do not see why rtnl is needed.
This will also be a big issue with per netns-RTNL anyway.
Quoted 8 lines
Quoted 4 lines
I deeply appreciate and respect both of your thoughts on this; I will hold off on sending a v6 until a decision is made on this particular issue.
I do not want to block your series.
Whatever is needed later, I can handle.
Thank you, Eric.
I am happy to help with the future changes if needed. Feel free to reach out if you'd like me to assist in any way as I know you have a tremendous amount of work on your plate.
I will submit the v6 shortly, after I've rebased and retested.
PATCH v5 7/9 bnxt: Add support for persistent NAPI config
In reply to Joe DamatoUse netif_napi_add_config to assign persistent per-NAPI config when initializing NAPIs.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
@@ -10986,7 +10986,8 @@ static void bnxt_init_napi(struct bnxt *bp) cp_nr_rings--;for (i =0 ; i < cp_nr_rings; i++) { bnapi = bp->bnapi[i]; -netif_napi_add (bp->dev, &bnapi->napi, poll_fn); +netif_napi_add_config (bp->dev, &bnapi->napi, poll_fn, + bnapi->index); }if (BNXT_CHIP_TYPE_NITRO_A0 (bp)) { bnapi = bp->bnapi[cp_nr_rings];
Signature · 1 line
2.34.1
Re: [net-next v5 7/9] bnxt: Add support for persistent NAPI config
Quoted 6 lines · Joe Damato
Use
netif_napi_add_configto assign persistent per-NAPI config when initializing NAPIs.Signed-off-by Joe Damato <[email protected]>---
PATCH v5 8/9 mlx5: Add support for persistent NAPI config
In reply to Joe DamatoUse netif_napi_add_config to assign persistent per-NAPI config when initializing NAPIs.
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -1
@@ -2697,7 +2697,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix, c->aff_mask =irq_get_effective_affinity_mask (irq); c->lag_port =mlx5e_enumerate_lag_port (mdev, ix); -netif_napi_add (netdev, &c->napi, mlx5e_napi_poll); +netif_napi_add_config (netdev, &c->napi, mlx5e_napi_poll, ix);netif_napi_set_irq (&c->napi, irq); err =mlx5e_open_queues (c, params, cparam);
Signature · 1 line
2.34.1
Re: [net-next v5 8/9] mlx5: Add support for persistent NAPI config
Quoted 6 lines · Joe Damato
Use
netif_napi_add_configto assign persistent per-NAPI config when initializing NAPIs.Signed-off-by Joe Damato <[email protected]>---
PATCH v5 9/9 mlx4: Add support for persistent NAPI config to RX CQs
In reply to Joe DamatoUse netif_napi_add_config to assign persistent per-NAPI config when initializing RX CQ NAPIs.
Presently, struct napi_config only has support for two fields used for RX, so there is no need to support them with TX CQs, yet.
--- drivers/net/ethernet/mellanox/mlx4/en_cq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/en_cq.c +2 -1
@@ -156,7 +156,8 @@ int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,break ;case RX : cq->mcq.comp = mlx4_en_rx_irq; -netif_napi_add (cq->dev, &cq->napi, mlx4_en_poll_rx_cq); +netif_napi_add_config (cq->dev, &cq->napi, mlx4_en_poll_rx_cq, + cq_idx);netif_napi_set_irq (&cq->napi, irq);napi_enable (&cq->napi);netif_queue_set_napi (cq->dev, cq_idx,NETDEV_QUEUE_TYPE_RX , &cq->napi);
Signature · 1 line
2.34.1
Re: [net-next v5 9/9] mlx4: Add support for persistent NAPI config to RX CQs
Quoted 9 lines · Joe Damato
Use
netif_napi_add_configto assign persistent per-NAPI config when initializing RX CQ NAPIs.Presently, struct
napi_configonly has support for two fields used for RX, so there is no need to support them with TX CQs, yet.Signed-off-by Joe Damato <[email protected]>---
nit: technically, the napi_defer_hard_irqs could benefit TX completions as well.
Re: [net-next v5 9/9] mlx4: Add support for persistent NAPI config to RX CQs
Quoted 5 lines · Eric Dumazet
Quoted 4 lines · Joe Damato
Use
netif_napi_add_configto assign persistent per-NAPI config when initializing RX CQ NAPIs.
Quoted 7 lines
Quoted 5 lines
Presently, struct
napi_configonly has support for two fields used for RX, so there is no need to support them with TX CQs, yet.Signed-off-by Joe Damato <[email protected]>---
nit: technically, the
napi_defer_hard_irqscould benefit TX completions as well.
That's true - I think I missed updating this commit message when I realized it. I can correct the commit message while retaining your Reviewed-by for the v6.
Note: This adds to the confusion I have around the support for allocating max(rxqs, txqs) config structs; it would seem we'll be missing config structure for some queues if the system is configured to use the maximum number of each? Perhaps that configuration is uncommon enough that it doesn't matter?
Quoted 1 line
Reviewed-by Eric Dumazet <[email protected]>
Quoted 2 lines · On Wed, 9 Oct 2024 00:54:54 +0000 Joe Damato wrote:
Welcome to v5, the first non-RFC version of this code! See the changelog below for more details on changes between revisions.
I'm probably going to end up applying this but just in case:
Very neat work !