Skip to content

Commit ebb2bdc

Browse files
pmladektorvalds
authored andcommitted
kthread_worker: document CPU hotplug handling
The kthread worker API is simple. In short, it allows to create, use, and destroy workers. kthread_create_worker_on_cpu() just allows to bind a newly created worker to a given CPU. It is up to the API user how to handle CPU hotplug. They have to decide how to handle pending work items, prevent queuing new ones, and restore the functionality when the CPU goes off and on. There are few catches: + The CPU affinity gets lost when it is scheduled on an offline CPU. + The worker might not exist when the CPU was off when the user created the workers. A good practice is to implement two CPU hotplug callbacks and destroy/create the worker when CPU goes down/up. Mention this in the function description. [akpm@linux-foundation.org: grammar tweaks] Link: https://lore.kernel.org/r/20201028073031.4536-1-qiang.zhang@windriver.com Link: https://lkml.kernel.org/r/20201102101039.19227-1-pmladek@suse.com Reported-by: Zhang Qiang <Qiang.Zhang@windriver.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f630c7c commit ebb2bdc

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎kernel/kthread.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,25 @@ EXPORT_SYMBOL(kthread_create_worker);
793793
* A good practice is to add the cpu number also into the worker name.
794794
* For example, use kthread_create_worker_on_cpu(cpu, "helper/%d", cpu).
795795
*
796-
* Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM)
796+
* CPU hotplug:
797+
* The kthread worker API is simple and generic. It just provides a way
798+
* to create, use, and destroy workers.
799+
*
800+
* It is up to the API user how to handle CPU hotplug. They have to decide
801+
* how to handle pending work items, prevent queuing new ones, and
802+
* restore the functionality when the CPU goes off and on. There are a
803+
* few catches:
804+
*
805+
* - CPU affinity gets lost when it is scheduled on an offline CPU.
806+
*
807+
* - The worker might not exist when the CPU was off when the user
808+
* created the workers.
809+
*
810+
* Good practice is to implement two CPU hotplug callbacks and to
811+
* destroy/create the worker when the CPU goes down/up.
812+
*
813+
* Return:
814+
* The pointer to the allocated worker on success, ERR_PTR(-ENOMEM)
797815
* when the needed structures could not get allocated, and ERR_PTR(-EINTR)
798816
* when the worker was SIGKILLed.
799817
*/

0 commit comments

Comments
 (0)