在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 *cs);
void (*disable)(struct clocksource *cs);

本文深入探讨Linux内核的时钟源设备,包括clock source的read()、rating、mult和shift等属性,以及注册、 watchdog和内核启动过程中时钟源的角色。通过sysfs接口,开发者可以对时钟源进行交互和监控。
最低0.47元/天 解锁文章
915

被折叠的 条评论
为什么被折叠?



