您的位置:首页 > 运维架构 > Linux

Linux 2.6 内核阅读笔记 时间度量

2014-07-27 17:14 423 查看
2014年7月27日 定时器

在80x86体系结构上,内核可能需要和好几种时钟和定时器打交道,大概有:

实时时钟(RTC),时间戳计数器(TSC),可编程间隔定时器(PIT),CPU本地定时器,高精度事件定时器(HPET),ACPI电源管理定时器。

linux内核使用来定时器对象来代表一种定时器,采用函数指针实现类似面向对象的功能。

<span style="font-size:14px;">struct timer_opts {
char* name;
void (*mark_offset)(void);
unsigned long (*get_offset)(void);
unsigned long long (*monotonic_clock)(void);
void (*delay)(unsigned long);
unsigned long (*read_timer)(void);
int (*suspend)(pm_message_t state);
int (*resume)(void);
};</span>
linux内核通过编译期宏定义来优先选择最优的定时器来使用,使用一个cur_timer的全局变量来表示系统正在使用的定时器。

<span style="font-size:14px;">static struct init_timer_opts* __initdata timers[] = {
#ifdef CONFIG_X86_CYCLONE_TIMER
&timer_cyclone_init,
#endif
#ifdef CONFIG_HPET_TIMER
&timer_hpet_init,
#endif
#ifdef CONFIG_X86_PM_TIMER
&timer_pmtmr_init,
#endif
&timer_tsc_init,
&timer_pit_init,
NULL,
};</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: