aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clocksource/arm_arch_timer.c
diff options
context:
space:
mode:
authorChristoffer Dall <cdall@linaro.org>2017-07-05 05:04:28 -0400
committerChristoffer Dall <christoffer.dall@linaro.org>2017-11-06 10:23:09 -0500
commite6d68b00e989f27116fd8575f1f9c217873e9b0e (patch)
treebac611b097d5e9a7b5e69aea4e2a44ab9f0521e3 /drivers/clocksource/arm_arch_timer.c
parentf2e600c149fda3453344f89c7e9353fe278ebd32 (diff)
arm64: Use physical counter for in-kernel reads when booted in EL2
Using the physical counter allows KVM to retain the offset between the virtual and physical counter as long as it is actively running a VCPU. As soon as a VCPU is released, another thread is scheduled or we start running userspace applications, we reset the offset to 0, so that userspace accessing the virtual timer can still read the virtual counter and get the same view of time as the kernel. This opens up potential improvements for KVM performance, but we have to make a few adjustments to preserve system consistency. Currently get_cycles() is hardwired to arch_counter_get_cntvct() on arm64, but as we move to using the physical timer for the in-kernel time-keeping on systems that boot in EL2, we should use the same counter for get_cycles() as for other in-kernel timekeeping operations. Similarly, implementations of arch_timer_set_next_event_phys() is modified to use the counter specific to the timer being programmed. VHE kernels or kernels continuing to use the virtual timer are unaffected. Cc: Will Deacon <will.deacon@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Acked-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <cdall@linaro.org>
Diffstat (limited to 'drivers/clocksource/arm_arch_timer.c')
-rw-r--r--drivers/clocksource/arm_arch_timer.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index ff8f8a177156..061476e92db7 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -158,6 +158,7 @@ u32 arch_timer_reg_read(int access, enum arch_timer_reg reg,
158 * if we don't have the cp15 accessors we won't have a problem. 158 * if we don't have the cp15 accessors we won't have a problem.
159 */ 159 */
160u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct; 160u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct;
161EXPORT_SYMBOL_GPL(arch_timer_read_counter);
161 162
162static u64 arch_counter_read(struct clocksource *cs) 163static u64 arch_counter_read(struct clocksource *cs)
163{ 164{
@@ -329,16 +330,19 @@ static void erratum_set_next_event_tval_generic(const int access, unsigned long
329 struct clock_event_device *clk) 330 struct clock_event_device *clk)
330{ 331{
331 unsigned long ctrl; 332 unsigned long ctrl;
332 u64 cval = evt + arch_counter_get_cntvct(); 333 u64 cval;
333 334
334 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, clk); 335 ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, clk);
335 ctrl |= ARCH_TIMER_CTRL_ENABLE; 336 ctrl |= ARCH_TIMER_CTRL_ENABLE;
336 ctrl &= ~ARCH_TIMER_CTRL_IT_MASK; 337 ctrl &= ~ARCH_TIMER_CTRL_IT_MASK;
337 338
338 if (access == ARCH_TIMER_PHYS_ACCESS) 339 if (access == ARCH_TIMER_PHYS_ACCESS) {
340 cval = evt + arch_counter_get_cntpct();
339 write_sysreg(cval, cntp_cval_el0); 341 write_sysreg(cval, cntp_cval_el0);
340 else 342 } else {
343 cval = evt + arch_counter_get_cntvct();
341 write_sysreg(cval, cntv_cval_el0); 344 write_sysreg(cval, cntv_cval_el0);
345 }
342 346
343 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk); 347 arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk);
344} 348}
@@ -913,7 +917,7 @@ static void __init arch_counter_register(unsigned type)
913 917
914 /* Register the CP15 based counter if we have one */ 918 /* Register the CP15 based counter if we have one */
915 if (type & ARCH_TIMER_TYPE_CP15) { 919 if (type & ARCH_TIMER_TYPE_CP15) {
916 if (IS_ENABLED(CONFIG_ARM64) || 920 if ((IS_ENABLED(CONFIG_ARM64) && !is_hyp_mode_available()) ||
917 arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI) 921 arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI)
918 arch_timer_read_counter = arch_counter_get_cntvct; 922 arch_timer_read_counter = arch_counter_get_cntvct;
919 else 923 else