From nobody Mon Jun 8 03:21:17 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 EEDED3D4107; Tue, 2 Jun 2026 09:45:51 +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=1780393555; cv=none; b=G1ZRervm+f2ktzPVriGxKTMdM80mWb+u21AvIBPlrrAD+a37iFpoLIJLjf8O00xCTOBOZx1d52VEEwYrTWYIi3s/j/lKHBxCTZKlNj1sYoK7hdSbjSdhlM3QgB4K2Alhel80dwCwljF1Ys/O2clc/O9/1vRjT9vv24R3y4bWKkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780393555; c=relaxed/simple; bh=CEaggdJGacwVPuZhcqKYt6s3Ulh2qNeM8R6BIUy9fbk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=ryb6UcXn2pEHHPfHWo+cL5ZLBQULxEG/rGC9mE0Xxv57KpPwpNZ6A8DC47vDlY/UgSoPSQzfLjjGLkMOXcQ3/QE8JlUUFSMri2SNk6dJNa+4Yqz0rRshmvQpXg9mKAx440gAt3+XnPEGVXT5fPrpZBqWNq4exO6Pbk1vxh/oM4o= 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=I4Z9c5n/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jXKH49q1; 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="I4Z9c5n/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jXKH49q1" Date: Tue, 02 Jun 2026 09:45:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780393550; 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=oa6dUKbuhho8QI4WhAMUhnyteAHP0UM9n1KGoXI6eBU=; b=I4Z9c5n/ZukgK7bFulFTuHRVtDLfPwRX5L4Qca2CL8n3Mpk+4ga5hCKcheJnhYXahGtsD8 i26k3NQOMq+6xCX98wGee1rLStmhHSe31Y5+OJxF6IHDWzmJQ5Tz28i9pxxI7nr9emAhiv NSIX/zIwTUpS5QPT3Z44bZjyqhS5PlJLadj2Yb/QiIwKb53trFo2f14DHJzAvMDs1k6og/ VCvNDBS5Wby4K1gRP++IOdlgVJ5kuYEqt0o5N8SXHgavJXwRlKmAvYjfpRgNj5r41I8Sc/ RyJLHibJ9xG0uGe+C6vbh0AjmHNwvyi0kDKm+ik2Qd6cHgxB81juUnBxR0qu+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780393550; 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=oa6dUKbuhho8QI4WhAMUhnyteAHP0UM9n1KGoXI6eBU=; b=jXKH49q1P3jGee7OCT64bdQFa/drGr7PohmNS1Jmk33QOFSvoYdfedl6aKlxbeM9FxgczI Qj1NiSIq2YOFY6Dg== 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: <178039354898.2140988.13067815750922196545.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: 1ed6bf4c4ea99a0b1cdc16621cd15fb2b559f9d4 Gitweb: https://git.kernel.org/tip/1ed6bf4c4ea99a0b1cdc16621cd15fb2b= 559f9d4 Author: Thomas Gleixner AuthorDate: Fri, 29 May 2026 22:01:25 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 02 Jun 2026 11:40:00 +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