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
parent
06fcfe123c
commit
f0b0c1116a
6
clock.c
6
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)
|
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;
|
enum servo_state state = SERVO_UNLOCKED;
|
||||||
|
|
||||||
c->ingress_ts = ingress;
|
c->ingress_ts = ingress;
|
||||||
|
|
||||||
tsproc_down_ts(c->tsproc, origin, 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;
|
return state;
|
||||||
|
|
||||||
if (clock_utc_correct(c, ingress))
|
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);
|
return clock_no_adjust(c, ingress, origin);
|
||||||
|
|
||||||
adj = servo_sample(c->servo, tmv_to_nanoseconds(c->master_offset),
|
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;
|
c->servo_state = state;
|
||||||
|
|
||||||
if (c->stats.max_count > 1) {
|
if (c->stats.max_count > 1) {
|
||||||
|
|
1
linreg.c
1
linreg.c
|
@ -209,6 +209,7 @@ static int get_best_size(struct linreg_servo *s)
|
||||||
static double linreg_sample(struct servo *servo,
|
static double linreg_sample(struct servo *servo,
|
||||||
int64_t offset,
|
int64_t offset,
|
||||||
uint64_t local_ts,
|
uint64_t local_ts,
|
||||||
|
double weight,
|
||||||
enum servo_state *state)
|
enum servo_state *state)
|
||||||
{
|
{
|
||||||
struct linreg_servo *s = container_of(servo, struct linreg_servo, servo);
|
struct linreg_servo *s = container_of(servo, struct linreg_servo, servo);
|
||||||
|
|
1
ntpshm.c
1
ntpshm.c
|
@ -80,6 +80,7 @@ static void ntpshm_destroy(struct servo *servo)
|
||||||
static double ntpshm_sample(struct servo *servo,
|
static double ntpshm_sample(struct servo *servo,
|
||||||
int64_t offset,
|
int64_t offset,
|
||||||
uint64_t local_ts,
|
uint64_t local_ts,
|
||||||
|
double weight,
|
||||||
enum servo_state *state)
|
enum servo_state *state)
|
||||||
{
|
{
|
||||||
struct ntpshm_servo *s = container_of(servo, struct ntpshm_servo, servo);
|
struct ntpshm_servo *s = container_of(servo, struct ntpshm_servo, servo);
|
||||||
|
|
|
@ -469,7 +469,7 @@ static void update_clock(struct node *node, struct clock *clock,
|
||||||
if (clock->sanity_check && clockcheck_sample(clock->sanity_check, ts))
|
if (clock->sanity_check && clockcheck_sample(clock->sanity_check, ts))
|
||||||
servo_reset(clock->servo);
|
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;
|
clock->servo_state = state;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
1
pi.c
1
pi.c
|
@ -64,6 +64,7 @@ static void pi_destroy(struct servo *servo)
|
||||||
static double pi_sample(struct servo *servo,
|
static double pi_sample(struct servo *servo,
|
||||||
int64_t offset,
|
int64_t offset,
|
||||||
uint64_t local_ts,
|
uint64_t local_ts,
|
||||||
|
double weight,
|
||||||
enum servo_state *state)
|
enum servo_state *state)
|
||||||
{
|
{
|
||||||
struct pi_servo *s = container_of(servo, struct pi_servo, servo);
|
struct pi_servo *s = container_of(servo, struct pi_servo, servo);
|
||||||
|
|
3
servo.c
3
servo.c
|
@ -78,11 +78,12 @@ void servo_destroy(struct servo *servo)
|
||||||
double servo_sample(struct servo *servo,
|
double servo_sample(struct servo *servo,
|
||||||
int64_t offset,
|
int64_t offset,
|
||||||
uint64_t local_ts,
|
uint64_t local_ts,
|
||||||
|
double weight,
|
||||||
enum servo_state *state)
|
enum servo_state *state)
|
||||||
{
|
{
|
||||||
double r;
|
double r;
|
||||||
|
|
||||||
r = servo->sample(servo, offset, local_ts, state);
|
r = servo->sample(servo, offset, local_ts, weight, state);
|
||||||
|
|
||||||
if (*state != SERVO_UNLOCKED)
|
if (*state != SERVO_UNLOCKED)
|
||||||
servo->first_update = 0;
|
servo->first_update = 0;
|
||||||
|
|
3
servo.h
3
servo.h
|
@ -104,12 +104,15 @@ void servo_destroy(struct servo *servo);
|
||||||
* @param servo Pointer to a servo obtained via @ref servo_create().
|
* @param servo Pointer to a servo obtained via @ref servo_create().
|
||||||
* @param offset The estimated clock offset in nanoseconds.
|
* @param offset The estimated clock offset in nanoseconds.
|
||||||
* @param local_ts The local time stamp of the sample 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.
|
* @param state Returns the servo's state.
|
||||||
* @return The clock adjustment in parts per billion.
|
* @return The clock adjustment in parts per billion.
|
||||||
*/
|
*/
|
||||||
double servo_sample(struct servo *servo,
|
double servo_sample(struct servo *servo,
|
||||||
int64_t offset,
|
int64_t offset,
|
||||||
uint64_t local_ts,
|
uint64_t local_ts,
|
||||||
|
double weight,
|
||||||
enum servo_state *state);
|
enum servo_state *state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct servo {
|
||||||
void (*destroy)(struct servo *servo);
|
void (*destroy)(struct servo *servo);
|
||||||
|
|
||||||
double (*sample)(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);
|
enum servo_state *state);
|
||||||
|
|
||||||
void (*sync_interval)(struct servo *servo, double interval);
|
void (*sync_interval)(struct servo *servo, double interval);
|
||||||
|
|
Loading…
Reference in New Issue