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