ptp4l: Read system clock maximum frequency adjustment.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2013-04-04 17:28:23 +02:00 committed by Richard Cochran
parent da347d7a36
commit f8563452a8
3 changed files with 22 additions and 1 deletions

View File

@ -589,7 +589,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
} else { } else {
c->clkid = CLOCK_REALTIME; c->clkid = CLOCK_REALTIME;
c->utc_timescale = 1; c->utc_timescale = 1;
max_adj = 512000; max_adj = clockadj_get_max_freq(c->clkid);
clockadj_set_leap(c->clkid, 0); clockadj_set_leap(c->clkid, 0);
} }
c->leap_set = 0; c->leap_set = 0;

View File

@ -94,3 +94,17 @@ void clockadj_set_leap(clockid_t clkid, int leap)
else if (m) else if (m)
pr_notice(m); pr_notice(m);
} }
int clockadj_get_max_freq(clockid_t clkid)
{
int f = 0;
struct timex tx;
memset(&tx, 0, sizeof(tx));
if (clock_adjtime(clkid, &tx) < 0)
pr_err("failed to read out the clock maximum adjustment: %m");
else
f = tx.tolerance / 65.536;
if (!f)
f = 500000;
return f;
}

View File

@ -51,4 +51,11 @@ void clockadj_step(clockid_t clkid, int64_t step);
* 0 to reset the leap state. * 0 to reset the leap state.
*/ */
void clockadj_set_leap(clockid_t clkid, int leap); void clockadj_set_leap(clockid_t clkid, int leap);
/*
* Read clock's maximum frequency adjustment.
* @param clkid CLOCK_REALTIME.
* @return The maximum frequency adjustment in parts per billion (ppb).
*/
int clockadj_get_max_freq(clockid_t clkid);
#endif #endif