add WQ_PERCPU to alloc_workqueue
cover 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-2] WQ_PERCPU added to alloc_workqueue()
This 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):
scsi: bnx2fc: add WQ_PERCPU to alloc_workqueue users
scsi: qedf: add WQ_PERCPU to alloc_workqueue users
drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 2 +- drivers/scsi/qedf/qedf_main.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-)
Signature · 1 line
2.51.1
PATCH 1/2 scsi: bnx2fc: add WQ_PERCPU to alloc_workqueue users
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.
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/scsi/bnx2fc/bnx2fc_fcoe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +1 -1
@@ -2695,7 +2695,7 @@ static int __init bnx2fc_mod_init(void)if (rc) goto detach_ft; - bnx2fc_wq =alloc_workqueue ("bnx2fc" ,0 ,0 ); + bnx2fc_wq =alloc_workqueue ("bnx2fc" ,WQ_PERCPU ,0 );if (!bnx2fc_wq) { rc = -ENOMEM ; goto release_bt;
Signature · 1 line
2.51.1
PATCH 2/2 scsi: qedf: add WQ_PERCPU to alloc_workqueue users
In reply to Marco CrivellariCurrently 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.
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/scsi/qedf/qedf_main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/scsi/qedf/qedf_main.c +10 -5
@@ -3374,7 +3374,8 @@ static int __qedf_probe(struct pci_dev *pdev, int mode)QEDF_INFO (&(qedf->dbg_ctx),QEDF_LOG_INFO ,"qedf->io_mempool=%p.\n" , qedf->io_mempool); - qedf->link_update_wq =alloc_workqueue ("qedf_%u_link" ,WQ_MEM_RECLAIM , + qedf->link_update_wq =alloc_workqueue ("qedf_%u_link" , +WQ_MEM_RECLAIM |WQ_PERCPU ,1 , qedf->lport->host->host_no);INIT_DELAYED_WORK (&qedf->link_update, qedf_handle_link_update);INIT_DELAYED_WORK (&qedf->link_recovery, qedf_link_recovery);
@@ -3585,7 +3586,8 @@ static int __qedf_probe(struct pci_dev *pdev, int mode)ether_addr_copy (params.ll2_mac_address, qedf->mac);/* Start LL2 processing thread */ - qedf->ll2_recv_wq =alloc_workqueue ("qedf_%d_ll2" ,WQ_MEM_RECLAIM ,1 , + qedf->ll2_recv_wq =alloc_workqueue ("qedf_%d_ll2" , +WQ_MEM_RECLAIM |WQ_PERCPU ,1 , host->host_no);if (!qedf->ll2_recv_wq) {QEDF_ERR (&(qedf->dbg_ctx),"Failed to LL2 workqueue.\n" );
@@ -3628,7 +3630,8 @@ static int __qedf_probe(struct pci_dev *pdev, int mode) } qedf->timer_work_queue =alloc_workqueue ("qedf_%u_timer" , -WQ_MEM_RECLAIM ,1 , qedf->lport->host->host_no); +WQ_MEM_RECLAIM |WQ_PERCPU ,1 , + qedf->lport->host->host_no);if (!qedf->timer_work_queue) {QEDF_ERR (&(qedf->dbg_ctx),"Failed to start timer " "workqueue.\n" );
@@ -3641,7 +3644,8 @@ static int __qedf_probe(struct pci_dev *pdev, int mode)sprintf (host_buf,"qedf_%u_dpc" , qedf->lport->host->host_no); qedf->dpc_wq = -alloc_workqueue ("%s" ,WQ_MEM_RECLAIM ,1 , host_buf); +alloc_workqueue ("%s" ,WQ_MEM_RECLAIM |WQ_PERCPU ,1 , + host_buf); }INIT_DELAYED_WORK (&qedf->recovery_work, qedf_recovery_handler);
@@ -4177,7 +4181,8 @@ static int __init qedf_init(void) goto err3; } - qedf_io_wq =alloc_workqueue ("%s" ,WQ_MEM_RECLAIM ,1 ,"qedf_io_wq" ); + qedf_io_wq =alloc_workqueue ("%s" ,WQ_MEM_RECLAIM |WQ_PERCPU ,1 , +"qedf_io_wq" );if (!qedf_io_wq) {QEDF_ERR (NULL ,"Could not create qedf_io_wq.\n" ); goto err4;
Signature · 1 line
2.51.1
Martin K. Petersen
AppliedQuoted 10 lines · Marco Crivellari
=== Current situation: problems ===
Let's consider a
nohz_fullsystem with isolated CPUs:wq_unbound_cpumaskis 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);[...]
Applied to 6.19/scsi-queue, thanks!
[1/2] scsi: bnx2fc: add WQ_PERCPU to alloc_workqueue users
https://git.kernel.org/mkp/scsi/c/a43a2e48d534 [2/2] scsi: qedf: add WQ_PERCPU to alloc_workqueue users https://git.kernel.org/mkp/scsi/c/e036dadf78f8
Signature · 1 line
Martin K. Petersen