* [PATCH v2 0/3] timekeeping: Implement and use read_snapshot() functionality
@ 2026-06-04 9:35 David Woodhouse
2026-06-04 9:35 ` [PATCH v2 1/3] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource David Woodhouse
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: David Woodhouse @ 2026-06-04 9:35 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Paolo Bonzini, Vitaly Kuznetsov, Michael Kelley, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li,
Daniel Lezcano, David Woodhouse, Richard Cochran, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, kvm,
linux-kernel, linux-hyperv, netdev
Commit ca1ec8bfac8c ("timekeeping: Add clocksource read_snapshot()
method and hw_cycles to snapshot") provided a way for clocksources like
kvmclock and Hyper-V to expose the underlying hardware counter value
from which their clock reading is calculated.
This is useful for consumers like the KVM masterclock (when hosting
nested guests), and vmclock which needs the hardware counter value to
calculate time according to the information it's given.
Now that Thomas has beaten my initial proof of concept¹ into shape and
merged it (thanks) here are the two providers and the trivial consumer
case in the vmclock driver, reworked accordingly.
I will rework the other four KVM master clock patches into my kvmclock
series² which I'll rebase on top of tip/timers/ptp in due course.
¹ https://lore.kernel.org/all/20260526230635.136914-1-dwmw2@infradead.org/#r
² https://lore.kernel.org/all/20260509224824.3264567-1-dwmw2@infradead.org/
David Woodhouse (3):
clocksource/hyperv: Implement read_snapshot() for TSC page clocksource
x86/kvmclock: Implement read_snapshot() for kvmclock clocksource
ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing
arch/x86/kernel/kvmclock.c | 36 +++++++++++++++++++++++++++++-------
drivers/clocksource/hyperv_timer.c | 37 +++++++++++++++++++++++++++----------
drivers/ptp/ptp_vmclock.c | 4 ++++
3 files changed, 60 insertions(+), 17 deletions(-)
base-commit: ca1ec8bfac8c95d0fed9e3611ea21400d1f37262
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/3] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource
2026-06-04 9:35 [PATCH v2 0/3] timekeeping: Implement and use read_snapshot() functionality David Woodhouse
@ 2026-06-04 9:35 ` David Woodhouse
2026-06-05 12:30 ` [tip: timers/ptp] " tip-bot2 for David Woodhouse
2026-06-04 9:35 ` [PATCH v2 2/3] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource David Woodhouse
2026-06-04 9:35 ` [PATCH v2 3/3] ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing David Woodhouse
2 siblings, 1 reply; 7+ messages in thread
From: David Woodhouse @ 2026-06-04 9:35 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Paolo Bonzini, Vitaly Kuznetsov, Michael Kelley, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li,
Daniel Lezcano, David Woodhouse, Richard Cochran, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, kvm,
linux-kernel, linux-hyperv, netdev
From: David Woodhouse <dwmw@amazon.co.uk>
Implement the read_snapshot() callback for the Hyper-V TSC page
clocksource. This returns the derived 10MHz reference time (for
timekeeping) while also providing the raw TSC value that was used
to compute it.
When the TSC page is valid, hv_read_tsc_page_tsc() atomically
captures both values from a single RDTSC inside the sequence-counter
protected read. When the TSC page is invalid (sequence == 0), the
hw_csid and hw_cycles are set to zero indicating no value is available.
This enables ktime_get_snapshot_id() to provide the raw TSC to consumers
like KVM's master clock when running nested guests under Hyper-V.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Assisted-by: Kiro:claude-opus-4.6-1m
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
---
drivers/clocksource/hyperv_timer.c | 37 ++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index e9f5034a1bc8..df567795d175 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -444,6 +444,22 @@ static u64 notrace read_hv_clock_tsc_cs(struct clocksource *arg)
return read_hv_clock_tsc();
}
+static u64 notrace read_hv_clock_tsc_cs_snapshot(struct clocksource *arg,
+ struct clocksource_hw_snapshot *chs)
+{
+ u64 time;
+
+ if (hv_read_tsc_page_tsc(tsc_page, &chs->hw_cycles, &time)) {
+ chs->hw_csid = CSID_X86_TSC;
+ } else {
+ chs->hw_cycles = 0;
+ chs->hw_csid = CSID_GENERIC;
+ time = read_hv_clock_msr();
+ }
+
+ return time;
+}
+
static u64 noinstr read_hv_sched_clock_tsc(void)
{
return (read_hv_clock_tsc() - hv_sched_clock_offset) *
@@ -492,18 +508,19 @@ static int hv_cs_enable(struct clocksource *cs)
#endif
static struct clocksource hyperv_cs_tsc = {
- .name = "hyperv_clocksource_tsc_page",
- .rating = 500,
- .read = read_hv_clock_tsc_cs,
- .mask = CLOCKSOURCE_MASK(64),
- .flags = CLOCK_SOURCE_IS_CONTINUOUS,
- .suspend= suspend_hv_clock_tsc,
- .resume = resume_hv_clock_tsc,
+ .name = "hyperv_clocksource_tsc_page",
+ .rating = 500,
+ .read = read_hv_clock_tsc_cs,
+ .read_snapshot = read_hv_clock_tsc_cs_snapshot,
+ .mask = CLOCKSOURCE_MASK(64),
+ .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+ .suspend = suspend_hv_clock_tsc,
+ .resume = resume_hv_clock_tsc,
#ifdef HAVE_VDSO_CLOCKMODE_HVCLOCK
- .enable = hv_cs_enable,
- .vdso_clock_mode = VDSO_CLOCKMODE_HVCLOCK,
+ .enable = hv_cs_enable,
+ .vdso_clock_mode = VDSO_CLOCKMODE_HVCLOCK,
#else
- .vdso_clock_mode = VDSO_CLOCKMODE_NONE,
+ .vdso_clock_mode = VDSO_CLOCKMODE_NONE,
#endif
};
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource
2026-06-04 9:35 [PATCH v2 0/3] timekeeping: Implement and use read_snapshot() functionality David Woodhouse
2026-06-04 9:35 ` [PATCH v2 1/3] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource David Woodhouse
@ 2026-06-04 9:35 ` David Woodhouse
2026-06-05 12:30 ` [tip: timers/ptp] " tip-bot2 for David Woodhouse
2026-06-04 9:35 ` [PATCH v2 3/3] ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing David Woodhouse
2 siblings, 1 reply; 7+ messages in thread
From: David Woodhouse @ 2026-06-04 9:35 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Paolo Bonzini, Vitaly Kuznetsov, Michael Kelley, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li,
Daniel Lezcano, David Woodhouse, Richard Cochran, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, kvm,
linux-kernel, linux-hyperv, netdev
From: David Woodhouse <dwmw@amazon.co.uk>
Implement the read_snapshot() callback for the kvmclock clocksource.
This returns the kvmclock nanosecond value (for timekeeping) while
also providing the raw TSC value that was used to compute it.
The TSC is read inside the pvclock seqlock-protected region, ensuring
the raw TSC and derived kvmclock value are atomically paired.
This enables ktime_get_snapshot_id() to provide the raw TSC to consumers
like the vmclock PTP driver, which currently has to do a separate call
to get_cycles() to obtain a value at *approximately* the same time, to
feed through the vmclock calculation.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Assisted-by: Kiro:claude-opus-4.6-1m
---
arch/x86/kernel/kvmclock.c | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index b5991d53fc0e..cb3d0ca1fa22 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -87,6 +87,27 @@ static u64 kvm_clock_get_cycles(struct clocksource *cs)
return kvm_clock_read();
}
+static u64 kvm_clock_get_cycles_snapshot(struct clocksource *cs,
+ struct clocksource_hw_snapshot *chs)
+{
+ struct pvclock_vcpu_time_info *src;
+ unsigned version;
+ u64 ret, tsc;
+
+ preempt_disable_notrace();
+ src = this_cpu_pvti();
+ do {
+ version = pvclock_read_begin(src);
+ tsc = rdtsc_ordered();
+ ret = __pvclock_read_cycles(src, tsc);
+ } while (pvclock_read_retry(src, version));
+ preempt_enable_notrace();
+
+ chs->hw_cycles = tsc;
+ chs->hw_csid = CSID_X86_TSC;
+ return ret;
+}
+
static noinstr u64 kvm_sched_clock_read(void)
{
return pvclock_clocksource_read_nowd(this_cpu_pvti()) - kvm_sched_clock_offset;
@@ -156,13 +177,14 @@ static int kvm_cs_enable(struct clocksource *cs)
}
static struct clocksource kvm_clock = {
- .name = "kvm-clock",
- .read = kvm_clock_get_cycles,
- .rating = 400,
- .mask = CLOCKSOURCE_MASK(64),
- .flags = CLOCK_SOURCE_IS_CONTINUOUS,
- .id = CSID_X86_KVM_CLK,
- .enable = kvm_cs_enable,
+ .name = "kvm-clock",
+ .read = kvm_clock_get_cycles,
+ .read_snapshot = kvm_clock_get_cycles_snapshot,
+ .rating = 400,
+ .mask = CLOCKSOURCE_MASK(64),
+ .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+ .id = CSID_X86_KVM_CLK,
+ .enable = kvm_cs_enable,
};
static void kvm_register_clock(char *txt)
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing
2026-06-04 9:35 [PATCH v2 0/3] timekeeping: Implement and use read_snapshot() functionality David Woodhouse
2026-06-04 9:35 ` [PATCH v2 1/3] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource David Woodhouse
2026-06-04 9:35 ` [PATCH v2 2/3] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource David Woodhouse
@ 2026-06-04 9:35 ` David Woodhouse
2026-06-05 12:30 ` [tip: timers/ptp] " tip-bot2 for David Woodhouse
2 siblings, 1 reply; 7+ messages in thread
From: David Woodhouse @ 2026-06-04 9:35 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Paolo Bonzini, Vitaly Kuznetsov, Michael Kelley, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li,
Daniel Lezcano, David Woodhouse, Richard Cochran, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, kvm,
linux-kernel, linux-hyperv, netdev
From: David Woodhouse <dwmw@amazon.co.uk>
When the system clocksource is kvmclock or Hyper-V (not the TSC
directly), vmclock_get_crosststamp() previously fell through to a
separate get_cycles() call, losing the atomic pairing between the
system time snapshot and the TSC reading.
Now that ktime_get_snapshot_id() populates hw_cycles with the
underlying TSC value for derived clocksources, use it when available.
This gives a perfect (system_time, tsc) pairing for the device time
calculation.
The SUPPORT_KVMCLOCK wrapper is still needed to convert the TSC into
kvmclock nanoseconds for system_counter->cycles, because otherwise
get_device_system_crosststamp() can't interpret the result against
the system clock.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Assisted-by: Kiro:claude-opus-4.6-1m
---
drivers/ptp/ptp_vmclock.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index d6a5a533164a..eebdcd5ebc08 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -140,6 +140,10 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,
if (sts->pre_sts.cs_id == st->cs_id) {
cycle = sts->pre_sts.cycles;
sts->post_sts = sts->pre_sts;
+ } else if (sts->pre_sts.hw_csid == st->cs_id &&
+ sts->pre_sts.hw_cycles) {
+ cycle = sts->pre_sts.hw_cycles;
+ sts->post_sts = sts->pre_sts;
} else {
cycle = get_cycles();
ptp_read_system_postts(sts);
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip: timers/ptp] ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing
2026-06-04 9:35 ` [PATCH v2 3/3] ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing David Woodhouse
@ 2026-06-05 12:30 ` tip-bot2 for David Woodhouse
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for David Woodhouse @ 2026-06-05 12:30 UTC (permalink / raw)
To: linux-tip-commits; +Cc: David Woodhouse, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: bc484a5096732cd858771cccd3164ec985bdc03d
Gitweb: https://git.kernel.org/tip/bc484a5096732cd858771cccd3164ec985bdc03d
Author: David Woodhouse <dwmw@amazon.co.uk>
AuthorDate: Thu, 04 Jun 2026 10:35:18 +01:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Fri, 05 Jun 2026 14:25:03 +02:00
ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing
When the system clocksource is kvmclock or Hyper-V (not the TSC directly),
vmclock_get_crosststamp() falls through to a separate get_cycles() call,
losing the atomic pairing between the system time snapshot and the TSC
reading.
Now that ktime_get_snapshot_id() populates hw_cycles with the underlying
TSC value for derived clocksources, use it when available. This gives a
perfect (system_time, tsc) pairing for the device time calculation.
The SUPPORT_KVMCLOCK wrapper is still needed to convert the TSC into
kvmclock nanoseconds for system_counter->cycles, because otherwise
get_device_system_crosststamp() can't interpret the result against the
system clock.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Assisted-by: Kiro:claude-opus-4.6-1m
Link: https://patch.msgid.link/20260604095755.64849-4-dwmw2@infradead.org
---
drivers/ptp/ptp_vmclock.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index d6a5a53..eebdcd5 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -140,6 +140,10 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,
if (sts->pre_sts.cs_id == st->cs_id) {
cycle = sts->pre_sts.cycles;
sts->post_sts = sts->pre_sts;
+ } else if (sts->pre_sts.hw_csid == st->cs_id &&
+ sts->pre_sts.hw_cycles) {
+ cycle = sts->pre_sts.hw_cycles;
+ sts->post_sts = sts->pre_sts;
} else {
cycle = get_cycles();
ptp_read_system_postts(sts);
^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip: timers/ptp] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource
2026-06-04 9:35 ` [PATCH v2 2/3] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource David Woodhouse
@ 2026-06-05 12:30 ` tip-bot2 for David Woodhouse
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for David Woodhouse @ 2026-06-05 12:30 UTC (permalink / raw)
To: linux-tip-commits; +Cc: David Woodhouse, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 19fa3e50644d2d47fca713b0df640f67dcd26634
Gitweb: https://git.kernel.org/tip/19fa3e50644d2d47fca713b0df640f67dcd26634
Author: David Woodhouse <dwmw@amazon.co.uk>
AuthorDate: Thu, 04 Jun 2026 10:35:17 +01:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Fri, 05 Jun 2026 14:25:03 +02:00
x86/kvmclock: Implement read_snapshot() for kvmclock clocksource
Implement the read_snapshot() callback for the kvmclock clocksource. This
returns the kvmclock nanosecond value (for timekeeping) while also
providing the raw TSC value that was used to compute it.
The TSC is read inside the pvclock seqlock-protected region, ensuring the
raw TSC and derived kvmclock value are atomically paired.
This enables ktime_get_snapshot_id() to provide the raw TSC to consumers
like the vmclock PTP driver, which currently has to do a separate call to
get_cycles() to obtain a value at *approximately* the same time, to feed
through the vmclock calculation.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Assisted-by: Kiro:claude-opus-4.6-1m
Link: https://patch.msgid.link/20260604095755.64849-3-dwmw2@infradead.org
---
arch/x86/kernel/kvmclock.c | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index b5991d5..cb3d0ca 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -87,6 +87,27 @@ static u64 kvm_clock_get_cycles(struct clocksource *cs)
return kvm_clock_read();
}
+static u64 kvm_clock_get_cycles_snapshot(struct clocksource *cs,
+ struct clocksource_hw_snapshot *chs)
+{
+ struct pvclock_vcpu_time_info *src;
+ unsigned version;
+ u64 ret, tsc;
+
+ preempt_disable_notrace();
+ src = this_cpu_pvti();
+ do {
+ version = pvclock_read_begin(src);
+ tsc = rdtsc_ordered();
+ ret = __pvclock_read_cycles(src, tsc);
+ } while (pvclock_read_retry(src, version));
+ preempt_enable_notrace();
+
+ chs->hw_cycles = tsc;
+ chs->hw_csid = CSID_X86_TSC;
+ return ret;
+}
+
static noinstr u64 kvm_sched_clock_read(void)
{
return pvclock_clocksource_read_nowd(this_cpu_pvti()) - kvm_sched_clock_offset;
@@ -156,13 +177,14 @@ static int kvm_cs_enable(struct clocksource *cs)
}
static struct clocksource kvm_clock = {
- .name = "kvm-clock",
- .read = kvm_clock_get_cycles,
- .rating = 400,
- .mask = CLOCKSOURCE_MASK(64),
- .flags = CLOCK_SOURCE_IS_CONTINUOUS,
- .id = CSID_X86_KVM_CLK,
- .enable = kvm_cs_enable,
+ .name = "kvm-clock",
+ .read = kvm_clock_get_cycles,
+ .read_snapshot = kvm_clock_get_cycles_snapshot,
+ .rating = 400,
+ .mask = CLOCKSOURCE_MASK(64),
+ .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+ .id = CSID_X86_KVM_CLK,
+ .enable = kvm_cs_enable,
};
static void kvm_register_clock(char *txt)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip: timers/ptp] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource
2026-06-04 9:35 ` [PATCH v2 1/3] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource David Woodhouse
@ 2026-06-05 12:30 ` tip-bot2 for David Woodhouse
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for David Woodhouse @ 2026-06-05 12:30 UTC (permalink / raw)
To: linux-tip-commits
Cc: David Woodhouse, Thomas Gleixner, Michael Kelley, x86, linux-kernel
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: c51100f9e26857f2b2376d5cd657a15f52b9e05c
Gitweb: https://git.kernel.org/tip/c51100f9e26857f2b2376d5cd657a15f52b9e05c
Author: David Woodhouse <dwmw@amazon.co.uk>
AuthorDate: Thu, 04 Jun 2026 10:35:16 +01:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Fri, 05 Jun 2026 14:25:03 +02:00
clocksource/hyperv: Implement read_snapshot() for TSC page clocksource
Implement the read_snapshot() callback for the Hyper-V TSC page clock-
source. This returns the derived 10MHz reference time (for timekeeping)
while also providing the raw TSC value that was used to compute it.
When the TSC page is valid, hv_read_tsc_page_tsc() atomically captures both
values from a single RDTSC inside the sequence-counter protected read. When
the TSC page is invalid (sequence == 0), the hw_csid and hw_cycles are set
to zero indicating no value is available.
This enables ktime_get_snapshot_id() to provide the raw TSC to consumers
like KVM's master clock when running nested guests under Hyper-V.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Assisted-by: Kiro:claude-opus-4.6-1m
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://patch.msgid.link/20260604095755.64849-2-dwmw2@infradead.org
---
drivers/clocksource/hyperv_timer.c | 37 +++++++++++++++++++++--------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index e9f5034..df56779 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -444,6 +444,22 @@ static u64 notrace read_hv_clock_tsc_cs(struct clocksource *arg)
return read_hv_clock_tsc();
}
+static u64 notrace read_hv_clock_tsc_cs_snapshot(struct clocksource *arg,
+ struct clocksource_hw_snapshot *chs)
+{
+ u64 time;
+
+ if (hv_read_tsc_page_tsc(tsc_page, &chs->hw_cycles, &time)) {
+ chs->hw_csid = CSID_X86_TSC;
+ } else {
+ chs->hw_cycles = 0;
+ chs->hw_csid = CSID_GENERIC;
+ time = read_hv_clock_msr();
+ }
+
+ return time;
+}
+
static u64 noinstr read_hv_sched_clock_tsc(void)
{
return (read_hv_clock_tsc() - hv_sched_clock_offset) *
@@ -492,18 +508,19 @@ static int hv_cs_enable(struct clocksource *cs)
#endif
static struct clocksource hyperv_cs_tsc = {
- .name = "hyperv_clocksource_tsc_page",
- .rating = 500,
- .read = read_hv_clock_tsc_cs,
- .mask = CLOCKSOURCE_MASK(64),
- .flags = CLOCK_SOURCE_IS_CONTINUOUS,
- .suspend= suspend_hv_clock_tsc,
- .resume = resume_hv_clock_tsc,
+ .name = "hyperv_clocksource_tsc_page",
+ .rating = 500,
+ .read = read_hv_clock_tsc_cs,
+ .read_snapshot = read_hv_clock_tsc_cs_snapshot,
+ .mask = CLOCKSOURCE_MASK(64),
+ .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+ .suspend = suspend_hv_clock_tsc,
+ .resume = resume_hv_clock_tsc,
#ifdef HAVE_VDSO_CLOCKMODE_HVCLOCK
- .enable = hv_cs_enable,
- .vdso_clock_mode = VDSO_CLOCKMODE_HVCLOCK,
+ .enable = hv_cs_enable,
+ .vdso_clock_mode = VDSO_CLOCKMODE_HVCLOCK,
#else
- .vdso_clock_mode = VDSO_CLOCKMODE_NONE,
+ .vdso_clock_mode = VDSO_CLOCKMODE_NONE,
#endif
};
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-06-05 12:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-04 9:35 [PATCH v2 0/3] timekeeping: Implement and use read_snapshot() functionality David Woodhouse
2026-06-04 9:35 ` [PATCH v2 1/3] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource David Woodhouse
2026-06-05 12:30 ` [tip: timers/ptp] " tip-bot2 for David Woodhouse
2026-06-04 9:35 ` [PATCH v2 2/3] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource David Woodhouse
2026-06-05 12:30 ` [tip: timers/ptp] " tip-bot2 for David Woodhouse
2026-06-04 9:35 ` [PATCH v2 3/3] ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing David Woodhouse
2026-06-05 12:30 ` [tip: timers/ptp] " tip-bot2 for David Woodhouse
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®