linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, Dexuan Cui <decui@microsoft.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-hyperv@vger.kernel.org (open list:Hyper-V CORE AND DRIVERS)
Subject: [PATCH 01/17] clocksource/drivers/hyper-v: Suspend/resume Hyper-V clocksource for hibernation
Date: Thu, 16 Jan 2020 19:22:48 +0100	[thread overview]
Message-ID: <20200116182304.4926-1-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <74bf7170-401f-2962-ea5a-1e21431a9349@linaro.org>

From: Dexuan Cui <decui@microsoft.com>

This is needed for hibernation, e.g. when we resume the old kernel, we need
to disable the "current" kernel's TSC page and then resume the old kernel's.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/1574233946-48377-1-git-send-email-decui@microsoft.com
---
 drivers/clocksource/hyperv_timer.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index 287d8d58c21a..1aec08e82b7a 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -330,12 +330,37 @@ static u64 read_hv_sched_clock_tsc(void)
 	return read_hv_clock_tsc(NULL) - hv_sched_clock_offset;
 }
 
+static void suspend_hv_clock_tsc(struct clocksource *arg)
+{
+	u64 tsc_msr;
+
+	/* Disable the TSC page */
+	hv_get_reference_tsc(tsc_msr);
+	tsc_msr &= ~BIT_ULL(0);
+	hv_set_reference_tsc(tsc_msr);
+}
+
+
+static void resume_hv_clock_tsc(struct clocksource *arg)
+{
+	phys_addr_t phys_addr = virt_to_phys(&tsc_pg);
+	u64 tsc_msr;
+
+	/* Re-enable the TSC page */
+	hv_get_reference_tsc(tsc_msr);
+	tsc_msr &= GENMASK_ULL(11, 0);
+	tsc_msr |= BIT_ULL(0) | (u64)phys_addr;
+	hv_set_reference_tsc(tsc_msr);
+}
+
 static struct clocksource hyperv_cs_tsc = {
 	.name	= "hyperv_clocksource_tsc_page",
 	.rating	= 400,
 	.read	= read_hv_clock_tsc,
 	.mask	= CLOCKSOURCE_MASK(64),
 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
+	.suspend= suspend_hv_clock_tsc,
+	.resume	= resume_hv_clock_tsc,
 };
 
 static u64 notrace read_hv_clock_msr(struct clocksource *arg)
-- 
2.17.1


  reply	other threads:[~2020-01-16 18:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16 18:21 [GIT PULL] timer drivers for 5.6 Daniel Lezcano
2020-01-16 18:22 ` Daniel Lezcano [this message]
2020-01-16 18:22   ` [PATCH 02/17] clocksource: Fix Kconfig indentation Daniel Lezcano
2020-01-16 18:22   ` [PATCH 03/17] dt-bindings: timer: renesas, cmt: Document r8a774b1 CMT support Daniel Lezcano
2020-01-16 18:22   ` [PATCH 04/17] clocksource: Fix Kconfig miscues Daniel Lezcano
2020-01-16 18:22   ` [PATCH 05/17] clocksource/drivers/hyper-v: Reserve PAGE_SIZE space for tsc page Daniel Lezcano
2020-01-16 18:22   ` [PATCH 06/17] clocksource/drivers/timer-microchip-pit64b: Add Microchip PIT64B support Daniel Lezcano
2020-01-16 18:22   ` [PATCH 07/17] clocksource/drivers/cadence-ttc: Use ttc driver as platform driver Daniel Lezcano
2020-01-16 18:22   ` [PATCH 08/17] clocksource/drivers/bcm2835_timer: Fix memory leak of timer Daniel Lezcano
2020-01-16 18:22   ` [PATCH 09/17] clocksource/drivers/em_sti: Convert to devm_platform_ioremap_resource Daniel Lezcano
2020-01-16 18:22   ` [PATCH 10/17] clocksource/drivers/em_sti: Fix variable declaration in em_sti_probe Daniel Lezcano
2020-01-16 18:22   ` [PATCH 11/17] clocksource/drivers/timer-ti-dm: Convert to devm_platform_ioremap_resource Daniel Lezcano
2020-01-16 18:22   ` [PATCH 12/17] clocksource/drivers/timer-ti-dm: Switch to platform_get_irq Daniel Lezcano
2020-01-16 18:23   ` [PATCH 13/17] clocksource/drivers/timer-ti-dm: Fix uninitialized pointer access Daniel Lezcano
2020-01-16 18:23   ` [PATCH 14/17] clocksource/drivers/exynos_mct: Rename Exynos to lowercase Daniel Lezcano
2020-01-16 18:23   ` [PATCH 15/17] clocksource/drivers/timer-microchip-pit64b: Fix sparse warning Daniel Lezcano
2020-01-16 18:23   ` [PATCH 16/17] clocksource/drivers/hyper-v: Untangle stimers and timesync from clocksources Daniel Lezcano
2020-01-16 18:23   ` [PATCH 17/17] clocksource/drivers/hyper-v: Set TSC clocksource as default w/ InvariantTSC Daniel Lezcano

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=20200116182304.4926-1-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    /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).