Post

tick

timer 源

timer描述频率
PIT最古老的pc时钟设备. intel 8253/8254 PLT有三个16bit counter1.193182MHz
HPETHigh Precision Event Timer, 设计初衷为了替代 PIT 和 RTC最低时钟频率为10MHz
APIC timerlocal apic timer古老机型频率不稳定, 所以启动初会通过PIT/Hpet 校准 Local APIC 频率
CMOS RTC电池供电,可以产生 Update interrupt, alarm interrupt2Hz~8192Hz
TSC根据CPU的时钟振荡器产生的周期计数古老机型频率稳定
ACPI timerPower management timer (PM timer)3.57945Mhz PIT时钟频率3倍

timer在系统中的作用

timer在系统中的角色很重要,其主要作用是让程序在当前配置期望的时间,做想 做的事情。而timer

早期linux时钟系统的设计

在Linux早期,timer的作用就是产生周期性的tick。在tick中,会去做一些周期性 的事务。但是有些事务全局性的,在smp中,只有一个cpu去做就行。另一类事务, 是和每个cpu相关的, 需要每个cpu都去做, 我们来简单列举下.

  • timekeeping – update wall time –global
  • low-precision clock – rolling timer wheel – percpu
  • sched related – update rq clock – percpu

其实, 除了update wall time,其他的处理的事项几乎都是percpu的。

固定周期往往会带来一个抉择问题 – 选择什么精度合适

每个cpu都需要timer,这样不就是需要很多么?

是这样的,但是以x86为例,在 smp 引入时,同时引入了 apic timer, 每个cpu的apic 都可以单独配置, 所以不存在timer不够的情况。

参考链接

1
2
3
4
5
6
7
8
9
10
11
12
commit 88ad0bf6890505cbd9ca1dbb79944a27b5c8697d
Author: Ingo Molnar <mingo@elte.hu>
Date:   Fri Feb 16 01:28:16 2007 -0800

    [PATCH] Add SysRq-Q to print timer_list debug info

...
commit b463fc60730bea6cdd73fec6edc6ec4658d47d37
Author: Andrew Morton <akpm@osdl.org>
Date:   Fri Feb 16 01:27:23 2007 -0800

    [PATCH] vmi-versus-hrtimers
  1. main timer
1
2
3
4
5
6
commit 73dea47faeb96d54a984b9d7f4de564816966354
Author: Andi Kleen <ak@suse.de>
Date:   Fri Feb 3 21:50:50 2006 +0100

    [PATCH] x86_64: Allow to run main time keeping from the local APIC interrupt

1
2
3
4
5
6
7
8
9
commit d25bf7e5fe73b5b6d2246ab0be08ae35d718456b
Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Date:   Wed Jan 11 22:44:24 2006 +0100

    [PATCH] x86_64: Handle missing local APIC timer interrupts on C3 state

    Whenever we see that a CPU is capable of C3 (during ACPI cstate init), we
    disable local APIC timer and switch to using a broadcast from external timer
    interrupt (IRQ 0).

timer 源参考

This post is licensed under CC BY 4.0 by the author.