linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hikaru Nishida <hikalium@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: suleiman@google.com, Hikaru Nishida <hikalium@chromium.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Ingo Molnar <mingo@kernel.org>,
	John Stultz <john.stultz@linaro.org>,
	Kurt Kanzenbach <kurt@linutronix.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Stephen Boyd <sboyd@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [RFC PATCH 1/2] timekeeping: Add timekeeping_adjust_boottime
Date: Wed, 10 Feb 2021 19:39:07 +0900	[thread overview]
Message-ID: <20210210193728.RFC.1.I123660cac7339e5b982ade27775a48b8ebbd9435@changeid> (raw)
In-Reply-To: <20210210103908.1720658-1-hikalium@google.com>

From: Hikaru Nishida <hikalium@chromium.org>

This introduces timekeeping_adjust_boottime() to give an interface to
modules that enables to advance CLOCK_BOOTTIME from userspace for
virtualized environments. Later patch introduces a sysfs interface
which calls this function.

Signed-off-by: Hikaru Nishida <hikalium@chromium.org>
---

 include/linux/timekeeping.h |  2 ++
 kernel/time/timekeeping.c   | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index c6792cf01bc7..9bb91fbd945c 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -221,6 +221,8 @@ extern bool timekeeping_rtc_skipresume(void);
 
 extern void timekeeping_inject_sleeptime64(const struct timespec64 *delta);
 
+extern int timekeeping_adjust_boottime(const struct timespec64 *delta);
+
 /*
  * struct ktime_timestanps - Simultaneous mono/boot/real timestamps
  * @mono:	Monotonic timestamp
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 6aee5768c86f..02892deede62 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1740,6 +1740,32 @@ void timekeeping_inject_sleeptime64(const struct timespec64 *delta)
 }
 #endif
 
+#if defined(CONFIG_BOOTTIME_ADJUSTMENT)
+/**
+ * timekeeping_adjust_boottime - Adjust CLOCK_BOOTTIME by adding a given delta
+ */
+int timekeeping_adjust_boottime(const struct timespec64 *delta)
+{
+	struct timekeeper *tk = &tk_core.timekeeper;
+	unsigned long flags;
+
+	if (!timespec64_valid_strict(delta))
+		return -EINVAL;
+
+	raw_spin_lock_irqsave(&timekeeper_lock, flags);
+	write_seqcount_begin(&tk_core.seq);
+
+	tk_update_sleep_time(tk, timespec64_to_ktime(*delta));
+	timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET);
+
+	write_seqcount_end(&tk_core.seq);
+	raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(timekeeping_adjust_boottime);
+#endif
+
 /**
  * timekeeping_resume - Resumes the generic timekeeping subsystem.
  */
-- 
2.30.0.478.g8a0d178c01-goog


  reply	other threads:[~2021-02-10 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 10:39 [RFC PATCH 0/2] Introduce a way to adjust CLOCK_BOOTTIME from userspace for VM guests Hikaru Nishida
2021-02-10 10:39 ` Hikaru Nishida [this message]
2021-02-10 13:12   ` [RFC PATCH 1/2] timekeeping: Add timekeeping_adjust_boottime Thomas Gleixner
2021-02-10 10:39 ` [RFC PATCH 2/2] drivers/virt: introduce CLOCK_BOOTTIME adjustment sysfs interface driver Hikaru Nishida
2021-02-10 10:48   ` Greg Kroah-Hartman
2021-02-10 10:51   ` Greg Kroah-Hartman
2021-02-10 13:10   ` Thomas Gleixner
2021-02-10 10:49 ` [RFC PATCH 0/2] Introduce a way to adjust CLOCK_BOOTTIME from userspace for VM guests Greg Kroah-Hartman
2021-02-10 11:17 ` Alexander Graf
2021-02-10 13:32 ` Arnd Bergmann

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=20210210193728.RFC.1.I123660cac7339e5b982ade27775a48b8ebbd9435@changeid \
    --to=hikalium@chromium.org \
    --cc=arnd@arndb.de \
    --cc=geert@linux-m68k.org \
    --cc=john.stultz@linaro.org \
    --cc=kurt@linutronix.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=suleiman@google.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).