mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	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 <daniel.m.jordan@oracle.com> Acked-by: Steffen Klassert <steffen.klassert@secunet.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Jonathan Corbet <corbet@lwn.net> 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-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
		
							parent
							
								
									007b3cf0af
								
							
						
					
					
						commit
						b128a30409
					
				
					 4 changed files with 24 additions and 28 deletions
				
			
		|  | @ -16,10 +16,12 @@ overall control of how tasks are to be run:: | ||||||
| 
 | 
 | ||||||
|     #include <linux/padata.h> |     #include <linux/padata.h> | ||||||
| 
 | 
 | ||||||
|     struct padata_instance *padata_alloc(struct workqueue_struct *wq, |     struct padata_instance *padata_alloc(const char *name, | ||||||
| 					 const struct cpumask *pcpumask, | 					 const struct cpumask *pcpumask, | ||||||
| 					 const struct cpumask *cbcpumask); | 					 const struct cpumask *cbcpumask); | ||||||
| 
 | 
 | ||||||
|  | 'name' simply identifies the instance. | ||||||
|  | 
 | ||||||
| The pcpumask describes which processors will be used to execute work | The pcpumask describes which processors will be used to execute work | ||||||
| submitted to this instance in parallel. The cbcpumask defines which | submitted to this instance in parallel. The cbcpumask defines which | ||||||
| processors are allowed to be used as the serialization callback processor. | 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. | ||||||
| 
 | 
 | ||||||
| Each task submitted to padata_do_parallel() will, in turn, be passed to | Each task submitted to padata_do_parallel() will, in turn, be passed to | ||||||
| exactly one call to the above-mentioned parallel() function, on one CPU, so | exactly one call to the above-mentioned parallel() function, on one CPU, so | ||||||
| true parallelism is achieved by submitting multiple tasks.  Despite the | true parallelism is achieved by submitting multiple tasks.  parallel() runs with | ||||||
| fact that the workqueue is used to make these calls, parallel() is run with |  | ||||||
| software interrupts disabled and thus cannot sleep.  The parallel() | software interrupts disabled and thus cannot sleep.  The parallel() | ||||||
| function gets the padata_priv structure pointer as its lone parameter; | function gets the padata_priv structure pointer as its lone parameter; | ||||||
| information about the actual work to be done is probably obtained by using | information about the actual work to be done is probably obtained by using | ||||||
|  | @ -148,7 +149,7 @@ fact with a call to:: | ||||||
| At some point in the future, padata_do_serial() will trigger a call to the | At some point in the future, padata_do_serial() will trigger a call to the | ||||||
| serial() function in the padata_priv structure.  That call will happen on | serial() function in the padata_priv structure.  That call will happen on | ||||||
| the CPU requested in the initial call to padata_do_parallel(); it, too, is | the CPU requested in the initial call to padata_do_parallel(); it, too, is | ||||||
| done through the workqueue, but with local software interrupts disabled. | run with local software interrupts disabled. | ||||||
| Note that this call may be deferred for a while since the padata code takes | Note that this call may be deferred for a while since the padata code takes | ||||||
| pains to ensure that tasks are completed in the order in which they were | pains to ensure that tasks are completed in the order in which they were | ||||||
| submitted. | submitted. | ||||||
|  | @ -159,5 +160,4 @@ when a padata instance is no longer needed:: | ||||||
|     void padata_free(struct padata_instance *pinst); |     void padata_free(struct padata_instance *pinst); | ||||||
| 
 | 
 | ||||||
| This function will busy-wait while any remaining tasks are completed, so it | This function will busy-wait while any remaining tasks are completed, so it | ||||||
| might be best not to call it while there is work outstanding.  Shutting | might be best not to call it while there is work outstanding. | ||||||
| down the workqueue, if necessary, should be done separately. |  | ||||||
|  |  | ||||||
|  | @ -20,7 +20,6 @@ | ||||||
| 
 | 
 | ||||||
| struct padata_pcrypt { | struct padata_pcrypt { | ||||||
| 	struct padata_instance *pinst; | 	struct padata_instance *pinst; | ||||||
| 	struct workqueue_struct *wq; |  | ||||||
| 
 | 
 | ||||||
| 	/*
 | 	/*
 | ||||||
| 	 * Cpumask for callback CPUs. It should be | 	 * Cpumask for callback CPUs. It should be | ||||||
|  | @ -397,14 +396,9 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt, | ||||||
| 
 | 
 | ||||||
| 	get_online_cpus(); | 	get_online_cpus(); | ||||||
| 
 | 
 | ||||||
| 	pcrypt->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, | 	pcrypt->pinst = padata_alloc_possible(name); | ||||||
| 				     1, name); |  | ||||||
| 	if (!pcrypt->wq) |  | ||||||
| 		goto err; |  | ||||||
| 
 |  | ||||||
| 	pcrypt->pinst = padata_alloc_possible(pcrypt->wq); |  | ||||||
| 	if (!pcrypt->pinst) | 	if (!pcrypt->pinst) | ||||||
| 		goto err_destroy_workqueue; | 		goto err; | ||||||
| 
 | 
 | ||||||
| 	mask = kmalloc(sizeof(*mask), GFP_KERNEL); | 	mask = kmalloc(sizeof(*mask), GFP_KERNEL); | ||||||
| 	if (!mask) | 	if (!mask) | ||||||
|  | @ -437,8 +431,6 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt, | ||||||
| 	kfree(mask); | 	kfree(mask); | ||||||
| err_free_padata: | err_free_padata: | ||||||
| 	padata_free(pcrypt->pinst); | 	padata_free(pcrypt->pinst); | ||||||
| err_destroy_workqueue: |  | ||||||
| 	destroy_workqueue(pcrypt->wq); |  | ||||||
| err: | err: | ||||||
| 	put_online_cpus(); | 	put_online_cpus(); | ||||||
| 
 | 
 | ||||||
|  | @ -452,7 +444,6 @@ static void pcrypt_fini_padata(struct padata_pcrypt *pcrypt) | ||||||
| 
 | 
 | ||||||
| 	padata_stop(pcrypt->pinst); | 	padata_stop(pcrypt->pinst); | ||||||
| 	padata_unregister_cpumask_notifier(pcrypt->pinst, &pcrypt->nblock); | 	padata_unregister_cpumask_notifier(pcrypt->pinst, &pcrypt->nblock); | ||||||
| 	destroy_workqueue(pcrypt->wq); |  | ||||||
| 	padata_free(pcrypt->pinst); | 	padata_free(pcrypt->pinst); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -151,8 +151,7 @@ struct padata_instance { | ||||||
| #define	PADATA_INVALID	4 | #define	PADATA_INVALID	4 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| extern struct padata_instance *padata_alloc_possible( | extern struct padata_instance *padata_alloc_possible(const char *name); | ||||||
| 					struct workqueue_struct *wq); |  | ||||||
| extern void padata_free(struct padata_instance *pinst); | extern void padata_free(struct padata_instance *pinst); | ||||||
| extern int padata_do_parallel(struct padata_instance *pinst, | extern int padata_do_parallel(struct padata_instance *pinst, | ||||||
| 			      struct padata_priv *padata, int cb_cpu); | 			      struct padata_priv *padata, int cb_cpu); | ||||||
|  |  | ||||||
|  | @ -805,6 +805,7 @@ static void __padata_free(struct padata_instance *pinst) | ||||||
| 	padata_free_pd(pinst->pd); | 	padata_free_pd(pinst->pd); | ||||||
| 	free_cpumask_var(pinst->cpumask.pcpu); | 	free_cpumask_var(pinst->cpumask.pcpu); | ||||||
| 	free_cpumask_var(pinst->cpumask.cbcpu); | 	free_cpumask_var(pinst->cpumask.cbcpu); | ||||||
|  | 	destroy_workqueue(pinst->wq); | ||||||
| 	kfree(pinst); | 	kfree(pinst); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -938,13 +939,13 @@ static struct kobj_type padata_attr_type = { | ||||||
|  * padata_alloc - allocate and initialize a padata instance and specify |  * padata_alloc - allocate and initialize a padata instance and specify | ||||||
|  *                cpumasks for serial and parallel workers. |  *                cpumasks for serial and parallel workers. | ||||||
|  * |  * | ||||||
|  * @wq: workqueue to use for the allocated padata instance |  * @name: used to identify the instance | ||||||
|  * @pcpumask: cpumask that will be used for padata parallelization |  * @pcpumask: cpumask that will be used for padata parallelization | ||||||
|  * @cbcpumask: cpumask that will be used for padata serialization |  * @cbcpumask: cpumask that will be used for padata serialization | ||||||
|  * |  * | ||||||
|  * Must be called from a cpus_read_lock() protected region |  * Must be called from a cpus_read_lock() protected region | ||||||
|  */ |  */ | ||||||
| static struct padata_instance *padata_alloc(struct workqueue_struct *wq, | static struct padata_instance *padata_alloc(const char *name, | ||||||
| 					    const struct cpumask *pcpumask, | 					    const struct cpumask *pcpumask, | ||||||
| 					    const struct cpumask *cbcpumask) | 					    const struct cpumask *cbcpumask) | ||||||
| { | { | ||||||
|  | @ -955,11 +956,16 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq, | ||||||
| 	if (!pinst) | 	if (!pinst) | ||||||
| 		goto err; | 		goto err; | ||||||
| 
 | 
 | ||||||
| 	if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL)) | 	pinst->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, | ||||||
|  | 				    1, name); | ||||||
|  | 	if (!pinst->wq) | ||||||
| 		goto err_free_inst; | 		goto err_free_inst; | ||||||
|  | 
 | ||||||
|  | 	if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL)) | ||||||
|  | 		goto err_free_wq; | ||||||
| 	if (!alloc_cpumask_var(&pinst->cpumask.cbcpu, GFP_KERNEL)) { | 	if (!alloc_cpumask_var(&pinst->cpumask.cbcpu, GFP_KERNEL)) { | ||||||
| 		free_cpumask_var(pinst->cpumask.pcpu); | 		free_cpumask_var(pinst->cpumask.pcpu); | ||||||
| 		goto err_free_inst; | 		goto err_free_wq; | ||||||
| 	} | 	} | ||||||
| 	if (!padata_validate_cpumask(pinst, pcpumask) || | 	if (!padata_validate_cpumask(pinst, pcpumask) || | ||||||
| 	    !padata_validate_cpumask(pinst, cbcpumask)) | 	    !padata_validate_cpumask(pinst, cbcpumask)) | ||||||
|  | @ -971,8 +977,6 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq, | ||||||
| 
 | 
 | ||||||
| 	rcu_assign_pointer(pinst->pd, pd); | 	rcu_assign_pointer(pinst->pd, pd); | ||||||
| 
 | 
 | ||||||
| 	pinst->wq = wq; |  | ||||||
| 
 |  | ||||||
| 	cpumask_copy(pinst->cpumask.pcpu, pcpumask); | 	cpumask_copy(pinst->cpumask.pcpu, pcpumask); | ||||||
| 	cpumask_copy(pinst->cpumask.cbcpu, cbcpumask); | 	cpumask_copy(pinst->cpumask.cbcpu, cbcpumask); | ||||||
| 
 | 
 | ||||||
|  | @ -990,6 +994,8 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq, | ||||||
| err_free_masks: | err_free_masks: | ||||||
| 	free_cpumask_var(pinst->cpumask.pcpu); | 	free_cpumask_var(pinst->cpumask.pcpu); | ||||||
| 	free_cpumask_var(pinst->cpumask.cbcpu); | 	free_cpumask_var(pinst->cpumask.cbcpu); | ||||||
|  | err_free_wq: | ||||||
|  | 	destroy_workqueue(pinst->wq); | ||||||
| err_free_inst: | err_free_inst: | ||||||
| 	kfree(pinst); | 	kfree(pinst); | ||||||
| err: | err: | ||||||
|  | @ -1001,14 +1007,14 @@ static struct padata_instance *padata_alloc(struct workqueue_struct *wq, | ||||||
|  *                         Use the cpu_possible_mask for serial and |  *                         Use the cpu_possible_mask for serial and | ||||||
|  *                         parallel workers. |  *                         parallel workers. | ||||||
|  * |  * | ||||||
|  * @wq: workqueue to use for the allocated padata instance |  * @name: used to identify the instance | ||||||
|  * |  * | ||||||
|  * Must be called from a cpus_read_lock() protected region |  * Must be called from a cpus_read_lock() protected region | ||||||
|  */ |  */ | ||||||
| struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq) | struct padata_instance *padata_alloc_possible(const char *name) | ||||||
| { | { | ||||||
| 	lockdep_assert_cpus_held(); | 	lockdep_assert_cpus_held(); | ||||||
| 	return padata_alloc(wq, cpu_possible_mask, cpu_possible_mask); | 	return padata_alloc(name, cpu_possible_mask, cpu_possible_mask); | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(padata_alloc_possible); | EXPORT_SYMBOL(padata_alloc_possible); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Daniel Jordan
						Daniel Jordan