高精度定时器在mips上的框架结构

大体流程:

run_timer_softirq
hrtimer_run_pending
hrtimer_switch_to_hres
tick_setup_sched_timer
hrtimer_init/*settup hr tick timer,tick-sched.c*/
tick_sched_timer /*hard irq context*/
plat_irq_dispatch
nlm_common_timer_interrupt
do_IRQ
desc->handle_irq
c0_compare_interrupt
struct clock_event_device *cd;
cd = &per_cpu(mips_clockevent_device, cpu);
  cd->event_handler(cd);
cd->event_handler
hrtimer_interrupt
tick_sched_timer
update_process_times
run_local_timers
hrtimer_run_queues (当前tick timer已被摘除,不在queue中,因此将自己再次加入红黑树并触发下一次时钟)


32内核的高精度定时运行环境是在硬中断下

1)系统刚初始化时,clock_device dev的 event_handler是一个空函数,后面被替换成tick_handle_periodic,
tick_check_new_device--->
tick_setup_device--->
tick_setup_periodic-->
tick_set_periodic_handler--->
dev->event_handler = tick_handle_periodic;
接着主动触发一个时钟中断
clockevents_program_event---> dev->set_next_event  操作compare寄存器来触发

2)timer_interrupt-->event_handler-->tick_handle_periodic---> tick_periodic--->
update_process_times--->run_local_timers--->raise_softirq(TIMER_SOFTIRQ);
详细的流程(plat_irq_dispatch
nlm_common_timer_interrupt
do_IRQ
desc->handle_irq
c0_compare_interrupt
struct clock_event_device *cd;
cd = &per_cpu(mips_clockevent_device, cpu);
  cd->event_handler(cd);
cd->event_handler
)


3)软中断里,每次都在hrtimer_run_pending尝试进行高精度时钟切换,如果切换不成功,即没有
配置高精度定时器,则在run_timer_softirq里走timer wheel定时器。

static void run_timer_softirq(struct softirq_action *h)
{
 struct tvec_base *base = __get_cpu_var(tvec_bases);

 perf_event_do_pending();

 hrtimer_run_pending();

 if (time_after_eq(jiffies, base->timer_jiffies))
  __run_timers(base);
}

 

run_timer_softirq-->hrtimer_run_pending--->hrtimer_switch_to_hres-->event_handler = hrtimer_interrupt;
event_handler被换成hrtimer_interrupt

          
          This _is_ ugly: We have to check in the softirq context,
   whether we can switch to highres and / or nohz mode.
       if (tick_check_oneshot_change(!hrtimer_is_hres_enabled()))
  hrtimer_switch_to_hres();


hrtimer_switch_to_hres-->tick_init_highres-->tick_switch_to_oneshot(hrtimer_interrupt);-->dev->event_handler = handler;

4)然后就是高精度定时器处理流程了
timer_interrupt-->event_handler--->hrtimer_interrupt-->


在高精度时钟切换完毕后,会有一个尝试启动周期定时器即系统心跳的操作。
tick_setup_sched_timer

 

 

 

如果系统没有高精度时钟支持(即没有count compare), 则在低精度模式下如何运作?

运行流程是什么?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章