Chinaunix首页 | 论坛 | 博客
  • 博客访问: 792433
  • 博文数量: 118
  • 博客积分: 2067
  • 博客等级: 大尉
  • 技术积分: 1751
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-17 14:27
文章存档

2016年(1)

2013年(1)

2012年(3)

2011年(26)

2010年(47)

2009年(40)

分类: LINUX

2011-04-22 13:48:08

------------------------------------------
硬件:PowerPC P1020MBG-PC,linux版本:2.6.35
------------------------------------------
先介绍几个kernel参数位置:
#cat /proc/timer_list  // 显示系统时间的一些参数和中断处理函数
#cat /sys/devices/system/clocksource/clocksource0/current_clocksource //显示时钟源
#hexdump /proc/device-tree/cpus/PowerPC\,P1020\@0/timebase-frequency //显示时基频率

1. 高精度时间系统加入后整个系统会有两个系统,再加上动态时钟模式共组合成4种模式,组合方式为:

-----------------------------------------------------------------------
                    |       HZ-based        |     dynamic ticks              
-----------------------------------------------------------------------
low resolution      |tick_handle_periodic   |  tick_nohz_handler
-----------------------------------------------------------------------
high resolution     | hrtimer_interrupt     |  hrtimer_interrupt
-----------------------------------------------------------------------
时间中断的处理函数为:timer_interrupt.在此函数执行时会调用:
  1. if (evt->event_handler) {
  2.         evt->event_handler(evt);
  3. }
其中evt->event_handler的值会根据不同的模式调用以上不同的处理函数。高精度模式产生中断的周期不同.

2. 内核启动时只选择low res, HZ-based模式,当内核启动完毕后再去判断是否支持其它模式,如果支持则进行切换,切换在每个CPU上都会进行,因为时间系统是每CPU的。
3. 在软中断中会进行是否切换到高精度的判断,流程为:
run_timer_softirq
        hrtimer_run_pending();
  1. 1423 /*
  2. 1424 * Called from timer softirq every jiffy, expire hrtimers:
  3. 1425 *
  4. 1426 * For HRT its the fall back code to run the softirq in the timer
  5. 1427 * softirq context in case the hrtimer initialization failed or has
  6. 1428 * not been done yet.
  7. 1429 */
  8. 1430 void hrtimer_run_pending(void)
  9. 1431 {
  10. 1432 if (hrtimer_hres_active())
  11. 1433 return;
  12. 1434
  13. 1435 /*
  14. 1436 * This _is_ ugly: We have to check in the softirq context,
  15. 1437 * whether we can switch to highres and / or nohz mode. The
  16. 1438 * clocksource switch happens in the timer interrupt with
  17. 1439 * xtime_lock held. Notification from there only sets the
  18. 1440 * check bit in the tick_oneshot code, otherwise we might
  19. 1441 * deadlock vs. xtime_lock.
  20. 1442 */
  21. 1443 if (tick_check_oneshot_change(!hrtimer_is_hres_enabled()))
  22. 1444 hrtimer_switch_to_hres();
  23. 1445 }
  24. 1446
hrtimer_is_hres_enabled:检查高精度是否被关闭,因为高精度支持不仅可以通过menuconfig,也可以通过内核命令行去关闭,即:highres=off.
tick_check_oneshot_change:进行真正的检测,如果返回为真,即切换到高精度模式条件满足,则调用函数 hrtimer_switch_to_hres完成切换。注意在此函数中也可能返回为0,但在函数内部切换到NOHZ模式,即低精度动态模式。函数流程为:
  1. 862 int tick_check_oneshot_change(int allow_nohz)
  2. 863 {
  3. 864 struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
  4. 865
  5. 866 if (!test_and_clear_bit(0, &ts->check_clocks))
  6. 867 return 0;
  7. 868
  8. 869 if (ts->nohz_mode != NOHZ_MODE_INACTIVE)
  9. 870 return 0;
  10. 871
  11. 872 if (!timekeeping_valid_for_hres() || !tick_is_oneshot_available())
  12. 873 return 0;
  13. 874
  14. 875 if (!allow_nohz)
  15. 876 return 1;
  16. 877
  17. 878 tick_nohz_switch_to_nohz();
  18. 879 return 0;
  19. 880 }















阅读(2824) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~