LoginSignup
0
1

More than 5 years have passed since last update.

[Linux][kernel module] kthreadの実行CPUを指定/制限する

Posted at

以下の記事の関連。各kthreadが実行されるCPUコアを制限する方法メモ。

[Linux][kernel module] カーネルモジュール内でkthreadを作成する - Qiita

実現方法

void kthread_bind(struct task_struct *k, unsigned int cpu) を使用すればよさそう。

kthread_bind()/linux2.6 - LinuxKernelHackJapan

複数指定する場合は、 kthread_bind_mask(2) というものも存在しているため、こちらを使えばよさそう(未検証)

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

使用例

使用例
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);

kthread_run() 時に取得した task_struct と cpu のコア番号を指定する。
現在の環境のcpuの状況に関しては /proc/cpuinfo などを参照。

関連

[Linux][kernel module] カーネルモジュール内でkthreadを作成する - Qiita

参考

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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1