diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2011-05-14 06:06:36 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2011-05-14 06:06:36 -0400 |
commit | a18f22a968de17b29f2310cdb7ba69163e65ec15 (patch) | |
tree | a7d56d88fad5e444d7661484109758a2f436129e /kernel/hrtimer.c | |
parent | a1c57e0fec53defe745e64417eacdbd3618c3e66 (diff) | |
parent | 798778b8653f64b7b2162ac70eca10367cff6ce8 (diff) |
Merge branch 'consolidate-clksrc-i8253' of master.kernel.org:~rmk/linux-2.6-arm into timers/clocksource
Conflicts:
arch/ia64/kernel/cyclone.c
arch/mips/kernel/i8253.c
arch/x86/kernel/i8253.c
Reason: Resolve conflicts so further cleanups do not conflict further
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r-- | kernel/hrtimer.c | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 0c8d7c048615..87fdb3f8db14 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
@@ -53,11 +53,10 @@ | |||
53 | /* | 53 | /* |
54 | * The timer bases: | 54 | * The timer bases: |
55 | * | 55 | * |
56 | * Note: If we want to add new timer bases, we have to skip the two | 56 | * There are more clockids then hrtimer bases. Thus, we index |
57 | * clock ids captured by the cpu-timers. We do this by holding empty | 57 | * into the timer bases by the hrtimer_base_type enum. When trying |
58 | * entries rather than doing math adjustment of the clock ids. | 58 | * to reach a base using a clockid, hrtimer_clockid_to_base() |
59 | * This ensures that we capture erroneous accesses to these clock ids | 59 | * is used to convert from clockid to the proper hrtimer_base_type. |
60 | * rather than moving them into the range of valid clock id's. | ||
61 | */ | 60 | */ |
62 | DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) = | 61 | DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) = |
63 | { | 62 | { |
@@ -74,30 +73,43 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) = | |||
74 | .get_time = &ktime_get, | 73 | .get_time = &ktime_get, |
75 | .resolution = KTIME_LOW_RES, | 74 | .resolution = KTIME_LOW_RES, |
76 | }, | 75 | }, |
76 | { | ||
77 | .index = CLOCK_BOOTTIME, | ||
78 | .get_time = &ktime_get_boottime, | ||
79 | .resolution = KTIME_LOW_RES, | ||
80 | }, | ||
77 | } | 81 | } |
78 | }; | 82 | }; |
79 | 83 | ||
84 | static int hrtimer_clock_to_base_table[MAX_CLOCKS] = { | ||
85 | [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME, | ||
86 | [CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC, | ||
87 | [CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME, | ||
88 | }; | ||
89 | |||
90 | static inline int hrtimer_clockid_to_base(clockid_t clock_id) | ||
91 | { | ||
92 | return hrtimer_clock_to_base_table[clock_id]; | ||
93 | } | ||
94 | |||
95 | |||
80 | /* | 96 | /* |
81 | * Get the coarse grained time at the softirq based on xtime and | 97 | * Get the coarse grained time at the softirq based on xtime and |
82 | * wall_to_monotonic. | 98 | * wall_to_monotonic. |
83 | */ | 99 | */ |
84 | static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base) | 100 | static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base) |
85 | { | 101 | { |
86 | ktime_t xtim, tomono; | 102 | ktime_t xtim, mono, boot; |
87 | struct timespec xts, tom; | 103 | struct timespec xts, tom, slp; |
88 | unsigned long seq; | ||
89 | 104 | ||
90 | do { | 105 | get_xtime_and_monotonic_and_sleep_offset(&xts, &tom, &slp); |
91 | seq = read_seqbegin(&xtime_lock); | ||
92 | xts = __current_kernel_time(); | ||
93 | tom = __get_wall_to_monotonic(); | ||
94 | } while (read_seqretry(&xtime_lock, seq)); | ||
95 | 106 | ||
96 | xtim = timespec_to_ktime(xts); | 107 | xtim = timespec_to_ktime(xts); |
97 | tomono = timespec_to_ktime(tom); | 108 | mono = ktime_add(xtim, timespec_to_ktime(tom)); |
98 | base->clock_base[CLOCK_REALTIME].softirq_time = xtim; | 109 | boot = ktime_add(mono, timespec_to_ktime(slp)); |
99 | base->clock_base[CLOCK_MONOTONIC].softirq_time = | 110 | base->clock_base[HRTIMER_BASE_REALTIME].softirq_time = xtim; |
100 | ktime_add(xtim, tomono); | 111 | base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time = mono; |
112 | base->clock_base[HRTIMER_BASE_BOOTTIME].softirq_time = boot; | ||
101 | } | 113 | } |
102 | 114 | ||
103 | /* | 115 | /* |
@@ -184,10 +196,11 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base, | |||
184 | struct hrtimer_cpu_base *new_cpu_base; | 196 | struct hrtimer_cpu_base *new_cpu_base; |
185 | int this_cpu = smp_processor_id(); | 197 | int this_cpu = smp_processor_id(); |
186 | int cpu = hrtimer_get_target(this_cpu, pinned); | 198 | int cpu = hrtimer_get_target(this_cpu, pinned); |
199 | int basenum = hrtimer_clockid_to_base(base->index); | ||
187 | 200 | ||
188 | again: | 201 | again: |
189 | new_cpu_base = &per_cpu(hrtimer_bases, cpu); | 202 | new_cpu_base = &per_cpu(hrtimer_bases, cpu); |
190 | new_base = &new_cpu_base->clock_base[base->index]; | 203 | new_base = &new_cpu_base->clock_base[basenum]; |
191 | 204 | ||
192 | if (base != new_base) { | 205 | if (base != new_base) { |
193 | /* | 206 | /* |
@@ -334,6 +347,11 @@ EXPORT_SYMBOL_GPL(ktime_add_safe); | |||
334 | 347 | ||
335 | static struct debug_obj_descr hrtimer_debug_descr; | 348 | static struct debug_obj_descr hrtimer_debug_descr; |
336 | 349 | ||
350 | static void *hrtimer_debug_hint(void *addr) | ||
351 | { | ||
352 | return ((struct hrtimer *) addr)->function; | ||
353 | } | ||
354 | |||
337 | /* | 355 | /* |
338 | * fixup_init is called when: | 356 | * fixup_init is called when: |
339 | * - an active object is initialized | 357 | * - an active object is initialized |
@@ -393,6 +411,7 @@ static int hrtimer_fixup_free(void *addr, enum debug_obj_state state) | |||
393 | 411 | ||
394 | static struct debug_obj_descr hrtimer_debug_descr = { | 412 | static struct debug_obj_descr hrtimer_debug_descr = { |
395 | .name = "hrtimer", | 413 | .name = "hrtimer", |
414 | .debug_hint = hrtimer_debug_hint, | ||
396 | .fixup_init = hrtimer_fixup_init, | 415 | .fixup_init = hrtimer_fixup_init, |
397 | .fixup_activate = hrtimer_fixup_activate, | 416 | .fixup_activate = hrtimer_fixup_activate, |
398 | .fixup_free = hrtimer_fixup_free, | 417 | .fixup_free = hrtimer_fixup_free, |
@@ -611,24 +630,23 @@ static int hrtimer_reprogram(struct hrtimer *timer, | |||
611 | static void retrigger_next_event(void *arg) | 630 | static void retrigger_next_event(void *arg) |
612 | { | 631 | { |
613 | struct hrtimer_cpu_base *base; | 632 | struct hrtimer_cpu_base *base; |
614 | struct timespec realtime_offset, wtm; | 633 | struct timespec realtime_offset, wtm, sleep; |
615 | unsigned long seq; | ||
616 | 634 | ||
617 | if (!hrtimer_hres_active()) | 635 | if (!hrtimer_hres_active()) |
618 | return; | 636 | return; |
619 | 637 | ||
620 | do { | 638 | get_xtime_and_monotonic_and_sleep_offset(&realtime_offset, &wtm, |
621 | seq = read_seqbegin(&xtime_lock); | 639 | &sleep); |
622 | wtm = __get_wall_to_monotonic(); | ||
623 | } while (read_seqretry(&xtime_lock, seq)); | ||
624 | set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec); | 640 | set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec); |
625 | 641 | ||
626 | base = &__get_cpu_var(hrtimer_bases); | 642 | base = &__get_cpu_var(hrtimer_bases); |
627 | 643 | ||
628 | /* Adjust CLOCK_REALTIME offset */ | 644 | /* Adjust CLOCK_REALTIME offset */ |
629 | raw_spin_lock(&base->lock); | 645 | raw_spin_lock(&base->lock); |
630 | base->clock_base[CLOCK_REALTIME].offset = | 646 | base->clock_base[HRTIMER_BASE_REALTIME].offset = |
631 | timespec_to_ktime(realtime_offset); | 647 | timespec_to_ktime(realtime_offset); |
648 | base->clock_base[HRTIMER_BASE_BOOTTIME].offset = | ||
649 | timespec_to_ktime(sleep); | ||
632 | 650 | ||
633 | hrtimer_force_reprogram(base, 0); | 651 | hrtimer_force_reprogram(base, 0); |
634 | raw_spin_unlock(&base->lock); | 652 | raw_spin_unlock(&base->lock); |
@@ -673,14 +691,6 @@ static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) | |||
673 | } | 691 | } |
674 | 692 | ||
675 | /* | 693 | /* |
676 | * Initialize the high resolution related parts of a hrtimer | ||
677 | */ | ||
678 | static inline void hrtimer_init_timer_hres(struct hrtimer *timer) | ||
679 | { | ||
680 | } | ||
681 | |||
682 | |||
683 | /* | ||
684 | * When High resolution timers are active, try to reprogram. Note, that in case | 694 | * When High resolution timers are active, try to reprogram. Note, that in case |
685 | * the state has HRTIMER_STATE_CALLBACK set, no reprogramming and no expiry | 695 | * the state has HRTIMER_STATE_CALLBACK set, no reprogramming and no expiry |
686 | * check happens. The timer gets enqueued into the rbtree. The reprogramming | 696 | * check happens. The timer gets enqueued into the rbtree. The reprogramming |
@@ -725,8 +735,9 @@ static int hrtimer_switch_to_hres(void) | |||
725 | return 0; | 735 | return 0; |
726 | } | 736 | } |
727 | base->hres_active = 1; | 737 | base->hres_active = 1; |
728 | base->clock_base[CLOCK_REALTIME].resolution = KTIME_HIGH_RES; | 738 | base->clock_base[HRTIMER_BASE_REALTIME].resolution = KTIME_HIGH_RES; |
729 | base->clock_base[CLOCK_MONOTONIC].resolution = KTIME_HIGH_RES; | 739 | base->clock_base[HRTIMER_BASE_MONOTONIC].resolution = KTIME_HIGH_RES; |
740 | base->clock_base[HRTIMER_BASE_BOOTTIME].resolution = KTIME_HIGH_RES; | ||
730 | 741 | ||
731 | tick_setup_sched_timer(); | 742 | tick_setup_sched_timer(); |
732 | 743 | ||
@@ -750,7 +761,6 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | |||
750 | return 0; | 761 | return 0; |
751 | } | 762 | } |
752 | static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { } | 763 | static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { } |
753 | static inline void hrtimer_init_timer_hres(struct hrtimer *timer) { } | ||
754 | 764 | ||
755 | #endif /* CONFIG_HIGH_RES_TIMERS */ | 765 | #endif /* CONFIG_HIGH_RES_TIMERS */ |
756 | 766 | ||
@@ -1121,6 +1131,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id, | |||
1121 | enum hrtimer_mode mode) | 1131 | enum hrtimer_mode mode) |
1122 | { | 1132 | { |
1123 | struct hrtimer_cpu_base *cpu_base; | 1133 | struct hrtimer_cpu_base *cpu_base; |
1134 | int base; | ||
1124 | 1135 | ||
1125 | memset(timer, 0, sizeof(struct hrtimer)); | 1136 | memset(timer, 0, sizeof(struct hrtimer)); |
1126 | 1137 | ||
@@ -1129,8 +1140,8 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id, | |||
1129 | if (clock_id == CLOCK_REALTIME && mode != HRTIMER_MODE_ABS) | 1140 | if (clock_id == CLOCK_REALTIME && mode != HRTIMER_MODE_ABS) |
1130 | clock_id = CLOCK_MONOTONIC; | 1141 | clock_id = CLOCK_MONOTONIC; |
1131 | 1142 | ||
1132 | timer->base = &cpu_base->clock_base[clock_id]; | 1143 | base = hrtimer_clockid_to_base(clock_id); |
1133 | hrtimer_init_timer_hres(timer); | 1144 | timer->base = &cpu_base->clock_base[base]; |
1134 | timerqueue_init(&timer->node); | 1145 | timerqueue_init(&timer->node); |
1135 | 1146 | ||
1136 | #ifdef CONFIG_TIMER_STATS | 1147 | #ifdef CONFIG_TIMER_STATS |
@@ -1165,9 +1176,10 @@ EXPORT_SYMBOL_GPL(hrtimer_init); | |||
1165 | int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp) | 1176 | int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp) |
1166 | { | 1177 | { |
1167 | struct hrtimer_cpu_base *cpu_base; | 1178 | struct hrtimer_cpu_base *cpu_base; |
1179 | int base = hrtimer_clockid_to_base(which_clock); | ||
1168 | 1180 | ||
1169 | cpu_base = &__raw_get_cpu_var(hrtimer_bases); | 1181 | cpu_base = &__raw_get_cpu_var(hrtimer_bases); |
1170 | *tp = ktime_to_timespec(cpu_base->clock_base[which_clock].resolution); | 1182 | *tp = ktime_to_timespec(cpu_base->clock_base[base].resolution); |
1171 | 1183 | ||
1172 | return 0; | 1184 | return 0; |
1173 | } | 1185 | } |