Skip to content

Commit b128a30

Browse files
danieljordan10herbertx
authored andcommitted
padata: allocate workqueue internally
Move workqueue allocation inside of padata to prepare for further changes to how padata uses workqueues. Guarantees the workqueue is created with max_active=1, which padata relies on to work correctly. No functional change. Signed-off-by: Daniel Jordan <[email protected]> Acked-by: Steffen Klassert <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Lai Jiangshan <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Tejun Heo <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Herbert Xu <[email protected]>
1 parent 007b3cf commit b128a30

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

Documentation/padata.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ overall control of how tasks are to be run::
1616

1717
#include <linux/padata.h>
1818

19-
struct padata_instance *padata_alloc(struct workqueue_struct *wq,
19+
struct padata_instance *padata_alloc(const char *name,
2020
const struct cpumask *pcpumask,
2121
const struct cpumask *cbcpumask);
2222

23+
'name' simply identifies the instance.
24+
2325
The pcpumask describes which processors will be used to execute work
2426
submitted to this instance in parallel. The cbcpumask defines which
2527
processors are allowed to be used as the serialization callback processor.
@@ -128,8 +130,7 @@ in that CPU mask or about a not running instance.
128130

129131
Each task submitted to padata_do_parallel() will, in turn, be passed to
130132
exactly one call to the above-mentioned parallel() function, on one CPU, so
131-
true parallelism is achieved by submitting multiple tasks. Despite the
132-
fact that the workqueue is used to make these calls, parallel() is run with
133+
true parallelism is achieved by submitting multiple tasks. parallel() runs with
133134
software interrupts disabled and thus cannot sleep. The parallel()
134135
function gets the padata_priv structure pointer as its lone parameter;
135136
information about the actual work to be done is probably obtained by using
@@ -148,7 +149,7 @@ fact with a call to::
148149
At some point in the future, padata_do_serial() will trigger a call to the
149150
serial() function in the padata_priv structure. That call will happen on
150151
the CPU requested in the initial call to padata_do_parallel(); it, too, is
151-
done through the workqueue, but with local software interrupts disabled.
152+
run with local software interrupts disabled.
152153
Note that this call may be deferred for a while since the padata code takes
153154
pains to ensure that tasks are completed in the order in which they were
154155
submitted.
@@ -159,5 +160,4 @@ when a padata instance is no longer needed::
159160
void padata_free(struct padata_instance *pinst);
160161

161162
This function will busy-wait while any remaining tasks are completed, so it
162-
might be best not to call it while there is work outstanding. Shutting
163-
down the workqueue, if necessary, should be done separately.
163+
might be best not to call it while there is work outstanding.

crypto/pcrypt.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
struct padata_pcrypt {
2222
struct padata_instance *pinst;
23-
struct workqueue_struct *wq;
2423

2524
/*
2625
* Cpumask for callback CPUs. It should be
@@ -397,14 +396,9 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
397396

398397
get_online_cpus();
399398

400-
pcrypt->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE,
401-
1, name);
402-
if (!pcrypt->wq)
403-
goto err;
404-
405-
pcrypt->pinst = padata_alloc_possible(pcrypt->wq);
399+
pcrypt->pinst = padata_alloc_possible(name);
406400
if (!pcrypt->pinst)
407-
goto err_destroy_workqueue;
401+
goto err;
408402

409403
mask = kmalloc(sizeof(*mask), GFP_KERNEL);
410404
if (!mask)
@@ -437,8 +431,6 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
437431
kfree(mask);
438432
err_free_padata:
439433
padata_free(pcrypt->pinst);
440-
err_destroy_workqueue:
441-
destroy_workqueue(pcrypt->wq);
442434
err:
443435
put_online_cpus();
444436

@@ -452,7 +444,6 @@ static void pcrypt_fini_padata(struct padata_pcrypt *pcrypt)
452444

453445
padata_stop(pcrypt->pinst);
454446
padata_unregister_cpumask_notifier(pcrypt->pinst, &pcrypt->nblock);
455-
destroy_workqueue(pcrypt->wq);
456447
padata_free(pcrypt->pinst);
457448
}
458449

include/linux/padata.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ struct padata_instance {
151151
#define PADATA_INVALID 4
152152
};
153153

154-
extern struct padata_instance *padata_alloc_possible(
155-
struct workqueue_struct *wq);
154+
extern struct padata_instance *padata_alloc_possible(const char *name);
156155
extern void padata_free(struct padata_instance *pinst);
157156
extern int padata_do_parallel(struct padata_instance *pinst,
158157
struct padata_priv *padata, int cb_cpu);

kernel/padata.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ static void __padata_free(struct padata_instance *pinst)
805805
padata_free_pd(pinst->pd);
806806
free_cpumask_var(pinst->cpumask.pcpu);
807807
free_cpumask_var(pinst->cpumask.cbcpu);
808+
destroy_workqueue(pinst->wq);
808809
kfree(pinst);
809810
}
810811

@@ -938,13 +939,13 @@ static struct kobj_type padata_attr_type = {
938939
* padata_alloc - allocate and initialize a padata instance and specify
939940
* cpumasks for serial and parallel workers.
940941
*
941-
* @wq: workqueue to use for the allocated padata instance
942+
* @name: used to identify the instance
942943
* @pcpumask: cpumask that will be used for padata parallelization
943944
* @cbcpumask: cpumask that will be used for padata serialization
944945
*
945946
* Must be called from a cpus_read_lock() protected region
946947
*/
947-
static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
948+
static struct padata_instance *padata_alloc(const char *name,
948949
const struct cpumask *pcpumask,
949950
const struct cpumask *cbcpumask)
950951
{
@@ -955,11 +956,16 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
955956
if (!pinst)
956957
goto err;
957958

958-
if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL))
959+
pinst->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE,
960+
1, name);
961+
if (!pinst->wq)
959962
goto err_free_inst;
963+
964+
if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL))
965+
goto err_free_wq;
960966
if (!alloc_cpumask_var(&pinst->cpumask.cbcpu, GFP_KERNEL)) {
961967
free_cpumask_var(pinst->cpumask.pcpu);
962-
goto err_free_inst;
968+
goto err_free_wq;
963969
}
964970
if (!padata_validate_cpumask(pinst, pcpumask) ||
965971
!padata_validate_cpumask(pinst, cbcpumask))
@@ -971,8 +977,6 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
971977

972978
rcu_assign_pointer(pinst->pd, pd);
973979

974-
pinst->wq = wq;
975-
976980
cpumask_copy(pinst->cpumask.pcpu, pcpumask);
977981
cpumask_copy(pinst->cpumask.cbcpu, cbcpumask);
978982

@@ -990,6 +994,8 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
990994
err_free_masks:
991995
free_cpumask_var(pinst->cpumask.pcpu);
992996
free_cpumask_var(pinst->cpumask.cbcpu);
997+
err_free_wq:
998+
destroy_workqueue(pinst->wq);
993999
err_free_inst:
9941000
kfree(pinst);
9951001
err:
@@ -1001,14 +1007,14 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
10011007
* Use the cpu_possible_mask for serial and
10021008
* parallel workers.
10031009
*
1004-
* @wq: workqueue to use for the allocated padata instance
1010+
* @name: used to identify the instance
10051011
*
10061012
* Must be called from a cpus_read_lock() protected region
10071013
*/
1008-
struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq)
1014+
struct padata_instance *padata_alloc_possible(const char *name)
10091015
{
10101016
lockdep_assert_cpus_held();
1011-
return padata_alloc(wq, cpu_possible_mask, cpu_possible_mask);
1017+
return padata_alloc(name, cpu_possible_mask, cpu_possible_mask);
10121018
}
10131019
EXPORT_SYMBOL(padata_alloc_possible);
10141020

0 commit comments

Comments
 (0)