既然时钟源对外提供了计数能力,那么可以通过哪些接口呢?
这里需要唯一说明的是,整个时钟源模块对外只有一个接口,即提供到timekeeping使用,其读取计数值计数,计算时间。
核心函数是timekeeping_notify();
这个函数在选取合适的clocksource后被调用。
/**
* timekeeping_notify - Install a new clock source
* @clock: pointer to the clock source
*
* This function is called from clocksource.c after a new, better clock
* source has been registered. The caller holds the clocksource_mutex.
*/
int timekeeping_notify(struct clocksource *clock)
{
struct timekeeper *tk = &tk_core.timekeeper;
if (tk->tkr_mono.clock == clock)
return 0;
stop_machine(change_clocksource, clock, NULL);
tick_clock_notify();
return tk->tkr_mono.clock == clock ? 0 : -1;
}
当然在timer在oneshot模式下,即配置CONFIG_TICK_ONESHOT时,通知tick sched模块。
/**
* Async notification about clocksource changes
*/
void tick_clock_notify(void)
{
int cpu;
for_each_possible_cpu(cpu)
set_bit(0, &per_cpu(tick_cpu_sched, cpu).check_clocks);
}