什么是 Linux 本地定时器中断?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10567214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:17:23  来源:igfitidea点击:

What are Linux Local timer interrupts?

clinuxlinux-kernelinterrupt

提问by Manuel Selva

All is in the title. Any links to good documentations are welcome.

一切都在标题中。欢迎任何指向良好文档的链接。

采纳答案by Michael Burr

The local timer interrupt is a timer implemented on the APIC that interrupts only a particular CPU instead of raising an interrupt that can be handled by any CPU. It's discussed in Bovet & Cesati's "Understanding the Linux Kernel". A snippet:

本地定时器中断是在 APIC 上实现的定时器,它只中断特定的 CPU,而不是引发可由任何 CPU 处理的中断。Bovet & Cesati 的“了解 Linux 内核”中对此进行了讨论。一个片段:

The local APIC present in recent 80x86 microprocessors (see the section “Interrupts and Exceptions” in Chapter 4) provides yet another time-measuring device: the CPU local timer.

The CPU local timer is a device similar to the Programmable Interval Timer just described that can issue one-shot or periodic interrupts. There are, however, a few differences:

  • The APIC's timer counter is 32 bits long, while the PIT's timer counter is 16 bits long; therefore, the local timer can be programmed to issue interrupts at very low frequencies (the counter stores the number of ticks that must elapse before the interrupt is issued).
  • The local APIC timer sends an interrupt only to its processor, while the PIT raises a global interrupt, which may be handled by any CPU in the system.
  • The APIC's timer is based on the bus clock signal (or the APIC bus signal, in older machines). It can be programmed in such a way to decrease the timer counter every 1, 2, 4, 8, 16, 32, 64, or 128 bus clock signals. Conversely, the PIT, which makes use of its own clock signals, can be programmed in a more flexible way.

最近出现在 80x86 微处理器中的本地 APIC(请参阅第 4 章中的“中断和异常”部分)提供了另一种时间测量设备:CPU 本地计时器。

CPU 本地定时器是一种类似于刚才描述的可编程间隔定时器的设备,可以发出一次性或周期性中断。但是,有一些区别:

  • APIC 的定时器计数器为 32 位长,而 PIT 的定时器计数器为 16 位长;因此,本地定时器可以编程为以非常低的频率发出中断(计数器存储在发出中断之前必须经过的滴答数)。
  • 本地 APIC 计时器仅向其处理器发送中断,而 PIT 引发全局中断,该中断可由系统中的任何 CPU 处理。
  • APIC 的计时器基于总线时钟信号(或旧机器中的 APIC 总线信号)。它可以编程为每 1、2、4、8、16、32、64 或 128 个总线时钟信号减少定时器计数器。相反,使用自己的时钟信号的 PIT 可以以更灵活的方式进行编程。

回答by ugoren

A less technical answer than Michael Burr's:

比 Michael Burr 的技术性回答低:

Some things need to be done every jiffy, doesn't matter on which CPU.
Other things need to be done every jiffy on each CPU. For example, checking if we need to switch to another process.

有些事情需要每时每刻完成,在哪个 CPU 上无关紧要。
其他事情需要在每个 CPU 上每时每刻完成。例如,检查我们是否需要切换到另一个进程。

The local timer interrupt exists for the second type - whenever it's executed, we check them and do what's needed.

第二种类型存在本地定时器中断 - 无论何时执行,我们都会检查它们并执行所需的操作。

回答by adkuv123

I feel the local timers are used for handling the IPI related functionality. I might be wrong in this guess, need t look at the code on what they are configured for and what the handler contains. But I feel the system timer and the jiffies are linked to one of the GP Timers and hence in SMP ARM for example, the interrupt from this timer is associated with one single core through the GIC affinity registration. Will get back wit more on the local timers.

我觉得本地计时器用于处理 IPI 相关功能。我的猜测可能是错误的,不需要查看代码来了解它们的配置以及处理程序包含的内容。但我觉得系统计时器和 jiffies 链接到 GP 计时器之一,因此在 SMP ARM 中,例如,来自该计时器的中断通过 GIC 关联注册与一个单核相关联。将在本地计时器上获得更多智慧。

回答by user1954941

On SMP systems apic timer is used for scheduler / rescheduling threads.

在 SMP 系统上,apic 计时器用于调度程序/重新调度线程。

On UP system pit timer is used for scheduler / rescheduling threads.

在 UP 系统上,pit timer 用于调度程序/重新调度线程。

Normaly the PIT is no longer used anymore in SMP systems.

通常,SMP 系统中不再使用 PIT。