replace system_wq with system_percpu_wq, add WQ_PERCPU to alloc_workqueue
cover replace system_wq with system_percpu_wq, add WQ_PERCPU to alloc_workqueue
Hi,
=== 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 consistency cannot be addressed without refactoring the API.
=== Recent changes to the WQ API ===
The following, address the recent changes in the Workqueue API:
- commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
- commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
The old workqueues will be removed in a future release cycle.
=== Introduced Changes by this series ===
1) [P 1] Replace uses of system_wq
system_wq is a per-CPU workqueue, but his name is not clear. Because of that, system_wq has been replaced with system_percpu_wq.
2) [P 2] WQ_PERCPU added to alloc_workqueue()
This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.
Thanks!
Marco Crivellari (2):
xen/events: replace use of system_wq with system_percpu_wq
xen: privcmd: WQ_PERCPU added to alloc_workqueue users
drivers/xen/events/events_base.c | 6 +++--- drivers/xen/privcmd.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.51.1
PATCH 1/2 xen/events: replace use of system_wq with system_percpu_wq
Currently if a user enqueues 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 consistency cannot be addressed without refactoring the API.
This continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
Switch to using system_percpu_wq because system_wq is going away as part of a workqueue restructuring.
--- drivers/xen/events/events_base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/xen/events/events_base.c +3 -3
@@ -581,7 +581,7 @@ static void lateeoi_list_add(struct irq_info *info) eoi_list);if (!elem || info->eoi_time < elem->eoi_time) {list_add (&info->eoi_list, &eoi->eoi_list); -mod_delayed_work_on (info->eoi_cpu, system_wq, +mod_delayed_work_on (info->eoi_cpu, system_percpu_wq, &eoi->delayed, delay); }else {list_for_each_entry_reverse (elem, &eoi->eoi_list, eoi_list) {
@@ -666,7 +666,7 @@ static void xen_irq_lateeoi_worker(struct work_struct *work)break ;if (now < info->eoi_time) { -mod_delayed_work_on (info->eoi_cpu, system_wq, +mod_delayed_work_on (info->eoi_cpu, system_percpu_wq, &eoi->delayed, info->eoi_time - now);break ;
@@ -782,7 +782,7 @@ static void xen_free_irq(struct irq_info *info)WARN_ON (info->refcnt >0 ); -queue_rcu_work (system_wq, &info->rwork); +queue_rcu_work (system_percpu_wq, &info->rwork); }/* Not called for lateeoi events. */
Signature · 1 line
2.51.1
Re: [PATCH 1/2] xen/events: replace use of system_wq with system_percpu_wq
Quoted 11 lines · Marco Crivellari
Currently if a user enqueues a work item using
schedule_delayed_work()the used wq is "system_wq" (per-cpu wq) whilequeue_delayed_work()useWORK_CPU_UNBOUND(used when a cpu is not specified). The same applies toschedule_work()that is usingsystem_wqandqueue_work(), that makes use again ofWORK_CPU_UNBOUND.This lack of consistency cannot be addressed without refactoring the API.
This continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new
alloc_workqueueflag in:
Quoted 8 lines
commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq") commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")Switch to using
system_percpu_wqbecausesystem_wqis going away as part of a workqueue restructuring.Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>
Juergen
PATCH 2/2 xen: privcmd: 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 continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.
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.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
--- drivers/xen/privcmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/xen/privcmd.c +2 -1
@@ -1091,7 +1091,8 @@ static long privcmd_ioctl_irqfd(struct file *file, void __user *udata)static int privcmd_irqfd_init (void ) { - irqfd_cleanup_wq =alloc_workqueue ("privcmd-irqfd-cleanup" ,0 ,0 ); + irqfd_cleanup_wq =alloc_workqueue ("privcmd-irqfd-cleanup" ,WQ_PERCPU , +0 );if (!irqfd_cleanup_wq)return -ENOMEM ;
Signature · 1 line
2.51.1
Re: [PATCH 2/2] xen: privcmd: WQ_PERCPU added to alloc_workqueue users
Quoted 27 lines · Marco Crivellari
Currently if a user enqueue a work item using
schedule_delayed_work()the used wq is "system_wq" (per-cpu wq) whilequeue_delayed_work()useWORK_CPU_UNBOUND(used when a cpu is not specified). The same applies toschedule_work()that is usingsystem_wqandqueue_work(), that makes use again ofWORK_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 viaWQ_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 continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new
alloc_workqueueflag in:commit
128ea9f6ccfb("workqueue: Addsystem_percpu_wqandsystem_dfl_wq") commit930c2ea566af("workqueue: Add newWQ_PERCPUflag")This change adds a new
WQ_PERCPUflag to explicitly requestalloc_workqueue()to be per-cpu whenWQ_UNBOUNDhas not been specified.With the introduction of the
WQ_PERCPUflag (equivalent to !WQ_UNBOUND), anyalloc_workqueue()caller that doesn’t explicitly specifyWQ_UNBOUNDmust now useWQ_PERCPU.
Quoted 5 lines
Once migration is complete,
WQ_UNBOUNDcan be removed and unbound will become the implicit default.Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>
Juergen
Quoted 7 lines · Marco Crivellari
[...]
xen/events: replace use ofsystem_wqwithsystem_percpu_wq
xen: privcmd:WQ_PERCPUadded toalloc_workqueueusersdrivers/xen/events/events_base.c | 6 +++--- drivers/xen/privcmd.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
Gentle ping.
Thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer