Consider a case where we have multiple processor/cores and two threads. Is it possible to force the linux scheduler to always schedule the specific thread(both) to a specific processor at every instance of its execution. Is setting processor affinity to the threads, while creation, sufficient for this purpose
Asked
Active
Viewed 1,959 times
1 Answers
3
If you look at the man page for taskset
you can see the following statement:
The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs.
This means that setting the CPU affinity for a particular process will make sure that it's always run on that CPU.
There exist API's that allow you to set thread affinity for particular threads, and I would imagine that this too will be honored by the OS scheduler.
If you look at sched_setaffinity
you'll see a line that says:
These restrictions on the actual set of CPUs on which the process will run are silently imposed by the kernel.
which means this will make sure your threads are only run on CPU's set by this function.

Tony The Lion
- 61,704
- 67
- 242
- 415
-
Thanks for the support @Tony The Lion. I used the taskset command. and came across affinity list and affinity mask. I need to know the difference between them and how to set/change affinity at run time – naran Feb 21 '13 at 05:19
-
I made an assumption about the OS you are on, but are you indeed on Linux? If so, you should use `shed_setaffinity` to set it in code. The affinity masks you should be able to look up. – Tony The Lion Feb 21 '13 at 08:40
-
is it possible to schedule a kernel thread to a specific core – naran Apr 15 '13 at 10:18