Similar to x86, add a new vclock_mode VCLOCK_HVCLOCK, and reuse the hv_read_tsc_page() for userspace to read tsc page clocksource. Signed-off-by: Boqun Feng (Microsoft) <boqun.feng@xxxxxxxxx> --- arch/arm64/include/asm/clocksource.h | 3 ++- arch/arm64/include/asm/mshyperv.h | 2 +- arch/arm64/include/asm/vdso/gettimeofday.h | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/clocksource.h b/arch/arm64/include/asm/clocksource.h index fbe80057468c..c6acd45fe748 100644 --- a/arch/arm64/include/asm/clocksource.h +++ b/arch/arm64/include/asm/clocksource.h @@ -4,7 +4,8 @@ #define VCLOCK_NONE 0 /* No vDSO clock available. */ #define VCLOCK_CNTVCT 1 /* vDSO should use cntvcnt */ -#define VCLOCK_MAX 1 +#define VCLOCK_HVCLOCK 2 /* vDSO should use vread_hvclock() */ +#define VCLOCK_MAX 2 struct arch_clocksource_data { int vclock_mode; diff --git a/arch/arm64/include/asm/mshyperv.h b/arch/arm64/include/asm/mshyperv.h index 0afb00e3501d..7c85dd816dca 100644 --- a/arch/arm64/include/asm/mshyperv.h +++ b/arch/arm64/include/asm/mshyperv.h @@ -90,7 +90,7 @@ extern void hv_get_vpreg_128(u32 reg, struct hv_get_vp_register_output *result); #define hv_set_reference_tsc(val) \ hv_set_vpreg(HV_REGISTER_REFERENCE_TSC, val) #define hv_set_clocksource_vdso(val) \ - ((val).archdata.vclock_mode = VCLOCK_NONE) + ((val).archdata.vclock_mode = VCLOCK_HVCLOCK) #if IS_ENABLED(CONFIG_HYPERV) #define hv_enable_stimer0_percpu_irq(irq) enable_percpu_irq(irq, 0) diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h index e6e3fe0488c7..7e689b903f4d 100644 --- a/arch/arm64/include/asm/vdso/gettimeofday.h +++ b/arch/arm64/include/asm/vdso/gettimeofday.h @@ -67,6 +67,20 @@ int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) return ret; } +#ifdef CONFIG_HYPERV_TIMER +/* This will override the default hv_get_raw_timer() */ +#define hv_get_raw_timer() __arch_counter_get_cntvct() +#include <clocksource/hyperv_timer.h> + +extern struct ms_hyperv_tsc_page +_hvclock_page __attribute__((visibility("hidden"))); + +static u64 vread_hvclock(void) +{ + return hv_read_tsc_page(&_hvclock_page); +} +#endif + static __always_inline u64 __arch_get_hw_counter(s32 clock_mode) { u64 res; @@ -78,6 +92,11 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode) if (clock_mode == VCLOCK_NONE) return __VDSO_USE_SYSCALL; +#ifdef CONFIG_HYPERV_TIMER + if (likely(clock_mode == VCLOCK_HVCLOCK)) + return vread_hvclock(); +#endif + /* * This isb() is required to prevent that the counter value * is speculated. -- 2.24.0