强制调度程序将线程分配给特定处理器 [英] force scheduler to allocate thread to specific processor

查看:73
本文介绍了强制调度程序将线程分配给特定处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一下我们有多个处理器/内核和两个线程的情况.是否有可能强制linux调度程序在执行每个实例时始终将特定线程(两者)调度到特定处理器.在创建线程时将处理器与线程的关联性设置为此目的就足够了

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

推荐答案

如果您查看

If you look at the man page for taskset you can see the following statement:

Linux调度程序将遵守给定的CPU亲和力,并且该进程将无法在任何其他CPU上运行.

The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs.

这意味着为特定进程设置CPU亲和力将确保该进程始终在该CPU上运行.

This means that setting the CPU affinity for a particular process will make sure that it's always run on that CPU.

存在一些API,可以让您设置特定线程的线程亲和力,我想这也将被OS调度程序所采用.

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.

如果您查看 sched_setaffinity ,则会看到一行内容:

If you look at sched_setaffinity you'll see a line that says:

这些对将在其上运行该进程的实际CPU的限制是内核默默施加的.

These restrictions on the actual set of CPUs on which the process will run are silently imposed by the kernel.

这意味着这将确保您的线程仅在此功能设置的CPU上运行.

which means this will make sure your threads are only run on CPU's set by this function.

这篇关于强制调度程序将线程分配给特定处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆