netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/4] ptp: add ptp_gettimex64any() support
@ 2023-09-29  2:37 Mahesh Bandewar
  2023-09-30 21:18 ` Richard Cochran
  0 siblings, 1 reply; 4+ messages in thread
From: Mahesh Bandewar @ 2023-09-29  2:37 UTC (permalink / raw)
  To: Netdev, Linux, David Miller, Jakub Kicinski, Eric Dumazet,
	Paolo Abeni
  Cc: Jonathan Corbet, Don Hatchett, Yuliang Li, Mahesh Bandewar,
	Mahesh Bandewar, Richard Cochran

add support for TS sandwich of the user preferred timebase. The options
supported are PTP_TS_REAL (CLOCK_REALTIME), PTP_TS_MONO (CLOCK_MONOTONIC),
PTP_TS_RAW (CLOCK_MONOTONIC_RAW), PTP_TS_CYCLES (raw-cycles)

The option PTP_TS_CYCLES will return the cycles in 'struct timespec64'
format so something equivalent of timespec64_to_ns() need to be applied to
covert back into cycles.

Option of PTP_TS_REAL is equivalent of 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: netdev@vger.kernel.org
---
 include/linux/ptp_clock_kernel.h | 57 ++++++++++++++++++++++++++++++++
 include/uapi/linux/ptp_clock.h   |  8 +++++
 2 files changed, 65 insertions(+)

diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 1ef4e0f9bd2a..87e75354d687 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -102,6 +102,15 @@ 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 type: any one of the TS opt from ptp_timestamp_types.
+ *
  * @getcrosststamp:  Reads the current time from the hardware clock and
  *                   system clock simultaneously.
  *                   parameter cts: Contains timestamp (device,system) pair,
@@ -180,6 +189,9 @@ 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,
+			     enum ptp_ts_types type);
 	int (*getcrosststamp)(struct ptp_clock_info *ptp,
 			      struct system_device_crosststamp *cts);
 	int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts);
@@ -464,4 +476,49 @@ static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts)
 		ktime_get_real_ts64(&sts->post_ts);
 }
 
+static inline void ptp_read_any_prets(struct ptp_system_timestamp *sts,
+				      enum ptp_ts_types type)
+{
+	if (sts) {
+		switch (type) {
+		case PTP_TS_CYCLES:
+			ktime_get_cycles64(&sts->pre_ts);
+			break;
+		case PTP_TS_REAL:
+			ktime_get_real_ts64(&sts->pre_ts);
+			break;
+		case PTP_TS_MONO:
+			ktime_get_ts64(&sts->pre_ts);
+			break;
+		case PTP_TS_RAW:
+			ktime_get_raw_ts64(&sts->pre_ts);
+			break;
+		default:
+			break;
+		}
+	}
+}
+
+static inline void ptp_read_any_postts(struct ptp_system_timestamp *sts,
+				       enum ptp_ts_types type)
+{
+	if (sts) {
+		switch (type) {
+		case PTP_TS_CYCLES:
+			ktime_get_cycles64(&sts->post_ts);
+			break;
+		case PTP_TS_REAL:
+			ktime_get_real_ts64(&sts->post_ts);
+			break;
+		case PTP_TS_MONO:
+			ktime_get_ts64(&sts->post_ts);
+			break;
+		case PTP_TS_RAW:
+			ktime_get_raw_ts64(&sts->post_ts);
+			break;
+		default:
+			break;
+		}
+	}
+}
 #endif
diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h
index 05cc35fc94ac..1f1e98966cff 100644
--- a/include/uapi/linux/ptp_clock.h
+++ b/include/uapi/linux/ptp_clock.h
@@ -69,6 +69,14 @@
  */
 #define PTP_PEROUT_V1_VALID_FLAGS	(0)
 
+enum ptp_ts_types {
+	PTP_TS_CYCLES = 0,
+	PTP_TS_REAL,
+	PTP_TS_MONO,
+	PTP_TS_RAW,
+	PTP_TS_MAX,
+};
+
 /*
  * struct ptp_clock_time - represents a time value
  *
-- 
2.42.0.582.g8ccd20d70d-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/4] ptp: add ptp_gettimex64any() support
  2023-09-29  2:37 [PATCH 2/4] ptp: add ptp_gettimex64any() support Mahesh Bandewar
@ 2023-09-30 21:18 ` Richard Cochran
  2023-10-03  0:24   ` Mahesh Bandewar (महेश बंडेवार)
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Cochran @ 2023-09-30 21:18 UTC (permalink / raw)
  To: Mahesh Bandewar
  Cc: Netdev, Linux, David Miller, Jakub Kicinski, Eric Dumazet,
	Paolo Abeni, Jonathan Corbet, Don Hatchett, Yuliang Li,
	Mahesh Bandewar

On Thu, Sep 28, 2023 at 07:37:40PM -0700, Mahesh Bandewar wrote:

> diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h
> index 05cc35fc94ac..1f1e98966cff 100644
> --- a/include/uapi/linux/ptp_clock.h
> +++ b/include/uapi/linux/ptp_clock.h
> @@ -69,6 +69,14 @@
>   */
>  #define PTP_PEROUT_V1_VALID_FLAGS	(0)
>  
> +enum ptp_ts_types {
> +	PTP_TS_CYCLES = 0,
> +	PTP_TS_REAL,
> +	PTP_TS_MONO,
> +	PTP_TS_RAW,
> +	PTP_TS_MAX,
> +};

There is no need for a new set of enumerated values.  Why not use the
existing clockid_t ?

Thanks,
Richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/4] ptp: add ptp_gettimex64any() support
  2023-09-30 21:18 ` Richard Cochran
@ 2023-10-03  0:24   ` Mahesh Bandewar (महेश बंडेवार)
  2023-10-04  4:27     ` Richard Cochran
  0 siblings, 1 reply; 4+ messages in thread
From: Mahesh Bandewar (महेश बंडेवार) @ 2023-10-03  0:24 UTC (permalink / raw)
  To: Richard Cochran
  Cc: Netdev, Linux, David Miller, Jakub Kicinski, Eric Dumazet,
	Paolo Abeni, Jonathan Corbet, Don Hatchett, Yuliang Li,
	Mahesh Bandewar

On Sat, Sep 30, 2023 at 2:18 PM Richard Cochran
<richardcochran@gmail.com> wrote:
>
> On Thu, Sep 28, 2023 at 07:37:40PM -0700, Mahesh Bandewar wrote:
>
> > diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h
> > index 05cc35fc94ac..1f1e98966cff 100644
> > --- a/include/uapi/linux/ptp_clock.h
> > +++ b/include/uapi/linux/ptp_clock.h
> > @@ -69,6 +69,14 @@
> >   */
> >  #define PTP_PEROUT_V1_VALID_FLAGS    (0)
> >
> > +enum ptp_ts_types {
> > +     PTP_TS_CYCLES = 0,
> > +     PTP_TS_REAL,
> > +     PTP_TS_MONO,
> > +     PTP_TS_RAW,
> > +     PTP_TS_MAX,
> > +};
>
> There is no need for a new set of enumerated values.  Why not use the
> existing clockid_t ?
>
I'm not sure which one you are referring to. These defs need to be
UAPI and the one defined in time.h are not all relevant in this case
(we just need only a few of those) hence the definition. However, if I
missed something, please point me to it.

> Thanks,
> Richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/4] ptp: add ptp_gettimex64any() support
  2023-10-03  0:24   ` Mahesh Bandewar (महेश बंडेवार)
@ 2023-10-04  4:27     ` Richard Cochran
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Cochran @ 2023-10-04  4:27 UTC (permalink / raw)
  To: Mahesh Bandewar (महेश बंडेवार)
  Cc: Netdev, Linux, David Miller, Jakub Kicinski, Eric Dumazet,
	Paolo Abeni, Jonathan Corbet, Don Hatchett, Yuliang Li,
	Mahesh Bandewar

On Mon, Oct 02, 2023 at 05:24:43PM -0700, Mahesh Bandewar (महेश बंडेवार) wrote:

> I'm not sure which one you are referring to. These defs need to be
> UAPI and the one defined in time.h are not all relevant in this case
> (we just need only a few of those) hence the definition. However, if I
> missed something, please point me to it.

You are missing this:

> > > +     PTP_TS_REAL,

#define CLOCK_REALTIME			0

> > > +     PTP_TS_MONO,

#define CLOCK_MONOTONIC			1

> > > +     PTP_TS_RAW,

#define CLOCK_MONOTONIC_RAW		4

See?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-04  4:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-29  2:37 [PATCH 2/4] ptp: add ptp_gettimex64any() support Mahesh Bandewar
2023-09-30 21:18 ` Richard Cochran
2023-10-03  0:24   ` Mahesh Bandewar (महेश बंडेवार)
2023-10-04  4:27     ` Richard Cochran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).