当前时间:当前的实际时间。用date命令得到的值
xtime:基本上相当于当前时间,但xtime只能被定期更新,所以略微滞后于当前时间。
滞后的时间由get_nsec_offset获得,二者相加得到当前时间(严格说来不
是如此。get_nsec_offset的值根据全局clock.cycle_last的值算
出,cycle_last的更新和xtime的更新并不同步)。
单调递增时钟:系统需要的一个计数器。并不能用来计量时间。
wall_to_monotonic:一个偏移量。xtime + wall_to_monotonic可以得到单调递增时
钟的值,但并没有实际的时间的含义。为了保证单调性,每次对xtime进行修
改后必须对wall_to_monotonic也进行修正。
struct clocksource:时钟源。里面的若干成员变量会被定期更新。
read():如果对应于硬件时钟,read函数返回计数值。
cycle_last:最近一次被更新的时间。在好几个地方可能被更新,包括
update_wall_time(),timekeeping_init(),timekeeping_resume()。
全局clock:当前正在使用的时钟源。
struct clock_event_device:可编程,定时产生事件(中断)的设备。一般在处理当次中断时设定下
次中断发生的时间。
unsigned long mult;
int shift
用于时间到计数器值的换算。cycle = (time * mult) » shift
int (*set_next_event)(unsigned long evt, struct clock_event_device *):
设定下次事件到来的时间
@evt:从现在到下次事件到来的时钟周期数。下次事件发生于当前时钟值加上evt值。
@struct clock_event_device *:不明
void (*event_handler)(struct clock_event_device *):
事件处理函数
next_event:下次事件发生的绝对时间
__get_nsec_offset():全局clock.cycle_last最近的一次被更新后所经过的纳秒数。
全局clock.cycle_last被更新的地方参考clocksource.cycle_last。
__get_realtime_clock_ts():获取当前时间。timerspec格式。
read_persistent_clock():读取用电池供电的时钟值,只能精确到秒。如果没有该时钟返回0。
update_wall_time():根据时钟源更新xtime,clock.cycle_last等数据。
int clockevents_program_event(struct clock_event_device *dev, ktime_t expires,
ktime_t now)
设置dev指向的clock_event_device的下次event的时间。
@dev:clock_event_device结构体指针
@expires:下次event的绝对时间
@now:当前时间
setup_arch() -> mxc_init_time() -> setup_irq(INT_GPT, &timer_irq)
每秒中发生100次中断。
mxc_timer_interrupt() ->
tick_handle_periodic() in gpt_clockevent ->
tick_periodic() ->
do_timer(1) ->
update_times() ->
update_wall_time