计划例程中一个 CPU 和多个 CPU 之间的区别 - Linux 内核

difference between one CPU and multiple CPU in schedule routine - Linux kernel

在 Linux 内核 (2.6) 中,"schedule()" 例程在只有一个处理器的系统中的性能与在多处理器系统中的性能有区别吗?

我试图在书中找到答案 "Understanding the Linux kernel (3rd ed.)" 但没有找到答案。

这个问题很难回答。

一个简单的答案是 "yes, of course, there is a difference in performance between one cpu and multiple cpus since, when there are multiple CPUs, the kernel must lock various data structures thereby potentially encountering contention, and must decide which CPU a task can next run on, and so forth -- decisions that need not be made (or can be made trivially) when there is only a single CPU."

另一个简单的答案是,"no, the performance impact of the various decisions is minimal and represents a negligible percentage of the total combined CPU 'bandwidth'"。

完整的答案需要了解并考虑在任何给定场景中对所有可用 CPU 进行调度决策的数千个因素:是否为每个进程设置了明确的关联掩码?每个 CPU 正在处理哪些中断和软中断?进程是否被安排在每个 CPU I/O-bound 或 CPU 范围内?是否存在与其他进程通信的进程,它们可以在不同的处理器上同时 运行?因素太多,不可能一一列举。