我正在编写一个 linux 内核模块,该模块需要将两个线程固定在两个不同的 cpu 上。我计划在将 sched_setaffinity() 导出到内核后使用它。是否还有其他相同的导出功能?
另外,如果我在 cpumask 中只设置了 1 个 CPU,线程会立即移动到该 cpu 吗?如果没有,我该如何执行?在 sched_setaffinity() 之后调用 schedule() 会有所帮助吗?
最佳答案
sched_setaffinity
的手册页说
If the process specified by
pid
is not currently running on one of the CPUs specified inmask
, then that process is migrated to one of the CPUs specified inmask
.
我的解释是,这种迁移会在调用
sched_setaffinity
之前立即发生。已经回来了。
关于multithreading - 立即使用 sched_setaffinity() 对 cpumask 进行更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2559546/