Currently the lifetime of the kthread of a threaded NAPI is tied to the napi_struct. netif_napi_del() stops the kthread when it destroys the NAPI struct.
This patch series reuses the same kthread (thus preserving all of its attributes) across napi_del/napi_add. This series now tie the lifetime of the kthread to net_device instead of napi_struct. A normal use case for threaded NAPI will be "enable threaded" -> "configure the thread". Driver reset (that can be caused by a NIC configuration change) often destroys the configuration and causes a usability issue. This series aims to solve the issue. There is a downside of this approach: If a device reduces number of queues while its NAPIs are threaded. The kthread associated with removed queues will not be stopped. Since the mapping between the index passed to napi_add_config() and NAPI is an implementation detail of individual drivers, it is not straightfoward to perform a garbage collection and stop kthreads that are no longer associated with a queue. This patch series tries to minimize the effect by parking the kthread in napi_del. The kthread still shows up in /proc, but should not consume CPU cycles. There was a discussion https://lore.kernel.org/caaywjhr0tpkz-xzqjsp709ovmzwuisdnv2cvc_vxgorxrto...@mail.gmail.com/ around what to do with the kthread between napi_disable/napi_enable. It seems that there was an intention to keep user configuration for the kthread across NIC configuration change. This patch series extends the effort to cover more NIC configuration changes. Roughly tracing through the call hierarchy of napi_del reveals that at least the following drivers will not preserve the user configurations: - idpf: idpf_set_channels(), idpf_set_ringparam() - mlx4: mlx4_en_set_ringparam(), mlx4_en_set_rxfh(), mlx4_en_setchannels() - bnx2: bnx2_set_ringparam(), bnx2_set_channels(), bnx2_change_mtu() - gve: gve_set_channels(), gve_set_ringparam() - ena2: ena_set_ringparam(), ena_set_channels() - (non exhaustive) These drivers destroy and recreate queues during configuration changes. If a NAPI was threaded before destruction, during the creation, a new kthread will be spawned for the NAPI. Some drivers do not have this problem, e.g. fbnic, netdevsim. But these drivers and the drivers mentioned above will still lose kthread during link flap (ndo_stop/ndo_open). Because the kthreads before and after these configuration changes are different, all the attributes associated with the kthread are lost. These include CPU mask, priority, scheduler policy, etc.. If the threaded state is preserved for a NAPI, it makes sense to want to preserve the attributes of the thread as well. Link: https://lore.kernel.org/caaywjhr0tpkz-xzqjsp709ovmzwuisdnv2cvc_vxgorxrto...@mail.gmail.com/ Shuhao Tan (2): net: Save kthread of threaded NAPI in napi_config in napi_del and restore in napi_add selftests: net: Add kthread preserving test in napi_threaded and busy_poll_test include/linux/netdevice.h | 13 +- net/core/dev.c | 151 ++++++++++++++---- net/core/netdev-genl.c | 12 +- .../selftests/drivers/net/napi_threaded.py | 41 ++++- tools/testing/selftests/net/busy_poll_test.sh | 24 +++ 5 files changed, 203 insertions(+), 38 deletions(-) -- 2.54.0.1136.gdb2ca164c4-goog

