Skip to content

Commit 31e5e64

Browse files
kelleymhliuw
authored andcommitted
drivers: hv: Decouple Hyper-V clock/timer code from VMbus drivers
Hyper-V clock/timer code in hyperv_timer.c is mostly independent from other VMbus drivers, but building for ARM64 without hyperv_timer.c shows some remaining entanglements. A default implementation of hv_read_reference_counter can just read a Hyper-V synthetic register and be independent of hyperv_timer.c, so move this code out and into hv_common.c. Then it can be used by the timesync driver even if hyperv_timer.c isn't built on a particular architecture. If hyperv_timer.c *is* built, it can override with a faster implementation. Also provide stubs for stimer functions called by the VMbus driver when hyperv_timer.c isn't built. No functional changes. Signed-off-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent 5f92b45 commit 31e5e64

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

drivers/clocksource/hyperv_timer.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,6 @@ EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup);
361361
* Hyper-V and 32-bit x86. The TSC reference page version is preferred.
362362
*/
363363

364-
u64 (*hv_read_reference_counter)(void);
365-
EXPORT_SYMBOL_GPL(hv_read_reference_counter);
366-
367364
static union {
368365
struct ms_hyperv_tsc_page page;
369366
u8 reserved[PAGE_SIZE];

drivers/hv/hv_common.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ bool hv_is_hibernation_supported(void)
222222
}
223223
EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);
224224

225+
/*
226+
* Default function to read the Hyper-V reference counter, independent
227+
* of whether Hyper-V enlightened clocks/timers are being used. But on
228+
* architectures where it is used, Hyper-V enlightenment code in
229+
* hyperv_timer.c may override this function.
230+
*/
231+
static u64 __hv_read_ref_counter(void)
232+
{
233+
return hv_get_register(HV_REGISTER_TIME_REF_COUNT);
234+
}
235+
236+
u64 (*hv_read_reference_counter)(void) = __hv_read_ref_counter;
237+
EXPORT_SYMBOL_GPL(hv_read_reference_counter);
238+
225239
/* These __weak functions provide default "no-op" behavior and
226240
* may be overridden by architecture specific versions. Architectures
227241
* for which the default "no-op" behavior is sufficient can leave

drivers/hv/hv_util.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <linux/hyperv.h>
1818
#include <linux/clockchips.h>
1919
#include <linux/ptp_clock_kernel.h>
20-
#include <clocksource/hyperv_timer.h>
2120
#include <asm/mshyperv.h>
2221

2322
#include "hyperv_vmbus.h"
@@ -735,10 +734,6 @@ static struct ptp_clock *hv_ptp_clock;
735734

736735
static int hv_timesync_init(struct hv_util_service *srv)
737736
{
738-
/* TimeSync requires Hyper-V clocksource. */
739-
if (!hv_read_reference_counter)
740-
return -ENODEV;
741-
742737
spin_lock_init(&host_ts.lock);
743738

744739
INIT_WORK(&adj_time_work, hv_set_host_time);

include/asm-generic/mshyperv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ extern bool hv_root_partition;
167167
extern u32 *hv_vp_index;
168168
extern u32 hv_max_vp_index;
169169

170+
extern u64 (*hv_read_reference_counter)(void);
171+
170172
/* Sentinel value for an uninitialized entry in hv_vp_index array */
171173
#define VP_INVAL U32_MAX
172174

include/clocksource/hyperv_timer.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#define HV_MAX_MAX_DELTA_TICKS 0xffffffff
2121
#define HV_MIN_DELTA_TICKS 1
2222

23+
#ifdef CONFIG_HYPERV_TIMER
24+
2325
/* Routines called by the VMbus driver */
2426
extern int hv_stimer_alloc(bool have_percpu_irqs);
2527
extern int hv_stimer_cleanup(unsigned int cpu);
@@ -28,8 +30,6 @@ extern void hv_stimer_legacy_cleanup(unsigned int cpu);
2830
extern void hv_stimer_global_cleanup(void);
2931
extern void hv_stimer0_isr(void);
3032

31-
#ifdef CONFIG_HYPERV_TIMER
32-
extern u64 (*hv_read_reference_counter)(void);
3333
extern void hv_init_clocksource(void);
3434

3535
extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void);
@@ -100,6 +100,13 @@ static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg,
100100
{
101101
return U64_MAX;
102102
}
103+
104+
static inline int hv_stimer_cleanup(unsigned int cpu) { return 0; }
105+
static inline void hv_stimer_legacy_init(unsigned int cpu, int sint) {}
106+
static inline void hv_stimer_legacy_cleanup(unsigned int cpu) {}
107+
static inline void hv_stimer_global_cleanup(void) {}
108+
static inline void hv_stimer0_isr(void) {}
109+
103110
#endif /* CONFIG_HYPERV_TIMER */
104111

105112
#endif

0 commit comments

Comments
 (0)