Re: [PATCH 7/8] time: Move xtime_nsec adjustment underflow handling timekeeping_adjust
* John Stultz wrote: > When we make adjustments speeding up the clock, its possible > for xtime_nsec to underflow. We already handle this properly, > but we do so from update_wall_time() instead of the more logical > timekeeping_adjust(), where the possible underflow actually > occurs. > > Thus, move the correction logic to the timekeeping_adjust, which > is the function that causes the issue. Making update_wall_time() > more readable. > > CC: Ingo Molnar > CC: Peter Zijlstra > CC: Richard Cochran > CC: Prarit Bhargava > CC: Thomas Gleixner > Signed-off-by: John Stultz > --- > kernel/time/timekeeping.c | 42 +- > 1 file changed, 21 insertions(+), 21 deletions(-) > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index dd119355..4b76432 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -987,6 +987,27 @@ static void timekeeping_adjust(s64 offset) > timekeeper.xtime_nsec -= offset; > timekeeper.ntp_error -= (interval - offset) << > timekeeper.ntp_error_shift; > + > + /* > + * It may be possible that when we entered this function, xtime_nsec > + * was very small. Further, if we're slightly speeding the clocksource > + * in the code above, its possible the required corrective factor to > + * xtime_nsec could cause it to underflow. s/slightly speeding/slightly speeding up ? > + * > + * Now, since we already accumulated the second, cannot simply roll > + * the accumulated second back, since the NTP subsystem has been s/cannot/we cannot ? Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 7/8] time: Move xtime_nsec adjustment underflow handling timekeeping_adjust
* John Stultz john.stu...@linaro.org wrote: When we make adjustments speeding up the clock, its possible for xtime_nsec to underflow. We already handle this properly, but we do so from update_wall_time() instead of the more logical timekeeping_adjust(), where the possible underflow actually occurs. Thus, move the correction logic to the timekeeping_adjust, which is the function that causes the issue. Making update_wall_time() more readable. CC: Ingo Molnar mi...@kernel.org CC: Peter Zijlstra a.p.zijls...@chello.nl CC: Richard Cochran richardcoch...@gmail.com CC: Prarit Bhargava pra...@redhat.com CC: Thomas Gleixner t...@linutronix.de Signed-off-by: John Stultz johns...@us.ibm.com --- kernel/time/timekeeping.c | 42 +- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index dd119355..4b76432 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -987,6 +987,27 @@ static void timekeeping_adjust(s64 offset) timekeeper.xtime_nsec -= offset; timekeeper.ntp_error -= (interval - offset) timekeeper.ntp_error_shift; + + /* + * It may be possible that when we entered this function, xtime_nsec + * was very small. Further, if we're slightly speeding the clocksource + * in the code above, its possible the required corrective factor to + * xtime_nsec could cause it to underflow. s/slightly speeding/slightly speeding up ? + * + * Now, since we already accumulated the second, cannot simply roll + * the accumulated second back, since the NTP subsystem has been s/cannot/we cannot ? Thanks, Ingo -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 7/8] time: Move xtime_nsec adjustment underflow handling timekeeping_adjust
When we make adjustments speeding up the clock, its possible for xtime_nsec to underflow. We already handle this properly, but we do so from update_wall_time() instead of the more logical timekeeping_adjust(), where the possible underflow actually occurs. Thus, move the correction logic to the timekeeping_adjust, which is the function that causes the issue. Making update_wall_time() more readable. CC: Ingo Molnar CC: Peter Zijlstra CC: Richard Cochran CC: Prarit Bhargava CC: Thomas Gleixner Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 42 +- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index dd119355..4b76432 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -987,6 +987,27 @@ static void timekeeping_adjust(s64 offset) timekeeper.xtime_nsec -= offset; timekeeper.ntp_error -= (interval - offset) << timekeeper.ntp_error_shift; + + /* +* It may be possible that when we entered this function, xtime_nsec +* was very small. Further, if we're slightly speeding the clocksource +* in the code above, its possible the required corrective factor to +* xtime_nsec could cause it to underflow. +* +* Now, since we already accumulated the second, cannot simply roll +* the accumulated second back, since the NTP subsystem has been +* notified via second_overflow. So instead we push xtime_nsec forward +* by the amount we underflowed, and add that amount into the error. +* +* We'll correct this error next time through this function, when +* xtime_nsec is not as small. +*/ + if (unlikely((s64)timekeeper.xtime_nsec < 0)) { + s64 neg = -(s64)timekeeper.xtime_nsec; + timekeeper.xtime_nsec = 0; + timekeeper.ntp_error += neg << timekeeper.ntp_error_shift; + } + } @@ -1112,27 +1133,6 @@ static void update_wall_time(void) /* correct the clock when NTP error is too big */ timekeeping_adjust(offset); - /* -* Since in the loop above, we accumulate any amount of time -* in xtime_nsec over a second into xtime.tv_sec, its possible for -* xtime_nsec to be fairly small after the loop. Further, if we're -* slightly speeding the clocksource up in timekeeping_adjust(), -* its possible the required corrective factor to xtime_nsec could -* cause it to underflow. -* -* Now, we cannot simply roll the accumulated second back, since -* the NTP subsystem has been notified via second_overflow. So -* instead we push xtime_nsec forward by the amount we underflowed, -* and add that amount into the error. -* -* We'll correct this error next time through this function, when -* xtime_nsec is not as small. -*/ - if (unlikely((s64)timekeeper.xtime_nsec < 0)) { - s64 neg = -(s64)timekeeper.xtime_nsec; - timekeeper.xtime_nsec = 0; - timekeeper.ntp_error += neg << timekeeper.ntp_error_shift; - } /* * Store only full nanoseconds into xtime_nsec after rounding -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 7/8] time: Move xtime_nsec adjustment underflow handling timekeeping_adjust
When we make adjustments speeding up the clock, its possible for xtime_nsec to underflow. We already handle this properly, but we do so from update_wall_time() instead of the more logical timekeeping_adjust(), where the possible underflow actually occurs. Thus, move the correction logic to the timekeeping_adjust, which is the function that causes the issue. Making update_wall_time() more readable. CC: Ingo Molnar mi...@kernel.org CC: Peter Zijlstra a.p.zijls...@chello.nl CC: Richard Cochran richardcoch...@gmail.com CC: Prarit Bhargava pra...@redhat.com CC: Thomas Gleixner t...@linutronix.de Signed-off-by: John Stultz johns...@us.ibm.com --- kernel/time/timekeeping.c | 42 +- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index dd119355..4b76432 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -987,6 +987,27 @@ static void timekeeping_adjust(s64 offset) timekeeper.xtime_nsec -= offset; timekeeper.ntp_error -= (interval - offset) timekeeper.ntp_error_shift; + + /* +* It may be possible that when we entered this function, xtime_nsec +* was very small. Further, if we're slightly speeding the clocksource +* in the code above, its possible the required corrective factor to +* xtime_nsec could cause it to underflow. +* +* Now, since we already accumulated the second, cannot simply roll +* the accumulated second back, since the NTP subsystem has been +* notified via second_overflow. So instead we push xtime_nsec forward +* by the amount we underflowed, and add that amount into the error. +* +* We'll correct this error next time through this function, when +* xtime_nsec is not as small. +*/ + if (unlikely((s64)timekeeper.xtime_nsec 0)) { + s64 neg = -(s64)timekeeper.xtime_nsec; + timekeeper.xtime_nsec = 0; + timekeeper.ntp_error += neg timekeeper.ntp_error_shift; + } + } @@ -1112,27 +1133,6 @@ static void update_wall_time(void) /* correct the clock when NTP error is too big */ timekeeping_adjust(offset); - /* -* Since in the loop above, we accumulate any amount of time -* in xtime_nsec over a second into xtime.tv_sec, its possible for -* xtime_nsec to be fairly small after the loop. Further, if we're -* slightly speeding the clocksource up in timekeeping_adjust(), -* its possible the required corrective factor to xtime_nsec could -* cause it to underflow. -* -* Now, we cannot simply roll the accumulated second back, since -* the NTP subsystem has been notified via second_overflow. So -* instead we push xtime_nsec forward by the amount we underflowed, -* and add that amount into the error. -* -* We'll correct this error next time through this function, when -* xtime_nsec is not as small. -*/ - if (unlikely((s64)timekeeper.xtime_nsec 0)) { - s64 neg = -(s64)timekeeper.xtime_nsec; - timekeeper.xtime_nsec = 0; - timekeeper.ntp_error += neg timekeeper.ntp_error_shift; - } /* * Store only full nanoseconds into xtime_nsec after rounding -- 1.7.9.5 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/