From nobody Mon Jun 8 03:20:21 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1A2A3FE641; Thu, 4 Jun 2026 09:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780564069; cv=none; b=rzYzvuTWsVpQFPY9SkRpfjh/ZR3e7n7qhffdhnv/XV8361gL1YAljWt9y6x61Y6r5Jng3tgev6UAec1MsolRO7CfTV7ci+12WgzrR/AVlZcruxB16H7La179QzGybgnRLVspnUVlFEjXQvyxY0mnB7Z9lnpyjIekeIiPC7CYvpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780564069; c=relaxed/simple; bh=N9mMvbasP6c8dG7W7mRK86CvY6CE35nTO+VZNsNMC10=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=ciPy+nbWcfHUCtEuITbotpAGHJpuHBIRiePVouuOUE89Xw90r74pX9UeRX3bj5smM7po3n60nKR/N8YCdFuuVc5d0ChdxEG9uqASn/LnkyKTfDDKObmKtWvbycidTY5QcE4UWLq2r13kve7tcnBiLGM8FqmROAO6+30lCAT88oc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xn5f3286; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1Iidj7v6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xn5f3286"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1Iidj7v6" Date: Thu, 04 Jun 2026 09:07:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780564066; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SVuhJSkzBurR5MTM4GoxAIpn8p2feL/0qfK2qlcQb74=; b=xn5f3286Y+ouaUfq5qAKraLvFQDTGZvqu4B8FnQnQxLJgKBFR22DpJ4dEcfIJs5U1Lb6AC KPB+ToNCqdnI+RFf8tMkdCFpcLxPXvoydNrRdYawVAswyjGN05O8P3EuUMESwuwR1RBEvu YW4qd/NI8ah3RZpAmqc2Qrg0HYIPqURcxsDLe0U7VmrSHV94Yl8Mu2+uvdvSTiCrWGASom GP+R1UbMWuyWHy3Xjxs8hgQXj/txmmsRJ3DzwVuAD759HkSIhqg3pgxxMFURVNrp1FNSrh 5ZE1nVjSNxyeGDrRgRz5PWAnuZ1ZY12puji+G7J03MGkNE1VQ6Oopi0E6LpVyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780564066; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SVuhJSkzBurR5MTM4GoxAIpn8p2feL/0qfK2qlcQb74=; b=1Iidj7v6TOAFd/FseGLAiKrb6ykh+XYCU1IJDSj9VfPN0M/HZwuCPuRYEbOmNolvCbYCLO CnGqA4mqzaPhngCw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/ptp] timekeeping: Prepare for cross timestamps on arbitrary clock IDs Cc: Thomas Gleixner , David Woodhouse , Arthur Kiyanovski , thomas.weissschuh@linutronix.de, Jacob Keller , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260529195557.846634842@kernel.org> References: <20260529195557.846634842@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178056406489.710.6671305213722825019.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the timers/ptp branch of tip: Commit-ID: 09fb74f77e02489d1d8c555d44bab99d4905127c Gitweb: https://git.kernel.org/tip/09fb74f77e02489d1d8c555d44bab99d4= 905127c Author: Thomas Gleixner AuthorDate: Fri, 29 May 2026 22:01:00 +02:00 Committer: Thomas Gleixner CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00 timekeeping: Prepare for cross timestamps on arbitrary clock IDs PTP device system crosstime stamps support only CLOCK_REALTIME, which is meaningless for AUX clocks. The PTP core hands in the clock ID already, so prepare the core code to honor it. - Add a new sys_systime field to struct system_device_crosststamp which aliases the sys_realtime field. Once all users are converted sys_realtime can be removed. - Prepare get_device_system_crosststamp() and the related code for it by switching to sys_systime and providing the initial changes to utilize different time keepers. No functional change intended. Signed-off-by: Thomas Gleixner Tested-by: David Woodhouse Tested-by: Arthur Kiyanovski Reviewed-by: David Woodhouse Reviewed-by: Thomas Wei=C3=9Fschuh Reviewed-by: Jacob Keller Link: https://patch.msgid.link/20260529195557.846634842@kernel.org --- include/linux/timekeeping.h | 7 +++- kernel/time/timekeeping.c | 60 +++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 2d9860e..017599d 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -319,13 +319,18 @@ struct system_counterval_t { * @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time * @sys_realtime: Realtime simultaneous with device time + * @sys_systime: System time for @clock_id * @sys_monoraw: Monotonic raw simultaneous with device time */ struct system_device_crosststamp { clockid_t clock_id; ktime_t device; struct system_counterval_t sys_counter; - ktime_t sys_realtime; + union { + /* realtime goes away once all users are converted */ + ktime_t sys_realtime; + ktime_t sys_systime; + }; ktime_t sys_monoraw; }; =20 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 372179f..dae61c9 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1312,7 +1312,7 @@ static int adjust_historical_crosststamp(struct syste= m_time_snapshot *history, struct system_device_crosststamp *ts) { struct timekeeper *tk =3D &tk_core.timekeeper; - u64 corr_raw, corr_real; + u64 corr_raw, corr_sys; bool interp_forward; int ret; =20 @@ -1329,8 +1329,7 @@ static int adjust_historical_crosststamp(struct syste= m_time_snapshot *history, * Scale the monotonic raw time delta by: * partial_history_cycles / total_history_cycles */ - corr_raw =3D (u64)ktime_to_ns( - ktime_sub(ts->sys_monoraw, history->monoraw)); + corr_raw =3D (u64)ktime_to_ns(ktime_sub(ts->sys_monoraw, history->monoraw= )); ret =3D scale64_check_overflow(partial_history_cycles, total_history_cycles, &corr_raw); if (ret) @@ -1338,30 +1337,29 @@ static int adjust_historical_crosststamp(struct sys= tem_time_snapshot *history, =20 /* * If there is a discontinuity in the history, scale monotonic raw - * correction by: - * mult(real)/mult(raw) yielding the realtime correction - * Otherwise, calculate the realtime correction similar to monotonic - * raw calculation + * correction by: + * mult(sys)/mult(raw) yielding the system time correction + * + * Otherwise, calculate the system time correction similar to monotonic + * raw calculation */ if (discontinuity) { - corr_real =3D mul_u64_u32_div - (corr_raw, tk->tkr_mono.mult, tk->tkr_raw.mult); + corr_sys =3D mul_u64_u32_div(corr_raw, tk->tkr_mono.mult, tk->tkr_raw.mu= lt); } else { - corr_real =3D (u64)ktime_to_ns( - ktime_sub(ts->sys_realtime, history->systime)); - ret =3D scale64_check_overflow(partial_history_cycles, - total_history_cycles, &corr_real); + corr_sys =3D (u64)ktime_to_ns(ktime_sub(ts->sys_systime, history->systim= e)); + ret =3D scale64_check_overflow(partial_history_cycles, total_history_cyc= les, + &corr_sys); if (ret) return ret; } =20 - /* Fixup monotonic raw and real time time values */ + /* Fixup monotonic raw and system time time values */ if (interp_forward) { ts->sys_monoraw =3D ktime_add_ns(history->monoraw, corr_raw); - ts->sys_realtime =3D ktime_add_ns(history->systime, corr_real); + ts->sys_systime =3D ktime_add_ns(history->systime, corr_sys); } else { ts->sys_monoraw =3D ktime_sub_ns(ts->sys_monoraw, corr_raw); - ts->sys_realtime =3D ktime_sub_ns(ts->sys_realtime, corr_real); + ts->sys_systime =3D ktime_sub_ns(ts->sys_systime, corr_sys); } =20 return 0; @@ -1505,16 +1503,29 @@ int get_device_system_crosststamp(int (*get_time_fn) struct system_device_crosststamp *xtstamp) { u64 syscnt_cycles, cycles, now, interval_start; - struct timekeeper *tk =3D &tk_core.timekeeper; unsigned int seq, clock_was_set_seq =3D 0; - ktime_t base_real, base_raw; - u64 nsec_real, nsec_raw; + ktime_t base_sys, base_raw, *offs; + u64 nsec_sys, nsec_raw; u8 cs_was_changed_seq; bool do_interp; + struct timekeeper *tk; + struct tk_data *tkd; int ret; =20 + switch (xtstamp->clock_id) { + case CLOCK_REALTIME: + tkd =3D &tk_core; + offs =3D &tk_core.timekeeper.offs_real; + break; + default: + WARN_ON_ONCE(1); + return -ENODEV; + } + + tk =3D &tkd->timekeeper; + do { - seq =3D read_seqcount_begin(&tk_core.seq); + seq =3D read_seqcount_begin(&tkd->seq); /* * Try to synchronously capture device time and a system * counter value calling back into the device driver @@ -1549,15 +1560,14 @@ int get_device_system_crosststamp(int (*get_time_fn) do_interp =3D false; } =20 - base_real =3D ktime_add(tk->tkr_mono.base, - tk_core.timekeeper.offs_real); + base_sys =3D ktime_add(tk->tkr_mono.base, *offs); base_raw =3D tk->tkr_raw.base; =20 - nsec_real =3D timekeeping_cycles_to_ns(&tk->tkr_mono, cycles); + nsec_sys =3D timekeeping_cycles_to_ns(&tk->tkr_mono, cycles); nsec_raw =3D timekeeping_cycles_to_ns(&tk->tkr_raw, cycles); - } while (read_seqcount_retry(&tk_core.seq, seq)); + } while (read_seqcount_retry(&tkd->seq, seq)); =20 - xtstamp->sys_realtime =3D ktime_add_ns(base_real, nsec_real); + xtstamp->sys_systime =3D ktime_add_ns(base_sys, nsec_sys); xtstamp->sys_monoraw =3D ktime_add_ns(base_raw, nsec_raw); =20 /*