kthread_crea...orker_on_cpu(9)
π kthread_create_worker_on_cpu(9) π
okay so this is a page out of the Kernel API Manual, and it's literally about spawning a kthread worker and pinning it to a specific CPU bestie. we're talking one CPU, one NUMA node, main character energy only. β¨
β¨ NAME β¨
kthread_create_worker_on_cpu β create a kthread worker and bind it to a given CPU and the associated NUMA node. that's the whole vibe. π
πΈ SYNOPSIS πΈ
struct kthread_worker * kthread_create_worker_on_cpu (int cpu , unsigned int flags , const char namefmt[] );
π¦ ARGUMENTS π¦
cpuβ the CPU number. just a number. the CPU number. πflagsβ flags that modify the default behavior of the worker, like little tweaks to the whole deal.namefmtβ aprintf-style name for the thread. and listen, the format is restricted to"name.*u"β that's not a suggestion, that's the rule. the code fills in the cpu number for you. π₯
π DESCRIPTION π
use a valid CPU number if you want to bind the kthread worker to the given CPU and the associated NUMA node. that's the deal, that's the assignment. π«Ά
good practice? yes bestie, add the cpu number into the worker name too. for example, use:
kthread_create_worker_on_cpu(cpu, "helper/d", cpu)
iconic. self-documenting. ate. π
β CPU hotplug β
the kthread worker API is simple and generic β it just gives you a way to create, use, and destroy workers. that's it. that's the whole API. no cap.
how you handle CPU hotplug is on you. the API user decides everything: how to handle pending work items, how to prevent queuing new ones, and how to restore the functionality when the CPU goes off and comes back on. π
there are a few catches, and ngl they're real:
- CPU affinity gets lost when it is scheduled on an offline CPU. π
- the worker might not exist when the CPU was off at the time the user created the workers. π
good practice is to implement two CPU hotplug callbacks and to destroy/create the worker when the CPU goes down/up. two callbacks. down and up. that's the move. β¨
π RETURN π
- the pointer to the allocated worker on success π
ERR_PTR(-ENOMEM)when the needed structures could not get allocated πERR_PTR(-EINTR)when the caller was killed by a fatal signal π
π§ SEE ALSO π§
kernel file ./kernel/kthread.c, and literally the whole kthread extended universe:
kthread_should_stop(9)kthread_should_park(9)kthread_freezable_should_stop(9)kthread_func(9)kthread_data(9)kthread_probe_data(9)kthread_complete_and_exit(9)kthread_create_on_node(9)kthread_bind(9)kthread_create_on_cpu(9)kthread_unpark(9)kthread_park(9)kthread_stop(9)kthread_stop_put(9)kthread_affine_preferred(9)kthreads_update_housekeeping(9)kthread_worker_fn(9)kthread_create_worker_on_node(9)kthread_queue_work(9)kthread_delayed_work_timer_fn(9)kthread_queue_delayed_work(9)kthread_flush_work(9)kthread_mod_delayed_work(9)kthread_cancel_work_sync(9)kthread_cancel_delayed_work_sync(9)kthread_flush_worker(9)kthread_destroy_worker(9)kthread_use_mm(9)kthread_unuse_mm(9)kthread_associate_blkcg(9)kthread_blkcg(9)
and that's the page bestie!! π«Ά
this one came straight out of ./kernel, dated October 2026, and honestly? she's serving kernel-internals realness. periodt. ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms