Le 17/09/2018 à 17:12, Richard Cochran a écrit :
> On Mon, Sep 17, 2018 at 08:14:04AM +0000, FUSTE Emmanuel wrote:
>> Running the command compiled without PTP_SYS_OFFSET_PRECISE support on a
>> kernel (and perhaps the hardware) with PTP_SYS_OFFSET_PRECISE will
>> return a definitively wrong answer.
> Yeah, this isn't ideal.
>
> Saying "unknown" is also a bit weird.  People will wonder, why can't
> you tell?
>
> How about this:
>
> /* from linux kernel v4.19-rc4 */
> struct compat_caps {
>       int max_adj;   /* Maximum frequency adjustment in parts per billon. */
>       int n_alarm;   /* Number of programmable alarms. */
>       int n_ext_ts;  /* Number of external time stamp channels. */
>       int n_per_out; /* Number of programmable periodic signals. */
>       int pps;       /* Whether the clock supports a PPS callback. */
>       int n_pins;    /* Number of input/output pins. */
>       /* Whether the clock supports precise system-device cross timestamps */
>       int cross_timestamping;
>       int rsv[13];   /* Reserved for future use. */
> };
>
> and then
>
> static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
> {
>       union {
>               struct ptp_clock_caps caps;
>               struct compat_caps compat;
>       } u;
>       ...
>       // check u.compat.cross_timestamping
> }
>
Yes, clever and more future proof. Damm, it was a long time since I did 
real C... |-)

diff --git a/phc.h b/phc.h
index 154e35e..2fe33c4 100644
--- a/phc.h
+++ b/phc.h
@@ -21,6 +21,19 @@
  
  #include "missing.h"
  
+/* from linux kernel v4.15 */
+struct compat_caps {
+        int max_adj;   /* Maximum frequency adjustment in parts per billon. */
+        int n_alarm;   /* Number of programmable alarms. */
+        int n_ext_ts;  /* Number of external time stamp channels. */
+        int n_per_out; /* Number of programmable periodic signals. */
+        int pps;       /* Whether the clock supports a PPS callback. */
+        int n_pins;    /* Number of input/output pins. */
+        /* Whether the clock supports precise system-device cross timestamps */
+        int cross_timestamping;
+        int rsv[13];   /* Reserved for future use. */
+};
+
  /**
   * Opens a PTP hardware clock device.
   *
diff --git a/phc_ctl.c b/phc_ctl.c
index 4a78a19..d33ff1f 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -334,14 +334,17 @@ static int do_freq(clockid_t clkid, int cmdc, char 
*cmdv[])
  
  static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
  {
-       struct ptp_clock_caps caps;
+       union {
+               struct ptp_clock_caps caps;
+               struct compat_caps compat;
+       } u;
  
        if (clkid == CLOCK_REALTIME) {
                pr_warning("CLOCK_REALTIME is not a PHC device.");
                return 0;
        }
  
-       if (ioctl(CLOCKID_TO_FD(clkid), PTP_CLOCK_GETCAPS, &caps)) {
+       if (ioctl(CLOCKID_TO_FD(clkid), PTP_CLOCK_GETCAPS, &u)) {
                pr_err("get capabilities failed: %s",
                        strerror(errno));
                return -1;
@@ -353,12 +356,14 @@ static int do_caps(clockid_t clkid, int cmdc, char 
*cmdv[])
                "  %d programable alarms\n"
                "  %d external time stamp channels\n"
                "  %d programmable periodic signals\n"
-               "  %s pulse per second support",
-               caps.max_adj,
-               caps.n_alarm,
-               caps.n_ext_ts,
-               caps.n_per_out,
-               caps.pps ? "has" : "doesn't have");
+               "  %s pulse per second support\n"
+               "  %s precise system-device cross timestamps support",
+               u.caps.max_adj,
+               u.caps.n_alarm,
+               u.caps.n_ext_ts,
+               u.caps.n_per_out,
+               u.caps.pps ? "has" : "doesn't have",
+               u.compat.cross_timestamping ? "has" : "doesn't have");
        return 0;
  }
  

_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to