Skip to content

Commit 128ea9f

Browse files
DispatchCodehtejun
authored andcommitted
workqueue: Add system_percpu_wq and 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_wq is a per-CPU worqueue, yet nothing in its name tells about that CPU affinity constraint, which is very often not required by users. Make it clear by adding a system_percpu_wq. 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. Suggested-by: Tejun Heo <[email protected]> Signed-off-by: Marco Crivellari <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 0ff41df commit 128ea9f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

include/linux/workqueue.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ enum wq_consts {
427427
/*
428428
* System-wide workqueues which are always present.
429429
*
430-
* system_wq is the one used by schedule[_delayed]_work[_on]().
430+
* system_percpu_wq is the one used by schedule[_delayed]_work[_on]().
431431
* Multi-CPU multi-threaded. There are users which expect relatively
432432
* short queue flush time. Don't queue works which can run for too
433433
* long.
@@ -438,7 +438,7 @@ enum wq_consts {
438438
* system_long_wq is similar to system_wq but may host long running
439439
* works. Queue flushing might take relatively long.
440440
*
441-
* system_unbound_wq is unbound workqueue. Workers are not bound to
441+
* system_dfl_wq is unbound workqueue. Workers are not bound to
442442
* any specific CPU, not concurrency managed, and all queued works are
443443
* executed immediately as long as max_active limit is not reached and
444444
* resources are available.
@@ -455,10 +455,12 @@ enum wq_consts {
455455
* system_bh[_highpri]_wq are convenience interface to softirq. BH work items
456456
* are executed in the queueing CPU's BH context in the queueing order.
457457
*/
458-
extern struct workqueue_struct *system_wq;
458+
extern struct workqueue_struct *system_wq; /* use system_percpu_wq, this will be removed */
459+
extern struct workqueue_struct *system_percpu_wq;
459460
extern struct workqueue_struct *system_highpri_wq;
460461
extern struct workqueue_struct *system_long_wq;
461462
extern struct workqueue_struct *system_unbound_wq;
463+
extern struct workqueue_struct *system_dfl_wq;
462464
extern struct workqueue_struct *system_freezable_wq;
463465
extern struct workqueue_struct *system_power_efficient_wq;
464466
extern struct workqueue_struct *system_freezable_power_efficient_wq;

kernel/workqueue.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,16 @@ static struct kthread_worker *pwq_release_worker __ro_after_init;
505505

506506
struct workqueue_struct *system_wq __ro_after_init;
507507
EXPORT_SYMBOL(system_wq);
508+
struct workqueue_struct *system_percpu_wq __ro_after_init;
509+
EXPORT_SYMBOL(system_percpu_wq);
508510
struct workqueue_struct *system_highpri_wq __ro_after_init;
509511
EXPORT_SYMBOL_GPL(system_highpri_wq);
510512
struct workqueue_struct *system_long_wq __ro_after_init;
511513
EXPORT_SYMBOL_GPL(system_long_wq);
512514
struct workqueue_struct *system_unbound_wq __ro_after_init;
513515
EXPORT_SYMBOL_GPL(system_unbound_wq);
516+
struct workqueue_struct *system_dfl_wq __ro_after_init;
517+
EXPORT_SYMBOL_GPL(system_dfl_wq);
514518
struct workqueue_struct *system_freezable_wq __ro_after_init;
515519
EXPORT_SYMBOL_GPL(system_freezable_wq);
516520
struct workqueue_struct *system_power_efficient_wq __ro_after_init;
@@ -7816,10 +7820,11 @@ void __init workqueue_init_early(void)
78167820
}
78177821

78187822
system_wq = alloc_workqueue("events", 0, 0);
7823+
system_percpu_wq = alloc_workqueue("events", 0, 0);
78197824
system_highpri_wq = alloc_workqueue("events_highpri", WQ_HIGHPRI, 0);
78207825
system_long_wq = alloc_workqueue("events_long", 0, 0);
7821-
system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND,
7822-
WQ_MAX_ACTIVE);
7826+
system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE);
7827+
system_dfl_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE);
78237828
system_freezable_wq = alloc_workqueue("events_freezable",
78247829
WQ_FREEZABLE, 0);
78257830
system_power_efficient_wq = alloc_workqueue("events_power_efficient",
@@ -7830,8 +7835,8 @@ void __init workqueue_init_early(void)
78307835
system_bh_wq = alloc_workqueue("events_bh", WQ_BH, 0);
78317836
system_bh_highpri_wq = alloc_workqueue("events_bh_highpri",
78327837
WQ_BH | WQ_HIGHPRI, 0);
7833-
BUG_ON(!system_wq || !system_highpri_wq || !system_long_wq ||
7834-
!system_unbound_wq || !system_freezable_wq ||
7838+
BUG_ON(!system_wq || !system_percpu_wq|| !system_highpri_wq || !system_long_wq ||
7839+
!system_unbound_wq || !system_freezable_wq || !system_dfl_wq ||
78357840
!system_power_efficient_wq ||
78367841
!system_freezable_power_efficient_wq ||
78377842
!system_bh_wq || !system_bh_highpri_wq);

0 commit comments

Comments
 (0)