From: "tip-bot2 for Thomas Gleixner" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
John Stultz <jstultz@google.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: timers/ptp] timekeeping: Make timekeeping_inject_offset() reusable
Date: Mon, 30 Jun 2025 15:05:22 -0000 [thread overview]
Message-ID: <175129592261.406.13807265836498784856.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250625183758.059934561@linutronix.de>
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: e8db3a55798d70f2c222c6103990776fca6a6ebc
Gitweb: https://git.kernel.org/tip/e8db3a55798d70f2c222c6103990776fca6a6ebc
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 25 Jun 2025 20:38:40 +02:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 27 Jun 2025 20:13:13 +02:00
timekeeping: Make timekeeping_inject_offset() reusable
Split out the inner workings for auxiliary clock support and feed the core time
keeper into it.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Link: https://lore.kernel.org/all/20250625183758.059934561@linutronix.de
---
kernel/time/timekeeping.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index b6ac784..2d294cf 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1433,32 +1433,32 @@ EXPORT_SYMBOL(do_settimeofday64);
/**
* __timekeeping_inject_offset - Adds or subtracts from the current time.
+ * @tkd: Pointer to the timekeeper to modify
* @ts: Pointer to the timespec variable containing the offset
*
* Adds or subtracts an offset value from the current time.
*/
-static int __timekeeping_inject_offset(const struct timespec64 *ts)
+static int __timekeeping_inject_offset(struct tk_data *tkd, const struct timespec64 *ts)
{
- struct timekeeper *tks = &tk_core.shadow_timekeeper;
+ struct timekeeper *tks = &tkd->shadow_timekeeper;
struct timespec64 tmp;
if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC)
return -EINVAL;
-
timekeeping_forward_now(tks);
/* Make sure the proposed value is valid */
tmp = timespec64_add(tk_xtime(tks), *ts);
if (timespec64_compare(&tks->wall_to_monotonic, ts) > 0 ||
!timespec64_valid_settod(&tmp)) {
- timekeeping_restore_shadow(&tk_core);
+ timekeeping_restore_shadow(tkd);
return -EINVAL;
}
tk_xtime_add(tks, ts);
tk_set_wall_to_mono(tks, timespec64_sub(tks->wall_to_monotonic, *ts));
- timekeeping_update_from_shadow(&tk_core, TK_UPDATE_ALL);
+ timekeeping_update_from_shadow(tkd, TK_UPDATE_ALL);
return 0;
}
@@ -1467,7 +1467,7 @@ static int timekeeping_inject_offset(const struct timespec64 *ts)
int ret;
scoped_guard (raw_spinlock_irqsave, &tk_core.lock)
- ret = __timekeeping_inject_offset(ts);
+ ret = __timekeeping_inject_offset(&tk_core, ts);
/* Signal hrtimers about time change */
if (!ret)
@@ -2568,6 +2568,7 @@ EXPORT_SYMBOL_GPL(random_get_entropy_fallback);
*/
int do_adjtimex(struct __kernel_timex *txc)
{
+ struct tk_data *tkd = &tk_core;
struct timespec64 delta, ts;
struct audit_ntp_data ad;
bool offset_set = false;
@@ -2585,16 +2586,19 @@ int do_adjtimex(struct __kernel_timex *txc)
ktime_get_real_ts64(&ts);
add_device_randomness(&ts, sizeof(ts));
- scoped_guard (raw_spinlock_irqsave, &tk_core.lock) {
- struct timekeeper *tks = &tk_core.shadow_timekeeper;
+ scoped_guard (raw_spinlock_irqsave, &tkd->lock) {
+ struct timekeeper *tks = &tkd->shadow_timekeeper;
s32 orig_tai, tai;
+ if (!tks->clock_valid)
+ return -ENODEV;
+
if (txc->modes & ADJ_SETOFFSET) {
delta.tv_sec = txc->time.tv_sec;
delta.tv_nsec = txc->time.tv_usec;
if (!(txc->modes & ADJ_NANO))
delta.tv_nsec *= 1000;
- ret = __timekeeping_inject_offset(&delta);
+ ret = __timekeeping_inject_offset(tkd, &delta);
if (ret)
return ret;
@@ -2607,7 +2611,7 @@ int do_adjtimex(struct __kernel_timex *txc)
if (tai != orig_tai) {
__timekeeping_set_tai_offset(tks, tai);
- timekeeping_update_from_shadow(&tk_core, TK_CLOCK_WAS_SET);
+ timekeeping_update_from_shadow(tkd, TK_CLOCK_WAS_SET);
clock_set = true;
} else {
tk_update_leap_state_all(&tk_core);
@@ -2615,7 +2619,7 @@ int do_adjtimex(struct __kernel_timex *txc)
/* Update the multiplier immediately if frequency was set directly */
if (txc->modes & (ADJ_FREQUENCY | ADJ_TICK))
- clock_set |= __timekeeping_advance(&tk_core, TK_ADV_FREQ);
+ clock_set |= __timekeeping_advance(tkd, TK_ADV_FREQ);
}
if (txc->modes & ADJ_SETOFFSET)
next prev parent reply other threads:[~2025-06-30 15:05 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 18:38 [patch V3 00/11] timekeeping: Provide support for auxiliary clocks - Remaining series Thomas Gleixner
2025-06-25 18:38 ` [patch V3 01/11] timekeeping: Update auxiliary timekeepers on clocksource change Thomas Gleixner
2025-06-27 4:43 ` John Stultz
2025-06-27 14:04 ` Thomas Gleixner
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 02/11] timekeeping: Provide time getters for auxiliary clocks Thomas Gleixner
2025-06-27 4:18 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 03/11] timekeeping: Add minimal posix-timers support " Thomas Gleixner
2025-06-27 4:19 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 04/11] timekeeping: Provide time setter " Thomas Gleixner
2025-06-27 4:23 ` John Stultz
2025-06-27 14:18 ` Thomas Gleixner
2025-06-27 14:57 ` Thomas Gleixner
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 05/11] timekeeping: Make timekeeping_inject_offset() reusable Thomas Gleixner
2025-06-27 4:26 ` John Stultz
2025-06-30 15:05 ` tip-bot2 for Thomas Gleixner [this message]
2025-06-25 18:38 ` [patch V3 06/11] timekeeping: Add auxiliary clock support to __timekeeping_inject_offset() Thomas Gleixner
2025-06-27 4:54 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 07/11] timekeeping: Make do_adjtimex() reusable Thomas Gleixner
2025-06-27 4:56 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 08/11] timekeeping: Prepare do_adtimex() for auxiliary clocks Thomas Gleixner
2025-06-27 5:00 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 09/11] timekeeping: Provide adjtimex() " Thomas Gleixner
2025-06-27 5:01 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 10/11] timekeeping: Provide update for auxiliary timekeepers Thomas Gleixner
2025-06-27 5:05 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
2025-06-25 18:38 ` [patch V3 11/11] timekeeping: Provide interface to control auxiliary clocks Thomas Gleixner
2025-06-27 5:07 ` John Stultz
2025-06-30 15:05 ` [tip: timers/ptp] " tip-bot2 for Thomas Gleixner
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=175129592261.406.13807265836498784856.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=tglx@linutronix.de \
--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