sched_setaffinity()
可以使用call将进程固定到一组特定的 CPU 内核。手册页说:
Restricting a process to run on a single CPU also avoids the
performance cost caused by the cache invalidation that occurs when a process
ceases to execute on one CPU and then recommences execution on a different
CPU.
这几乎是显而易见的事情(或不是?)。对我来说不是那么明显的是 -
将 LWP 固定到特定 CPU 或 SMP 节点是否会减少缓存一致性总线流量?例如,由于一个进程正在运行,因此其他 CPU 不应修改其私有内存,因此只有属于同一 SMP 节点的 CPU 应保持缓存一致。