Linux HTE (hardware timestamp engine) subsytem
 help / color / mirror / Atom feed
From: Eli Gavril <eli.gavril@gmail.com>
To: Dipen Patel <dipenp@nvidia.com>,
	Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>
Cc: Kent Gibson <warthog618@gmail.com>,
	Thierry Reding <thierry.reding@kernel.org>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	timestamp@lists.linux.dev, linux-gpio@vger.kernel.org,
	linux-tegra@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-api@vger.kernel.org
Subject: [PATCH 2/3] hte: tegra194: correlate captured timestamps to CLOCK_REALTIME
Date: Mon, 30 Nov 2026 16:24:34 +0200	[thread overview]
Message-ID: <20261130142435.1292201-3-eli.gavril@gmail.com> (raw)
In-Reply-To: <20261130142435.1292201-1-eli.gavril@gmail.com>

The GTE timestamps with the arch counter, which also backs the
arm_arch_timer clocksource. Take one ktime_get_snapshot_id() per FIFO
entry and subtract the time since the captured edge to fill in
realtime_ns. A single snapshot gives the counter value and
CLOCK_REALTIME from the same read, so no gap between two reads biases
the result.

Leave realtime_ns 0 when the snapshot is invalid or the arch timer is
not the clocksource, as its cycles are then in other units.

Signed-off-by: Eli Gavril <eli.gavril@gmail.com>
---
 drivers/hte/hte-tegra194.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/hte/hte-tegra194.c b/drivers/hte/hte-tegra194.c
index dea5f9e79005..72ae7bbbb295 100644
--- a/drivers/hte/hte-tegra194.c
+++ b/drivers/hte/hte-tegra194.c
@@ -14,6 +14,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/hte.h>
+#include <linux/timekeeping.h>
 #include <linux/uaccess.h>
 #include <linux/gpio/driver.h>
 #include <linux/gpio/consumer.h>
@@ -722,6 +723,7 @@ static void tegra_hte_read_fifo(struct tegra_hte_soc *gs)
 	u32 tsh, tsl, src, pv, cv, acv, slice, bit_index, line_id;
 	u64 tsc;
 	u8 tsc_ns_shift;
+	struct system_time_snapshot snap;
 	struct hte_ts_data el;
 
 	tsc_ns_shift = __builtin_ctz(gs->prov_data->tsc_clkrate_ns);
@@ -739,10 +741,18 @@ static void tegra_hte_read_fifo(struct tegra_hte_soc *gs)
 		pv = tegra_hte_readl(gs, HTE_TEPCV);
 		cv = tegra_hte_readl(gs, HTE_TECCV);
 		acv = pv ^ cv;
+
+		el.tsc = tsc << tsc_ns_shift;
+		ktime_get_snapshot_id(CLOCK_REALTIME, &snap);
+		if (snap.valid && snap.cs_id == CSID_ARM_ARCH_COUNTER)
+			el.realtime_ns = ktime_to_ns(snap.systime) -
+				(((u64)snap.cycles << tsc_ns_shift) - el.tsc);
+		else
+			el.realtime_ns = 0;
+
 		while (acv) {
 			bit_index = __builtin_ctz(acv);
 			line_id = bit_index + (slice << 5);
-			el.tsc = tsc << tsc_ns_shift;
 			el.raw_level = tegra_hte_get_level(gs, line_id);
 			hte_push_ts_ns(gs->chip, line_id, &el);
 			acv &= ~BIT(bit_index);
-- 
2.43.0


  parent reply	other threads:[~2026-11-30 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:24 [PATCH 0/3] hte, gpio: HTE timestamps in CLOCK_REALTIME on NVIDIA Tegra Eli Gavril
2026-11-30 14:24 ` [PATCH 1/3] hte: add CLOCK_REALTIME-correlated timestamp to hte_ts_data Eli Gavril
2026-11-30 14:24 ` Eli Gavril [this message]
2026-11-30 14:24 ` [PATCH 3/3] gpiolib: cdev: report HTE timestamps in the CLOCK_REALTIME domain Eli Gavril

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=20261130142435.1292201-3-eli.gavril@gmail.com \
    --to=eli.gavril@gmail.com \
    --cc=brgl@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dipenp@nvidia.com \
    --cc=jonathanh@nvidia.com \
    --cc=linusw@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=thierry.reding@kernel.org \
    --cc=timestamp@lists.linux.dev \
    --cc=warthog618@gmail.com \
    /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