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 36FE3369D69; Thu, 4 Jun 2026 09:07:39 +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=1780564061; cv=none; b=pvTzKQulLCZ9PCZ/Lt1AsMRsil7M29xSclidLvriU6MT/UhdgWMdZXATXe2wK6tjR0ip60dlWFEdebHuHx0MhOAa4B29pzHCmWrInpmX5S96xcuopB7l3Hen6fNQai4mUWrpn4dYCYQ9mH/GBUUx6V49gttnjMdeuTK8L07TcQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780564061; c=relaxed/simple; bh=dkr48kLS8skhV5THdpvKl/20IVkjD6fY8bYrA1Q+KJw=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=c1MXskxvibctDDWuSouJ6LSgJRPTchl5EZsIRsk5JXS5dwqapFmblNqvyrq4dwSCe2ZSfMXbNZbFCodu9liXBiQV5CM8bW5DcNTTvDPDBs0hfl/rak+9UezuKATxI4GFdTbbFzjIVFknzVdvNdvkQDj04mz7hHKqlDSSgwsmdFY= 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=mL2jec6G; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=twomI6FF; 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="mL2jec6G"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="twomI6FF" Date: Thu, 04 Jun 2026 09:07:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780564058; 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=SG8k7HF0QKCxrKzSk+eOtc0KyLsj7WRS6IJuAxwY80I=; b=mL2jec6GElCXNRQ9kEMrf5kZwMCntzPsLgBpg66sgxh0v3kAKJMfuqC/q54owv4oS8hSMm IXmQEScJfmHyH88yWhv2vyoJjyXkXaf+9Ifsa0lIB7KvQP/WXXk5TFGyxtlcP6huZifxSc yZ4Dw912k60iH6gbzXv4fK9zWNLOxvwlITF9OF4nHst7ZpaOrdY7QX8m4Nu7dO1teBOCYC gM4p/g9T4OcxuToLAinuDsL1kzKZYOCAgKRBlJonphYqZ5V6uM6k4XBxdkuw9ed9SQJeQH dMqM7twqDt8ZSZWZ1XKS6XQC6nJUAtm8zCaCepmZyrcRHkh3IxVAzG+gkvwyQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780564058; 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=SG8k7HF0QKCxrKzSk+eOtc0KyLsj7WRS6IJuAxwY80I=; b=twomI6FFoSw7xVewkddavslMWjD0B64r2dLFIzwz/0GBOvdoZumWNBUfewjWWdvJLCYx7N io6QUVwJRrCZraBg== 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] ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps Cc: Thomas Gleixner , David Woodhouse , Arthur Kiyanovski , Jacob Keller , Vadim Fedorenko , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260529195558.149589566@kernel.org> References: <20260529195558.149589566@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178056405718.710.8996404319977714501.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: a6d799608e6a61b48908bff955200d03c34c90ca Gitweb: https://git.kernel.org/tip/a6d799608e6a61b48908bff955200d03c= 34c90ca Author: Thomas Gleixner AuthorDate: Fri, 29 May 2026 22:01:25 +02:00 Committer: Thomas Gleixner CommitterDate: Thu, 04 Jun 2026 11:04:18 +02:00 ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps To prepare for a new PTP IOCTL, which exposes the raw counter value along with the requested system time snapshot, switch the pre/post time stamp sampling over to use ktime_get_snapshot_id() and fix up all usage sites. No functional change intended. The ptp_vmclock conversion was simplified by David Woodhouse. Signed-off-by: Thomas Gleixner Tested-by: David Woodhouse Tested-by: Arthur Kiyanovski Reviewed-by: David Woodhouse Reviewed-by: Jacob Keller Acked-by: Vadim Fedorenko Link: https://patch.msgid.link/20260529195558.149589566@kernel.org --- drivers/net/dsa/sja1105/sja1105_main.c | 8 ++++---- drivers/ptp/ptp_chardev.c | 14 +++++++++----- drivers/ptp/ptp_ocp.c | 11 ++++------- drivers/ptp/ptp_vmclock.c | 23 +++++++---------------- include/linux/ptp_clock_kernel.h | 15 ++++++++------- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja11= 05/sja1105_main.c index c72c2bf..2697073 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2310,10 +2310,10 @@ int sja1105_static_config_reload(struct sja1105_pri= vate *priv, goto out; } =20 - t1 =3D timespec64_to_ns(&ptp_sts_before.pre_ts); - t2 =3D timespec64_to_ns(&ptp_sts_before.post_ts); - t3 =3D timespec64_to_ns(&ptp_sts_after.pre_ts); - t4 =3D timespec64_to_ns(&ptp_sts_after.post_ts); + t1 =3D ktime_to_ns(ptp_sts_before.pre_sts.systime); + t2 =3D ktime_to_ns(ptp_sts_before.post_sts.systime); + t3 =3D ktime_to_ns(ptp_sts_after.pre_sts.systime); + t4 =3D ktime_to_ns(ptp_sts_after.post_sts.systime); /* Mid point, corresponds to pre-reset PTPCLKVAL */ t12 =3D t1 + (t2 - t1) / 2; /* Mid point, corresponds to post-reset PTPCLKVAL, aka 0 */ diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index f52bbb3..dc23cd7 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -386,15 +386,19 @@ static long ptp_sys_offset_extended(struct ptp_clock = *ptp, void __user *arg, return err; =20 /* Filter out disabled or unavailable clocks */ - if (sts.pre_ts.tv_sec < 0 || sts.post_ts.tv_sec < 0) + if (!sts.pre_sts.valid || !sts.post_sts.valid) return -EINVAL; =20 - extoff->ts[i][0].sec =3D sts.pre_ts.tv_sec; - extoff->ts[i][0].nsec =3D sts.pre_ts.tv_nsec; extoff->ts[i][1].sec =3D ts.tv_sec; extoff->ts[i][1].nsec =3D ts.tv_nsec; - extoff->ts[i][2].sec =3D sts.post_ts.tv_sec; - extoff->ts[i][2].nsec =3D sts.post_ts.tv_nsec; + + ts =3D ktime_to_timespec64(sts.pre_sts.systime); + extoff->ts[i][0].sec =3D ts.tv_sec; + extoff->ts[i][0].nsec =3D ts.tv_nsec; + + ts =3D ktime_to_timespec64(sts.post_sts.systime); + extoff->ts[i][2].sec =3D ts.tv_sec; + extoff->ts[i][2].nsec =3D ts.tv_nsec; } =20 return copy_to_user(arg, extoff, sizeof(*extoff)) ? -EFAULT : 0; diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index beacc2f..28b0302 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -1491,11 +1491,8 @@ __ptp_ocp_gettime_locked(struct ptp_ocp *bp, struct = timespec64 *ts, } ptp_read_system_postts(sts); =20 - if (sts && bp->ts_window_adjust) { - s64 ns =3D timespec64_to_ns(&sts->post_ts); - - sts->post_ts =3D ns_to_timespec64(ns - bp->ts_window_adjust); - } + if (sts && bp->ts_window_adjust) + sts->post_sts.systime -=3D bp->ts_window_adjust; =20 time_ns =3D ioread32(&bp->reg->time_ns); time_sec =3D ioread32(&bp->reg->time_sec); @@ -4595,8 +4592,8 @@ ptp_ocp_summary_show(struct seq_file *s, void *data) struct timespec64 sys_ts; s64 pre_ns, post_ns, ns; =20 - pre_ns =3D timespec64_to_ns(&sts.pre_ts); - post_ns =3D timespec64_to_ns(&sts.post_ts); + pre_ns =3D ktime_to_ns(sts.pre_sts.systime); + post_ns =3D ktime_to_ns(sts.post_sts.systime); ns =3D (pre_ns + post_ns) / 2; ns +=3D (s64)bp->utc_tai_offset * NSEC_PER_SEC; sys_ts =3D ns_to_timespec64(ns); diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c index 0f12b54..d6a5a53 100644 --- a/drivers/ptp/ptp_vmclock.c +++ b/drivers/ptp/ptp_vmclock.c @@ -101,7 +101,6 @@ static int vmclock_get_crosststamp(struct vmclock_state= *st, struct timespec64 *tspec) { ktime_t deadline =3D ktime_add(ktime_get(), VMCLOCK_MAX_WAIT); - struct system_time_snapshot systime_snapshot; uint64_t cycle, delta, seq, frac_sec; =20 #ifdef CONFIG_X86 @@ -132,17 +131,15 @@ static int vmclock_get_crosststamp(struct vmclock_sta= te *st, * will be derived from the *same* counter value. * * If the system isn't using the same counter, then the value - * from ktime_get_snapshot_id() will still be used as pre_ts, and - * ptp_read_system_postts() is called to populate postts after - * calling get_cycles(). - * - * The conversion to timespec64 happens further down, outside - * the seq_count loop. + * from ptp_read_system_prets() will still be used as pre_ts, + * and ptp_read_system_postts() is called to populate postts + * after calling get_cycles(). */ if (sts) { - ktime_get_snapshot_id(CLOCK_REALTIME, &systime_snapshot); - if (systime_snapshot.cs_id =3D=3D st->cs_id) { - cycle =3D systime_snapshot.cycles; + ptp_read_system_prets(sts); + if (sts->pre_sts.cs_id =3D=3D st->cs_id) { + cycle =3D sts->pre_sts.cycles; + sts->post_sts =3D sts->pre_sts; } else { cycle =3D get_cycles(); ptp_read_system_postts(sts); @@ -180,12 +177,6 @@ static int vmclock_get_crosststamp(struct vmclock_stat= e *st, system_counter->cs_id =3D st->cs_id; } =20 - if (sts) { - sts->pre_ts =3D ktime_to_timespec64(systime_snapshot.systime); - if (systime_snapshot.cs_id =3D=3D st->cs_id) - sts->post_ts =3D sts->pre_ts; - } - return 0; } =20 diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_ker= nel.h index 8843645..36a27a9 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -12,6 +12,7 @@ #include #include #include +#include #include =20 #define PTP_CLOCK_NAME_LEN 32 @@ -45,13 +46,13 @@ struct system_device_crosststamp; =20 /** * struct ptp_system_timestamp - system time corresponding to a PHC timest= amp - * @pre_ts: system timestamp before capturing PHC - * @post_ts: system timestamp after capturing PHC - * @clockid: clock-base used for capturing the system timestamps + * @pre_sts: system time snapshot before capturing PHC + * @post_sts: system time snapshot after capturing PHC + * @clockid: clock-base used for capturing the system timestamps */ struct ptp_system_timestamp { - struct timespec64 pre_ts; - struct timespec64 post_ts; + struct system_time_snapshot pre_sts; + struct system_time_snapshot post_sts; clockid_t clockid; }; =20 @@ -510,13 +511,13 @@ static inline ktime_t ptp_convert_timestamp(const kti= me_t *hwtstamp, static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts) { if (sts) - ktime_get_clock_ts64(sts->clockid, &sts->pre_ts); + ktime_get_snapshot_id(sts->clockid, &sts->pre_sts); } =20 static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts) { if (sts) - ktime_get_clock_ts64(sts->clockid, &sts->post_ts); + ktime_get_snapshot_id(sts->clockid, &sts->post_sts); } =20 #endif