History

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.

Marco Crivellari committed 1 year ago

Commit 128ea9f1 parent 0ff41df2 files · +14 −7Browse files

Showing the changes to kernel/workqueue.c (1 of 2 files). Show all

Unified · Split

kernel/workqueue.c+9−4
@@ -505,12 +505,16 @@ static struct kthread_worker *pwq_release_worker __ro_after_init; · 504 unmodified lines
505 505
506struct workqueue_struct *system_wq __ro_after_init;506struct workqueue_struct *system_wq __ro_after_init;
507EXPORT_SYMBOL(system_wq);507EXPORT_SYMBOL(system_wq);
508struct workqueue_struct *system_percpu_wq __ro_after_init;
509EXPORT_SYMBOL(system_percpu_wq);
508struct workqueue_struct *system_highpri_wq __ro_after_init;510struct workqueue_struct *system_highpri_wq __ro_after_init;
509EXPORT_SYMBOL_GPL(system_highpri_wq);511EXPORT_SYMBOL_GPL(system_highpri_wq);
510struct workqueue_struct *system_long_wq __ro_after_init;512struct workqueue_struct *system_long_wq __ro_after_init;
511EXPORT_SYMBOL_GPL(system_long_wq);513EXPORT_SYMBOL_GPL(system_long_wq);
512struct workqueue_struct *system_unbound_wq __ro_after_init;514struct workqueue_struct *system_unbound_wq __ro_after_init;
513EXPORT_SYMBOL_GPL(system_unbound_wq);515EXPORT_SYMBOL_GPL(system_unbound_wq);
516struct workqueue_struct *system_dfl_wq __ro_after_init;
517EXPORT_SYMBOL_GPL(system_dfl_wq);
514struct workqueue_struct *system_freezable_wq __ro_after_init;518struct workqueue_struct *system_freezable_wq __ro_after_init;
515EXPORT_SYMBOL_GPL(system_freezable_wq);519EXPORT_SYMBOL_GPL(system_freezable_wq);
516struct workqueue_struct *system_power_efficient_wq __ro_after_init;520struct workqueue_struct *system_power_efficient_wq __ro_after_init;
@@ -7816,10 +7820,11 @@ void __init workqueue_init_early(void) · 7299 unmodified lines
7816 }7820 }
7817 7821
7818 system_wq = alloc_workqueue("events", 0, 0);7822 system_wq = alloc_workqueue("events", 0, 0);
7823 system_percpu_wq = alloc_workqueue("events", 0, 0);
7819 system_highpri_wq = alloc_workqueue("events_highpri", WQ_HIGHPRI, 0);7824 system_highpri_wq = alloc_workqueue("events_highpri", WQ_HIGHPRI, 0);
7820 system_long_wq = alloc_workqueue("events_long", 0, 0);7825 system_long_wq = alloc_workqueue("events_long", 0, 0);
7821 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND,7826 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE);
7822 WQ_MAX_ACTIVE);7827 system_dfl_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE);
7823 system_freezable_wq = alloc_workqueue("events_freezable",7828 system_freezable_wq = alloc_workqueue("events_freezable",
7824 WQ_FREEZABLE, 0);7829 WQ_FREEZABLE, 0);
7825 system_power_efficient_wq = alloc_workqueue("events_power_efficient",7830 system_power_efficient_wq = alloc_workqueue("events_power_efficient",
@@ -7830,8 +7835,8 @@ void __init workqueue_init_early(void) · 4 unmodified lines
7830 system_bh_wq = alloc_workqueue("events_bh", WQ_BH, 0);7835 system_bh_wq = alloc_workqueue("events_bh", WQ_BH, 0);
7831 system_bh_highpri_wq = alloc_workqueue("events_bh_highpri",7836 system_bh_highpri_wq = alloc_workqueue("events_bh_highpri",
7832 WQ_BH | WQ_HIGHPRI, 0);7837 WQ_BH | WQ_HIGHPRI, 0);
7833 BUG_ON(!system_wq || !system_highpri_wq || !system_long_wq ||7838 BUG_ON(!system_wq || !system_percpu_wq|| !system_highpri_wq || !system_long_wq ||
7834 !system_unbound_wq || !system_freezable_wq ||7839 !system_unbound_wq || !system_freezable_wq || !system_dfl_wq ||
7835 !system_power_efficient_wq ||7840 !system_power_efficient_wq ||
7836 !system_freezable_power_efficient_wq ||7841 !system_freezable_power_efficient_wq ||
7837 !system_bh_wq || !system_bh_highpri_wq);7842 !system_bh_wq || !system_bh_highpri_wq);