Currently it is very finicky to deploy linuxptp in an automated build
system and make KBUILD_OUTPUT pick up the output of "make
headers_install" in order for the application to make full use of the
features exposed by the runtime kernel. And the toolchain/libc will
almost certainly never contain recent enough kernel headers to be of any
use here. And there's no good reason for that: the application can probe
at runtime for the sysoff methods supported by the kernel anyway.

So let's provide the kernel definitions for sysoff, sysoff_precise and
sysoff_extended, such that SYSOFF_COMPILE_TIME_MISSING is not something
that will bother us any longer.

Signed-off-by: Vladimir Oltean <[email protected]>
---
 missing.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 sysoff.c  | 27 +--------------------------
 sysoff.h  |  2 +-
 3 files changed, 50 insertions(+), 27 deletions(-)

diff --git a/missing.h b/missing.h
index bc708cbbbe8a..c77d381e76b4 100644
--- a/missing.h
+++ b/missing.h
@@ -97,6 +97,54 @@ struct compat_ptp_clock_caps {
 
 #endif /*LINUX_VERSION_CODE < 5.8*/
 
+#ifndef PTP_SYS_OFFSET
+
+#define PTP_SYS_OFFSET     _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
+
+struct ptp_sys_offset {
+       unsigned int n_samples; /* Desired number of measurements. */
+       unsigned int rsv[3];    /* Reserved for future use. */
+       /*
+        * Array of interleaved system/phc time stamps. The kernel
+        * will provide 2*n_samples + 1 time stamps, with the last
+        * one as a system time stamp.
+        */
+       struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
+};
+
+#endif /* PTP_SYS_OFFSET */
+
+#ifndef PTP_SYS_OFFSET_PRECISE
+
+#define PTP_SYS_OFFSET_PRECISE \
+       _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
+
+struct ptp_sys_offset_precise {
+       struct ptp_clock_time device;
+       struct ptp_clock_time sys_realtime;
+       struct ptp_clock_time sys_monoraw;
+       unsigned int rsv[4];    /* Reserved for future use. */
+};
+
+#endif /* PTP_SYS_OFFSET_PRECISE */
+
+#ifndef PTP_SYS_OFFSET_EXTENDED
+
+#define PTP_SYS_OFFSET_EXTENDED \
+       _IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended)
+
+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.
+        */
+       struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
+};
+
+#endif /* PTP_SYS_OFFSET_EXTENDED */
+
 #ifndef PTP_PIN_SETFUNC
 
 enum ptp_pin_function {
diff --git a/sysoff.c b/sysoff.c
index 05d2ed617780..03cdb87dcab2 100644
--- a/sysoff.c
+++ b/sysoff.c
@@ -27,8 +27,6 @@
 
 #define NS_PER_SEC 1000000000LL
 
-#ifdef PTP_SYS_OFFSET
-
 static int64_t pctns(struct ptp_clock_time *t)
 {
        return t->sec * NS_PER_SEC + t->nsec;
@@ -42,7 +40,6 @@ static struct {
 
 static int sysoff_precise(int fd, int64_t *result, uint64_t *ts)
 {
-#ifdef PTP_SYS_OFFSET_PRECISE
        struct ptp_sys_offset_precise pso;
        memset(&pso, 0, sizeof(pso));
        if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, &pso)) {
@@ -52,9 +49,6 @@ static int sysoff_precise(int fd, int64_t *result, uint64_t 
*ts)
        *result = pctns(&pso.sys_realtime) - pctns(&pso.device);
        *ts = pctns(&pso.sys_realtime);
        return SYSOFF_PRECISE;
-#else
-       return SYSOFF_COMPILE_TIME_MISSING;
-#endif
 }
 
 static void insertion_sort(int length, int64_t interval, int64_t offset, 
uint64_t ts)
@@ -100,7 +94,6 @@ static int64_t sysoff_estimate(struct ptp_clock_time *pct, 
int extended,
 static int sysoff_extended(int fd, int n_samples,
                           int64_t *result, uint64_t *ts, int64_t *delay)
 {
-#ifdef PTP_SYS_OFFSET_EXTENDED
        struct ptp_sys_offset_extended pso;
        memset(&pso, 0, sizeof(pso));
        pso.n_samples = n_samples;
@@ -110,9 +103,6 @@ static int sysoff_extended(int fd, int n_samples,
        }
        *result = sysoff_estimate(&pso.ts[0][0], 1, n_samples, ts, delay);
        return SYSOFF_EXTENDED;
-#else
-       return SYSOFF_COMPILE_TIME_MISSING;
-#endif
 }
 
 static int sysoff_basic(int fd, int n_samples,
@@ -141,7 +131,7 @@ int sysoff_measure(int fd, int method, int n_samples,
        case SYSOFF_BASIC:
                return sysoff_basic(fd, n_samples, result, ts, delay);
        }
-       return SYSOFF_COMPILE_TIME_MISSING;
+       return SYSOFF_RUN_TIME_MISSING;
 }
 
 int sysoff_probe(int fd, int n_samples)
@@ -165,18 +155,3 @@ int sysoff_probe(int fd, int n_samples)
 
        return SYSOFF_RUN_TIME_MISSING;
 }
-
-#else /* !PTP_SYS_OFFSET */
-
-int sysoff_measure(int fd, int method, int n_samples,
-                  int64_t *result, uint64_t *ts, int64_t *delay)
-{
-       return SYSOFF_COMPILE_TIME_MISSING;
-}
-
-int sysoff_probe(int fd, int n_samples)
-{
-       return SYSOFF_COMPILE_TIME_MISSING;
-}
-
-#endif /* PTP_SYS_OFFSET */
diff --git a/sysoff.h b/sysoff.h
index 79d22908ce48..e4de91948231 100644
--- a/sysoff.h
+++ b/sysoff.h
@@ -19,9 +19,9 @@
  */
 
 #include <stdint.h>
+#include "missing.h"
 
 enum {
-       SYSOFF_COMPILE_TIME_MISSING = -2,
        SYSOFF_RUN_TIME_MISSING = -1,
        SYSOFF_PRECISE,
        SYSOFF_EXTENDED,
-- 
2.25.1



_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to