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 3/3] gpiolib: cdev: report HTE timestamps in the CLOCK_REALTIME domain
Date: Mon, 30 Nov 2026 16:24:35 +0200 [thread overview]
Message-ID: <20261130142435.1292201-4-eli.gavril@gmail.com> (raw)
In-Reply-To: <20261130142435.1292201-1-eli.gavril@gmail.com>
HTE timestamps are in the provider's counter epoch, which user space
cannot convert to wall-clock time.
Requesting GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE together with
GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME is rejected with -EINVAL today.
Accept it and report the HTE timestamp correlated to CLOCK_REALTIME; a
provider that cannot correlate reports 0.
Signed-off-by: Eli Gavril <eli.gavril@gmail.com>
---
.../gpio/gpio-v2-get-line-ioctl.rst | 3 ++-
drivers/gpio/gpiolib-cdev.c | 21 ++++++++-----------
include/uapi/linux/gpio.h | 4 +++-
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/Documentation/userspace-api/gpio/gpio-v2-get-line-ioctl.rst b/Documentation/userspace-api/gpio/gpio-v2-get-line-ioctl.rst
index 6615d6ced755..b05c5b8f374e 100644
--- a/Documentation/userspace-api/gpio/gpio-v2-get-line-ioctl.rst
+++ b/Documentation/userspace-api/gpio/gpio-v2-get-line-ioctl.rst
@@ -77,7 +77,8 @@ The edge flags, ``GPIO_V2_LINE_FLAG_EDGE_xxx``, require
and falling edges. Requesting edge detection from a line that does not support
it is an error (**ENXIO**).
-Only one event clock flag, ``GPIO_V2_LINE_FLAG_EVENT_CLOCK_xxx``, may be set.
+Only one event clock flag, ``GPIO_V2_LINE_FLAG_EVENT_CLOCK_xxx``, may be set,
+except HTE with REALTIME, which gives HTE timestamps in ``CLOCK_REALTIME``.
If none are set then the event clock defaults to ``CLOCK_MONOTONIC``.
The ``GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE`` flag requires supporting hardware
and a kernel with ``CONFIG_HTE`` set. Requesting HTE from a device that
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index ceecce572a52..efec7fdb20ab 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -567,11 +567,11 @@ static void linereq_put_event(struct linereq *lr,
static u64 line_event_timestamp(struct line *line)
{
- if (test_bit(GPIOD_FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags))
- return ktime_get_real_ns();
- else if (IS_ENABLED(CONFIG_HTE) &&
- test_bit(GPIOD_FLAG_EVENT_CLOCK_HTE, &line->desc->flags))
+ if (IS_ENABLED(CONFIG_HTE) &&
+ test_bit(GPIOD_FLAG_EVENT_CLOCK_HTE, &line->desc->flags))
return line->timestamp_ns;
+ else if (test_bit(GPIOD_FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags))
+ return ktime_get_real_ns();
return ktime_get_ns();
}
@@ -680,7 +680,10 @@ static enum hte_return process_hw_ts(struct hte_ts_data *ts, void *p)
return HTE_CB_HANDLED;
line = p;
- line->timestamp_ns = ts->tsc;
+ if (test_bit(GPIOD_FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags))
+ line->timestamp_ns = ts->realtime_ns;
+ else
+ line->timestamp_ns = ts->tsc;
line->raw_level = ts->raw_level;
lr = line->req;
@@ -1176,12 +1179,6 @@ static int gpio_v2_line_flags_validate(u64 flags)
(flags & GPIO_V2_LINE_FLAG_OUTPUT))
return -EINVAL;
- /* Only allow one event clock source */
- if (IS_ENABLED(CONFIG_HTE) &&
- (flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME) &&
- (flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE))
- return -EINVAL;
-
/* Edge detection requires explicit input. */
if ((flags & GPIO_V2_LINE_EDGE_FLAGS) &&
!(flags & GPIO_V2_LINE_FLAG_INPUT))
@@ -2319,7 +2316,7 @@ static int gpio_desc_to_lineinfo(struct gpio_desc *desc,
if (test_bit(GPIOD_FLAG_EVENT_CLOCK_REALTIME, &dflags))
info->flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME;
- else if (test_bit(GPIOD_FLAG_EVENT_CLOCK_HTE, &dflags))
+ if (test_bit(GPIOD_FLAG_EVENT_CLOCK_HTE, &dflags))
info->flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE;
debounce_period_us = READ_ONCE(desc->debounce_period_us);
diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h
index 5515b718886e..eef4e388b2ea 100644
--- a/include/uapi/linux/gpio.h
+++ b/include/uapi/linux/gpio.h
@@ -67,7 +67,9 @@ struct gpiochip_info {
* @GPIO_V2_LINE_FLAG_BIAS_DISABLED: line has bias disabled
* @GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME: line events contain REALTIME timestamps
* @GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE: line events contain timestamps from
- * the hardware timestamping engine (HTE) subsystem
+ * the hardware timestamping engine (HTE) subsystem. If combined with
+ * GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME, the HTE timestamp is correlated
+ * to CLOCK_REALTIME when the provider supports it.
*/
enum gpio_v2_line_flag {
GPIO_V2_LINE_FLAG_USED = _BITULL(0),
--
2.43.0
prev 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 ` [PATCH 2/3] hte: tegra194: correlate captured timestamps to CLOCK_REALTIME Eli Gavril
2026-11-30 14:24 ` Eli Gavril [this message]
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-4-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