multithreading - 立即使用 sched_setaffinity() 对 cpumask 进行更改

标签 multithreading linux-kernel affinity

我正在编写一个 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 in mask, then that process is migrated to one of the CPUs specified in mask.



我的解释是,这种迁移会在调用 sched_setaffinity 之前立即发生。已经回来了。

关于multithreading - 立即使用 sched_setaffinity() 对 cpumask 进行更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2559546/

相关文章:

java - java中线程之间的通信: stopping a thread if another thread has finished

javascript - NodeJS 是单线程的 - 在无限循环的情况下仍然不会阻塞

android - 为什么要用-fno-pic 编译Android 内核模块?

c - 内核模块在使用 insmod 时被杀死

linux - Linux 中的堆栈预故障 - 需要单个或多个故障

linux - Linux 中的线程亲和性

android - RxJava : return a cached value synchronously/immediately

multithreading - 为什么 std::condition_variable::wait 需要互斥锁?

assembly - 在多核 x86 处理器中设置关联

c - 如何确保代码在调用 sched_setaffinity() 之后立即在指定线程上运行,然后再等待 cpu 队列的下一轮?