timer event
/* linux/kernel/time/jiffies.c*/ static cycle_t jiffies_read(struct clocksource *cs) { return (cycle_t) jiffies; } struct clocksource clocksource_jiffies = { .name = "jiffies", .rating = 1, /* lowest valid rating*/ .read = jiffies_read, .mask = 0xffffffff, /*32bits*/ .mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */ .mult_orig = NSEC_PER_JIFFY << JIFFIES_SHIFT, .shift = JIFFIES_SHIFT, }; static int __init init_jiffies_clocksource(void) { return clocksource_register(&clocksource_jiffies); } core_initcall(init_jiffies_clocksource); int clocksource_register(struct clocksource *c) -->ret = clocksource_enqueue(c); /*静态全局变量存储下一个精度最高的时钟源 static struct clocksource *next_clocksource;*/ -->next_clocksource = select_clocksource(); struct clocksource *clocksource_get_next(void) /*静态全局变量存储当前使用的时钟源 static struct clocksource *curr_clocksource = &clocksource_jiffies;*/ -->curr_clocksource = next_clocksource; /*什么时间更换时钟源,以下两种方法选择其一*/ /*1.jiffies时间中断处理函数*/ static irqreturn_t s3c2410_timer_interrupt(int irq, void *dev_id) -->void timer_tick(void) -->void do_timer(unsigned long ticks) -->jiffies_64 += ticks; -->update_times(ticks); -->void update_wall_time(void) /* check to see if there is a new clocksource to use */ -->change_clocksource(); /*2.jiffies时间中断处理函数*/ void clockevents_register_device(struct clock_event_device *dev) /*内核通知链触发*/ -->clockevents_do_notify(CLOCK_EVT_NOTIFY_ADD, dev); /*通知链注册*/ void __init tick_init(void) /*static struct notifier_block tick_notifier = { .notifier_call = tick_notify, };*/ -->clockevents_register_notifier(&tick_notifier); /*通知链回调*/ static int tick_notify(struct notifier_block *nb, unsigned long reason,void *dev) -->static int tick_check_new_device(struct clock_event_device *newdev) -->static void tick_setup_device(struct tick_device *td,struct clock_event_device *newdev, int cpu,const struct cpumask *cpumask) -->void tick_setup_periodic(struct clock_event_device *dev, int broadcast) -->void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast) -->dev->event_handler = tick_handle_periodic; /*event时间处理函数调用*/ void tick_handle_periodic(struct clock_event_device *dev) -->static void tick_periodic(int cpu) -->void do_timer(unsigned long ticks) -->jiffies_64 += ticks; -->update_times(ticks); -->void update_wall_time(void) /* check to see if there is a new clocksource to use */ -->change_clocksource();
/* linux/kernel/time/jiffies.c*/static cycle_t jiffies_read(struct clocksource *cs){return (cycle_t) jiffies;}
struct clocksource clocksource_jiffies = {.name= "jiffies",.rating= 1, /* lowest valid rating*/.read= jiffies_read,.mask= 0xffffffff, /*32bits*/.mult= NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */.mult_orig= NSEC_PER_JIFFY << JIFFIES_SHIFT,.shift= JIFFIES_SHIFT,};
static int __init init_jiffies_clocksource(void){return clocksource_register(&clocksource_jiffies);}
core_initcall(init_jiffies_clocksource);
int clocksource_register(struct clocksource *c)-->ret = clocksource_enqueue(c);/*静态全局变量存储下一个精度最高的时钟源static struct clocksource *next_clocksource;*/-->next_clocksource = select_clocksource();
struct clocksource *clocksource_get_next(void)/*静态全局变量存储当前使用的时钟源static struct clocksource *curr_clocksource = &clocksource_jiffies;*/-->curr_clocksource = next_clocksource;
/*什么时间更换时钟源,以下两种方法选择其一*//*1.jiffies时间中断处理函数*/static irqreturn_t s3c2410_timer_interrupt(int irq, void *dev_id)-->void timer_tick(void)-->void do_timer(unsigned long ticks)-->jiffies_64 += ticks;-->update_times(ticks);-->void update_wall_time(void)/* check to see if there is a new clocksource to use */-->change_clocksource();/*2.jiffies时间中断处理函数*/void clockevents_register_device(struct clock_event_device *dev)/*内核通知链触发*/-->clockevents_do_notify(CLOCK_EVT_NOTIFY_ADD, dev);
/*通知链注册*/void __init tick_init(void)/*static struct notifier_block tick_notifier = {.notifier_call = tick_notify,};*/-->clockevents_register_notifier(&tick_notifier);/*通知链回调*/static int tick_notify(struct notifier_block *nb, unsigned long reason,void *dev)-->static int tick_check_new_device(struct clock_event_device *newdev)-->static void tick_setup_device(struct tick_device *td,struct clock_event_device *newdev, int cpu,const struct cpumask *cpumask)-->void tick_setup_periodic(struct clock_event_device *dev, int broadcast)-->void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)-->dev->event_handler = tick_handle_periodic;/*event时间处理函数调用*/void tick_handle_periodic(struct clock_event_device *dev)-->static void tick_periodic(int cpu)-->void do_timer(unsigned long ticks)-->jiffies_64 += ticks;-->update_times(ticks);-->void update_wall_time(void)/* check to see if there is a new clocksource to use */-->change_clocksource();