Skip to content

Commit 45d153c

Browse files
danieljordan10herbertx
authored andcommitted
padata: use separate workqueues for parallel and serial work
padata currently uses one per-CPU workqueue per instance for all work. Prepare for running parallel jobs on an unbound workqueue by introducing dedicated workqueues for parallel and serial work. Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com> Acked-by: Steffen Klassert <steffen.klassert@secunet.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Lai Jiangshan <jiangshanlai@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tejun Heo <tj@kernel.org> Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent cc491d8 commit 45d153c

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎include/linux/padata.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ struct parallel_data {
127127
* struct padata_instance - The overall control structure.
128128
*
129129
* @cpu_notifier: cpu hotplug notifier.
130-
* @wq: The workqueue in use.
130+
* @parallel_wq: The workqueue used for parallel work.
131+
* @serial_wq: The workqueue used for serial work.
131132
* @pd: The internal control structure.
132133
* @cpumask: User supplied cpumasks for parallel and serial works.
133134
* @cpumask_change_notifier: Notifiers chain for user-defined notify
@@ -139,7 +140,8 @@ struct parallel_data {
139140
*/
140141
struct padata_instance {
141142
struct hlist_node node;
142-
struct workqueue_struct *wq;
143+
struct workqueue_struct *parallel_wq;
144+
struct workqueue_struct *serial_wq;
143145
struct parallel_data *pd;
144146
struct padata_cpumask cpumask;
145147
struct blocking_notifier_head cpumask_change_notifier;

‎kernel/padata.c‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int padata_do_parallel(struct padata_instance *pinst,
152152
list_add_tail(&padata->list, &queue->parallel.list);
153153
spin_unlock(&queue->parallel.lock);
154154

155-
queue_work_on(target_cpu, pinst->wq, &queue->work);
155+
queue_work_on(target_cpu, pinst->parallel_wq, &queue->work);
156156

157157
out:
158158
rcu_read_unlock_bh();
@@ -261,7 +261,7 @@ static void padata_reorder(struct parallel_data *pd)
261261
list_add_tail(&padata->list, &squeue->serial.list);
262262
spin_unlock(&squeue->serial.lock);
263263

264-
queue_work_on(cb_cpu, pinst->wq, &squeue->work);
264+
queue_work_on(cb_cpu, pinst->serial_wq, &squeue->work);
265265
}
266266

267267
spin_unlock_bh(&pd->lock);
@@ -278,7 +278,7 @@ static void padata_reorder(struct parallel_data *pd)
278278

279279
next_queue = per_cpu_ptr(pd->pqueue, pd->cpu);
280280
if (!list_empty(&next_queue->reorder.list))
281-
queue_work(pinst->wq, &pd->reorder_work);
281+
queue_work(pinst->serial_wq, &pd->reorder_work);
282282
}
283283

284284
static void invoke_padata_reorder(struct work_struct *work)
@@ -818,7 +818,8 @@ static void __padata_free(struct padata_instance *pinst)
818818
padata_free_pd(pinst->pd);
819819
free_cpumask_var(pinst->cpumask.pcpu);
820820
free_cpumask_var(pinst->cpumask.cbcpu);
821-
destroy_workqueue(pinst->wq);
821+
destroy_workqueue(pinst->serial_wq);
822+
destroy_workqueue(pinst->parallel_wq);
822823
kfree(pinst);
823824
}
824825

@@ -967,18 +968,23 @@ static struct padata_instance *padata_alloc(const char *name,
967968
if (!pinst)
968969
goto err;
969970

970-
pinst->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE,
971-
1, name);
972-
if (!pinst->wq)
971+
pinst->parallel_wq = alloc_workqueue("%s_parallel", WQ_MEM_RECLAIM |
972+
WQ_CPU_INTENSIVE, 1, name);
973+
if (!pinst->parallel_wq)
973974
goto err_free_inst;
974975

975976
get_online_cpus();
976977

977-
if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL))
978+
pinst->serial_wq = alloc_workqueue("%s_serial", WQ_MEM_RECLAIM |
979+
WQ_CPU_INTENSIVE, 1, name);
980+
if (!pinst->serial_wq)
978981
goto err_put_cpus;
982+
983+
if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL))
984+
goto err_free_serial_wq;
979985
if (!alloc_cpumask_var(&pinst->cpumask.cbcpu, GFP_KERNEL)) {
980986
free_cpumask_var(pinst->cpumask.pcpu);
981-
goto err_put_cpus;
987+
goto err_free_serial_wq;
982988
}
983989
if (!padata_validate_cpumask(pinst, pcpumask) ||
984990
!padata_validate_cpumask(pinst, cbcpumask))
@@ -1010,9 +1016,11 @@ static struct padata_instance *padata_alloc(const char *name,
10101016
err_free_masks:
10111017
free_cpumask_var(pinst->cpumask.pcpu);
10121018
free_cpumask_var(pinst->cpumask.cbcpu);
1019+
err_free_serial_wq:
1020+
destroy_workqueue(pinst->serial_wq);
10131021
err_put_cpus:
10141022
put_online_cpus();
1015-
destroy_workqueue(pinst->wq);
1023+
destroy_workqueue(pinst->parallel_wq);
10161024
err_free_inst:
10171025
kfree(pinst);
10181026
err:

0 commit comments

Comments
 (0)