@@ -1594,7 +1594,9 @@ static __always_inline void timekeeping_freqadjust(struct timekeeper *tk,
s64 xinterval = tk->xtime_interval;
s64 tick_error;
bool negative;
- u32 adj;
+ u32 adj_scale;
+ s32 cur_adj;
+ u32 max;
/* Remove any current error adj from freq calculation */
if (tk->ntp_err_mult)
@@ -1613,13 +1615,24 @@ static __always_inline void timekeeping_freqadjust(struct timekeeper *tk,
/* preserve the direction of correction */
negative = (tick_error < 0);
- /* Sort out the magnitude of the correction */
+ /*
+ * Sort out the magnitude of the correction, but
+ * avoid making so large a correction that we go
+ * over the max adjustment.
+ */
+ adj_scale = 0;
+ max = tk->tkr_mono.clock->maxadj;
+ cur_adj = tk->tkr_mono.mult - tk->tkr_mono.clock->mult;
tick_error = abs(tick_error);
- for (adj = 0; tick_error > interval; adj++)
+ while((tick_error > interval) &&
+ (abs(cur_adj - (1 << (adj_scale + 1)) < max)) &&
+ (abs(cur_adj + (1 << (adj_scale + 1)) < max))) {
+ adj_scale++;
tick_error >>= 1;
+ }
/* scale the corrections */
- timekeeping_apply_adjustment(tk, offset, negative, adj);
+ timekeeping_apply_adjustment(tk, offset, negative, adj_scale);
}
/*
Thus its been occasionally noted that users have seen confusing warnings like: Adjusting tsc more than 11% (5941981 vs 7759439) We try to limit the maximum total adjustment to 11% (10% tick adjustment + 0.5% frequency adjustment). But this is done by bounding the requested adjustment values, and the internal steering that is done by tracking the error from what was requested and what was applied, does not have any such limits. This is usually not problematic, but in some cases has a risk that an adjustment could cause the clocksource mult value to overflow, so its an indication things are outside of what is expected. It ends up most of the reports of this 11% warning are on systems using chrony, which utilizes the adjtimex() ADJ_TICK interface (which allows a +-10% adjustment). The original ratonal for ADJ_TICK unlcear to me but my assumption it was originally added to allow broken systems to get a big constant correction at boot (see adjtimex userspace package for an example) which would allow the system to work w/ ntpd's 0.5% adjustment limit. Chrony uses ADJ_TICK to make very aggressive short term corrections (usually right at startup). Which push us close enough to the max bound that a few late ticks can cause the internal steering to push past the max adjust value (tripping the warning). Thus this patch adds some extra logic to enforce the max adjustment cap in the internal steering. Signed-off-by: John Stultz <john.stultz@linaro.org> --- kernel/time/timekeeping.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) -- 1.9.1