diff --git a/clock.c b/clock.c index 71fda50..3350b3d 100644 --- a/clock.c +++ b/clock.c @@ -1351,14 +1351,14 @@ int clock_switch_phc(struct clock *c, int phc_index) enum servo_state clock_synchronize(struct clock *c, tmv_t ingress, tmv_t origin) { - double adj; + double adj, weight; enum servo_state state = SERVO_UNLOCKED; c->ingress_ts = ingress; tsproc_down_ts(c->tsproc, origin, ingress); - if (tsproc_update_offset(c->tsproc, &c->master_offset, NULL)) + if (tsproc_update_offset(c->tsproc, &c->master_offset, &weight)) return state; if (clock_utc_correct(c, ingress)) @@ -1370,7 +1370,7 @@ enum servo_state clock_synchronize(struct clock *c, tmv_t ingress, tmv_t origin) return clock_no_adjust(c, ingress, origin); adj = servo_sample(c->servo, tmv_to_nanoseconds(c->master_offset), - tmv_to_nanoseconds(ingress), &state); + tmv_to_nanoseconds(ingress), weight, &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..2739ebd 100644 --- a/servo.c +++ b/servo.c @@ -78,11 +78,12 @@ void servo_destroy(struct servo *servo) 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..4be8c23 100644 --- a/servo.h +++ b/servo.h @@ -104,12 +104,15 @@ void servo_destroy(struct servo *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..b8c3c98 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, + int64_t offset, uint64_t local_ts, double weight, enum servo_state *state); void (*sync_interval)(struct servo *servo, double interval);