diff options
Diffstat (limited to 'kernel/timer.c')
-rw-r--r-- | kernel/timer.c | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/kernel/timer.c b/kernel/timer.c index a3d25f415019..5db5a8d26811 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include <linux/delay.h> | 37 | #include <linux/delay.h> |
38 | #include <linux/tick.h> | 38 | #include <linux/tick.h> |
39 | #include <linux/kallsyms.h> | 39 | #include <linux/kallsyms.h> |
40 | #include <linux/perf_counter.h> | 40 | #include <linux/perf_event.h> |
41 | #include <linux/sched.h> | 41 | #include <linux/sched.h> |
42 | 42 | ||
43 | #include <asm/uaccess.h> | 43 | #include <asm/uaccess.h> |
@@ -46,6 +46,9 @@ | |||
46 | #include <asm/timex.h> | 46 | #include <asm/timex.h> |
47 | #include <asm/io.h> | 47 | #include <asm/io.h> |
48 | 48 | ||
49 | #define CREATE_TRACE_POINTS | ||
50 | #include <trace/events/timer.h> | ||
51 | |||
49 | u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES; | 52 | u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES; |
50 | 53 | ||
51 | EXPORT_SYMBOL(jiffies_64); | 54 | EXPORT_SYMBOL(jiffies_64); |
@@ -72,6 +75,7 @@ struct tvec_base { | |||
72 | spinlock_t lock; | 75 | spinlock_t lock; |
73 | struct timer_list *running_timer; | 76 | struct timer_list *running_timer; |
74 | unsigned long timer_jiffies; | 77 | unsigned long timer_jiffies; |
78 | unsigned long next_timer; | ||
75 | struct tvec_root tv1; | 79 | struct tvec_root tv1; |
76 | struct tvec tv2; | 80 | struct tvec tv2; |
77 | struct tvec tv3; | 81 | struct tvec tv3; |
@@ -520,6 +524,25 @@ static inline void debug_timer_activate(struct timer_list *timer) { } | |||
520 | static inline void debug_timer_deactivate(struct timer_list *timer) { } | 524 | static inline void debug_timer_deactivate(struct timer_list *timer) { } |
521 | #endif | 525 | #endif |
522 | 526 | ||
527 | static inline void debug_init(struct timer_list *timer) | ||
528 | { | ||
529 | debug_timer_init(timer); | ||
530 | trace_timer_init(timer); | ||
531 | } | ||
532 | |||
533 | static inline void | ||
534 | debug_activate(struct timer_list *timer, unsigned long expires) | ||
535 | { | ||
536 | debug_timer_activate(timer); | ||
537 | trace_timer_start(timer, expires); | ||
538 | } | ||
539 | |||
540 | static inline void debug_deactivate(struct timer_list *timer) | ||
541 | { | ||
542 | debug_timer_deactivate(timer); | ||
543 | trace_timer_cancel(timer); | ||
544 | } | ||
545 | |||
523 | static void __init_timer(struct timer_list *timer, | 546 | static void __init_timer(struct timer_list *timer, |
524 | const char *name, | 547 | const char *name, |
525 | struct lock_class_key *key) | 548 | struct lock_class_key *key) |
@@ -548,7 +571,7 @@ void init_timer_key(struct timer_list *timer, | |||
548 | const char *name, | 571 | const char *name, |
549 | struct lock_class_key *key) | 572 | struct lock_class_key *key) |
550 | { | 573 | { |
551 | debug_timer_init(timer); | 574 | debug_init(timer); |
552 | __init_timer(timer, name, key); | 575 | __init_timer(timer, name, key); |
553 | } | 576 | } |
554 | EXPORT_SYMBOL(init_timer_key); | 577 | EXPORT_SYMBOL(init_timer_key); |
@@ -567,7 +590,7 @@ static inline void detach_timer(struct timer_list *timer, | |||
567 | { | 590 | { |
568 | struct list_head *entry = &timer->entry; | 591 | struct list_head *entry = &timer->entry; |
569 | 592 | ||
570 | debug_timer_deactivate(timer); | 593 | debug_deactivate(timer); |
571 | 594 | ||
572 | __list_del(entry->prev, entry->next); | 595 | __list_del(entry->prev, entry->next); |
573 | if (clear_pending) | 596 | if (clear_pending) |
@@ -622,13 +645,16 @@ __mod_timer(struct timer_list *timer, unsigned long expires, | |||
622 | 645 | ||
623 | if (timer_pending(timer)) { | 646 | if (timer_pending(timer)) { |
624 | detach_timer(timer, 0); | 647 | detach_timer(timer, 0); |
648 | if (timer->expires == base->next_timer && | ||
649 | !tbase_get_deferrable(timer->base)) | ||
650 | base->next_timer = base->timer_jiffies; | ||
625 | ret = 1; | 651 | ret = 1; |
626 | } else { | 652 | } else { |
627 | if (pending_only) | 653 | if (pending_only) |
628 | goto out_unlock; | 654 | goto out_unlock; |
629 | } | 655 | } |
630 | 656 | ||
631 | debug_timer_activate(timer); | 657 | debug_activate(timer, expires); |
632 | 658 | ||
633 | new_base = __get_cpu_var(tvec_bases); | 659 | new_base = __get_cpu_var(tvec_bases); |
634 | 660 | ||
@@ -663,6 +689,9 @@ __mod_timer(struct timer_list *timer, unsigned long expires, | |||
663 | } | 689 | } |
664 | 690 | ||
665 | timer->expires = expires; | 691 | timer->expires = expires; |
692 | if (time_before(timer->expires, base->next_timer) && | ||
693 | !tbase_get_deferrable(timer->base)) | ||
694 | base->next_timer = timer->expires; | ||
666 | internal_add_timer(base, timer); | 695 | internal_add_timer(base, timer); |
667 | 696 | ||
668 | out_unlock: | 697 | out_unlock: |
@@ -780,7 +809,10 @@ void add_timer_on(struct timer_list *timer, int cpu) | |||
780 | BUG_ON(timer_pending(timer) || !timer->function); | 809 | BUG_ON(timer_pending(timer) || !timer->function); |
781 | spin_lock_irqsave(&base->lock, flags); | 810 | spin_lock_irqsave(&base->lock, flags); |
782 | timer_set_base(timer, base); | 811 | timer_set_base(timer, base); |
783 | debug_timer_activate(timer); | 812 | debug_activate(timer, timer->expires); |
813 | if (time_before(timer->expires, base->next_timer) && | ||
814 | !tbase_get_deferrable(timer->base)) | ||
815 | base->next_timer = timer->expires; | ||
784 | internal_add_timer(base, timer); | 816 | internal_add_timer(base, timer); |
785 | /* | 817 | /* |
786 | * Check whether the other CPU is idle and needs to be | 818 | * Check whether the other CPU is idle and needs to be |
@@ -817,6 +849,9 @@ int del_timer(struct timer_list *timer) | |||
817 | base = lock_timer_base(timer, &flags); | 849 | base = lock_timer_base(timer, &flags); |
818 | if (timer_pending(timer)) { | 850 | if (timer_pending(timer)) { |
819 | detach_timer(timer, 1); | 851 | detach_timer(timer, 1); |
852 | if (timer->expires == base->next_timer && | ||
853 | !tbase_get_deferrable(timer->base)) | ||
854 | base->next_timer = base->timer_jiffies; | ||
820 | ret = 1; | 855 | ret = 1; |
821 | } | 856 | } |
822 | spin_unlock_irqrestore(&base->lock, flags); | 857 | spin_unlock_irqrestore(&base->lock, flags); |
@@ -850,6 +885,9 @@ int try_to_del_timer_sync(struct timer_list *timer) | |||
850 | ret = 0; | 885 | ret = 0; |
851 | if (timer_pending(timer)) { | 886 | if (timer_pending(timer)) { |
852 | detach_timer(timer, 1); | 887 | detach_timer(timer, 1); |
888 | if (timer->expires == base->next_timer && | ||
889 | !tbase_get_deferrable(timer->base)) | ||
890 | base->next_timer = base->timer_jiffies; | ||
853 | ret = 1; | 891 | ret = 1; |
854 | } | 892 | } |
855 | out: | 893 | out: |
@@ -984,7 +1022,9 @@ static inline void __run_timers(struct tvec_base *base) | |||
984 | */ | 1022 | */ |
985 | lock_map_acquire(&lockdep_map); | 1023 | lock_map_acquire(&lockdep_map); |
986 | 1024 | ||
1025 | trace_timer_expire_entry(timer); | ||
987 | fn(data); | 1026 | fn(data); |
1027 | trace_timer_expire_exit(timer); | ||
988 | 1028 | ||
989 | lock_map_release(&lockdep_map); | 1029 | lock_map_release(&lockdep_map); |
990 | 1030 | ||
@@ -1007,8 +1047,8 @@ static inline void __run_timers(struct tvec_base *base) | |||
1007 | #ifdef CONFIG_NO_HZ | 1047 | #ifdef CONFIG_NO_HZ |
1008 | /* | 1048 | /* |
1009 | * Find out when the next timer event is due to happen. This | 1049 | * Find out when the next timer event is due to happen. This |
1010 | * is used on S/390 to stop all activity when a cpus is idle. | 1050 | * is used on S/390 to stop all activity when a CPU is idle. |
1011 | * This functions needs to be called disabled. | 1051 | * This function needs to be called with interrupts disabled. |
1012 | */ | 1052 | */ |
1013 | static unsigned long __next_timer_interrupt(struct tvec_base *base) | 1053 | static unsigned long __next_timer_interrupt(struct tvec_base *base) |
1014 | { | 1054 | { |
@@ -1134,7 +1174,9 @@ unsigned long get_next_timer_interrupt(unsigned long now) | |||
1134 | unsigned long expires; | 1174 | unsigned long expires; |
1135 | 1175 | ||
1136 | spin_lock(&base->lock); | 1176 | spin_lock(&base->lock); |
1137 | expires = __next_timer_interrupt(base); | 1177 | if (time_before_eq(base->next_timer, base->timer_jiffies)) |
1178 | base->next_timer = __next_timer_interrupt(base); | ||
1179 | expires = base->next_timer; | ||
1138 | spin_unlock(&base->lock); | 1180 | spin_unlock(&base->lock); |
1139 | 1181 | ||
1140 | if (time_before_eq(expires, now)) | 1182 | if (time_before_eq(expires, now)) |
@@ -1169,7 +1211,7 @@ static void run_timer_softirq(struct softirq_action *h) | |||
1169 | { | 1211 | { |
1170 | struct tvec_base *base = __get_cpu_var(tvec_bases); | 1212 | struct tvec_base *base = __get_cpu_var(tvec_bases); |
1171 | 1213 | ||
1172 | perf_counter_do_pending(); | 1214 | perf_event_do_pending(); |
1173 | 1215 | ||
1174 | hrtimer_run_pending(); | 1216 | hrtimer_run_pending(); |
1175 | 1217 | ||
@@ -1522,6 +1564,7 @@ static int __cpuinit init_timers_cpu(int cpu) | |||
1522 | INIT_LIST_HEAD(base->tv1.vec + j); | 1564 | INIT_LIST_HEAD(base->tv1.vec + j); |
1523 | 1565 | ||
1524 | base->timer_jiffies = jiffies; | 1566 | base->timer_jiffies = jiffies; |
1567 | base->next_timer = base->timer_jiffies; | ||
1525 | return 0; | 1568 | return 0; |
1526 | } | 1569 | } |
1527 | 1570 | ||
@@ -1534,6 +1577,9 @@ static void migrate_timer_list(struct tvec_base *new_base, struct list_head *hea | |||
1534 | timer = list_first_entry(head, struct timer_list, entry); | 1577 | timer = list_first_entry(head, struct timer_list, entry); |
1535 | detach_timer(timer, 0); | 1578 | detach_timer(timer, 0); |
1536 | timer_set_base(timer, new_base); | 1579 | timer_set_base(timer, new_base); |
1580 | if (time_before(timer->expires, new_base->next_timer) && | ||
1581 | !tbase_get_deferrable(timer->base)) | ||
1582 | new_base->next_timer = timer->expires; | ||
1537 | internal_add_timer(new_base, timer); | 1583 | internal_add_timer(new_base, timer); |
1538 | } | 1584 | } |
1539 | } | 1585 | } |