mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	kthread: Unify kthread_create_on_cpu() and kthread_create_worker_on_cpu() automatic format
kthread_create_on_cpu() uses the CPU argument as an implicit and unique printf argument to add to the format whereas kthread_create_worker_on_cpu() still relies on explicitly passing the printf arguments. This difference in behaviour is error prone and doesn't help standardizing per-CPU kthread names. Unify the behaviours and convert kthread_create_worker_on_cpu() to use the printf behaviour of kthread_create_on_cpu(). Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
This commit is contained in:
		
							parent
							
								
									db7ee3cb62
								
							
						
					
					
						commit
						41f70d8e16
					
				
					 3 changed files with 52 additions and 30 deletions
				
			
		|  | @ -320,7 +320,7 @@ static void erofs_destroy_percpu_workers(void) | ||||||
| static struct kthread_worker *erofs_init_percpu_worker(int cpu) | static struct kthread_worker *erofs_init_percpu_worker(int cpu) | ||||||
| { | { | ||||||
| 	struct kthread_worker *worker = | 	struct kthread_worker *worker = | ||||||
| 		kthread_create_worker_on_cpu(cpu, 0, "erofs_worker/%u", cpu); | 		kthread_create_worker_on_cpu(cpu, 0, "erofs_worker/%u"); | ||||||
| 
 | 
 | ||||||
| 	if (IS_ERR(worker)) | 	if (IS_ERR(worker)) | ||||||
| 		return worker; | 		return worker; | ||||||
|  |  | ||||||
|  | @ -187,13 +187,24 @@ extern void __kthread_init_worker(struct kthread_worker *worker, | ||||||
| 
 | 
 | ||||||
| int kthread_worker_fn(void *worker_ptr); | int kthread_worker_fn(void *worker_ptr); | ||||||
| 
 | 
 | ||||||
| __printf(2, 3) | __printf(3, 4) | ||||||
| struct kthread_worker * | struct kthread_worker *kthread_create_worker_on_node(unsigned int flags, | ||||||
| kthread_create_worker(unsigned int flags, const char namefmt[], ...); | 						     int node, | ||||||
|  | 						     const char namefmt[], ...); | ||||||
| 
 | 
 | ||||||
| __printf(3, 4) struct kthread_worker * | #define kthread_create_worker(flags, namefmt, ...) \ | ||||||
|  | ({									   \ | ||||||
|  | 	struct kthread_worker *__kw					   \ | ||||||
|  | 		= kthread_create_worker_on_node(flags, NUMA_NO_NODE,	   \ | ||||||
|  | 						namefmt, ## __VA_ARGS__);  \ | ||||||
|  | 	if (!IS_ERR(__kw))						   \ | ||||||
|  | 		wake_up_process(__kw->task);				   \ | ||||||
|  | 	__kw;								   \ | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | struct kthread_worker * | ||||||
| kthread_create_worker_on_cpu(int cpu, unsigned int flags, | kthread_create_worker_on_cpu(int cpu, unsigned int flags, | ||||||
| 			     const char namefmt[], ...); | 			     const char namefmt[]); | ||||||
| 
 | 
 | ||||||
| bool kthread_queue_work(struct kthread_worker *worker, | bool kthread_queue_work(struct kthread_worker *worker, | ||||||
| 			struct kthread_work *work); | 			struct kthread_work *work); | ||||||
|  |  | ||||||
|  | @ -1030,12 +1030,11 @@ int kthread_worker_fn(void *worker_ptr) | ||||||
| EXPORT_SYMBOL_GPL(kthread_worker_fn); | EXPORT_SYMBOL_GPL(kthread_worker_fn); | ||||||
| 
 | 
 | ||||||
| static __printf(3, 0) struct kthread_worker * | static __printf(3, 0) struct kthread_worker * | ||||||
| __kthread_create_worker(int cpu, unsigned int flags, | __kthread_create_worker_on_node(unsigned int flags, int node, | ||||||
| 			const char namefmt[], va_list args) | 				const char namefmt[], va_list args) | ||||||
| { | { | ||||||
| 	struct kthread_worker *worker; | 	struct kthread_worker *worker; | ||||||
| 	struct task_struct *task; | 	struct task_struct *task; | ||||||
| 	int node = NUMA_NO_NODE; |  | ||||||
| 
 | 
 | ||||||
| 	worker = kzalloc(sizeof(*worker), GFP_KERNEL); | 	worker = kzalloc(sizeof(*worker), GFP_KERNEL); | ||||||
| 	if (!worker) | 	if (!worker) | ||||||
|  | @ -1043,20 +1042,14 @@ __kthread_create_worker(int cpu, unsigned int flags, | ||||||
| 
 | 
 | ||||||
| 	kthread_init_worker(worker); | 	kthread_init_worker(worker); | ||||||
| 
 | 
 | ||||||
| 	if (cpu >= 0) |  | ||||||
| 		node = cpu_to_node(cpu); |  | ||||||
| 
 |  | ||||||
| 	task = __kthread_create_on_node(kthread_worker_fn, worker, | 	task = __kthread_create_on_node(kthread_worker_fn, worker, | ||||||
| 						node, namefmt, args); | 					node, namefmt, args); | ||||||
| 	if (IS_ERR(task)) | 	if (IS_ERR(task)) | ||||||
| 		goto fail_task; | 		goto fail_task; | ||||||
| 
 | 
 | ||||||
| 	if (cpu >= 0) |  | ||||||
| 		kthread_bind(task, cpu); |  | ||||||
| 
 |  | ||||||
| 	worker->flags = flags; | 	worker->flags = flags; | ||||||
| 	worker->task = task; | 	worker->task = task; | ||||||
| 	wake_up_process(task); | 
 | ||||||
| 	return worker; | 	return worker; | ||||||
| 
 | 
 | ||||||
| fail_task: | fail_task: | ||||||
|  | @ -1067,6 +1060,7 @@ __kthread_create_worker(int cpu, unsigned int flags, | ||||||
| /**
 | /**
 | ||||||
|  * kthread_create_worker - create a kthread worker |  * kthread_create_worker - create a kthread worker | ||||||
|  * @flags: flags modifying the default behavior of the worker |  * @flags: flags modifying the default behavior of the worker | ||||||
|  |  * @node: task structure for the thread is allocated on this node | ||||||
|  * @namefmt: printf-style name for the kthread worker (task). |  * @namefmt: printf-style name for the kthread worker (task). | ||||||
|  * |  * | ||||||
|  * Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM) |  * Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM) | ||||||
|  | @ -1074,25 +1068,49 @@ __kthread_create_worker(int cpu, unsigned int flags, | ||||||
|  * when the caller was killed by a fatal signal. |  * when the caller was killed by a fatal signal. | ||||||
|  */ |  */ | ||||||
| struct kthread_worker * | struct kthread_worker * | ||||||
| kthread_create_worker(unsigned int flags, const char namefmt[], ...) | kthread_create_worker_on_node(unsigned int flags, int node, const char namefmt[], ...) | ||||||
| { | { | ||||||
| 	struct kthread_worker *worker; | 	struct kthread_worker *worker; | ||||||
| 	va_list args; | 	va_list args; | ||||||
| 
 | 
 | ||||||
| 	va_start(args, namefmt); | 	va_start(args, namefmt); | ||||||
| 	worker = __kthread_create_worker(-1, flags, namefmt, args); | 	worker = __kthread_create_worker_on_node(flags, node, namefmt, args); | ||||||
| 	va_end(args); | 	va_end(args); | ||||||
| 
 | 
 | ||||||
|  | 	if (worker) | ||||||
|  | 		wake_up_process(worker->task); | ||||||
|  | 
 | ||||||
|  | 	return worker; | ||||||
|  | } | ||||||
|  | EXPORT_SYMBOL(kthread_create_worker_on_node); | ||||||
|  | 
 | ||||||
|  | static __printf(3, 4) struct kthread_worker * | ||||||
|  | __kthread_create_worker_on_cpu(int cpu, unsigned int flags, | ||||||
|  | 			       const char namefmt[], ...) | ||||||
|  | { | ||||||
|  | 	struct kthread_worker *worker; | ||||||
|  | 	va_list args; | ||||||
|  | 
 | ||||||
|  | 	va_start(args, namefmt); | ||||||
|  | 	worker = __kthread_create_worker_on_node(flags, cpu_to_node(cpu), | ||||||
|  | 						 namefmt, args); | ||||||
|  | 	va_end(args); | ||||||
|  | 
 | ||||||
|  | 	if (worker) { | ||||||
|  | 		kthread_bind(worker->task, cpu); | ||||||
|  | 		wake_up_process(worker->task); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return worker; | 	return worker; | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(kthread_create_worker); |  | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * kthread_create_worker_on_cpu - create a kthread worker and bind it |  * kthread_create_worker_on_cpu - create a kthread worker and bind it | ||||||
|  *	to a given CPU and the associated NUMA node. |  *	to a given CPU and the associated NUMA node. | ||||||
|  * @cpu: CPU number |  * @cpu: CPU number | ||||||
|  * @flags: flags modifying the default behavior of the worker |  * @flags: flags modifying the default behavior of the worker | ||||||
|  * @namefmt: printf-style name for the kthread worker (task). |  * @namefmt: printf-style name for the thread. Format is restricted | ||||||
|  |  *	     to "name.*%u". Code fills in cpu number. | ||||||
|  * |  * | ||||||
|  * Use a valid CPU number if you want to bind the kthread worker |  * Use a valid CPU number if you want to bind the kthread worker | ||||||
|  * to the given CPU and the associated NUMA node. |  * to the given CPU and the associated NUMA node. | ||||||
|  | @ -1124,16 +1142,9 @@ EXPORT_SYMBOL(kthread_create_worker); | ||||||
|  */ |  */ | ||||||
| struct kthread_worker * | struct kthread_worker * | ||||||
| kthread_create_worker_on_cpu(int cpu, unsigned int flags, | kthread_create_worker_on_cpu(int cpu, unsigned int flags, | ||||||
| 			     const char namefmt[], ...) | 			     const char namefmt[]) | ||||||
| { | { | ||||||
| 	struct kthread_worker *worker; | 	return __kthread_create_worker_on_cpu(cpu, flags, namefmt, cpu); | ||||||
| 	va_list args; |  | ||||||
| 
 |  | ||||||
| 	va_start(args, namefmt); |  | ||||||
| 	worker = __kthread_create_worker(cpu, flags, namefmt, args); |  | ||||||
| 	va_end(args); |  | ||||||
| 
 |  | ||||||
| 	return worker; |  | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(kthread_create_worker_on_cpu); | EXPORT_SYMBOL(kthread_create_worker_on_cpu); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Frederic Weisbecker
						Frederic Weisbecker