From 2aa6b10c3bbe7bffac0d57109bf8f4857c5a141e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 20 Jun 2014 16:32:48 +0200 Subject: [PATCH] Add leap function to servo. Introduce a new function to inform the servo about upcoming leap second. This is used when the kernel leap is disabled to allow the servo to handle better the sudden 1 second step in the offset when the leap second is inserted or deleted. Signed-off-by: Miroslav Lichvar --- clock.c | 2 ++ phc2sys.c | 2 ++ servo.c | 6 ++++++ servo.h | 8 ++++++++ servo_private.h | 2 ++ 5 files changed, 20 insertions(+) diff --git a/clock.c b/clock.c index 14e20ad..ddea72f 100644 --- a/clock.c +++ b/clock.c @@ -697,6 +697,8 @@ static int clock_utc_correct(struct clock *c, tmv_t ingress) if (c->leap_set != clock_leap) { if (c->kernel_leap) sysclk_set_leap(clock_leap); + else + servo_leap(c->servo, clock_leap); c->leap_set = clock_leap; } } diff --git a/phc2sys.c b/phc2sys.c index 06fbddb..3f5d144 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -1114,6 +1114,8 @@ static int clock_handle_leap(struct node *node, struct clock *clock, if (clock->clkid == CLOCK_REALTIME && node->kernel_leap) sysclk_set_leap(clock_leap); + else + servo_leap(clock->servo, clock_leap); clock->leap_set = clock_leap; } } diff --git a/servo.c b/servo.c index 58bd4eb..f200f75 100644 --- a/servo.c +++ b/servo.c @@ -107,3 +107,9 @@ double servo_rate_ratio(struct servo *servo) return 1.0; } + +void servo_leap(struct servo *servo, int leap) +{ + if (servo->leap) + servo->leap(servo, leap); +} diff --git a/servo.h b/servo.h index 9cec6f4..e054501 100644 --- a/servo.h +++ b/servo.h @@ -132,4 +132,12 @@ void servo_reset(struct servo *servo); */ double servo_rate_ratio(struct servo *servo); +/** + * Inform a clock servo about upcoming leap second. + * @param servo Pointer to a servo obtained via @ref servo_create(). + * @param leap +1 when leap second will be inserted, -1 when leap second + * will be deleted, 0 when it passed. + */ +void servo_leap(struct servo *servo, int leap); + #endif diff --git a/servo_private.h b/servo_private.h index ebb7e3b..9a1a459 100644 --- a/servo_private.h +++ b/servo_private.h @@ -38,6 +38,8 @@ struct servo { void (*reset)(struct servo *servo); double (*rate_ratio)(struct servo *servo); + + void (*leap)(struct servo *servo, int leap); }; #endif