手动产生定时器中断

Manually generate a timer interrupt

在我的机器上;

/proc/interrupts

          CPU0       CPU1       CPU2       CPU3
  0:         54          0          0          0   IO-APIC-edge      timer
  1:         10          0          0          0   IO-APIC-edge      i8042
  6:          2          0          0          0   IO-APIC-edge      floppy
  8:          1          0          0          0   IO-APIC-edge      rtc0
  9:          0          0          0          0   IO-APIC-fasteoi   acpi
 12:         16          0          0          0   IO-APIC-edge      i8042
 14:          0          0          0          0   IO-APIC-edge      ata_piix
 15:    3984107          0          0          0   IO-APIC-edge      ata_piix
 16:          2          0          0          0   IO-APIC-fasteoi   vmwgfx
 17:     980727     939643    1334876     770403   IO-APIC-fasteoi   ioc0
 24:          0          0          0          0   PCI-MSI-edge      PCIe PME, pciehp
 25:          0          0          0          0   PCI-MSI-edge      PCIe PME, pciehp
 26:          0          0          0          0   PCI-MSI-edge      PCIe PME, pciehp
 27:          0          0          0          0   PCI-MSI-edge      PCIe PME, pciehp
 28:          0          0          0          0   PCI-MSI-edge      PCIe PME, pciehp

我了解中断,我想了解定时器中断。 This page 表示,每次出现定时器中断都会触发以下主要活动,例如更新自系统启动以来经过的时间。

在我的机器上它只显示 54,但机器已经启动了几天。

我在这里错过了什么?

第二个问题,如何手动生成中断,使计数从54变为55?

您没有生成计时器 interrupts。硬件确实如此(可能每秒有数百次中断)。内核配置硬件来做到这一点。

另请阅读 time(7),这是处理来自 user-land Linux 应用程序的时间相关内容的方法(这可能对您更重要)。

如果您关心处理中断,您可以编写自己的 OS kernel and scheduler (and then the linux tag would be off-topic). See Operating systems: Three Easy Pieces (freely downloadable). For practical hints on OS development, see OSDEV wiki。

操作系统在这里隐藏你的硬件细节,比如中断和管理硬件,并为你提供高于它的抽象。 /proc/interrupts 只是一种 查询 OS 内核状态的方法。它的格式因内核版本和硬件而异(在我的系统上输出与你的完全不同),它主要对系统管理员有用(例如,作为硬件故障的提示,当一些奇怪的硬件发送大量中断时)。参见 proc(5)

How can I manually generate an interrupt

在 Linux 系统中,你不能。

顺便说一句,Linux 还有 signal(7)-s (see also signal-safety(7)...) but these signals are not interrupts (even if some interrupts might indirectly trigger signals). And signals can indeed "interrupt" (in a very figurative way, not the same as hardware interrupts) your process

(在您的特定硬件和内核上,大多数 "timer" 中断可能进入 ioc0 行)