diff options
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r-- | kernel/hrtimer.c | 95 |
1 files changed, 67 insertions, 28 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index c03f221fee44..3e1c36e7998f 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
@@ -48,6 +48,8 @@ | |||
48 | 48 | ||
49 | #include <asm/uaccess.h> | 49 | #include <asm/uaccess.h> |
50 | 50 | ||
51 | #include <trace/events/timer.h> | ||
52 | |||
51 | /* | 53 | /* |
52 | * The timer bases: | 54 | * The timer bases: |
53 | * | 55 | * |
@@ -442,6 +444,26 @@ static inline void debug_hrtimer_activate(struct hrtimer *timer) { } | |||
442 | static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { } | 444 | static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { } |
443 | #endif | 445 | #endif |
444 | 446 | ||
447 | static inline void | ||
448 | debug_init(struct hrtimer *timer, clockid_t clockid, | ||
449 | enum hrtimer_mode mode) | ||
450 | { | ||
451 | debug_hrtimer_init(timer); | ||
452 | trace_hrtimer_init(timer, clockid, mode); | ||
453 | } | ||
454 | |||
455 | static inline void debug_activate(struct hrtimer *timer) | ||
456 | { | ||
457 | debug_hrtimer_activate(timer); | ||
458 | trace_hrtimer_start(timer); | ||
459 | } | ||
460 | |||
461 | static inline void debug_deactivate(struct hrtimer *timer) | ||
462 | { | ||
463 | debug_hrtimer_deactivate(timer); | ||
464 | trace_hrtimer_cancel(timer); | ||
465 | } | ||
466 | |||
445 | /* High resolution timer related functions */ | 467 | /* High resolution timer related functions */ |
446 | #ifdef CONFIG_HIGH_RES_TIMERS | 468 | #ifdef CONFIG_HIGH_RES_TIMERS |
447 | 469 | ||
@@ -487,13 +509,14 @@ static inline int hrtimer_hres_active(void) | |||
487 | * next event | 509 | * next event |
488 | * Called with interrupts disabled and base->lock held | 510 | * Called with interrupts disabled and base->lock held |
489 | */ | 511 | */ |
490 | static void hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base) | 512 | static void |
513 | hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) | ||
491 | { | 514 | { |
492 | int i; | 515 | int i; |
493 | struct hrtimer_clock_base *base = cpu_base->clock_base; | 516 | struct hrtimer_clock_base *base = cpu_base->clock_base; |
494 | ktime_t expires; | 517 | ktime_t expires, expires_next; |
495 | 518 | ||
496 | cpu_base->expires_next.tv64 = KTIME_MAX; | 519 | expires_next.tv64 = KTIME_MAX; |
497 | 520 | ||
498 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) { | 521 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) { |
499 | struct hrtimer *timer; | 522 | struct hrtimer *timer; |
@@ -509,10 +532,15 @@ static void hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base) | |||
509 | */ | 532 | */ |
510 | if (expires.tv64 < 0) | 533 | if (expires.tv64 < 0) |
511 | expires.tv64 = 0; | 534 | expires.tv64 = 0; |
512 | if (expires.tv64 < cpu_base->expires_next.tv64) | 535 | if (expires.tv64 < expires_next.tv64) |
513 | cpu_base->expires_next = expires; | 536 | expires_next = expires; |
514 | } | 537 | } |
515 | 538 | ||
539 | if (skip_equal && expires_next.tv64 == cpu_base->expires_next.tv64) | ||
540 | return; | ||
541 | |||
542 | cpu_base->expires_next.tv64 = expires_next.tv64; | ||
543 | |||
516 | if (cpu_base->expires_next.tv64 != KTIME_MAX) | 544 | if (cpu_base->expires_next.tv64 != KTIME_MAX) |
517 | tick_program_event(cpu_base->expires_next, 1); | 545 | tick_program_event(cpu_base->expires_next, 1); |
518 | } | 546 | } |
@@ -595,7 +623,7 @@ static void retrigger_next_event(void *arg) | |||
595 | base->clock_base[CLOCK_REALTIME].offset = | 623 | base->clock_base[CLOCK_REALTIME].offset = |
596 | timespec_to_ktime(realtime_offset); | 624 | timespec_to_ktime(realtime_offset); |
597 | 625 | ||
598 | hrtimer_force_reprogram(base); | 626 | hrtimer_force_reprogram(base, 0); |
599 | spin_unlock(&base->lock); | 627 | spin_unlock(&base->lock); |
600 | } | 628 | } |
601 | 629 | ||
@@ -698,8 +726,6 @@ static int hrtimer_switch_to_hres(void) | |||
698 | /* "Retrigger" the interrupt to get things going */ | 726 | /* "Retrigger" the interrupt to get things going */ |
699 | retrigger_next_event(NULL); | 727 | retrigger_next_event(NULL); |
700 | local_irq_restore(flags); | 728 | local_irq_restore(flags); |
701 | printk(KERN_DEBUG "Switched to high resolution mode on CPU %d\n", | ||
702 | smp_processor_id()); | ||
703 | return 1; | 729 | return 1; |
704 | } | 730 | } |
705 | 731 | ||
@@ -708,7 +734,8 @@ static int hrtimer_switch_to_hres(void) | |||
708 | static inline int hrtimer_hres_active(void) { return 0; } | 734 | static inline int hrtimer_hres_active(void) { return 0; } |
709 | static inline int hrtimer_is_hres_enabled(void) { return 0; } | 735 | static inline int hrtimer_is_hres_enabled(void) { return 0; } |
710 | static inline int hrtimer_switch_to_hres(void) { return 0; } | 736 | static inline int hrtimer_switch_to_hres(void) { return 0; } |
711 | static inline void hrtimer_force_reprogram(struct hrtimer_cpu_base *base) { } | 737 | static inline void |
738 | hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { } | ||
712 | static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | 739 | static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, |
713 | struct hrtimer_clock_base *base, | 740 | struct hrtimer_clock_base *base, |
714 | int wakeup) | 741 | int wakeup) |
@@ -798,7 +825,7 @@ static int enqueue_hrtimer(struct hrtimer *timer, | |||
798 | struct hrtimer *entry; | 825 | struct hrtimer *entry; |
799 | int leftmost = 1; | 826 | int leftmost = 1; |
800 | 827 | ||
801 | debug_hrtimer_activate(timer); | 828 | debug_activate(timer); |
802 | 829 | ||
803 | /* | 830 | /* |
804 | * Find the right place in the rbtree: | 831 | * Find the right place in the rbtree: |
@@ -851,19 +878,29 @@ static void __remove_hrtimer(struct hrtimer *timer, | |||
851 | struct hrtimer_clock_base *base, | 878 | struct hrtimer_clock_base *base, |
852 | unsigned long newstate, int reprogram) | 879 | unsigned long newstate, int reprogram) |
853 | { | 880 | { |
854 | if (timer->state & HRTIMER_STATE_ENQUEUED) { | 881 | if (!(timer->state & HRTIMER_STATE_ENQUEUED)) |
855 | /* | 882 | goto out; |
856 | * Remove the timer from the rbtree and replace the | 883 | |
857 | * first entry pointer if necessary. | 884 | /* |
858 | */ | 885 | * Remove the timer from the rbtree and replace the first |
859 | if (base->first == &timer->node) { | 886 | * entry pointer if necessary. |
860 | base->first = rb_next(&timer->node); | 887 | */ |
861 | /* Reprogram the clock event device. if enabled */ | 888 | if (base->first == &timer->node) { |
862 | if (reprogram && hrtimer_hres_active()) | 889 | base->first = rb_next(&timer->node); |
863 | hrtimer_force_reprogram(base->cpu_base); | 890 | #ifdef CONFIG_HIGH_RES_TIMERS |
891 | /* Reprogram the clock event device. if enabled */ | ||
892 | if (reprogram && hrtimer_hres_active()) { | ||
893 | ktime_t expires; | ||
894 | |||
895 | expires = ktime_sub(hrtimer_get_expires(timer), | ||
896 | base->offset); | ||
897 | if (base->cpu_base->expires_next.tv64 == expires.tv64) | ||
898 | hrtimer_force_reprogram(base->cpu_base, 1); | ||
864 | } | 899 | } |
865 | rb_erase(&timer->node, &base->active); | 900 | #endif |
866 | } | 901 | } |
902 | rb_erase(&timer->node, &base->active); | ||
903 | out: | ||
867 | timer->state = newstate; | 904 | timer->state = newstate; |
868 | } | 905 | } |
869 | 906 | ||
@@ -884,7 +921,7 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base) | |||
884 | * reprogramming happens in the interrupt handler. This is a | 921 | * reprogramming happens in the interrupt handler. This is a |
885 | * rare case and less expensive than a smp call. | 922 | * rare case and less expensive than a smp call. |
886 | */ | 923 | */ |
887 | debug_hrtimer_deactivate(timer); | 924 | debug_deactivate(timer); |
888 | timer_stats_hrtimer_clear_start_info(timer); | 925 | timer_stats_hrtimer_clear_start_info(timer); |
889 | reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases); | 926 | reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases); |
890 | __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, | 927 | __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, |
@@ -1117,7 +1154,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id, | |||
1117 | void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, | 1154 | void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, |
1118 | enum hrtimer_mode mode) | 1155 | enum hrtimer_mode mode) |
1119 | { | 1156 | { |
1120 | debug_hrtimer_init(timer); | 1157 | debug_init(timer, clock_id, mode); |
1121 | __hrtimer_init(timer, clock_id, mode); | 1158 | __hrtimer_init(timer, clock_id, mode); |
1122 | } | 1159 | } |
1123 | EXPORT_SYMBOL_GPL(hrtimer_init); | 1160 | EXPORT_SYMBOL_GPL(hrtimer_init); |
@@ -1141,7 +1178,7 @@ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp) | |||
1141 | } | 1178 | } |
1142 | EXPORT_SYMBOL_GPL(hrtimer_get_res); | 1179 | EXPORT_SYMBOL_GPL(hrtimer_get_res); |
1143 | 1180 | ||
1144 | static void __run_hrtimer(struct hrtimer *timer) | 1181 | static void __run_hrtimer(struct hrtimer *timer, ktime_t *now) |
1145 | { | 1182 | { |
1146 | struct hrtimer_clock_base *base = timer->base; | 1183 | struct hrtimer_clock_base *base = timer->base; |
1147 | struct hrtimer_cpu_base *cpu_base = base->cpu_base; | 1184 | struct hrtimer_cpu_base *cpu_base = base->cpu_base; |
@@ -1150,7 +1187,7 @@ static void __run_hrtimer(struct hrtimer *timer) | |||
1150 | 1187 | ||
1151 | WARN_ON(!irqs_disabled()); | 1188 | WARN_ON(!irqs_disabled()); |
1152 | 1189 | ||
1153 | debug_hrtimer_deactivate(timer); | 1190 | debug_deactivate(timer); |
1154 | __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0); | 1191 | __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0); |
1155 | timer_stats_account_hrtimer(timer); | 1192 | timer_stats_account_hrtimer(timer); |
1156 | fn = timer->function; | 1193 | fn = timer->function; |
@@ -1161,7 +1198,9 @@ static void __run_hrtimer(struct hrtimer *timer) | |||
1161 | * the timer base. | 1198 | * the timer base. |
1162 | */ | 1199 | */ |
1163 | spin_unlock(&cpu_base->lock); | 1200 | spin_unlock(&cpu_base->lock); |
1201 | trace_hrtimer_expire_entry(timer, now); | ||
1164 | restart = fn(timer); | 1202 | restart = fn(timer); |
1203 | trace_hrtimer_expire_exit(timer); | ||
1165 | spin_lock(&cpu_base->lock); | 1204 | spin_lock(&cpu_base->lock); |
1166 | 1205 | ||
1167 | /* | 1206 | /* |
@@ -1272,7 +1311,7 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
1272 | break; | 1311 | break; |
1273 | } | 1312 | } |
1274 | 1313 | ||
1275 | __run_hrtimer(timer); | 1314 | __run_hrtimer(timer, &basenow); |
1276 | } | 1315 | } |
1277 | base++; | 1316 | base++; |
1278 | } | 1317 | } |
@@ -1394,7 +1433,7 @@ void hrtimer_run_queues(void) | |||
1394 | hrtimer_get_expires_tv64(timer)) | 1433 | hrtimer_get_expires_tv64(timer)) |
1395 | break; | 1434 | break; |
1396 | 1435 | ||
1397 | __run_hrtimer(timer); | 1436 | __run_hrtimer(timer, &base->softirq_time); |
1398 | } | 1437 | } |
1399 | spin_unlock(&cpu_base->lock); | 1438 | spin_unlock(&cpu_base->lock); |
1400 | } | 1439 | } |
@@ -1571,7 +1610,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | |||
1571 | while ((node = rb_first(&old_base->active))) { | 1610 | while ((node = rb_first(&old_base->active))) { |
1572 | timer = rb_entry(node, struct hrtimer, node); | 1611 | timer = rb_entry(node, struct hrtimer, node); |
1573 | BUG_ON(hrtimer_callback_running(timer)); | 1612 | BUG_ON(hrtimer_callback_running(timer)); |
1574 | debug_hrtimer_deactivate(timer); | 1613 | debug_deactivate(timer); |
1575 | 1614 | ||
1576 | /* | 1615 | /* |
1577 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the | 1616 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the |