wifi: add WQ_UNBOUND to alloc_workqueue users and rename system_unbound_wq
Subsystems (7)
cover wifi: add WQ_UNBOUND to alloc_workqueue users and rename system_unbound_wq
Hi!
Below is a summary of a discussion about the Workqueue API and cpu isolation considerations. Details and more information are available here:
"workqueue: Always use wq_select_unbound_cpu() for WORK_CPU_UNBOUND."
https://lore.kernel.org/all/[email protected]/
=== Current situation: problems ===
Let's consider a nohz_full system with isolated CPUs: wq_unbound_cpumask is set to the housekeeping CPUs, for !WQ_UNBOUND the local CPU is selected.
This leads to different scenarios if a work item is scheduled on an isolated CPU where "delay" value is 0 or greater then 0:
schedule_delayed_work(, 0);
This will be handled by __queue_work() that will queue the work item on the current local (isolated) CPU, while:
schedule_delayed_work(, 1);
Will move the timer on an housekeeping CPU, and schedule the work there.
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
=== Plan and future plans ===
This patchset is the first stone on a refactoring needed in order to address the points aforementioned; it will have a positive impact also on the cpu isolation, in the long term, moving away percpu workqueue in favor to an unbound model.
These are the main steps:
1) API refactoring (that this patch is introducing)
- Make more clear and uniform the system wq names, both per-cpu and
unbound. This to avoid any possible confusion on what should be used.
- Introduction of WQ_PERCPU: this flag is the complement of WQ_UNBOUND,
introduced in this patchset and used on all the callers that are not currently using WQ_UNBOUND.
WQ_UNBOUND will be removed in a future release cycle.
Most users don't need to be per-cpu, because they don't have locality requirements, because of that, a next future step will be make "unbound" the default behavior.
2) Check who really needs to be per-cpu
- Remove the WQ_PERCPU flag when is not strictly required.
3) Add a new API (prefer local cpu)
- There are users that don't require a local execution, like mentioned
above; despite that, local execution yeld to performance gain.
This new API will prefer the local execution, without requiring it.
=== Introduced Changes by this series ===
1) [P 1] replace system_unbound_wq with system_dfl_workqueue
system_unbound_wq is to be used when locality is not required. This should be the default choice. Make this clear renaming the workqueue in system_dfl_wq.
2) [P 2] WQ_PERCPU added to alloc_workqueue() users
Every alloc_workqueue() users should specify one among WQ_PERCPU or WQ_UNBOUND.
Make this change ensuring that every alloc_workqueue() without WQ_UNBOUND now make use of WQ_PERCPU.
Thanks!
Marco Crivellari (2):
wifi: replace use of system_unbound_wq with system_dfl_wq
wifi: WQ_PERCPU added to alloc_workqueue users
drivers/net/wireless/ath/ath6kl/usb.c | 2 +- drivers/net/wireless/quantenna/qtnfmac/core.c | 3 ++- drivers/net/wireless/realtek/rtlwifi/base.c | 2 +- drivers/net/wireless/realtek/rtw88/usb.c | 3 ++- drivers/net/wireless/silabs/wfx/main.c | 2 +- drivers/net/wireless/st/cw1200/bh.c | 4 ++-- net/wireless/core.c | 4 ++-- net/wireless/sysfs.c | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/2 wifi: replace use of system_unbound_wq with system_dfl_wq
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
system_unbound_wq should be the default workqueue so as not to enforce locality constraints for random work whenever it's not required.
Adding system_dfl_wq to encourage its use when unbound work should be used.
The old system_unbound_wq will be kept for a few release cycles.
--- net/wireless/core.c | 4 ++-- net/wireless/sysfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
net/wireless/core.c +2 -2
@@ -428,7 +428,7 @@ static void cfg80211_wiphy_work(struct work_struct *work)if (wk) {list_del_init (&wk->entry);if (!list_empty (&rdev->wiphy_work_list)) -queue_work (system_unbound_wq, work); +queue_work (system_dfl_wq, work);spin_unlock_irq (&rdev->wiphy_work_lock);trace_wiphy_work_run (&rdev->wiphy, wk);
@@ -1698,7 +1698,7 @@ void wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *work)list_add_tail (&work->entry, &rdev->wiphy_work_list);spin_unlock_irqrestore (&rdev->wiphy_work_lock, flags); -queue_work (system_unbound_wq, &rdev->wiphy_work); +queue_work (system_dfl_wq, &rdev->wiphy_work); }EXPORT_SYMBOL_GPL (wiphy_work_queue);
net/wireless/sysfs.c +1 -1
@@ -137,7 +137,7 @@ static int wiphy_resume(struct device *dev)if (rdev->wiphy.registered && rdev->ops->resume) ret =rdev_resume (rdev); rdev->suspended = false; -queue_work (system_unbound_wq, &rdev->wiphy_work); +queue_work (system_dfl_wq, &rdev->wiphy_work);wiphy_unlock (&rdev->wiphy);if (ret)
Signature · 1 line
2.51.0
PATCH 2/2 wifi: WQ_PERCPU added to alloc_workqueue users
In reply to Marco CrivellariCurrently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND.
This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated.
This patch adds a new WQ_PERCPU flag, to explicitly request the use of the per-CPU behavior. Both flags coexist for one release cycle to allow callers to transition their calls.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU.
All existing users have been updated accordingly.
--- drivers/net/wireless/ath/ath6kl/usb.c | 2 +- drivers/net/wireless/quantenna/qtnfmac/core.c | 3 ++- drivers/net/wireless/realtek/rtlwifi/base.c | 2 +- drivers/net/wireless/realtek/rtw88/usb.c | 3 ++- drivers/net/wireless/silabs/wfx/main.c | 2 +- drivers/net/wireless/st/cw1200/bh.c | 4 ++-- 6 files changed, 9 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath6kl/usb.c +1 -1
@@ -637,7 +637,7 @@ static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface) ar_usb =kzalloc (sizeof (struct ath6kl_usb ),GFP_KERNEL );if (ar_usb ==NULL )return NULL ; - ar_usb->wq =alloc_workqueue ("ath6kl_wq" ,0 ,0 ); + ar_usb->wq =alloc_workqueue ("ath6kl_wq" ,WQ_PERCPU ,0 );if (!ar_usb->wq) {kfree (ar_usb);return NULL ;
drivers/net/wireless/quantenna/qtnfmac/core.c +2 -1
@@ -714,7 +714,8 @@ int qtnf_core_attach(struct qtnf_bus *bus) goto error; } - bus->hprio_workqueue =alloc_workqueue ("QTNF_HPRI" ,WQ_HIGHPRI ,0 ); + bus->hprio_workqueue =alloc_workqueue ("QTNF_HPRI" , +WQ_HIGHPRI |WQ_PERCPU ,0 );if (!bus->hprio_workqueue) {pr_err ("failed to alloc high prio workqueue\n" ); ret = -ENOMEM ;
drivers/net/wireless/realtek/rtlwifi/base.c +1 -1
@@ -445,7 +445,7 @@ static int _rtl_init_deferred_work(struct ieee80211_hw *hw)struct rtl_priv *rtlpriv =rtl_priv (hw);struct workqueue_struct *wq; - wq =alloc_workqueue ("%s" ,0 ,0 , rtlpriv->cfg->name); + wq =alloc_workqueue ("%s" ,WQ_PERCPU ,0 , rtlpriv->cfg->name);if (!wq)return -ENOMEM ;
drivers/net/wireless/realtek/rtw88/usb.c +2 -1
@@ -965,7 +965,8 @@ static int rtw_usb_init_rx(struct rtw_dev *rtwdev)struct sk_buff *rx_skb;int i; - rtwusb->rxwq =alloc_workqueue ("rtw88_usb: rx wq" ,WQ_BH ,0 ); + rtwusb->rxwq =alloc_workqueue ("rtw88_usb: rx wq" ,WQ_BH |WQ_PERCPU , +0 );if (!rtwusb->rxwq) {rtw_err (rtwdev,"failed to create RX work queue\n" );return -ENOMEM ;
drivers/net/wireless/silabs/wfx/main.c +1 -1
@@ -364,7 +364,7 @@ int wfx_probe(struct wfx_dev *wdev) wdev->pdata.gpio_wakeup =NULL ; wdev->poll_irq = true; - wdev->bh_wq =alloc_workqueue ("wfx_bh_wq" ,WQ_HIGHPRI ,0 ); + wdev->bh_wq =alloc_workqueue ("wfx_bh_wq" ,WQ_HIGHPRI |WQ_PERCPU ,0 );if (!wdev->bh_wq)return -ENOMEM ;
drivers/net/wireless/st/cw1200/bh.c +2 -2
@@ -54,8 +54,8 @@ int cw1200_register_bh(struct cw1200_common *priv)int err =0 ;/* Realtime workqueue */ priv->bh_workqueue =alloc_workqueue ("cw1200_bh" , -WQ_MEM_RECLAIM |WQ_HIGHPRI - |WQ_CPU_INTENSIVE ,1 ); +WQ_MEM_RECLAIM |WQ_HIGHPRI |WQ_CPU_INTENSIVE |WQ_PERCPU , +1 );if (!priv->bh_workqueue)return -ENOMEM ;
Signature · 1 line
2.51.0
Johannes Berg
maintainerRe: [PATCH 2/2] wifi: WQ_PERCPU added to alloc_workqueue users
Hi,
So I don't know if I really need to tell you this, but generally the subject should be _imperative_, not describing what you did after the fact (i.e. "add WQ_PERCPU to ..." rather than "added ...")
Quoted 1 line
All existing users have been updated accordingly.
Surely this is not _all_ existing users? :)
Quoted 9 lines
Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>--- drivers/net/wireless/ath/ath6kl/usb.c | 2 +- drivers/net/wireless/quantenna/qtnfmac/core.c | 3 ++- drivers/net/wireless/realtek/rtlwifi/base.c | 2 +- drivers/net/wireless/realtek/rtw88/usb.c | 3 ++- drivers/net/wireless/silabs/wfx/main.c | 2 +- drivers/net/wireless/st/cw1200/bh.c | 4 ++--
These have different maintainers, please split up accordingly.
Quoted 7 lines
6 files changed, 9 insertions(+), 7 deletions(-)drivers/net/wireless/ath/ath6kl/usb.c +0
-0
drivers/net/wireless/ath/ath6kl/usb.c static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface) · line 642
Quoted 7 lines
drivers/net/wireless/ath/ath6kl/usb.c +1
-1@@ -637,7 +637,7 @@ static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface) ar_usb =kzalloc (sizeof (struct ath6kl_usb ),GFP_KERNEL );if (ar_usb ==NULL )return NULL ; - ar_usb->wq =alloc_workqueue ("ath6kl_wq" ,0 ,0 ); + ar_usb->wq =alloc_workqueue ("ath6kl_wq" ,WQ_PERCPU ,0 );if (!ar_usb->wq) {kfree (ar_usb);
I'd also think that WQ_PERCPU doesn't actually make sense for any of these instances, but for those that still have an active maintainer I'll defer to them, of course.
(and patch 1 should be prefixed with "wifi: cfg80211:" I'd think)
johannes
Re: [PATCH 2/2] wifi: WQ_PERCPU added to alloc_workqueue users
Hi Johannes,
Quoted 6 lines · Johannes Berg
Hi,
So I don't know if I really need to tell you this, but generally the subject should be _imperative_, not describing what you did after the fact (i.e. "add
WQ_PERCPUto ..." rather than "added ...")
Aha, thanks for the hint.
Quoted 3 lines
Quoted 1 line
All existing users have been updated accordingly.
Surely this is not _all_ existing users? :)
Yeah :-)
Quoted 11 lines
Quoted 9 lines
Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>--- drivers/net/wireless/ath/ath6kl/usb.c | 2 +- drivers/net/wireless/quantenna/qtnfmac/core.c | 3 ++- drivers/net/wireless/realtek/rtlwifi/base.c | 2 +- drivers/net/wireless/realtek/rtw88/usb.c | 3 ++- drivers/net/wireless/silabs/wfx/main.c | 2 +- drivers/net/wireless/st/cw1200/bh.c | 4 ++--These have different maintainers, please split up accordingly.
Sure, I will do it, like I did for the others.
Quoted 18 lines
Quoted 7 lines
6 files changed, 9 insertions(+), 7 deletions(-)drivers/net/wireless/ath/ath6kl/usb.c +0
-0drivers/net/wireless/ath/ath6kl/usb.c static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface) · line 642
Quoted 7 lines
drivers/net/wireless/ath/ath6kl/usb.c +1
-1@@ -637,7 +637,7 @@ static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface) ar_usb =kzalloc (sizeof (struct ath6kl_usb ),GFP_KERNEL );if (ar_usb ==NULL )return NULL ; - ar_usb->wq =alloc_workqueue ("ath6kl_wq" ,0 ,0 ); + ar_usb->wq =alloc_workqueue ("ath6kl_wq" ,WQ_PERCPU ,0 );if (!ar_usb->wq) {kfree (ar_usb);I'd also think that
WQ_PERCPUdoesn't actually make sense for any of these instances, but for those that still have an active maintainer I'll defer to them, of course.
Thanks for the pointer!
Signature · 3 lines
Marco Crivellari L3 Support Engineer, Technology & Product