diff options
| author | Mark Rutland <mark.rutland@arm.com> | 2013-01-30 12:51:26 -0500 |
|---|---|---|
| committer | Mark Rutland <mark.rutland@arm.com> | 2013-06-07 05:20:28 -0400 |
| commit | 0d651e4e65e96989f72236bf83bd4c6e55eb6ce4 (patch) | |
| tree | 85897795e32a2cc107b9c8bda0b4641785b38e8d | |
| parent | f793c23ebbe5afd1cabf4a42a3a297022213756f (diff) | |
clocksource: arch_timer: use virtual counters
Switching between reading the virtual or physical counters is
problematic, as some core code wants a view of time before we're fully
set up. Using a function pointer and switching the source after the
first read can make time appear to go backwards, and having a check in
the read function is an unfortunate block on what we want to be a fast
path.
Instead, this patch makes us always use the virtual counters. If we're a
guest, or don't have hyp mode, we'll use the virtual timers, and as such
don't care about CNTVOFF as long as it doesn't change in such a way as
to make time appear to travel backwards. As the guest will use the
virtual timers, a (potential) KVM host must use the physical timers
(which can wake up the host even if they fire while a guest is
executing), and hence a host must have CNTVOFF set to zero so as to have
a consistent view of time between the physical timers and virtual
counters.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Cc: Rob Herring <rob.herring@calxeda.com>
| -rw-r--r-- | arch/arm/include/asm/arch_timer.h | 9 | ||||
| -rw-r--r-- | arch/arm64/include/asm/arch_timer.h | 10 | ||||
| -rw-r--r-- | drivers/clocksource/arm_arch_timer.c | 23 | ||||
| -rw-r--r-- | include/clocksource/arm_arch_timer.h | 2 |
4 files changed, 6 insertions, 38 deletions
diff --git a/arch/arm/include/asm/arch_timer.h b/arch/arm/include/asm/arch_timer.h index 7c1bfc0aea0c..accefe099182 100644 --- a/arch/arm/include/asm/arch_timer.h +++ b/arch/arm/include/asm/arch_timer.h | |||
| @@ -80,15 +80,6 @@ static inline u32 arch_timer_get_cntfrq(void) | |||
| 80 | return val; | 80 | return val; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | static inline u64 arch_counter_get_cntpct(void) | ||
| 84 | { | ||
| 85 | u64 cval; | ||
| 86 | |||
| 87 | isb(); | ||
| 88 | asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (cval)); | ||
| 89 | return cval; | ||
| 90 | } | ||
| 91 | |||
| 92 | static inline u64 arch_counter_get_cntvct(void) | 83 | static inline u64 arch_counter_get_cntvct(void) |
| 93 | { | 84 | { |
| 94 | u64 cval; | 85 | u64 cval; |
diff --git a/arch/arm64/include/asm/arch_timer.h b/arch/arm64/include/asm/arch_timer.h index bf6ab242f047..d56ed11ba9a3 100644 --- a/arch/arm64/include/asm/arch_timer.h +++ b/arch/arm64/include/asm/arch_timer.h | |||
| @@ -110,16 +110,6 @@ static inline void __cpuinit arch_counter_set_user_access(void) | |||
| 110 | asm volatile("msr cntkctl_el1, %0" : : "r" (cntkctl)); | 110 | asm volatile("msr cntkctl_el1, %0" : : "r" (cntkctl)); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | static inline u64 arch_counter_get_cntpct(void) | ||
| 114 | { | ||
| 115 | u64 cval; | ||
| 116 | |||
| 117 | isb(); | ||
| 118 | asm volatile("mrs %0, cntpct_el0" : "=r" (cval)); | ||
| 119 | |||
| 120 | return cval; | ||
| 121 | } | ||
| 122 | |||
| 123 | static inline u64 arch_counter_get_cntvct(void) | 113 | static inline u64 arch_counter_get_cntvct(void) |
| 124 | { | 114 | { |
| 125 | u64 cval; | 115 | u64 cval; |
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index a2b254189782..053d846ab5b1 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c | |||
| @@ -186,27 +186,19 @@ u32 arch_timer_get_rate(void) | |||
| 186 | return arch_timer_rate; | 186 | return arch_timer_rate; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | /* | 189 | u64 arch_timer_read_counter(void) |
| 190 | * Some external users of arch_timer_read_counter (e.g. sched_clock) may try to | ||
| 191 | * call it before it has been initialised. Rather than incur a performance | ||
| 192 | * penalty checking for initialisation, provide a default implementation that | ||
| 193 | * won't lead to time appearing to jump backwards. | ||
| 194 | */ | ||
| 195 | static u64 arch_timer_read_zero(void) | ||
| 196 | { | 190 | { |
| 197 | return 0; | 191 | return arch_counter_get_cntvct(); |
| 198 | } | 192 | } |
| 199 | 193 | ||
| 200 | u64 (*arch_timer_read_counter)(void) = arch_timer_read_zero; | ||
| 201 | |||
| 202 | static cycle_t arch_counter_read(struct clocksource *cs) | 194 | static cycle_t arch_counter_read(struct clocksource *cs) |
| 203 | { | 195 | { |
| 204 | return arch_timer_read_counter(); | 196 | return arch_counter_get_cntvct(); |
| 205 | } | 197 | } |
| 206 | 198 | ||
| 207 | static cycle_t arch_counter_read_cc(const struct cyclecounter *cc) | 199 | static cycle_t arch_counter_read_cc(const struct cyclecounter *cc) |
| 208 | { | 200 | { |
| 209 | return arch_timer_read_counter(); | 201 | return arch_counter_get_cntvct(); |
| 210 | } | 202 | } |
| 211 | 203 | ||
| 212 | static struct clocksource clocksource_counter = { | 204 | static struct clocksource clocksource_counter = { |
| @@ -287,7 +279,7 @@ static int __init arch_timer_register(void) | |||
| 287 | cyclecounter.mult = clocksource_counter.mult; | 279 | cyclecounter.mult = clocksource_counter.mult; |
| 288 | cyclecounter.shift = clocksource_counter.shift; | 280 | cyclecounter.shift = clocksource_counter.shift; |
| 289 | timecounter_init(&timecounter, &cyclecounter, | 281 | timecounter_init(&timecounter, &cyclecounter, |
| 290 | arch_counter_get_cntpct()); | 282 | arch_counter_get_cntvct()); |
| 291 | 283 | ||
| 292 | if (arch_timer_use_virtual) { | 284 | if (arch_timer_use_virtual) { |
| 293 | ppi = arch_timer_ppi[VIRT_PPI]; | 285 | ppi = arch_timer_ppi[VIRT_PPI]; |
| @@ -376,11 +368,6 @@ static void __init arch_timer_init(struct device_node *np) | |||
| 376 | } | 368 | } |
| 377 | } | 369 | } |
| 378 | 370 | ||
| 379 | if (arch_timer_use_virtual) | ||
| 380 | arch_timer_read_counter = arch_counter_get_cntvct; | ||
| 381 | else | ||
| 382 | arch_timer_read_counter = arch_counter_get_cntpct; | ||
| 383 | |||
| 384 | arch_timer_register(); | 371 | arch_timer_register(); |
| 385 | arch_timer_arch_init(); | 372 | arch_timer_arch_init(); |
| 386 | } | 373 | } |
diff --git a/include/clocksource/arm_arch_timer.h b/include/clocksource/arm_arch_timer.h index e6c9c4cc9b23..c463ce990c48 100644 --- a/include/clocksource/arm_arch_timer.h +++ b/include/clocksource/arm_arch_timer.h | |||
| @@ -32,7 +32,7 @@ | |||
| 32 | #ifdef CONFIG_ARM_ARCH_TIMER | 32 | #ifdef CONFIG_ARM_ARCH_TIMER |
| 33 | 33 | ||
| 34 | extern u32 arch_timer_get_rate(void); | 34 | extern u32 arch_timer_get_rate(void); |
| 35 | extern u64 (*arch_timer_read_counter)(void); | 35 | extern u64 arch_timer_read_counter(void); |
| 36 | extern struct timecounter *arch_timer_get_timecounter(void); | 36 | extern struct timecounter *arch_timer_get_timecounter(void); |
| 37 | 37 | ||
| 38 | #else | 38 | #else |
