Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

workqueue: WQ_PERCPU added to alloc_workqueue users

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>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Marco Crivellari and committed by
Tejun Heo
dadb3ebc a2be943b

+12 -12
+2 -2
include/linux/workqueue.h
··· 410 410 __WQ_LEGACY = 1 << 18, /* internal: create*_workqueue() */ 411 411 412 412 /* BH wq only allows the following flags */ 413 - __WQ_BH_ALLOWS = WQ_BH | WQ_HIGHPRI, 413 + __WQ_BH_ALLOWS = WQ_BH | WQ_HIGHPRI | WQ_PERCPU, 414 414 }; 415 415 416 416 enum wq_consts { ··· 570 570 alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, ##args) 571 571 572 572 #define create_workqueue(name) \ 573 - alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, 1, (name)) 573 + alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_PERCPU, 1, (name)) 574 574 #define create_freezable_workqueue(name) \ 575 575 alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \ 576 576 WQ_MEM_RECLAIM, 1, (name))
+10 -10
kernel/workqueue.c
··· 7828 7828 ordered_wq_attrs[i] = attrs; 7829 7829 } 7830 7830 7831 - system_wq = alloc_workqueue("events", 0, 0); 7832 - system_percpu_wq = alloc_workqueue("events", 0, 0); 7833 - system_highpri_wq = alloc_workqueue("events_highpri", WQ_HIGHPRI, 0); 7834 - system_long_wq = alloc_workqueue("events_long", 0, 0); 7831 + system_wq = alloc_workqueue("events", WQ_PERCPU, 0); 7832 + system_percpu_wq = alloc_workqueue("events", WQ_PERCPU, 0); 7833 + system_highpri_wq = alloc_workqueue("events_highpri", 7834 + WQ_HIGHPRI | WQ_PERCPU, 0); 7835 + system_long_wq = alloc_workqueue("events_long", WQ_PERCPU, 0); 7835 7836 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE); 7836 7837 system_dfl_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE); 7837 7838 system_freezable_wq = alloc_workqueue("events_freezable", 7838 - WQ_FREEZABLE, 0); 7839 + WQ_FREEZABLE | WQ_PERCPU, 0); 7839 7840 system_power_efficient_wq = alloc_workqueue("events_power_efficient", 7840 - WQ_POWER_EFFICIENT, 0); 7841 + WQ_POWER_EFFICIENT | WQ_PERCPU, 0); 7841 7842 system_freezable_power_efficient_wq = alloc_workqueue("events_freezable_pwr_efficient", 7842 - WQ_FREEZABLE | WQ_POWER_EFFICIENT, 7843 - 0); 7844 - system_bh_wq = alloc_workqueue("events_bh", WQ_BH, 0); 7843 + WQ_FREEZABLE | WQ_POWER_EFFICIENT | WQ_PERCPU, 0); 7844 + system_bh_wq = alloc_workqueue("events_bh", WQ_BH | WQ_PERCPU, 0); 7845 7845 system_bh_highpri_wq = alloc_workqueue("events_bh_highpri", 7846 - WQ_BH | WQ_HIGHPRI, 0); 7846 + WQ_BH | WQ_HIGHPRI | WQ_PERCPU, 0); 7847 7847 BUG_ON(!system_wq || !system_percpu_wq|| !system_highpri_wq || !system_long_wq || 7848 7848 !system_unbound_wq || !system_freezable_wq || !system_dfl_wq || 7849 7849 !system_power_efficient_wq ||