From: Mahesh Bandewar <maheshb@google.com>
To: Netdev <netdev@vger.kernel.org>,
Linux <linux-kernel@vger.kernel.org>,
David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
John Stultz <jstultz@google.com>, Don Hatchett <hatch@google.com>,
Yuliang Li <yuliangli@google.com>,
Mahesh Bandewar <mahesh@bandewar.net>,
Mahesh Bandewar <maheshb@google.com>,
Richard Cochran <richardcochran@gmail.com>,
Willem de Bruijn <willemb@google.com>
Subject: [PATCHv3 net-next 1/3] ptp: add new method ptp_gettimex64any()
Date: Thu, 4 Jan 2024 13:24:36 -0800 [thread overview]
Message-ID: <20240104212436.3276057-1-maheshb@google.com> (raw)
The current method that gets pre/post timestamps for PHC-read
supports only CLOCK_REALTIME timebase while most of the systems
have their clock disciplined by NTP service. There are applications
that can benefit from pre/post timestamps that are not changing
or have different timebases.
This patch adds the new API ptp_gettimex64any() which allows user
to specify the timebase for these pre/post timestamps. The options
supported are CLOCK_REALTIME, CLOCK_MONOTONIC, and CLOCK_MONOTONIC_RAW
Option of CLOCK_REALTIME is equivalent to using ptp_gettimex64().
Signed-off-by: Mahesh Bandewar <maheshb@google.com>
CC: Richard Cochran <richardcochran@gmail.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: John Stultz <jstultz@google.com>
CC: Jakub Kicinski <kuba@kernel.org>
CC: "Willem de Bruijn" <willemb@google.com>
CC: netdev@vger.kernel.org
---
include/linux/ptp_clock_kernel.h | 50 ++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 1ef4e0f9bd2a..b1316d82721a 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -102,6 +102,17 @@ struct ptp_system_timestamp {
* reading the lowest bits of the PHC timestamp and the second
* reading immediately follows that.
*
+ * @gettimex64any: Reads the current time from the hardware clock and
+ * optionally also any of the MONO, MONO_RAW, or SYS clock
+ * parameter ts: Holds the PHC timestamp.
+ * parameter sts: If not NULL, it holds a pair of
+ * timestamps from the clock of choice. The first reading
+ * is made right before reading the lowest bits of the
+ * PHC timestamp and the second reading immediately
+ * follows that.
+ * parameter clkid: any one of the supported clockids
+ * (CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW)
+ *
* @getcrosststamp: Reads the current time from the hardware clock and
* system clock simultaneously.
* parameter cts: Contains timestamp (device,system) pair,
@@ -180,6 +191,10 @@ struct ptp_clock_info {
int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts);
int (*gettimex64)(struct ptp_clock_info *ptp, struct timespec64 *ts,
struct ptp_system_timestamp *sts);
+ int (*gettimex64any)(struct ptp_clock_info *ptp,
+ struct timespec64 *ts,
+ struct ptp_system_timestamp *sts,
+ clockid_t clockid);
int (*getcrosststamp)(struct ptp_clock_info *ptp,
struct system_device_crosststamp *cts);
int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts);
@@ -452,16 +467,47 @@ static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp,
#endif
+static inline void ptp_read_any_ts64(struct timespec64 *ts,
+ clockid_t clkid)
+{
+ switch (clkid) {
+ case CLOCK_REALTIME:
+ ktime_get_real_ts64(ts);
+ break;
+ case CLOCK_MONOTONIC:
+ ktime_get_ts64(ts);
+ break;
+ case CLOCK_MONOTONIC_RAW:
+ ktime_get_raw_ts64(ts);
+ break;
+ default:
+ break;
+ }
+}
+
static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts)
{
if (sts)
- ktime_get_real_ts64(&sts->pre_ts);
+ ptp_read_any_ts64(&sts->pre_ts, CLOCK_REALTIME);
}
static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts)
{
if (sts)
- ktime_get_real_ts64(&sts->post_ts);
+ ptp_read_any_ts64(&sts->pre_ts, CLOCK_REALTIME);
}
+static inline void ptp_read_any_prets(struct ptp_system_timestamp *sts,
+ clockid_t clkid)
+{
+ if (sts)
+ ptp_read_any_ts64(&sts->pre_ts, clkid);
+}
+
+static inline void ptp_read_any_postts(struct ptp_system_timestamp *sts,
+ clockid_t clkid)
+{
+ if (sts)
+ ptp_read_any_ts64(&sts->post_ts, clkid);
+}
#endif
--
2.43.0.195.gebba966016-goog
reply other threads:[~2024-01-04 21:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240104212436.3276057-1-maheshb@google.com \
--to=maheshb@google.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hatch@google.com \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mahesh@bandewar.net \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=willemb@google.com \
--cc=yuliangli@google.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
all inboxes | Powered by JetHome®