Add refclock precision

This commit is contained in:
Miroslav Lichvar 2010-03-02 13:10:54 +01:00
parent b9b0326d15
commit 5fb5551c36
4 changed files with 18 additions and 3 deletions

View file

@ -2315,6 +2315,9 @@ to be inaccurate (in seconds). Increasing the value is useful to
avoid having no majority in the source selection algorithm or to make avoid having no majority in the source selection algorithm or to make
the algorithm prefer other refclocks. The default is 1e-9 (1 the algorithm prefer other refclocks. The default is 1e-9 (1
nanosecond). nanosecond).
@item precision
Refclock precision (in seconds). The default is 1e-6 (1 microsecond)
for SHM refclock, and 1e-9 (1 nanosecond) for SOCK and PPS refclocks.
@end table @end table
@c }}} @c }}}

7
conf.c
View file

@ -437,7 +437,7 @@ parse_refclock(const char *line)
{ {
int i, n, poll, dpoll, filter_length, pps_rate; int i, n, poll, dpoll, filter_length, pps_rate;
unsigned long ref_id, lock_ref_id; unsigned long ref_id, lock_ref_id;
double offset, delay; double offset, delay, precision;
const char *tmp; const char *tmp;
char name[5], cmd[10 + 1], *param; char name[5], cmd[10 + 1], *param;
unsigned char ref[5]; unsigned char ref[5];
@ -452,6 +452,7 @@ parse_refclock(const char *line)
pps_rate = 0; pps_rate = 0;
offset = 0.0; offset = 0.0;
delay = 1e-9; delay = 1e-9;
precision = 0.0;
ref_id = 0; ref_id = 0;
lock_ref_id = 0; lock_ref_id = 0;
@ -507,6 +508,9 @@ parse_refclock(const char *line)
} else if (!strncasecmp(cmd, "delay", 5)) { } else if (!strncasecmp(cmd, "delay", 5)) {
if (sscanf(line, "%lf%n", &delay, &n) != 1) if (sscanf(line, "%lf%n", &delay, &n) != 1)
break; break;
} else if (!strncasecmp(cmd, "precision", 9)) {
if (sscanf(line, "%lf%n", &precision, &n) != 1)
break;
} else { } else {
LOG(LOGS_WARN, LOGF_Configure, "Unknown refclock parameter %s at line %d", cmd, line_number); LOG(LOGS_WARN, LOGF_Configure, "Unknown refclock parameter %s at line %d", cmd, line_number);
break; break;
@ -522,6 +526,7 @@ parse_refclock(const char *line)
refclock_sources[i].pps_rate = pps_rate; refclock_sources[i].pps_rate = pps_rate;
refclock_sources[i].offset = offset; refclock_sources[i].offset = offset;
refclock_sources[i].delay = delay; refclock_sources[i].delay = delay;
refclock_sources[i].precision = precision;
refclock_sources[i].ref_id = ref_id; refclock_sources[i].ref_id = ref_id;
refclock_sources[i].lock_ref_id = lock_ref_id; refclock_sources[i].lock_ref_id = lock_ref_id;

View file

@ -78,6 +78,7 @@ struct RCL_Instance_Record {
unsigned long lock_ref; unsigned long lock_ref;
double offset; double offset;
double delay; double delay;
double precision;
SCH_TimeoutID timeout_id; SCH_TimeoutID timeout_id;
SRC_Instance source; SRC_Instance source;
}; };
@ -166,11 +167,14 @@ RCL_AddRefclock(RefclockParameters *params)
if (strncmp(params->driver_name, "SHM", 4) == 0) { if (strncmp(params->driver_name, "SHM", 4) == 0) {
inst->driver = &RCL_SHM_driver; inst->driver = &RCL_SHM_driver;
inst->precision = 1e-6;
} else if (strncmp(params->driver_name, "SOCK", 4) == 0) { } else if (strncmp(params->driver_name, "SOCK", 4) == 0) {
inst->driver = &RCL_SOCK_driver; inst->driver = &RCL_SOCK_driver;
inst->precision = 1e-9;
pps_source = 1; pps_source = 1;
} else if (strncmp(params->driver_name, "PPS", 4) == 0) { } else if (strncmp(params->driver_name, "PPS", 4) == 0) {
inst->driver = &RCL_PPS_driver; inst->driver = &RCL_PPS_driver;
inst->precision = 1e-9;
pps_source = 1; pps_source = 1;
} else { } else {
LOG_FATAL(LOGF_Refclock, "unknown refclock driver %s", params->driver_name); LOG_FATAL(LOGF_Refclock, "unknown refclock driver %s", params->driver_name);
@ -194,6 +198,8 @@ RCL_AddRefclock(RefclockParameters *params)
inst->lock_ref = params->lock_ref_id; inst->lock_ref = params->lock_ref_id;
inst->offset = params->offset; inst->offset = params->offset;
inst->delay = params->delay; inst->delay = params->delay;
if (params->precision > 0.0)
inst->precision = params->precision;
inst->timeout_id = -1; inst->timeout_id = -1;
inst->source = NULL; inst->source = NULL;
@ -351,7 +357,7 @@ RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset,
LCL_GetOffsetCorrection(sample_time, &correction, &dispersion); LCL_GetOffsetCorrection(sample_time, &correction, &dispersion);
UTI_AddDoubleToTimeval(sample_time, correction, &cooked_time); UTI_AddDoubleToTimeval(sample_time, correction, &cooked_time);
dispersion += LCL_GetSysPrecisionAsQuantum() + filter_get_avg_sample_dispersion(&instance->filter); dispersion += instance->precision + filter_get_avg_sample_dispersion(&instance->filter);
if (!valid_sample_time(instance, sample_time)) if (!valid_sample_time(instance, sample_time))
return 0; return 0;
@ -377,7 +383,7 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
LCL_GetOffsetCorrection(pulse_time, &correction, &dispersion); LCL_GetOffsetCorrection(pulse_time, &correction, &dispersion);
UTI_AddDoubleToTimeval(pulse_time, correction, &cooked_time); UTI_AddDoubleToTimeval(pulse_time, correction, &cooked_time);
dispersion += LCL_GetSysPrecisionAsQuantum() + filter_get_avg_sample_dispersion(&instance->filter); dispersion += instance->precision + filter_get_avg_sample_dispersion(&instance->filter);
if (!valid_sample_time(instance, pulse_time)) if (!valid_sample_time(instance, pulse_time))
return 0; return 0;

View file

@ -42,6 +42,7 @@ typedef struct {
unsigned long lock_ref_id; unsigned long lock_ref_id;
double offset; double offset;
double delay; double delay;
double precision;
} RefclockParameters; } RefclockParameters;
typedef struct RCL_Instance_Record *RCL_Instance; typedef struct RCL_Instance_Record *RCL_Instance;