aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/hrtimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r--kernel/hrtimer.c93
1 files changed, 67 insertions, 26 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index c03f221fee44..6d7020490f94 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) { }
442static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { } 444static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { }
443#endif 445#endif
444 446
447static inline void
448debug_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
455static inline void debug_activate(struct hrtimer *timer)
456{
457 debug_hrtimer_activate(timer);
458 trace_hrtimer_start(timer);
459}
460
461static 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 */
490static void hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base) 512static void
513hrtimer_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
@@ -708,7 +736,8 @@ static int hrtimer_switch_to_hres(void)
708static inline int hrtimer_hres_active(void) { return 0; } 736static inline int hrtimer_hres_active(void) { return 0; }
709static inline int hrtimer_is_hres_enabled(void) { return 0; } 737static inline int hrtimer_is_hres_enabled(void) { return 0; }
710static inline int hrtimer_switch_to_hres(void) { return 0; } 738static inline int hrtimer_switch_to_hres(void) { return 0; }
711static inline void hrtimer_force_reprogram(struct hrtimer_cpu_base *base) { } 739static inline void
740hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
712static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, 741static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
713 struct hrtimer_clock_base *base, 742 struct hrtimer_clock_base *base,
714 int wakeup) 743 int wakeup)
@@ -798,7 +827,7 @@ static int enqueue_hrtimer(struct hrtimer *timer,
798 struct hrtimer *entry; 827 struct hrtimer *entry;
799 int leftmost = 1; 828 int leftmost = 1;
800 829
801 debug_hrtimer_activate(timer); 830 debug_activate(timer);
802 831
803 /* 832 /*
804 * Find the right place in the rbtree: 833 * Find the right place in the rbtree:
@@ -851,19 +880,29 @@ static void __remove_hrtimer(struct hrtimer *timer,
851 struct hrtimer_clock_base *base, 880 struct hrtimer_clock_base *base,
852 unsigned long newstate, int reprogram) 881 unsigned long newstate, int reprogram)
853{ 882{
854 if (timer->state & HRTIMER_STATE_ENQUEUED) { 883 if (!(timer->state & HRTIMER_STATE_ENQUEUED))
855 /* 884 goto out;
856 * Remove the timer from the rbtree and replace the 885
857 * first entry pointer if necessary. 886 /*
858 */ 887 * Remove the timer from the rbtree and replace the first
859 if (base->first == &timer->node) { 888 * entry pointer if necessary.
860 base->first = rb_next(&timer->node); 889 */
861 /* Reprogram the clock event device. if enabled */ 890 if (base->first == &timer->node) {
862 if (reprogram && hrtimer_hres_active()) 891 base->first = rb_next(&timer->node);
863 hrtimer_force_reprogram(base->cpu_base); 892#ifdef CONFIG_HIGH_RES_TIMERS
893 /* Reprogram the clock event device. if enabled */
894 if (reprogram && hrtimer_hres_active()) {
895 ktime_t expires;
896
897 expires = ktime_sub(hrtimer_get_expires(timer),
898 base->offset);
899 if (base->cpu_base->expires_next.tv64 == expires.tv64)
900 hrtimer_force_reprogram(base->cpu_base, 1);
864 } 901 }
865 rb_erase(&timer->node, &base->active); 902#endif
866 } 903 }
904 rb_erase(&timer->node, &base->active);
905out:
867 timer->state = newstate; 906 timer->state = newstate;
868} 907}
869 908
@@ -884,7 +923,7 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
884 * reprogramming happens in the interrupt handler. This is a 923 * reprogramming happens in the interrupt handler. This is a
885 * rare case and less expensive than a smp call. 924 * rare case and less expensive than a smp call.
886 */ 925 */
887 debug_hrtimer_deactivate(timer); 926 debug_deactivate(timer);
888 timer_stats_hrtimer_clear_start_info(timer); 927 timer_stats_hrtimer_clear_start_info(timer);
889 reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases); 928 reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases);
890 __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, 929 __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE,
@@ -1117,7 +1156,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
1117void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, 1156void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
1118 enum hrtimer_mode mode) 1157 enum hrtimer_mode mode)
1119{ 1158{
1120 debug_hrtimer_init(timer); 1159 debug_init(timer, clock_id, mode);
1121 __hrtimer_init(timer, clock_id, mode); 1160 __hrtimer_init(timer, clock_id, mode);
1122} 1161}
1123EXPORT_SYMBOL_GPL(hrtimer_init); 1162EXPORT_SYMBOL_GPL(hrtimer_init);
@@ -1141,7 +1180,7 @@ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
1141} 1180}
1142EXPORT_SYMBOL_GPL(hrtimer_get_res); 1181EXPORT_SYMBOL_GPL(hrtimer_get_res);
1143 1182
1144static void __run_hrtimer(struct hrtimer *timer) 1183static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
1145{ 1184{
1146 struct hrtimer_clock_base *base = timer->base; 1185 struct hrtimer_clock_base *base = timer->base;
1147 struct hrtimer_cpu_base *cpu_base = base->cpu_base; 1186 struct hrtimer_cpu_base *cpu_base = base->cpu_base;
@@ -1150,7 +1189,7 @@ static void __run_hrtimer(struct hrtimer *timer)
1150 1189
1151 WARN_ON(!irqs_disabled()); 1190 WARN_ON(!irqs_disabled());
1152 1191
1153 debug_hrtimer_deactivate(timer); 1192 debug_deactivate(timer);
1154 __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0); 1193 __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0);
1155 timer_stats_account_hrtimer(timer); 1194 timer_stats_account_hrtimer(timer);
1156 fn = timer->function; 1195 fn = timer->function;
@@ -1161,7 +1200,9 @@ static void __run_hrtimer(struct hrtimer *timer)
1161 * the timer base. 1200 * the timer base.
1162 */ 1201 */
1163 spin_unlock(&cpu_base->lock); 1202 spin_unlock(&cpu_base->lock);
1203 trace_hrtimer_expire_entry(timer, now);
1164 restart = fn(timer); 1204 restart = fn(timer);
1205 trace_hrtimer_expire_exit(timer);
1165 spin_lock(&cpu_base->lock); 1206 spin_lock(&cpu_base->lock);
1166 1207
1167 /* 1208 /*
@@ -1272,7 +1313,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
1272 break; 1313 break;
1273 } 1314 }
1274 1315
1275 __run_hrtimer(timer); 1316 __run_hrtimer(timer, &basenow);
1276 } 1317 }
1277 base++; 1318 base++;
1278 } 1319 }
@@ -1394,7 +1435,7 @@ void hrtimer_run_queues(void)
1394 hrtimer_get_expires_tv64(timer)) 1435 hrtimer_get_expires_tv64(timer))
1395 break; 1436 break;
1396 1437
1397 __run_hrtimer(timer); 1438 __run_hrtimer(timer, &base->softirq_time);
1398 } 1439 }
1399 spin_unlock(&cpu_base->lock); 1440 spin_unlock(&cpu_base->lock);
1400 } 1441 }
@@ -1571,7 +1612,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
1571 while ((node = rb_first(&old_base->active))) { 1612 while ((node = rb_first(&old_base->active))) {
1572 timer = rb_entry(node, struct hrtimer, node); 1613 timer = rb_entry(node, struct hrtimer, node);
1573 BUG_ON(hrtimer_callback_running(timer)); 1614 BUG_ON(hrtimer_callback_running(timer));
1574 debug_hrtimer_deactivate(timer); 1615 debug_deactivate(timer);
1575 1616
1576 /* 1617 /*
1577 * Mark it as STATE_MIGRATE not INACTIVE otherwise the 1618 * Mark it as STATE_MIGRATE not INACTIVE otherwise the