Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set thread affinity in a linux kernel module

as most C programmers know libc gives a non portable functions for thread cpu affinity tuning (pthread_attr_setaffinity_np()). However, what I do not really know is how can this be done when implementing a kernel module. Any answer that mentions or redirects to some real examples would be rather helpful.

like image 476
user1533288 Avatar asked Oct 04 '22 08:10

user1533288


2 Answers

You should use kthreads, which stands for kernel threads. To create such on specified cpu, you should invoke kthread_create_on_cpu(). It is defined in include/linux/kthread.h. Thread will be created in sleep state, so you should call wake_up_process() on it. That's all.

You can get one example of using kthreads in my answer in this question.

like image 84
Alexey Shmalko Avatar answered Oct 07 '22 20:10

Alexey Shmalko


You can use kthread_bind() function.

like image 40
Artem Romanov Avatar answered Oct 07 '22 19:10

Artem Romanov