ptp/ioctl: support MONOTONIC{,_RAW} timestamps for PTP_SYS_OFFSET_EXTENDED

The ability to read the PHC (Physical Hardware Clock) alongside
multiple system clocks is currently dependent on the specific
hardware architecture. This limitation restricts the use of
PTP_SYS_OFFSET_PRECISE to certain hardware configurations.

The generic soultion which would work across all architectures
is to read the PHC along with the latency to perform PHC-read as
offered by PTP_SYS_OFFSET_EXTENDED which provides pre and post
timestamps.  However, these timestamps are currently limited
to the CLOCK_REALTIME timebase. Since CLOCK_REALTIME is affected
by NTP (or similar time synchronization services), it can
experience significant jumps forward or backward. This hinders
the precise latency measurements that PTP_SYS_OFFSET_EXTENDED
is designed to provide.

This problem could be addressed by supporting MONOTONIC_RAW
timestamps within PTP_SYS_OFFSET_EXTENDED. Unlike CLOCK_REALTIME
or CLOCK_MONOTONIC, the MONOTONIC_RAW timebase is unaffected
by NTP adjustments.

This enhancement can be implemented by utilizing one of the three
reserved words within the PTP_SYS_OFFSET_EXTENDED struct to pass
the clock-id for timestamps.  The current behavior aligns with
clock-id for CLOCK_REALTIME timebase (value of 0), ensuring
backward compatibility of the UAPI.

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Mahesh Bandewar
2024-09-04 07:13:05 -07:00
committed by David S. Miller
parent d5c4546062
commit c259acab83
3 changed files with 56 additions and 12 deletions
+18 -6
View File
@@ -155,13 +155,25 @@ struct ptp_sys_offset {
struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
};
/*
* ptp_sys_offset_extended - data structure for IOCTL operation
* PTP_SYS_OFFSET_EXTENDED
*
* @n_samples: Desired number of measurements.
* @clockid: clockid of a clock-base used for pre/post timestamps.
* @rsv: Reserved for future use.
* @ts: Array of samples in the form [pre-TS, PHC, post-TS]. The
* kernel provides @n_samples.
*
* Starting from kernel 6.12 and onwards, the first word of the reserved-field
* is used for @clockid. That's backward compatible since previous kernel
* expect all three reserved words (@rsv[3]) to be 0 while the clockid (first
* word in the new structure) for CLOCK_REALTIME is '0'.
*/
struct ptp_sys_offset_extended {
unsigned int n_samples; /* Desired number of measurements. */
unsigned int rsv[3]; /* Reserved for future use. */
/*
* Array of [system, phc, system] time stamps. The kernel will provide
* 3*n_samples time stamps.
*/
unsigned int n_samples;
__kernel_clockid_t clockid;
unsigned int rsv[2];
struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
};