phc2sys: Print clock reading delay.

If the delay is known, print it together with the offset and frequency.
Remove the time stamp from the output to fit it into 80 chars.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2013-02-07 19:56:52 +01:00 committed by Richard Cochran
parent cb5ebd9b24
commit 42b305478d
3 changed files with 35 additions and 21 deletions

View File

@ -121,7 +121,7 @@ static void clock_step(clockid_t clkid, int64_t ns)
} }
static int read_phc(clockid_t clkid, clockid_t sysclk, int readings, static int read_phc(clockid_t clkid, clockid_t sysclk, int readings,
int64_t *offset, uint64_t *ts) int64_t *offset, uint64_t *ts, int64_t *delay)
{ {
struct timespec tdst1, tdst2, tsrc; struct timespec tdst1, tdst2, tsrc;
int i; int i;
@ -146,6 +146,7 @@ static int read_phc(clockid_t clkid, clockid_t sysclk, int readings,
*ts = tdst2.tv_sec * NS_PER_SEC + tdst2.tv_nsec; *ts = tdst2.tv_sec * NS_PER_SEC + tdst2.tv_nsec;
} }
} }
*delay = best_interval;
return 1; return 1;
} }
@ -156,7 +157,8 @@ struct clock {
const char *source_label; const char *source_label;
}; };
static void update_clock(struct clock *clock, int64_t offset, uint64_t ts) static void update_clock(struct clock *clock,
int64_t offset, uint64_t ts, int64_t delay)
{ {
enum servo_state state; enum servo_state state;
double ppb; double ppb;
@ -174,9 +176,14 @@ static void update_clock(struct clock *clock, int64_t offset, uint64_t ts)
break; break;
} }
pr_info("%s %9" PRId64 " s%d %lld.%09llu freq %+7.0f", if (delay >= 0) {
clock->source_label, offset, state, pr_info("%s offset %9" PRId64 " s%d freq %+7.0f "
ts / NS_PER_SEC, ts % NS_PER_SEC, ppb); "delay %6" PRId64,
clock->source_label, offset, state, ppb, delay);
} else {
pr_info("%s offset %9" PRId64 " s%d freq %+7.0f",
clock->source_label, offset, state, ppb);
}
} }
static int read_pps(int fd, int64_t *offset, uint64_t *ts) static int read_pps(int fd, int64_t *offset, uint64_t *ts)
@ -204,7 +211,7 @@ static int read_pps(int fd, int64_t *offset, uint64_t *ts)
static int do_pps_loop(struct clock *clock, int fd, static int do_pps_loop(struct clock *clock, int fd,
clockid_t src, int n_readings, int sync_offset) clockid_t src, int n_readings, int sync_offset)
{ {
int64_t pps_offset, phc_offset; int64_t pps_offset, phc_offset, phc_delay;
uint64_t pps_ts, phc_ts; uint64_t pps_ts, phc_ts;
clock->source_label = "pps"; clock->source_label = "pps";
@ -218,7 +225,7 @@ static int do_pps_loop(struct clock *clock, int fd,
of seconds in the offset and PPS for the rest. */ of seconds in the offset and PPS for the rest. */
if (src != CLOCK_INVALID) { if (src != CLOCK_INVALID) {
if (!read_phc(src, clock->clkid, n_readings, if (!read_phc(src, clock->clkid, n_readings,
&phc_offset, &phc_ts)) &phc_offset, &phc_ts, &phc_delay))
return -1; return -1;
/* Convert the time stamp to the PHC time. */ /* Convert the time stamp to the PHC time. */
@ -236,7 +243,7 @@ static int do_pps_loop(struct clock *clock, int fd,
pps_offset -= sync_offset * NS_PER_SEC; pps_offset -= sync_offset * NS_PER_SEC;
} }
update_clock(clock, pps_offset, pps_ts); update_clock(clock, pps_offset, pps_ts, -1);
} }
close(fd); close(fd);
return 0; return 0;
@ -246,19 +253,19 @@ static int do_sysoff_loop(struct clock *clock, clockid_t src,
int rate, int n_readings, int sync_offset) int rate, int n_readings, int sync_offset)
{ {
uint64_t ts; uint64_t ts;
int64_t offset; int64_t offset, delay;
int err = 0, fd = CLOCKID_TO_FD(src); int err = 0, fd = CLOCKID_TO_FD(src);
clock->source_label = "sys"; clock->source_label = "sys";
while (1) { while (1) {
usleep(1000000 / rate); usleep(1000000 / rate);
if (sysoff_measure(fd, n_readings, &offset, &ts)) { if (sysoff_measure(fd, n_readings, &offset, &ts, &delay)) {
err = -1; err = -1;
break; break;
} }
offset -= sync_offset * NS_PER_SEC; offset -= sync_offset * NS_PER_SEC;
update_clock(clock, offset, ts); update_clock(clock, offset, ts, delay);
} }
return err; return err;
} }
@ -267,17 +274,18 @@ static int do_phc_loop(struct clock *clock, clockid_t src,
int rate, int n_readings, int sync_offset) int rate, int n_readings, int sync_offset)
{ {
uint64_t ts; uint64_t ts;
int64_t offset; int64_t offset, delay;
clock->source_label = "phc"; clock->source_label = "phc";
while (1) { while (1) {
usleep(1000000 / rate); usleep(1000000 / rate);
if (!read_phc(src, clock->clkid, n_readings, &offset, &ts)) { if (!read_phc(src, clock->clkid, n_readings,
&offset, &ts, &delay)) {
continue; continue;
} }
offset -= sync_offset * NS_PER_SEC; offset -= sync_offset * NS_PER_SEC;
update_clock(clock, offset, ts); update_clock(clock, offset, ts, delay);
} }
return 0; return 0;
} }

View File

@ -52,7 +52,8 @@ static void insertion_sort(int length, int64_t interval, int64_t offset, uint64_
samples[i+1].timestamp = ts; samples[i+1].timestamp = ts;
} }
static int64_t sysoff_estimate(struct ptp_clock_time *pct, int n_samples, uint64_t *ts) static int64_t sysoff_estimate(struct ptp_clock_time *pct, int n_samples,
uint64_t *ts, int64_t *delay)
{ {
int64_t t1, t2, tp; int64_t t1, t2, tp;
int64_t interval, offset; int64_t interval, offset;
@ -67,10 +68,12 @@ static int64_t sysoff_estimate(struct ptp_clock_time *pct, int n_samples, uint64
insertion_sort(i, interval, offset, (t2 + t1) / 2); insertion_sort(i, interval, offset, (t2 + t1) / 2);
} }
*ts = samples[0].timestamp; *ts = samples[0].timestamp;
*delay = samples[0].interval;
return samples[0].offset; return samples[0].offset;
} }
int sysoff_measure(int fd, int n_samples, int64_t *result, uint64_t *ts) int sysoff_measure(int fd, int n_samples,
int64_t *result, uint64_t *ts, int64_t *delay)
{ {
struct ptp_sys_offset pso; struct ptp_sys_offset pso;
pso.n_samples = n_samples; pso.n_samples = n_samples;
@ -78,13 +81,13 @@ int sysoff_measure(int fd, int n_samples, int64_t *result, uint64_t *ts)
perror("ioctl PTP_SYS_OFFSET"); perror("ioctl PTP_SYS_OFFSET");
return SYSOFF_RUN_TIME_MISSING; return SYSOFF_RUN_TIME_MISSING;
} }
*result = sysoff_estimate(pso.ts, n_samples, ts); *result = sysoff_estimate(pso.ts, n_samples, ts, delay);
return SYSOFF_SUPPORTED; return SYSOFF_SUPPORTED;
} }
int sysoff_probe(int fd, int n_samples) int sysoff_probe(int fd, int n_samples)
{ {
int64_t junk; int64_t junk, delay;
uint64_t ts; uint64_t ts;
if (n_samples > PTP_MAX_SAMPLES) { if (n_samples > PTP_MAX_SAMPLES) {
@ -94,12 +97,13 @@ int sysoff_probe(int fd, int n_samples)
return SYSOFF_RUN_TIME_MISSING; return SYSOFF_RUN_TIME_MISSING;
} }
return sysoff_measure(fd, n_samples, &junk, &ts); return sysoff_measure(fd, n_samples, &junk, &ts, &delay);
} }
#else /* !PTP_SYS_OFFSET */ #else /* !PTP_SYS_OFFSET */
int sysoff_measure(int fd, int n_samples, int64_t *result, uint64_t *ts) int sysoff_measure(int fd, int n_samples,
int64_t *result, uint64_t *ts, int64_t *delay)
{ {
return SYSOFF_COMPILE_TIME_MISSING; return SYSOFF_COMPILE_TIME_MISSING;
} }

View File

@ -39,6 +39,8 @@ int sysoff_probe(int fd, int n_samples);
* @param n_samples The number of consecutive readings to make. * @param n_samples The number of consecutive readings to make.
* @param result The estimated offset in nanoseconds. * @param result The estimated offset in nanoseconds.
* @param ts The system time corresponding to the 'result'. * @param ts The system time corresponding to the 'result'.
* @param delay The delay in reading of the clock in nanoseconds.
* @return One of the SYSOFF_ enumeration values. * @return One of the SYSOFF_ enumeration values.
*/ */
int sysoff_measure(int fd, int n_samples, int64_t *result, uint64_t *ts); int sysoff_measure(int fd, int n_samples,
int64_t *result, uint64_t *ts, int64_t *delay);