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 /drivers/clocksource | |
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>
Diffstat (limited to 'drivers/clocksource')
-rw-r--r-- | drivers/clocksource/arm_arch_timer.c | 23 |
1 files changed, 5 insertions, 18 deletions
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 | } |