[PATCH 2/2] wifi: WQ_PERCPU added to alloc_workqueue users

Marco Crivellari posted 2 patches 4 months, 2 weeks ago
[PATCH 2/2] wifi: WQ_PERCPU added to alloc_workqueue users
Posted by Marco Crivellari 4 months, 2 weeks ago
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.

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.

Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
---
 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(-)

diff --git a/drivers/net/wireless/ath/ath6kl/usb.c b/drivers/net/wireless/ath/ath6kl/usb.c
index 38bb501fc553..bfb21725d779 100644
--- a/drivers/net/wireless/ath/ath6kl/usb.c
+++ b/drivers/net/wireless/ath/ath6kl/usb.c
@@ -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;
diff --git a/drivers/net/wireless/quantenna/qtnfmac/core.c b/drivers/net/wireless/quantenna/qtnfmac/core.c
index 825b05dd3271..38af6cdc2843 100644
--- a/drivers/net/wireless/quantenna/qtnfmac/core.c
+++ b/drivers/net/wireless/quantenna/qtnfmac/core.c
@@ -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;
diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c b/drivers/net/wireless/realtek/rtlwifi/base.c
index e26feb8de658..2786e4ee67eb 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -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;
 
diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c
index 3b5126ffc81a..db60e142268d 100644
--- a/drivers/net/wireless/realtek/rtw88/usb.c
+++ b/drivers/net/wireless/realtek/rtw88/usb.c
@@ -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;
diff --git a/drivers/net/wireless/silabs/wfx/main.c b/drivers/net/wireless/silabs/wfx/main.c
index a61128debbad..dda36e41eed1 100644
--- a/drivers/net/wireless/silabs/wfx/main.c
+++ b/drivers/net/wireless/silabs/wfx/main.c
@@ -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;
 
diff --git a/drivers/net/wireless/st/cw1200/bh.c b/drivers/net/wireless/st/cw1200/bh.c
index 3b4ded2ac801..3f07f4e1deee 100644
--- a/drivers/net/wireless/st/cw1200/bh.c
+++ b/drivers/net/wireless/st/cw1200/bh.c
@@ -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;
-- 
2.51.0

Re: [PATCH 2/2] wifi: WQ_PERCPU added to alloc_workqueue users
Posted by Johannes Berg 3 months, 3 weeks ago
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 ...")

> All existing users have been updated accordingly.

Surely this is not _all_ existing users? :)

> Suggested-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
> ---
>  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.

>  6 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/wireless/ath/ath6kl/usb.c b/drivers/net/wireless/ath/ath6kl/usb.c
> index 38bb501fc553..bfb21725d779 100644
> --- a/drivers/net/wireless/ath/ath6kl/usb.c
> +++ b/drivers/net/wireless/ath/ath6kl/usb.c
> @@ -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
Posted by Marco Crivellari 3 months, 2 weeks ago
Hi Johannes,

On Mon, Oct 20, 2025 at 4:21 PM Johannes Berg <johannes@sipsolutions.net> wrote:
>
> 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 ...")

Aha, thanks for the hint.

> > All existing users have been updated accordingly.
>
> Surely this is not _all_ existing users? :)

Yeah :-)

> > Suggested-by: Tejun Heo <tj@kernel.org>
> > Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
> > ---
> >  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.

> >  6 files changed, 9 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/net/wireless/ath/ath6kl/usb.c b/drivers/net/wireless/ath/ath6kl/usb.c
> > index 38bb501fc553..bfb21725d779 100644
> > --- a/drivers/net/wireless/ath/ath6kl/usb.c
> > +++ b/drivers/net/wireless/ath/ath6kl/usb.c
> > @@ -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.

Thanks for the pointer!

-- 

Marco Crivellari

L3 Support Engineer, Technology & Product