在Linux内核中有两种不同的clock设备,一种是clock source设备,另一种是clock event设备。Clock source设备一般是一个根据固定频率不停增加的计数器,内核利用该设备可以计算出从系统启动到当前所经过的时间,再加上RTC所提供的初始时间就能得到当前时间(墙上时间)。Clock event设备则用来提供中断,Clock event设备可以配置为按固定周期发生中断(periodic)或者产生一个特定时间间隔后的中断(onshot)
Clock Source设备
内核将Clock Source设备抽象为如下的数据结构。这种方式屏蔽了不同体系结构上时钟源的区别,确保硬件相关和硬件无关代码能够互不干扰的实现。
struct clocksource {
/*
* Hotpath data, fits in a single cache line when the
* clocksource itself is cacheline aligned.
*/
cycle_t (*read)(struct clocksource *cs);
cycle_t cycle_last;
cycle_t mask;
u32 mult;
u32 shift;
u64 max_idle_ns;
u32 maxadj;
#ifdef CONFIG_ARCH_CLOCKSOURCE_DATA
struct arch_clocksource_data archdata;
#endif
const char *name;
struct list_head list;
int rating;
int (*enable)(struct clocksource *