From: Michael Kelley <mikelley@microsoft.com>
To: sthemmin@microsoft.com, kys@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, daniel.lezcano@linaro.org,
tglx@linutronix.de, arnd@arndb.de, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org
Cc: mikelley@microsoft.com, linux-arch@vger.kernel.org
Subject: [PATCH 1/1] drivers: hv: Decouple Hyper-V clock/timer code from VMbus drivers
Date: Tue, 13 Jul 2021 17:01:46 -0700 [thread overview]
Message-ID: <1626220906-22629-1-git-send-email-mikelley@microsoft.com> (raw)
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 <mikelley@microsoft.com>
---
drivers/clocksource/hyperv_timer.c | 3 ---
drivers/hv/hv_common.c | 14 ++++++++++++++
drivers/hv/hv_util.c | 5 -----
include/asm-generic/mshyperv.h | 2 ++
include/clocksource/hyperv_timer.h | 11 +++++++++--
5 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index d6ece7b..ff188ab 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -361,9 +361,6 @@ void hv_stimer_global_cleanup(void)
* Hyper-V and 32-bit x86. The TSC reference page version is preferred.
*/
-u64 (*hv_read_reference_counter)(void);
-EXPORT_SYMBOL_GPL(hv_read_reference_counter);
-
static union {
struct ms_hyperv_tsc_page page;
u8 reserved[PAGE_SIZE];
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 3ff8446..e213433 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -215,6 +215,20 @@ bool hv_is_hibernation_supported(void)
}
EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);
+/*
+ * Default function to read the Hyper-V reference counter, independent
+ * of whether Hyper-V enlightened clocks/timers are being used. But on
+ * architectures where it is used, Hyper-V enlightenment code in
+ * hyperv_timer.c may override this function.
+ */
+static u64 __hv_read_ref_counter(void)
+{
+ return hv_get_register(HV_REGISTER_TIME_REF_COUNT);
+}
+
+u64 (*hv_read_reference_counter)(void) = __hv_read_ref_counter;
+EXPORT_SYMBOL_GPL(hv_read_reference_counter);
+
/* These __weak functions provide default "no-op" behavior and
* may be overridden by architecture specific versions. Architectures
* for which the default "no-op" behavior is sufficient can leave
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index 136576c..835e603 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -17,7 +17,6 @@
#include <linux/hyperv.h>
#include <linux/clockchips.h>
#include <linux/ptp_clock_kernel.h>
-#include <clocksource/hyperv_timer.h>
#include <asm/mshyperv.h>
#include "hyperv_vmbus.h"
@@ -735,10 +734,6 @@ static int hv_ptp_gettime(struct ptp_clock_info *info, struct timespec64 *ts)
static int hv_timesync_init(struct hv_util_service *srv)
{
- /* TimeSync requires Hyper-V clocksource. */
- if (!hv_read_reference_counter)
- return -ENODEV;
-
spin_lock_init(&host_ts.lock);
INIT_WORK(&adj_time_work, hv_set_host_time);
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index 2a187fe..f6245fe 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -166,6 +166,8 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
extern u32 *hv_vp_index;
extern u32 hv_max_vp_index;
+extern u64 (*hv_read_reference_counter)(void);
+
/* Sentinel value for an uninitialized entry in hv_vp_index array */
#define VP_INVAL U32_MAX
diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyperv_timer.h
index b6774aa..1c566c7 100644
--- a/include/clocksource/hyperv_timer.h
+++ b/include/clocksource/hyperv_timer.h
@@ -20,6 +20,8 @@
#define HV_MAX_MAX_DELTA_TICKS 0xffffffff
#define HV_MIN_DELTA_TICKS 1
+#ifdef CONFIG_HYPERV_TIMER
+
/* Routines called by the VMbus driver */
extern int hv_stimer_alloc(bool have_percpu_irqs);
extern int hv_stimer_cleanup(unsigned int cpu);
@@ -28,8 +30,6 @@
extern void hv_stimer_global_cleanup(void);
extern void hv_stimer0_isr(void);
-#ifdef CONFIG_HYPERV_TIMER
-extern u64 (*hv_read_reference_counter)(void);
extern void hv_init_clocksource(void);
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,
{
return U64_MAX;
}
+
+static inline int hv_stimer_cleanup(unsigned int cpu) {return 0; }
+static inline void hv_stimer_legacy_init(unsigned int cpu, int sint) {}
+static inline void hv_stimer_legacy_cleanup(unsigned int cpu) {}
+static inline void hv_stimer_global_cleanup(void) {}
+static inline void hv_stimer0_isr(void) {}
+
#endif /* CONFIG_HYPERV_TIMER */
#endif
--
1.8.3.1
next reply other threads:[~2021-07-14 0:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 0:01 Michael Kelley [this message]
2021-07-14 9:52 ` [PATCH 1/1] drivers: hv: Decouple Hyper-V clock/timer code from VMbus drivers Wei Liu
2021-07-19 9:24 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1626220906-22629-1-git-send-email-mikelley@microsoft.com \
--to=mikelley@microsoft.com \
--cc=arnd@arndb.de \
--cc=daniel.lezcano@linaro.org \
--cc=decui@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sthemmin@microsoft.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).