servo: add support for weighted samples.

Add weight parameter to the sample function. Samples with smaller weight
are less reliable, they can be ignored by the servo or the adjustments
of the clock can be smaller.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2015-03-26 16:32:15 +01:00 committed by Richard Cochran
parent 06fcfe123c
commit f0b0c1116a
8 changed files with 13 additions and 6 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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) {

1
pi.c
View File

@ -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);

View File

@ -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;

View File

@ -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);
/**

View File

@ -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);