mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for David Woodhouse" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: David Woodhouse <dwmw@amazon.co.uk>,
	Thomas Gleixner <tglx@kernel.org>,
	Michael Kelley <mhklinux@outlook.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: timers/ptp] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource
Date: Fri, 05 Jun 2026 12:30:16 -0000	[thread overview]
Message-ID: <178066261631.710.13032581932741239024.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260604095755.64849-2-dwmw2@infradead.org>

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
 };
 

  reply	other threads:[~2026-06-05 12:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-bot2 for David Woodhouse [this message]
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

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=178066261631.710.13032581932741239024.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=dwmw@amazon.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=tglx@kernel.org \
    --cc=x86@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

all inboxes | Powered by JetHome®