Add weight parameter to the sample function and add a new function to
check if the servo prefers weighted (and more noisy) samples. Samples
with smaller weight are less reliable, they can be ignored or the
adjustments of the clock can be smaller.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 clock.c         |  2 +-
 linreg.c        |  1 +
 ntpshm.c        |  1 +
 phc2sys.c       |  2 +-
 pi.c            |  1 +
 servo.c         | 11 ++++++++++-
 servo.h         | 10 ++++++++++
 servo_private.h |  4 +++-
 8 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/clock.c b/clock.c
index d42d604..64ce562 100644
--- a/clock.c
+++ b/clock.c
@@ -1451,7 +1451,7 @@ enum servo_state clock_synchronize(struct clock *c,
                return clock_no_adjust(c);
 
        adj = servo_sample(c->servo, tmv_to_nanoseconds(c->master_offset),
-                          tmv_to_nanoseconds(ingress), &state);
+                          tmv_to_nanoseconds(ingress), 1.0, &state);
        c->servo_state = state;
 
        if (c->stats.max_count > 1) {
diff --git a/linreg.c b/linreg.c
index fde604d..3f7fe9a 100644
--- a/linreg.c
+++ b/linreg.c
@@ -209,6 +209,7 @@ static int get_best_size(struct linreg_servo *s)
 static double linreg_sample(struct servo *servo,
                            int64_t offset,
                            uint64_t local_ts,
+                           double weight,
                            enum servo_state *state)
 {
        struct linreg_servo *s = container_of(servo, struct linreg_servo, 
servo);
diff --git a/ntpshm.c b/ntpshm.c
index 21a11cf..8b18e2d 100644
--- a/ntpshm.c
+++ b/ntpshm.c
@@ -80,6 +80,7 @@ static void ntpshm_destroy(struct servo *servo)
 static double ntpshm_sample(struct servo *servo,
                            int64_t offset,
                            uint64_t local_ts,
+                           double weight,
                            enum servo_state *state)
 {
        struct ntpshm_servo *s = container_of(servo, struct ntpshm_servo, 
servo);
diff --git a/phc2sys.c b/phc2sys.c
index 23993ac..9ff5bf9 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -469,7 +469,7 @@ static void update_clock(struct node *node, struct clock 
*clock,
        if (clock->sanity_check && clockcheck_sample(clock->sanity_check, ts))
                servo_reset(clock->servo);
 
-       ppb = servo_sample(clock->servo, offset, ts, &state);
+       ppb = servo_sample(clock->servo, offset, ts, 1.0, &state);
        clock->servo_state = state;
 
        switch (state) {
diff --git a/pi.c b/pi.c
index c8b8587..9c7b148 100644
--- a/pi.c
+++ b/pi.c
@@ -64,6 +64,7 @@ static void pi_destroy(struct servo *servo)
 static double pi_sample(struct servo *servo,
                        int64_t offset,
                        uint64_t local_ts,
+                       double weight,
                        enum servo_state *state)
 {
        struct pi_servo *s = container_of(servo, struct pi_servo, servo);
diff --git a/servo.c b/servo.c
index f200f75..38a5729 100644
--- a/servo.c
+++ b/servo.c
@@ -75,14 +75,23 @@ void servo_destroy(struct servo *servo)
        servo->destroy(servo);
 }
 
+int servo_weight_samples(struct servo *servo)
+{
+       if (servo->weight_samples)
+               return servo->weight_samples(servo);
+
+       return 0;
+}
+
 double servo_sample(struct servo *servo,
                    int64_t offset,
                    uint64_t local_ts,
+                   double weight,
                    enum servo_state *state)
 {
        double r;
 
-       r = servo->sample(servo, offset, local_ts, state);
+       r = servo->sample(servo, offset, local_ts, weight, state);
 
        if (*state != SERVO_UNLOCKED)
                servo->first_update = 0;
diff --git a/servo.h b/servo.h
index e054501..12eb249 100644
--- a/servo.h
+++ b/servo.h
@@ -100,16 +100,26 @@ struct servo *servo_create(enum servo_type type, int 
fadj, int max_ppb, int sw_t
 void servo_destroy(struct servo *servo);
 
 /**
+ * Check if a clock servo prefers weighted samples.
+ * @param servo    Pointer to a servo obtained via @ref servo_create().
+ * @return         1 if yes, 0 otherwise.
+ */
+int servo_weight_samples(struct servo *servo);
+
+/**
  * Feed a sample into a clock servo.
  * @param servo     Pointer to a servo obtained via @ref servo_create().
  * @param offset    The estimated clock offset in nanoseconds.
  * @param local_ts  The local time stamp of the sample in nanoseconds.
+ * @param weight    The weight of the sample, larger if more reliable,
+ *                  1.0 is the maximum value.
  * @param state     Returns the servo's state.
  * @return The clock adjustment in parts per billion.
  */
 double servo_sample(struct servo *servo,
                    int64_t offset,
                    uint64_t local_ts,
+                   double weight,
                    enum servo_state *state);
 
 /**
diff --git a/servo_private.h b/servo_private.h
index 9a1a459..b98e7e7 100644
--- a/servo_private.h
+++ b/servo_private.h
@@ -29,8 +29,10 @@ struct servo {
 
        void (*destroy)(struct servo *servo);
 
+       int (*weight_samples)(struct servo *servo);
+
        double (*sample)(struct servo *servo,
-                        int64_t offset, uint64_t local_ts,
+                        int64_t offset, uint64_t local_ts, double weight,
                         enum servo_state *state);
 
        void (*sync_interval)(struct servo *servo, double interval);
-- 
2.1.0


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to