force scheduler to allocate thread to specific processor

我是研究僧i 提交于 2019-12-06 10:29:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/14979031/force-scheduler-to-allocate-thread-to-specific-processor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!