[Linux] [kernel module] Specify / limit the execution CPU of kthread

Related to the following articles. A note on how to limit the CPU cores on which each kthread runs.

[Linux] [kernel module] Create kthread in kernel module --Qiita

Realization method

You can use void kthread_bind (struct task_struct * k, unsigned int cpu).

kthread_bind()/linux2.6 - LinuxKernelHackJapan

If you specify more than one, there is also kthread_bind_mask (2), so you should use this (unverified).

void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask)

Example of use

Example of use


struct task_struct *k0;
struct task_struct *k1;

k0 = kthread_run(kthread_func0, NULL, "task0");
k1 = kthread_run(kthread_func1, NULL, "task1");

kthread_bind(k0, 0);
kthread_bind(k1, 1);

Specify the task_struct and cpu core number obtained at the time of kthread_run (). See / proc / cpuinfo etc. for the status of cpu in the current environment.

Relation

[Linux] [kernel module] Create kthread in kernel module --Qiita

reference

linux/include/linux/kthread.h - Elixir - Free Electrons kthread_bind()/linux2.6 - LinuxKernelHackJapan

Recommended Posts

[Linux] [kernel module] Specify / limit the execution CPU of kthread
[Linux] [kernel module] Create kthread in kernel module
A quick overview of the Linux kernel
What is the Linux kernel?
Test the version of the argparse module
Try the Linux kernel lockdown mechanism
Take the execution log of Celery
About the upper limit of threads-max
A memo for utilizing the unit test mechanism KUnit of the Linux kernel
[Understanding in 3 minutes] The beginning of Linux
Pass the path of the imported python module
Build the execution environment of Jupyter Lab
Check the path of the Python imported module
Understand the "temporary" part of UNIX / Linux
[Linux] Learn the basics of shell commands
Compiling the Linux kernel (Linux 5.x on Ubuntu 20.04)