Pass the clock offset to servo_sample() as a floating point value,
allowing the servo to take fractional nanoseconds into account.

Note that a floating point value can sensibly hold a clock offset, but
cannot sensibly hold an absolute time due to its limited range.
Servos that perform calculations on absolute times therefore cannot
make use of fractional nanoseconds.  At present, only the PI servo is
structured in a way that allows fractional nanoseconds to be used.

Signed-off-by: Michael Brown <mbr...@fensystems.co.uk>
---
 clock.c         | 2 +-
 linreg.c        | 3 ++-
 ntpshm.c        | 3 ++-
 nullf.c         | 2 +-
 pi.c            | 4 ++--
 servo.c         | 2 +-
 servo.h         | 2 +-
 servo_private.h | 2 +-
 8 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/clock.c b/clock.c
index d72efb2..121d9fb 100644
--- a/clock.c
+++ b/clock.c
@@ -1606,7 +1606,7 @@ enum servo_state clock_synchronize(struct clock *c, tmv_t 
ingress, tmv_t origin)
        if (c->free_running)
                return clock_no_adjust(c, ingress, origin);
 
-       adj = servo_sample(c->servo, tmv_to_nanoseconds(c->master_offset),
+       adj = servo_sample(c->servo, tmv_dbl(c->master_offset),
                           tmv_to_nanoseconds(ingress), weight, &state);
        c->servo_state = state;
 
diff --git a/linreg.c b/linreg.c
index 8f354f4..163f573 100644
--- a/linreg.c
+++ b/linreg.c
@@ -214,7 +214,7 @@ static void update_size(struct linreg_servo *s)
 }
 
 static double linreg_sample(struct servo *servo,
-                           int64_t offset,
+                           double xoffset,
                            uint64_t local_ts,
                            double weight,
                            enum servo_state *state)
@@ -222,6 +222,7 @@ static double linreg_sample(struct servo *servo,
        struct linreg_servo *s = container_of(servo, struct linreg_servo, 
servo);
        struct result *res;
        int corr_interval;
+       int64_t offset = (int64_t) xoffset;
 
        /*
         * The current time and the time when will be the frequency of the
diff --git a/ntpshm.c b/ntpshm.c
index 3b62a3f..53f8a6e 100644
--- a/ntpshm.c
+++ b/ntpshm.c
@@ -74,12 +74,13 @@ static void ntpshm_destroy(struct servo *servo)
 }
 
 static double ntpshm_sample(struct servo *servo,
-                           int64_t offset,
+                           double xoffset,
                            uint64_t local_ts,
                            double weight,
                            enum servo_state *state)
 {
        struct ntpshm_servo *s = container_of(servo, struct ntpshm_servo, 
servo);
+       int64_t offset = (int64_t) xoffset;
        uint64_t clock_ts = local_ts - offset;
 
        s->shm->mode = 1;
diff --git a/nullf.c b/nullf.c
index 5512837..f934459 100644
--- a/nullf.c
+++ b/nullf.c
@@ -34,7 +34,7 @@ static void nullf_destroy(struct servo *servo)
        free(s);
 }
 
-static double nullf_sample(struct servo *servo, int64_t offset,
+static double nullf_sample(struct servo *servo, double offset,
                           uint64_t local_ts, double weight,
                           enum servo_state *state)
 {
diff --git a/pi.c b/pi.c
index 35556e1..831a2dc 100644
--- a/pi.c
+++ b/pi.c
@@ -37,7 +37,7 @@
 
 struct pi_servo {
        struct servo servo;
-       int64_t offset[2];
+       double offset[2];
        uint64_t local[2];
        double drift;
        double kp;
@@ -62,7 +62,7 @@ static void pi_destroy(struct servo *servo)
 }
 
 static double pi_sample(struct servo *servo,
-                       int64_t offset,
+                       double offset,
                        uint64_t local_ts,
                        double weight,
                        enum servo_state *state)
diff --git a/servo.c b/servo.c
index 8be4b92..2912608 100644
--- a/servo.c
+++ b/servo.c
@@ -89,7 +89,7 @@ void servo_destroy(struct servo *servo)
 }
 
 double servo_sample(struct servo *servo,
-                   int64_t offset,
+                   double offset,
                    uint64_t local_ts,
                    double weight,
                    enum servo_state *state)
diff --git a/servo.h b/servo.h
index f90befd..236afb5 100644
--- a/servo.h
+++ b/servo.h
@@ -90,7 +90,7 @@ void servo_destroy(struct servo *servo);
  * @return The clock adjustment in parts per billion.
  */
 double servo_sample(struct servo *servo,
-                   int64_t offset,
+                   double offset,
                    uint64_t local_ts,
                    double weight,
                    enum servo_state *state);
diff --git a/servo_private.h b/servo_private.h
index b8c3c98..3787f80 100644
--- a/servo_private.h
+++ b/servo_private.h
@@ -30,7 +30,7 @@ struct servo {
        void (*destroy)(struct servo *servo);
 
        double (*sample)(struct servo *servo,
-                        int64_t offset, uint64_t local_ts, double weight,
+                        double offset, uint64_t local_ts, double weight,
                         enum servo_state *state);
 
        void (*sync_interval)(struct servo *servo, double interval);
-- 
2.9.5


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to