diff options
Diffstat (limited to 'kernel/timer.c')
| -rw-r--r-- | kernel/timer.c | 71 |
1 files changed, 59 insertions, 12 deletions
diff --git a/kernel/timer.c b/kernel/timer.c index 54d3912f8cad..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; |
| @@ -380,6 +384,8 @@ static void timer_stats_account_timer(struct timer_list *timer) | |||
| 380 | { | 384 | { |
| 381 | unsigned int flag = 0; | 385 | unsigned int flag = 0; |
| 382 | 386 | ||
| 387 | if (likely(!timer->start_site)) | ||
| 388 | return; | ||
| 383 | if (unlikely(tbase_get_deferrable(timer->base))) | 389 | if (unlikely(tbase_get_deferrable(timer->base))) |
| 384 | flag |= TIMER_STATS_FLAG_DEFERRABLE; | 390 | flag |= TIMER_STATS_FLAG_DEFERRABLE; |
| 385 | 391 | ||
| @@ -518,6 +524,25 @@ static inline void debug_timer_activate(struct timer_list *timer) { } | |||
| 518 | static inline void debug_timer_deactivate(struct timer_list *timer) { } | 524 | static inline void debug_timer_deactivate(struct timer_list *timer) { } |
| 519 | #endif | 525 | #endif |
| 520 | 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 | |||
| 521 | static void __init_timer(struct timer_list *timer, | 546 | static void __init_timer(struct timer_list *timer, |
| 522 | const char *name, | 547 | const char *name, |
| 523 | struct lock_class_key *key) | 548 | struct lock_class_key *key) |
| @@ -546,7 +571,7 @@ void init_timer_key(struct timer_list *timer, | |||
| 546 | const char *name, | 571 | const char *name, |
| 547 | struct lock_class_key *key) | 572 | struct lock_class_key *key) |
| 548 | { | 573 | { |
| 549 | debug_timer_init(timer); | 574 | debug_init(timer); |
| 550 | __init_timer(timer, name, key); | 575 | __init_timer(timer, name, key); |
| 551 | } | 576 | } |
| 552 | EXPORT_SYMBOL(init_timer_key); | 577 | EXPORT_SYMBOL(init_timer_key); |
| @@ -565,7 +590,7 @@ static inline void detach_timer(struct timer_list *timer, | |||
| 565 | { | 590 | { |
| 566 | struct list_head *entry = &timer->entry; | 591 | struct list_head *entry = &timer->entry; |
| 567 | 592 | ||
| 568 | debug_timer_deactivate(timer); | 593 | debug_deactivate(timer); |
| 569 | 594 | ||
| 570 | __list_del(entry->prev, entry->next); | 595 | __list_del(entry->prev, entry->next); |
| 571 | if (clear_pending) | 596 | if (clear_pending) |
| @@ -620,13 +645,16 @@ __mod_timer(struct timer_list *timer, unsigned long expires, | |||
| 620 | 645 | ||
| 621 | if (timer_pending(timer)) { | 646 | if (timer_pending(timer)) { |
| 622 | 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; | ||
| 623 | ret = 1; | 651 | ret = 1; |
| 624 | } else { | 652 | } else { |
| 625 | if (pending_only) | 653 | if (pending_only) |
| 626 | goto out_unlock; | 654 | goto out_unlock; |
| 627 | } | 655 | } |
| 628 | 656 | ||
| 629 | debug_timer_activate(timer); | 657 | debug_activate(timer, expires); |
| 630 | 658 | ||
| 631 | new_base = __get_cpu_var(tvec_bases); | 659 | new_base = __get_cpu_var(tvec_bases); |
| 632 | 660 | ||
| @@ -661,6 +689,9 @@ __mod_timer(struct timer_list *timer, unsigned long expires, | |||
| 661 | } | 689 | } |
| 662 | 690 | ||
| 663 | 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; | ||
| 664 | internal_add_timer(base, timer); | 695 | internal_add_timer(base, timer); |
| 665 | 696 | ||
| 666 | out_unlock: | 697 | out_unlock: |
| @@ -712,7 +743,7 @@ int mod_timer(struct timer_list *timer, unsigned long expires) | |||
| 712 | * networking code - if the timer is re-modified | 743 | * networking code - if the timer is re-modified |
| 713 | * to be the same thing then just return: | 744 | * to be the same thing then just return: |
| 714 | */ | 745 | */ |
| 715 | if (timer->expires == expires && timer_pending(timer)) | 746 | if (timer_pending(timer) && timer->expires == expires) |
| 716 | return 1; | 747 | return 1; |
| 717 | 748 | ||
| 718 | return __mod_timer(timer, expires, false, TIMER_NOT_PINNED); | 749 | return __mod_timer(timer, expires, false, TIMER_NOT_PINNED); |
| @@ -778,7 +809,10 @@ void add_timer_on(struct timer_list *timer, int cpu) | |||
| 778 | BUG_ON(timer_pending(timer) || !timer->function); | 809 | BUG_ON(timer_pending(timer) || !timer->function); |
| 779 | spin_lock_irqsave(&base->lock, flags); | 810 | spin_lock_irqsave(&base->lock, flags); |
| 780 | timer_set_base(timer, base); | 811 | timer_set_base(timer, base); |
| 781 | 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; | ||
| 782 | internal_add_timer(base, timer); | 816 | internal_add_timer(base, timer); |
| 783 | /* | 817 | /* |
| 784 | * Check whether the other CPU is idle and needs to be | 818 | * Check whether the other CPU is idle and needs to be |
| @@ -815,6 +849,9 @@ int del_timer(struct timer_list *timer) | |||
| 815 | base = lock_timer_base(timer, &flags); | 849 | base = lock_timer_base(timer, &flags); |
| 816 | if (timer_pending(timer)) { | 850 | if (timer_pending(timer)) { |
| 817 | 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; | ||
| 818 | ret = 1; | 855 | ret = 1; |
| 819 | } | 856 | } |
| 820 | spin_unlock_irqrestore(&base->lock, flags); | 857 | spin_unlock_irqrestore(&base->lock, flags); |
| @@ -848,6 +885,9 @@ int try_to_del_timer_sync(struct timer_list *timer) | |||
| 848 | ret = 0; | 885 | ret = 0; |
| 849 | if (timer_pending(timer)) { | 886 | if (timer_pending(timer)) { |
| 850 | 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; | ||
| 851 | ret = 1; | 891 | ret = 1; |
| 852 | } | 892 | } |
| 853 | out: | 893 | out: |
| @@ -982,7 +1022,9 @@ static inline void __run_timers(struct tvec_base *base) | |||
| 982 | */ | 1022 | */ |
| 983 | lock_map_acquire(&lockdep_map); | 1023 | lock_map_acquire(&lockdep_map); |
| 984 | 1024 | ||
| 1025 | trace_timer_expire_entry(timer); | ||
| 985 | fn(data); | 1026 | fn(data); |
| 1027 | trace_timer_expire_exit(timer); | ||
| 986 | 1028 | ||
| 987 | lock_map_release(&lockdep_map); | 1029 | lock_map_release(&lockdep_map); |
| 988 | 1030 | ||
| @@ -1005,8 +1047,8 @@ static inline void __run_timers(struct tvec_base *base) | |||
| 1005 | #ifdef CONFIG_NO_HZ | 1047 | #ifdef CONFIG_NO_HZ |
| 1006 | /* | 1048 | /* |
| 1007 | * 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 |
| 1008 | * 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. |
| 1009 | * This functions needs to be called disabled. | 1051 | * This function needs to be called with interrupts disabled. |
| 1010 | */ | 1052 | */ |
| 1011 | static unsigned long __next_timer_interrupt(struct tvec_base *base) | 1053 | static unsigned long __next_timer_interrupt(struct tvec_base *base) |
| 1012 | { | 1054 | { |
| @@ -1132,7 +1174,9 @@ unsigned long get_next_timer_interrupt(unsigned long now) | |||
| 1132 | unsigned long expires; | 1174 | unsigned long expires; |
| 1133 | 1175 | ||
| 1134 | spin_lock(&base->lock); | 1176 | spin_lock(&base->lock); |
| 1135 | 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; | ||
| 1136 | spin_unlock(&base->lock); | 1180 | spin_unlock(&base->lock); |
| 1137 | 1181 | ||
| 1138 | if (time_before_eq(expires, now)) | 1182 | if (time_before_eq(expires, now)) |
| @@ -1154,8 +1198,7 @@ void update_process_times(int user_tick) | |||
| 1154 | /* Note: this timer irq context must be accounted for as well. */ | 1198 | /* Note: this timer irq context must be accounted for as well. */ |
| 1155 | account_process_tick(p, user_tick); | 1199 | account_process_tick(p, user_tick); |
| 1156 | run_local_timers(); | 1200 | run_local_timers(); |
| 1157 | if (rcu_pending(cpu)) | 1201 | rcu_check_callbacks(cpu, user_tick); |
| 1158 | rcu_check_callbacks(cpu, user_tick); | ||
| 1159 | printk_tick(); | 1202 | printk_tick(); |
| 1160 | scheduler_tick(); | 1203 | scheduler_tick(); |
| 1161 | run_posix_cpu_timers(p); | 1204 | run_posix_cpu_timers(p); |
| @@ -1168,7 +1211,7 @@ static void run_timer_softirq(struct softirq_action *h) | |||
| 1168 | { | 1211 | { |
| 1169 | struct tvec_base *base = __get_cpu_var(tvec_bases); | 1212 | struct tvec_base *base = __get_cpu_var(tvec_bases); |
| 1170 | 1213 | ||
| 1171 | perf_counter_do_pending(); | 1214 | perf_event_do_pending(); |
| 1172 | 1215 | ||
| 1173 | hrtimer_run_pending(); | 1216 | hrtimer_run_pending(); |
| 1174 | 1217 | ||
| @@ -1521,6 +1564,7 @@ static int __cpuinit init_timers_cpu(int cpu) | |||
| 1521 | INIT_LIST_HEAD(base->tv1.vec + j); | 1564 | INIT_LIST_HEAD(base->tv1.vec + j); |
| 1522 | 1565 | ||
| 1523 | base->timer_jiffies = jiffies; | 1566 | base->timer_jiffies = jiffies; |
| 1567 | base->next_timer = base->timer_jiffies; | ||
| 1524 | return 0; | 1568 | return 0; |
| 1525 | } | 1569 | } |
| 1526 | 1570 | ||
| @@ -1533,6 +1577,9 @@ static void migrate_timer_list(struct tvec_base *new_base, struct list_head *hea | |||
| 1533 | timer = list_first_entry(head, struct timer_list, entry); | 1577 | timer = list_first_entry(head, struct timer_list, entry); |
| 1534 | detach_timer(timer, 0); | 1578 | detach_timer(timer, 0); |
| 1535 | 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; | ||
| 1536 | internal_add_timer(new_base, timer); | 1583 | internal_add_timer(new_base, timer); |
| 1537 | } | 1584 | } |
| 1538 | } | 1585 | } |
