Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

看懂 Linux 的系統時鐘:HZ、Tick、Jiffies 與 RTC

內核怎麼知道「一秒」有多長?答案藏在四個名詞裡:HZ、Tick、Jiffies 與 RTC。

Hertz(HZ)

Linux 核心每隔固定週期發出 timer interrupt(IRQ 0),HZ 用來定義每秒有幾次 timer interrupt。查法(可能需要 root 權限,且相依核心版本):

# cat /boot/config-`uname -r` | grep '^CONFIG_HZ='

若上述指令不可用,可以改看中斷計數的變化:

# cat /proc/interrupts | grep timer && sleep 1 && cat /proc/interrupts | grep timer

四核環境的實際輸出(第一欄相差 747、第四欄相差 260,合計 1007):

0: 1249518864 1255370360 1250872127 1255434916   IO-APIC-edge  timer
0: 1249519611 1255370360 1250872127 1255435176   IO-APIC-edge  timer

另一組四核輸出,看起來系統閒置時只有第一顆核心在響應:

0: 1249611896 1255460391 1250962154 1255525210   IO-APIC-edge  timer
0: 1249612902 1255460391 1250962154 1255525210   IO-APIC-edge  timer

本機虛擬機的輸出則只有一欄有數字:

0:  12175178      0   IO-APIC-edge  timer
0:  12176036      0   IO-APIC-edge  timer

Tick

Tick 是 HZ 的倒數,也就是每次 timer interrupt 的間隔時間。HZ 為 250 時,tick 就是 4 毫秒。

Jiffies

系統自開機以來已經走過多少個 tick,就是 jiffies。它是內核內部最常用的時間計量單位。

RTC

硬體時鐘,用來持久保存系統時間,關機後靠主機板上的微型電池維持計時。系統啟動時內核讀取 RTC 來初始化 Wall Time,存放到 xtime 變數,這是 RTC 最主要的用途。

延伸閱讀:

  • https://blog.csdn.net/linweig/article/details/5341231
  • https://blog.csdn.net/zhandoushi1982/article/details/5536210
Copyright © Linux教程網 All Rights Reserved