Linux 是否会在所有内核上都进入内核?
对于运行Linux 2.6.x的多核计算机,当线程进行系统调用时会发生什么?它是仅在线程运行的核心上落入内核,还是在所有核心上落入内核(抱歉,如果这是一个新手问题)。
一般来说,这种行为(以正确的行为为准)在接收中断时是否相同?如果不是,有什么区别?
For a multi-core computer running Linux 2.6.x, what happens when a thread makes a system call? Does it drop into the kernel only on the core that the thread is running on, or does it drop into the kernel on all cores (sorry if this is a newbie question).
Is this behaviour (whichever is the correct one) the same when receiving interrupts in general? If not, what are the differences?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只有执行系统调用的线程才会进入内核。 Linux 中的所有调度都是在线程粒度上完成的。至于中断 - 它们被路由到一个核心,即对于每个给定的硬件事件只有一个处理器被中断。然后可以手动将中断分配给特定的内核。这是通过
/proc/irq/IRQ-NUMBER/smp_affinity
中的掩码完成的。您可以在/proc/interrupts
中查看哪些 CPU 接收哪些硬件中断。Only the thread that does the syscall enters the kernel. All scheduling in Linux is done on thread granularity. As for interrupts - they are routed to one core, i.e. only one processor is interrupted for each given hardware event. Then interrupts could be manually assigned to specific cores. This is done with a mask in
/proc/irq/IRQ-NUMBER/smp_affinity
. You can see which CPUs receive what hardware interrupts in/proc/interrupts
.只有一个核心处理系统调用,并且只有一个核心处理中断。
我没有任何关于中断具体如何路由的参考资料 - 也许英特尔系统编程指南 在这里会有帮助。
但是,想象一下如果所有内核都被每个系统调用或中断中断。 Linux 被设计为可扩展到多个内核。这会破坏可扩展性——在大型服务器上,每个磁盘 I/O、计时器中断等都会有效地停止系统中的每个核心,阻止它们执行有用的工作。
Ony one core handles a system call, and only one core handles an interrupt.
I don't have any references off hand for exactly how interrupts are routed - perhaps Intel's System Programming Guide would be helpful here.
But, imagine if all cores were interrupted by every system call or interrupt. Linux is designed to scale to many cores. This would kill that scalability - on a massive server every disk I/O, timer interrupt, etc., would effectively stall every single core in the system, preventing them from doing useful work.