From f8563452a82b0690a838b493719eb99f559d1c3f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 4 Apr 2013 17:28:23 +0200 Subject: [PATCH] ptp4l: Read system clock maximum frequency adjustment. Signed-off-by: Miroslav Lichvar --- clock.c | 2 +- clockadj.c | 14 ++++++++++++++ clockadj.h | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clock.c b/clock.c index 44ef81a..e4af8f4 100644 --- a/clock.c +++ b/clock.c @@ -589,7 +589,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count, } else { c->clkid = CLOCK_REALTIME; c->utc_timescale = 1; - max_adj = 512000; + max_adj = clockadj_get_max_freq(c->clkid); clockadj_set_leap(c->clkid, 0); } c->leap_set = 0; diff --git a/clockadj.c b/clockadj.c index 31fc765..7587dda 100644 --- a/clockadj.c +++ b/clockadj.c @@ -94,3 +94,17 @@ void clockadj_set_leap(clockid_t clkid, int leap) else if (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; +} diff --git a/clockadj.h b/clockadj.h index 6e76e0f..dc94cfa 100644 --- a/clockadj.h +++ b/clockadj.h @@ -51,4 +51,11 @@ void clockadj_step(clockid_t clkid, int64_t step); * 0 to reset the leap state. */ 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