Add support for per-NAPI config via netlink
Subsystems (11)
v4 cover Add support for per-NAPI config via netlink
Greetings:
Welcome to RFC v4.
Very important and significant changes have been made since RFC v3 [1], please see the changelog below for details.
A couple important call outs for this revision for reviewers:
1. idpf embeds a napi_struct in an internal data structure and includes an assertion on the size of napi_struct. The maintainers have stated that they think anyone touching napi_struct should update the assertion [2], so I've done this in patch 3.
Even though the assertion has been updated, I've given the cacheline placement of napi_struct within idpf's internals no thought or consideration.
Would appreciate other opinions on this; I think idpf should be fixed. It seems unreasonable to me that anyone changing the size of a struct in the core should need to think about cachelines in idpf.
2. This revision seems to work (see below for a full walk through). Is this the behavior we want? Am I missing some use case or some behavioral thing other folks need?
3. 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 (I am pretty sure).
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.
4. 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.
5. 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. Once those are addressed, modulo any feedback on the code/white space wrapping I still need to do, I think this is close to an official submission.
Now, on to the implementation:
This implementation allocates an array of "struct napi_config" in net_device and each NAPI instance is assigned an index into the config array.
Per-NAPI settings like:
- NAPI ID
- gro_flush_timeout
- defer_hard_irqs
are persisted in napi_config and restored on napi_disable/napi_enable respectively.
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 :)
This iteration seems to persist NAPI IDs and settings even when resizing queues, see below, so I think maybe this is getting close to where we want to land in terms of functionality.
Here's how it works when I test it on my 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
[1]: https://lore.kernel.org/netdev/[email protected]/
[2]: https://lore.kernel.org/netdev/[email protected]/T/#m56b743bd16304a626848b14f90cecb661f464b74
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/intel/idpf/idpf_txrx.h | 2 +- drivers/net/ethernet/mellanox/mlx4/en_cq.c | 3 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 2 +- include/linux/netdevice.h | 38 +++++++- include/uapi/linux/netdev.h | 3 + net/core/dev.c | 95 ++++++++++++++++--- net/core/dev.h | 90 ++++++++++++++++++ net/core/net-sysfs.c | 4 +- net/core/netdev-genl-gen.c | 14 +++ net/core/netdev-genl-gen.h | 1 + net/core/netdev-genl.c | 57 +++++++++++ tools/include/uapi/linux/netdev.h | 3 + 15 files changed, 320 insertions(+), 25 deletions(-)
Signature · 1 line
2.25.1
RFC v4 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
@@ -99,7 +99,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
@@ -183,3 +182,4 @@ struct_devlink_port* devlink_port struct_dpll_pin* dpll_pin struct hlist_head page_pools struct dim_irq_moder* irq_moder +u32 napi_defer_hard_irqs
include/linux/netdevice.h +2 -1
@@ -377,6 +377,7 @@ struct napi_struct {struct list_head dev_list;struct hlist_node napi_hash_node;int irq; +u32 defer_hard_irqs; };enum {
@@ -2075,7 +2076,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;
@@ -2398,6 +2398,7 @@ struct net_device {/** @irq_moder: dim parameters used if IS_ENABLED(CONFIG_DIMLIB). */ struct dim_irq_moder *irq_moder; +u32 napi_defer_hard_irqs; u8 priv[] ____cacheline_aligned__counted_by (priv_len );
net/core/dev.c +5 -5
@@ -6227,7 +6227,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--;
@@ -6365,7 +6365,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 );
@@ -6647,6 +6647,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);
@@ -11053,7 +11054,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);
@@ -11991,7 +11992,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);
@@ -12003,7 +12003,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.25.1
Jakub Kicinski
maintainerRe: [RFC net-next v4 1/9] net: napi: Make napi_defer_hard_irqs per-NAPI
include/linux/netdevice.h struct napi_struct { · line 380
Quoted 5 lines · On Tue, 1 Oct 2024 23:52:32 +0000 Joe Damato wrote:
include/linux/netdevice.h +1
-0@@ -377,6 +377,7 @@ struct napi_struct {struct list_head dev_list;struct hlist_node napi_hash_node;int irq; +u32 defer_hard_irqs;
This will be read on every unmasking, let's put it above the "/* control-path-only fields follow */" comment
RFC v4 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.25.1
RFC v4 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.
Note that idpf has embedded napi_struct in its internals and has established some series of asserts that involve the size of napi structure. Since this change increases the napi_struct size from 400 to 416 (according to pahole on my system), I've increased the assertion in idpf by 16 bytes. No attention whatsoever was paid to the cacheline placement of idpf internals as a result of this change.
--- .../networking/net_cachelines/net_device.rst | 2 +- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 2 +- include/linux/netdevice.h | 3 +- net/core/dev.c | 12 +++--- net/core/dev.h | 40 +++++++++++++++++++ net/core/net-sysfs.c | 2 +- 6 files changed, 51 insertions(+), 10 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -1
@@ -98,7 +98,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
@@ -182,4 +181,5 @@ struct_devlink_port* devlink_port struct_dpll_pin* dpll_pin struct hlist_head page_pools struct dim_irq_moder* irq_moder +unsigned_long gro_flush_timeout u32 napi_defer_hard_irqs
drivers/net/ethernet/intel/idpf/idpf_txrx.h +1 -1
@@ -438,7 +438,7 @@ struct idpf_q_vector {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_q_vector, 112, -424 +2 *sizeof (struct dim ), +440 +2 *sizeof (struct dim ), 8 + sizeof(cpumask_var_t)); struct idpf_rx_queue_stats {
include/linux/netdevice.h +2 -1
@@ -377,6 +377,7 @@ struct napi_struct {struct list_head dev_list;struct hlist_node napi_hash_node;int irq; +unsigned long gro_flush_timeout;u32 defer_hard_irqs; };
@@ -2075,7 +2076,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;
@@ -2398,6 +2398,7 @@ struct net_device {/** @irq_moder: dim parameters used if IS_ENABLED(CONFIG_DIMLIB). */ struct dim_irq_moder *irq_moder; +unsigned long gro_flush_timeout;u32 napi_defer_hard_irqs;u8 priv[]____cacheline_aligned
net/core/dev.c +6 -6
@@ -6226,12 +6226,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; }
@@ -6366,7 +6366,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;
@@ -6648,6 +6648,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);
@@ -11053,7 +11054,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 ); } }
@@ -11991,7 +11992,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);
@@ -12003,7 +12003,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.25.1
Re: [RFC net-next v4 3/9] net: napi: Make gro_flush_timeout per-NAPI
On Tue, Oct 01, 2024 at 11:52:34PM +0000, Joe Damato wrote:
[...]
Quoted 16 lines
Note that idpf has embedded
napi_structin its internals and has established some series of asserts that involve the size of napi structure. Since this change increases thenapi_structsize from 400 to 416 (according to pahole on my system), I've increased the assertion in idpf by 16 bytes. No attention whatsoever was paid to the cacheline placement of idpf internals as a result of this change.Signed-off-by Joe Damato <[email protected]>--- .../networking/net_cachelines/net_device.rst | 2 +- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 2 +- include/linux/netdevice.h | 3 +- net/core/dev.c | 12 +++--- net/core/dev.h | 40 +++++++++++++++++++ net/core/net-sysfs.c | 2 +- 6 files changed, 51 insertions(+), 10 deletions(-)
[...]
drivers/net/ethernet/intel/idpf/idpf_txrx.h struct idpf_q_vector { · line 444
Quoted 13 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.h +1
-1@@ -438,7 +438,7 @@ struct idpf_q_vector {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_q_vector, 112, -424 +2 *sizeof (struct dim ), +440 +2 *sizeof (struct dim ), 8 + sizeof(cpumask_var_t)); struct idpf_rx_queue_stats {
Now that idpf was fixed separately [1], this will be removed in the v5.
Jakub Kicinski
maintainerRe: [RFC net-next v4 3/9] net: napi: Make gro_flush_timeout per-NAPI
In reply to Joe Damatoinclude/linux/netdevice.h struct napi_struct { · line 382
Quoted 11 lines · On Tue, 1 Oct 2024 23:52:34 +0000 Joe Damato wrote:
include/linux/netdevice.h +1
-0@@ -377,6 +377,7 @@ struct napi_struct {struct list_head dev_list;struct hlist_node napi_hash_node;int irq; +unsigned long gro_flush_timeout;u32 defer_hard_irqs; };
Same story
RFC v4 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.25.1
RFC v4 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 | 32 ++++++++ net/core/dev.c | 79 +++++++++++++++++-- net/core/dev.h | 14 ++++ 4 files changed, 119 insertions(+), 7 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -0
@@ -183,3 +183,4 @@ struct hlist_head page_pools struct dim_irq_moder* irq_moder unsigned_long gro_flush_timeout u32 napi_defer_hard_irqs +struct napi_config* napi_config
include/linux/netdevice.h +32 -0
@@ -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 {int irq;unsigned long gro_flush_timeout;u32 defer_hard_irqs; +int index; +struct napi_config *config; };enum {
@@ -2011,6 +2022,9 @@ enum netdev_reg_state {* @dpll_pin: Pointer to the SyncE source pin of a DPLL subsystem, * where the clock is recovered. * +* @napi_config: An array of napi_config structures containing per-NAPI +* settings. +* * FIXME: cleanup struct net_device such that network protocol info * moves out. */
@@ -2400,6 +2414,7 @@ struct net_device {struct dim_irq_moder *irq_moder;unsigned long gro_flush_timeout;u32 napi_defer_hard_irqs; +struct napi_config *napi_config; u8 priv[] ____cacheline_aligned__counted_by (priv_len );
@@ -2650,6 +2665,23 @@ 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 +* @weight: the poll weight of this NAPI +* @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 +14 -0
@@ -167,11 +167,18 @@ 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); + +if (netdev->napi_config) +for (i =0 ; i < count; i++) + netdev->napi_config[i].defer_hard_irqs = defer; }/**
@@ -207,11 +214,18 @@ 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); + +if (netdev->napi_config) +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.25.1
kernel test robot
build botRe: [RFC net-next v4 5/9] net: napi: Add napi_config
kernel test robot noticed the following build errors:
Hi Joe,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Joe-Damato/net-napi-Make-napi_defer_hard_irqs-per-NAPI/20241002-075725 base: net-next/main patch link: https://lore.kernel.org/r/20241001235302.57609-6-jdamato%40fastly.com patch subject: [RFC net-next v4 5/9] net: napi: Add napi_config config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20241005/[email protected]/config) compiler: s390-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241005/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/minmax.h:5,
from include/linux/jiffies.h:8,
from include/net/pkt_sched.h:5,
from drivers/net/ethernet/intel/idpf/idpf.h:12, from drivers/net/ethernet/intel/idpf/idpf_dev.c:4:
>> include/linux/build_bug.h:78:41: error: static assertion failed: "offsetof(struct idpf_q_vector, __cacheline_group_end__read_write) - offsetofend(struct idpf_q_vector, __cacheline_group_begin__read_write) <= (440 + 2 * sizeof(struct dim))"
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~~~~~~~~~~~
include/linux/build_bug.h:77:34: note: in expansion of macro '__static_assert'
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ^~~~~~~~~~~~~~~
include/net/libeth/cache.h:24:9: note: in expansion of macro 'static_assert'
24 | static_assert(offsetof(type, __cacheline_group_end__##grp) - \
| ^~~~~~~~~~~~~
include/net/libeth/cache.h:62:9: note: in expansion of macro 'libeth_cacheline_group_assert'
62 | libeth_cacheline_group_assert(type, read_write, rw); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/intel/idpf/idpf_txrx.h:440:1: note: in expansion of macro 'libeth_cacheline_set_assert'
440 | libeth_cacheline_set_assert(struct idpf_q_vector, 112,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +78 include/linux/build_bug.h
bc6245e5efd70c Ian Abbott 2017-07-10 60 6bab69c65013be Rasmus Villemoes 2019-03-07 61 /** 6bab69c65013be Rasmus Villemoes 2019-03-07 62 * static_assert - check integer constant expression at build time 6bab69c65013be Rasmus Villemoes 2019-03-07 63 * 6bab69c65013be Rasmus Villemoes 2019-03-07 64 * static_assert() is a wrapper for the C11 _Static_assert, with a 6bab69c65013be Rasmus Villemoes 2019-03-07 65 * little macro magic to make the message optional (defaulting to the 6bab69c65013be Rasmus Villemoes 2019-03-07 66 * stringification of the tested expression). 6bab69c65013be Rasmus Villemoes 2019-03-07 67 * 6bab69c65013be Rasmus Villemoes 2019-03-07 68 * Contrary to BUILD_BUG_ON(), static_assert() can be used at global 6bab69c65013be Rasmus Villemoes 2019-03-07 69 * scope, but requires the expression to be an integer constant 6bab69c65013be Rasmus Villemoes 2019-03-07 70 * expression (i.e., it is not enough that __builtin_constant_p() is 6bab69c65013be Rasmus Villemoes 2019-03-07 71 * true for expr). 6bab69c65013be Rasmus Villemoes 2019-03-07 72 * 6bab69c65013be Rasmus Villemoes 2019-03-07 73 * Also note that BUILD_BUG_ON() fails the build if the condition is 6bab69c65013be Rasmus Villemoes 2019-03-07 74 * true, while static_assert() fails the build if the expression is 6bab69c65013be Rasmus Villemoes 2019-03-07 75 * false. 6bab69c65013be Rasmus Villemoes 2019-03-07 76 */ 6bab69c65013be Rasmus Villemoes 2019-03-07 77 #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
6bab69c65013be Rasmus Villemoes 2019-03-07 @78 #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) 6bab69c65013be Rasmus Villemoes 2019-03-07 7907a368b3f55a79 Maxim Levitsky 2022-10-25 80
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC net-next v4 5/9] net: napi: Add napi_config
In reply to Joe Damatokernel test robot noticed the following build errors:
Hi Joe,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Joe-Damato/net-napi-Make-napi_defer_hard_irqs-per-NAPI/20241002-075725 base: net-next/main patch link: https://lore.kernel.org/r/20241001235302.57609-6-jdamato%40fastly.com patch subject: [RFC net-next v4 5/9] net: napi: Add napi_config config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20241005/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241005/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c:7:
In file included from drivers/net/ethernet/intel/idpf/idpf.h:22:
>> drivers/net/ethernet/intel/idpf/idpf_txrx.h:440:1: error: static assertion failed due to requirement '__builtin_offsetof(struct idpf_q_vector, __cacheline_group_end__read_write) - (__builtin_offsetof(struct idpf_q_vector, __cacheline_group_begin__read_write) + sizeof ((((struct idpf_q_vector *)0)->__cacheline_group_begin__read_write))) == (440 + 2 * sizeof(struct dim))': offsetof(struct idpf_q_vector, __cacheline_group_end__read_write) - offsetofend(struct idpf_q_vector, __cacheline_group_begin__read_write) == (440 + 2 * sizeof(struct dim))
440 | libeth_cacheline_set_assert(struct idpf_q_vector, 112,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
441 | 440 + 2 * sizeof(struct dim),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442 | 8 + sizeof(cpumask_var_t));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:62:2: note: expanded from macro 'libeth_cacheline_set_assert'
62 | libeth_cacheline_group_assert(type, read_write, rw); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:17:16: note: expanded from macro 'libeth_cacheline_group_assert'
17 | static_assert(offsetof(type, __cacheline_group_end__##grp) - \
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | offsetofend(type, __cacheline_group_begin__##grp) == \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 | (sz))
| ~~~~~
include/linux/stddef.h:16:32: note: expanded from macro 'offsetof'
16 | #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
| ^
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
drivers/net/ethernet/intel/idpf/idpf_txrx.h:440:1: note: expression evaluates to '784 == 776'
440 | libeth_cacheline_set_assert(struct idpf_q_vector, 112,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
441 | 440 + 2 * sizeof(struct dim),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442 | 8 + sizeof(cpumask_var_t));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:62:2: note: expanded from macro 'libeth_cacheline_set_assert'
62 | libeth_cacheline_group_assert(type, read_write, rw); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:18:59: note: expanded from macro 'libeth_cacheline_group_assert'
17 | static_assert(offsetof(type, __cacheline_group_end__##grp) - \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | offsetofend(type, __cacheline_group_begin__##grp) == \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
19 | (sz))
| ~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~ 1 error generated.
--
In file included from drivers/net/ethernet/intel/idpf/idpf_main.c:4:
In file included from drivers/net/ethernet/intel/idpf/idpf.h:22:
>> drivers/net/ethernet/intel/idpf/idpf_txrx.h:440:1: error: static assertion failed due to requirement '__builtin_offsetof(struct idpf_q_vector, __cacheline_group_end__read_write) - (__builtin_offsetof(struct idpf_q_vector, __cacheline_group_begin__read_write) + sizeof ((((struct idpf_q_vector *)0)->__cacheline_group_begin__read_write))) == (440 + 2 * sizeof(struct dim))': offsetof(struct idpf_q_vector, __cacheline_group_end__read_write) - offsetofend(struct idpf_q_vector, __cacheline_group_begin__read_write) == (440 + 2 * sizeof(struct dim))
440 | libeth_cacheline_set_assert(struct idpf_q_vector, 112,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
441 | 440 + 2 * sizeof(struct dim),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442 | 8 + sizeof(cpumask_var_t));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:62:2: note: expanded from macro 'libeth_cacheline_set_assert'
62 | libeth_cacheline_group_assert(type, read_write, rw); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:17:16: note: expanded from macro 'libeth_cacheline_group_assert'
17 | static_assert(offsetof(type, __cacheline_group_end__##grp) - \
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | offsetofend(type, __cacheline_group_begin__##grp) == \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 | (sz))
| ~~~~~
include/linux/stddef.h:16:32: note: expanded from macro 'offsetof'
16 | #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
| ^
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
drivers/net/ethernet/intel/idpf/idpf_txrx.h:440:1: note: expression evaluates to '784 == 776'
440 | libeth_cacheline_set_assert(struct idpf_q_vector, 112,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
441 | 440 + 2 * sizeof(struct dim),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442 | 8 + sizeof(cpumask_var_t));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:62:2: note: expanded from macro 'libeth_cacheline_set_assert'
62 | libeth_cacheline_group_assert(type, read_write, rw); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/net/libeth/cache.h:18:59: note: expanded from macro 'libeth_cacheline_group_assert'
17 | static_assert(offsetof(type, __cacheline_group_end__##grp) - \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 | offsetofend(type, __cacheline_group_begin__##grp) == \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
19 | (sz))
| ~~~~~
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
drivers/net/ethernet/intel/idpf/idpf_main.c:167:39: warning: shift count >= width of type [-Wshift-count-overflow]
167 | err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
| ^~~~~~~~~~~~~~~~ include/linux/dma-mapping.h:77:54: note: expanded from macro 'DMA_BIT_MASK'
77 | #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
| ^ ~~~
1 warning and 1 error generated.
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for MODVERSIONS
Depends on [n]: MODULES [=y] && !COMPILE_TEST [=y]
Selected by [y]:
- RANDSTRUCT_FULL [=y] && (CC_HAS_RANDSTRUCT [=y] || GCC_PLUGINS [=n]) && MODULES [=y]
vim +440 drivers/net/ethernet/intel/idpf/idpf_txrx.h
4930fbf419a72d Pavan Kumar Linga 2023-08-07 375
4930fbf419a72d Pavan Kumar Linga 2023-08-07 376 /**
4930fbf419a72d Pavan Kumar Linga 2023-08-07 377 * struct idpf_q_vector
1c325aac10a82f Alan Brady 2023-08-07 378 * @vport: Vport back pointer
5a816aae2d463d Alexander Lobakin 2024-06-20 379 * @num_rxq: Number of RX queues
d4d5587182664b Pavan Kumar Linga 2023-08-07 380 * @num_txq: Number of TX queues
5a816aae2d463d Alexander Lobakin 2024-06-20 381 * @num_bufq: Number of buffer queues
e4891e4687c8dd Alexander Lobakin 2024-06-20 382 * @num_complq: number of completion queues
5a816aae2d463d Alexander Lobakin 2024-06-20 383 * @rx: Array of RX queues to service
1c325aac10a82f Alan Brady 2023-08-07 384 * @tx: Array of TX queues to service
5a816aae2d463d Alexander Lobakin 2024-06-20 385 * @bufq: Array of buffer queues to service
e4891e4687c8dd Alexander Lobakin 2024-06-20 386 * @complq: array of completion queues
5a816aae2d463d Alexander Lobakin 2024-06-20 387 * @intr_reg: See struct idpf_intr_reg
5a816aae2d463d Alexander Lobakin 2024-06-20 388 * @napi: napi handler
5a816aae2d463d Alexander Lobakin 2024-06-20 389 * @total_events: Number of interrupts processed
9c4a27da0ecc40 Joshua Hay 2024-09-04 390 * @wb_on_itr: whether WB on ITR is enabled
c2d548cad1508d Joshua Hay 2023-08-07 391 * @tx_dim: Data for TX net_dim algorithm
1c325aac10a82f Alan Brady 2023-08-07 392 * @tx_itr_value: TX interrupt throttling rate
1c325aac10a82f Alan Brady 2023-08-07 393 * @tx_intr_mode: Dynamic ITR or not
1c325aac10a82f Alan Brady 2023-08-07 394 * @tx_itr_idx: TX ITR index
3a8845af66edb3 Alan Brady 2023-08-07 395 * @rx_dim: Data for RX net_dim algorithm
95af467d9a4e3b Alan Brady 2023-08-07 396 * @rx_itr_value: RX interrupt throttling rate
95af467d9a4e3b Alan Brady 2023-08-07 397 * @rx_intr_mode: Dynamic ITR or not
95af467d9a4e3b Alan Brady 2023-08-07 398 * @rx_itr_idx: RX ITR index
5a816aae2d463d Alexander Lobakin 2024-06-20 399 * @v_idx: Vector index
bf9bf7042a38eb Alexander Lobakin 2024-06-20 400 * @affinity_mask: CPU affinity mask
4930fbf419a72d Pavan Kumar Linga 2023-08-07 401 */
4930fbf419a72d Pavan Kumar Linga 2023-08-07 402 struct idpf_q_vector {
5a816aae2d463d Alexander Lobakin 2024-06-20 403 __cacheline_group_begin_aligned(read_mostly);
1c325aac10a82f Alan Brady 2023-08-07 404 struct idpf_vport *vport;
1c325aac10a82f Alan Brady 2023-08-07 405
5a816aae2d463d Alexander Lobakin 2024-06-20 406 u16 num_rxq;
d4d5587182664b Pavan Kumar Linga 2023-08-07 407 u16 num_txq;
5a816aae2d463d Alexander Lobakin 2024-06-20 408 u16 num_bufq;
e4891e4687c8dd Alexander Lobakin 2024-06-20 409 u16 num_complq;
5a816aae2d463d Alexander Lobakin 2024-06-20 410 struct idpf_rx_queue **rx;
e4891e4687c8dd Alexander Lobakin 2024-06-20 411 struct idpf_tx_queue **tx;
5a816aae2d463d Alexander Lobakin 2024-06-20 412 struct idpf_buf_queue **bufq;
e4891e4687c8dd Alexander Lobakin 2024-06-20 413 struct idpf_compl_queue **complq;
e4891e4687c8dd Alexander Lobakin 2024-06-20 414
5a816aae2d463d Alexander Lobakin 2024-06-20 415 struct idpf_intr_reg intr_reg;
5a816aae2d463d Alexander Lobakin 2024-06-20 416 __cacheline_group_end_aligned(read_mostly);
5a816aae2d463d Alexander Lobakin 2024-06-20 417
5a816aae2d463d Alexander Lobakin 2024-06-20 418 __cacheline_group_begin_aligned(read_write);
5a816aae2d463d Alexander Lobakin 2024-06-20 419 struct napi_struct napi;
5a816aae2d463d Alexander Lobakin 2024-06-20 420 u16 total_events;
9c4a27da0ecc40 Joshua Hay 2024-09-04 421 bool wb_on_itr;
5a816aae2d463d Alexander Lobakin 2024-06-20 422
c2d548cad1508d Joshua Hay 2023-08-07 423 struct dim tx_dim;
1c325aac10a82f Alan Brady 2023-08-07 424 u16 tx_itr_value;
1c325aac10a82f Alan Brady 2023-08-07 425 bool tx_intr_mode;
1c325aac10a82f Alan Brady 2023-08-07 426 u32 tx_itr_idx;
1c325aac10a82f Alan Brady 2023-08-07 427
3a8845af66edb3 Alan Brady 2023-08-07 428 struct dim rx_dim;
95af467d9a4e3b Alan Brady 2023-08-07 429 u16 rx_itr_value;
95af467d9a4e3b Alan Brady 2023-08-07 430 bool rx_intr_mode;
95af467d9a4e3b Alan Brady 2023-08-07 431 u32 rx_itr_idx;
5a816aae2d463d Alexander Lobakin 2024-06-20 432 __cacheline_group_end_aligned(read_write);
95af467d9a4e3b Alan Brady 2023-08-07 433
5a816aae2d463d Alexander Lobakin 2024-06-20 434 __cacheline_group_begin_aligned(cold);
5a816aae2d463d Alexander Lobakin 2024-06-20 435 u16 v_idx;
bf9bf7042a38eb Alexander Lobakin 2024-06-20 436
bf9bf7042a38eb Alexander Lobakin 2024-06-20 437 cpumask_var_t affinity_mask;
5a816aae2d463d Alexander Lobakin 2024-06-20 438 __cacheline_group_end_aligned(cold);
4930fbf419a72d Pavan Kumar Linga 2023-08-07 439 };
9c4a27da0ecc40 Joshua Hay 2024-09-04 @440 libeth_cacheline_set_assert(struct idpf_q_vector, 112,
cb5dc755af3703 Joe Damato 2024-10-01 441 440 + 2 * sizeof(struct dim),
5a816aae2d463d Alexander Lobakin 2024-06-20 442 8 + sizeof(cpumask_var_t));0fe45467a1041e Pavan Kumar Linga 2023-08-07 443
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [RFC net-next v4 5/9] net: napi: Add napi_config
In reply to Joe DamatoQuoted 21 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 | 32 ++++++++ net/core/dev.c | 79 +++++++++++++++++-- net/core/dev.h | 14 ++++ 4 files changed, 119 insertions(+), 7 deletions(-)
[...]
Quoted 6 lines
+/**
+ *netif_napi_add_config- initialize a NAPI context with persistent config
+ * @dev: network device
+ * @napi: NAPI context
+ * @poll: polling function
+ * @weight: the poll weight of this NAPI
For anyone following along, I noticed this unnecessary bit of kdoc left in from a previous revision and will remove it when submitting v5.
Jakub Kicinski
maintainerRe: [RFC net-next v4 5/9] net: napi: Add napi_config
In reply to Joe Damatonet/core/dev.h static inline void napi_set_defer_hard_irqs(struct napi_struct *n, u32 defer) · line 179
Quoted 13 lines · On Tue, 1 Oct 2024 23:52:36 +0000 Joe Damato wrote:
static inline void netdev_set_defer_hard_irqs(struct
net_device*netdev,net/core/dev.h +5
-0u32 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); + +if (netdev->napi_config)
Could this ever be NULL ?
Quoted 3 lines
net/core/dev.h +2
-0+for (i =0 ; i < count; i++) + netdev->napi_config[i].defer_hard_irqs = defer; }
Re: [RFC net-next v4 5/9] net: napi: Add napi_config
Quoted 9 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 1 Oct 2024 23:52:36 +0000 Joe Damato wrote:
static inline void netdev_set_defer_hard_irqs(struct
net_device*netdev,net/core/dev.h +3
-0u32 defer) { +unsigned int count =max (netdev->num_rx_queues, + netdev->num_tx_queues);struct napi_struct *napi; +int i;
Quoted 7 lines
net/core/dev.h static inline void napi_set_defer_hard_irqs(struct napi_struct *n, u32 defer) · line 179
Quoted 5 lines
net/core/dev.h +2
-0WRITE_ONCE (netdev->napi_defer_hard_irqs, defer);list_for_each_entry (napi, &netdev->napi_list, dev_list)napi_set_defer_hard_irqs (napi, defer); + +if (netdev->napi_config)Could this ever be NULL ?
Ah, good catch. I think this was an artifact from a previous revision where it could have been. But, I'll double check.
In the current proposed implementation, however, I don't think it can be NULL as it is always allocated.
RFC v4 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 | 14 ++++++++ net/core/netdev-genl-gen.h | 1 + net/core/netdev-genl.c | 45 +++++++++++++++++++++++++ tools/include/uapi/linux/netdev.h | 1 + 6 files changed, 73 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: + - napi-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 +14 -0
@@ -87,6 +87,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 - set */ +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 ] = { .type =NLA_S32 }, + [NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT ] = { .type =NLA_UINT }, +}; +/* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { {
@@ -171,6 +178,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
@@ -30,6 +30,7 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);int netdev_nl_napi_get_doit (struct sk_buff *skb,struct genl_info *info);int netdev_nl_napi_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info);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);
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.25.1
Re: [RFC net-next v4 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 11 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 | 14 ++++++++ net/core/netdev-genl-gen.h | 1 + net/core/netdev-genl.c | 45 +++++++++++++++++++++++++ tools/include/uapi/linux/netdev.h | 1 + 6 files changed, 73 insertions(+)
[...]
net/core/netdev-genl-gen.c static const struct nla_policy netdev_bind_rx_nl_policy[NETDEV_A_DMABUF_FD + 1] · line 93
Quoted 12 lines
net/core/netdev-genl-gen.c +4
-0@@ -87,6 +87,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 - set */ +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 ] = { .type =NLA_S32 },
Noticed this while re-reading the code; planning on changing this from NLA_S32 to NLA_U32 for v5.
Jakub Kicinski
maintainerRe: [RFC net-next v4 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 2 lines · On Tue, 8 Oct 2024 11:20:47 -0700 Joe Damato wrote:
Noticed this while re-reading the code; planning on changing this from
NLA_S32toNLA_U32for v5.
Make sure you edit the spec, not the output. Looks like there may be a problem here (napi-id vs id in the attributes).
Make sure you run: ./tools/net/ynl/ynl-regen.sh -f and the tree is clean afterwards
Re: [RFC net-next v4 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 8 Oct 2024 11:20:47 -0700 Joe Damato wrote:
Noticed this while re-reading the code; planning on changing this from
NLA_S32toNLA_U32for v5.Make sure you edit the spec, not the output. Looks like there may be a problem here (napi-id vs id in the attributes).
I'm not sure I follow this part, sorry if I'm just missing something here.
I was referring to NETDEV_A_NAPI_DEFER_HARD_IRQS which in RFCv4 is listed as NLA_S32 (in this patch):
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] = { .type = NLA_S32 },However, in the yaml spec (patch 2/9):
+ -
+ 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
So the type is u32 but with a "checks" to match what happens now in sysfs.
That's why I mentioned changing NLA_S32 to NLA_U32.
Am I missing something? Not sure what you meant by "napi-id vs id" ?
Quoted 2 lines
Make sure you run:
./tools/net/ynl/ynl-regen.sh-f and the tree is clean afterwards
OK, will do.
Jakub Kicinski
maintainerRe: [RFC net-next v4 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 23 lines · On Tue, 8 Oct 2024 16:00:41 -0700 Joe Damato wrote:
Quoted 2 lines
Make sure you edit the spec, not the output. Looks like there may be a problem here (napi-id vs id in the attributes).
I'm not sure I follow this part, sorry if I'm just missing something here.
I was referring to
NETDEV_A_NAPI_DEFER_HARD_IRQSwhich in RFCv4 is listed asNLA_S32(in this patch):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] = { .type = NLA_S32 },However, in the yaml spec (patch 2/9):
(quoted diff) +7
-0+ - + 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
Quoted 6 lines
So the type is u32 but with a "checks" to match what happens now in sysfs.
That's why I mentioned changing
NLA_S32toNLA_U32.Am I missing something?
YNL will generate the correct code for your - the right type and the right range validation. Run the command below to see.
Quoted 1 line
Not sure what you meant by "napi-id vs id" ?
I can't apply the series now, but when it was posted the YNL code generation failed here complaining about napi-id not existing in the attribute set in which it is used. In the napi attribute set the NAPI ID is called just "id", not "napi-id".
Quoted 4 lines
Quoted 2 lines
Make sure you run:
./tools/net/ynl/ynl-regen.sh-f and the tree is clean afterwardsOK, will do.
Re: [RFC net-next v4 6/9] netdev-genl: Support setting per-NAPI config values
Quoted 34 lines · Jakub Kicinski
Quoted 23 lines · On Tue, 8 Oct 2024 16:00:41 -0700 Joe Damato wrote:
Quoted 2 lines
Make sure you edit the spec, not the output. Looks like there may be a problem here (napi-id vs id in the attributes).
I'm not sure I follow this part, sorry if I'm just missing something here.
I was referring to
NETDEV_A_NAPI_DEFER_HARD_IRQSwhich in RFCv4 is listed asNLA_S32(in this patch):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] = { .type = NLA_S32 },However, in the yaml spec (patch 2/9):
(quoted diff) +7
-0+ - + 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-maxQuoted 6 lines
So the type is u32 but with a "checks" to match what happens now in sysfs.
That's why I mentioned changing
NLA_S32toNLA_U32.Am I missing something?
YNL will generate the correct code for your - the right type and the right range validation. Run the command below to see.
Quoted 6 lines
Quoted 1 line
Not sure what you meant by "napi-id vs id" ?
I can't apply the series now, but when it was posted the YNL code generation failed here complaining about napi-id not existing in the attribute set in which it is used. In the napi attribute set the NAPI ID is called just "id", not "napi-id".
Ah, I see what you mean now. It should have been obvious, but the -gen* files are, uh, auto-generated ;)
And yes, I see now that the attribute set names it "id", so I've fixed it and the command runs clean and I'll include the generated output this time in the v5.
RFC v4 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.25.1
RFC v4 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.25.1
RFC v4 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.25.1
Quoted 21 lines · Joe Damato
Greetings:
Welcome to RFC v4.
Very important and significant changes have been made since RFC v3 [1], please see the changelog below for details.
A couple important call outs for this revision for reviewers:
1. idpf embeds a
napi_structin an internal data structure and includes an assertion on the size ofnapi_struct. The maintainers have stated that they think anyone touchingnapi_structshould update the assertion [2], so I've done this in patch 3.Even though the assertion has been updated, I've given the cacheline placement of
napi_structwithin idpf's internals no thought or consideration.Would appreciate other opinions on this; I think idpf should be fixed. It seems unreasonable to me that anyone changing the size of a struct in the core should need to think about cachelines in idpf.
[..]
Quoted 3 lines
2. This revision seems to work (see below for a full walk through). Is this the behavior we want? Am I missing some use case or some behavioral thing other folks need?
The walk through looks good!
Quoted 7 lines
3. Re a previous point made by Stanislav regarding "taking over a NAPI ID" when the channel count changes: mlx5 seems to call
napi_disablefollowed bynetif_napi_delfor the old queues and then callsnapi_enablefor the new ones. In this RFC, the NAPI ID generation is deferred tonapi_enable. This means we won't end up with two of the same NAPI IDs added to the hash at the same time (I am pretty sure).
[..]
Quoted 3 lines
Can we assume all drivers will
napi_disablethe old queues beforenapi_enablethe new ones? If yes, we might not need to worry about a NAPI ID takeover function.
With the explicit driver opt-in via netif_napi_add_config, this shouldn't matter? When somebody gets to converting the drivers that don't follow this common pattern they'll have to solve the takeover part :-)
Quoted 1 line · Stanislav Fomichev
On 10/01, Joe Damato wrote:
[...]
Quoted 5 lines
Quoted 3 lines
2. This revision seems to work (see below for a full walk through). Is this the behavior we want? Am I missing some use case or some behavioral thing other folks need?
The walk through looks good!
Thanks for taking a look.
Quoted 11 lines
Quoted 7 lines
3. Re a previous point made by Stanislav regarding "taking over a NAPI ID" when the channel count changes: mlx5 seems to call
napi_disablefollowed bynetif_napi_delfor the old queues and then callsnapi_enablefor the new ones. In this RFC, the NAPI ID generation is deferred tonapi_enable. This means we won't end up with two of the same NAPI IDs added to the hash at the same time (I am pretty sure).[..]
Quoted 8 lines
Quoted 3 lines
Can we assume all drivers will
napi_disablethe old queues beforenapi_enablethe new ones? If yes, we might not need to worry about a NAPI ID takeover function.With the explicit driver opt-in via
netif_napi_add_config, this shouldn't matter? When somebody gets to converting the drivers that don't follow this common pattern they'll have to solve the takeover part :-)
That is true; that's a good point. I'll let the RFC hang out on the list for another day or two just to give Jakub time to catch up on his mails ;) but if you all agree... this might be ready to be resent as a PATCH instead of an RFC.
Quoted 28 lines · Joe Damato
Quoted 1 line · Stanislav Fomichev
On 10/01, Joe Damato wrote:
[...]
Quoted 5 lines
Quoted 3 lines
2. This revision seems to work (see below for a full walk through). Is this the behavior we want? Am I missing some use case or some behavioral thing other folks need?
The walk through looks good!
Thanks for taking a look.
Quoted 15 lines
Quoted 7 lines
3. Re a previous point made by Stanislav regarding "taking over a NAPI ID" when the channel count changes: mlx5 seems to call
napi_disablefollowed bynetif_napi_delfor the old queues and then callsnapi_enablefor the new ones. In this RFC, the NAPI ID generation is deferred tonapi_enable. This means we won't end up with two of the same NAPI IDs added to the hash at the same time (I am pretty sure).[..]
Quoted 3 lines
Can we assume all drivers will
napi_disablethe old queues beforenapi_enablethe new ones? If yes, we might not need to worry about a NAPI ID takeover function.
Quoted 6 lines
Quoted 4 lines
With the explicit driver opt-in via
netif_napi_add_config, this shouldn't matter? When somebody gets to converting the drivers that don't follow this common pattern they'll have to solve the takeover part :-)That is true; that's a good point.
Actually, sorry, that isn't strictly true. NAPI ID generation is moved for everything to napi_enable; they just are (or are not) persisted depending on whether the driver opted in to add_config or not.
So, the change does affect all drivers. NAPI IDs won't be generated and added to the hash until napi_enable and they will be removed from the hash in napi_disable... even if you didn't opt-in to having storage.
Opt-ing in to storage via netif_napi_add_config just means that your NAPI IDs (and other settings) will be persistent.
Sorry about my confusion when replying earlier.
Quoted 46 lines · Joe Damato
Quoted 28 lines · Joe Damato
Quoted 1 line · Stanislav Fomichev
On 10/01, Joe Damato wrote:
[...]
Quoted 5 lines
Quoted 3 lines
2. This revision seems to work (see below for a full walk through). Is this the behavior we want? Am I missing some use case or some behavioral thing other folks need?
The walk through looks good!
Thanks for taking a look.
Quoted 15 lines
Quoted 7 lines
3. Re a previous point made by Stanislav regarding "taking over a NAPI ID" when the channel count changes: mlx5 seems to call
napi_disablefollowed bynetif_napi_delfor the old queues and then callsnapi_enablefor the new ones. In this RFC, the NAPI ID generation is deferred tonapi_enable. This means we won't end up with two of the same NAPI IDs added to the hash at the same time (I am pretty sure).[..]
Quoted 3 lines
Can we assume all drivers will
napi_disablethe old queues beforenapi_enablethe new ones? If yes, we might not need to worry about a NAPI ID takeover function.Quoted 6 lines
Quoted 4 lines
With the explicit driver opt-in via
netif_napi_add_config, this shouldn't matter? When somebody gets to converting the drivers that don't follow this common pattern they'll have to solve the takeover part :-)That is true; that's a good point.
Actually, sorry, that isn't strictly true. NAPI ID generation is moved for everything to
napi_enable; they just are (or are not) persisted depending on whether the driver opted in toadd_configor not.So, the change does affect all drivers. NAPI IDs won't be generated and added to the hash until
napi_enableand they will be removed from the hash innapi_disable... even if you didn't opt-in to having storage.
Quoted 4 lines
Opt-ing in to storage via
netif_napi_add_configjust means that your NAPI IDs (and other settings) will be persistent.Sorry about my confusion when replying earlier.
AFAIA, all control operations (ethtool or similar ones via netlink), should grab rtnl lock. So as long as both enable/disable happen under rtnl (and in my mind they should), I don't think there is gonna be any user-visible side-effects of your change. But I might be wrong, let's see if others can come up with some corner cases..