From: tip-bot for John Stultz <john.stultz@linaro.org>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
a.p.zijlstra@chello.nl, johnstul@us.ibm.com,
richardcochran@gmail.com, john.stultz@linaro.org,
tglx@linutronix.de, prarit@redhat.com
Subject: [tip:timers/core] time: Move xtime_nsec adjustment underflow handling timekeeping_adjust
Date: Sun, 15 Jul 2012 02:00:40 -0700 [thread overview]
Message-ID: <tip-2a8c0883c3cfffcc148ea606e2a4e7453cd75e73@git.kernel.org> (raw)
In-Reply-To: <1342156917-25092-8-git-send-email-john.stultz@linaro.org>
Commit-ID: 2a8c0883c3cfffcc148ea606e2a4e7453cd75e73
Gitweb: http://git.kernel.org/tip/2a8c0883c3cfffcc148ea606e2a4e7453cd75e73
Author: John Stultz <john.stultz@linaro.org>
AuthorDate: Fri, 13 Jul 2012 01:21:56 -0400
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 15 Jul 2012 10:39:07 +0200
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.
Signed-off-by: John Stultz <johnstul@us.ibm.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Link: http://lkml.kernel.org/r/1342156917-25092-8-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/time/timekeeping.c | 42 +++++++++++++++++++++---------------------
1 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index e43289d..aeeaab8 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -980,6 +980,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;
+ }
+
}
@@ -1105,27 +1126,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
next prev parent reply other threads:[~2012-07-15 9:01 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-13 5:21 [PATCH 0/8] Time fixes and cleanups for 3.6 John Stultz
2012-07-13 5:21 ` [PATCH 1/8] ntp: Fix STA_INS/DEL clearing bug John Stultz
2012-07-13 5:58 ` Ingo Molnar
2012-07-13 18:36 ` John Stultz
2012-07-15 7:57 ` [tip:timers/urgent] " tip-bot for John Stultz
2012-07-13 5:21 ` [PATCH 2/8] time: Whitespace cleanups per Ingo's requests John Stultz
2012-07-15 8:56 ` [tip:timers/core] time: Whitespace cleanups per Ingo%27s requests tip-bot for John Stultz
2012-07-13 5:21 ` [PATCH 3/8] time: Explicitly use u32 instead of int for shift values John Stultz
2012-07-15 8:57 ` [tip:timers/core] " tip-bot for John Stultz
2012-07-13 5:21 ` [PATCH 4/8] time: Condense timekeeper.xtime into xtime_sec John Stultz
2012-07-13 6:00 ` Ingo Molnar
2012-07-15 8:57 ` [tip:timers/core] " tip-bot for John Stultz
2012-08-19 21:02 ` [PATCH 4/8] " Andreas Schwab
2012-08-20 18:58 ` John Stultz
2012-08-20 19:45 ` Andreas Schwab
2012-08-20 19:57 ` John Stultz
2012-08-20 20:04 ` Andreas Schwab
2012-08-21 3:38 ` John Stultz
2012-08-21 7:14 ` Andreas Schwab
2012-08-21 18:14 ` John Stultz
2012-07-13 5:21 ` [PATCH 5/8] time: Refactor accumulation of nsecs to secs John Stultz
2012-07-13 5:56 ` Ingo Molnar
2012-07-13 6:01 ` Ingo Molnar
2012-07-15 8:58 ` [tip:timers/core] " tip-bot for John Stultz
2012-07-13 5:21 ` [PATCH 6/8] time: Move arch_gettimeoffset() usage into timekeeping_get_ns() John Stultz
2012-07-13 6:03 ` Ingo Molnar
2012-07-15 8:59 ` [tip:timers/core] " tip-bot for John Stultz
2012-07-13 5:21 ` [PATCH 7/8] time: Move xtime_nsec adjustment underflow handling timekeeping_adjust John Stultz
2012-07-13 6:04 ` Ingo Molnar
2012-07-15 9:00 ` tip-bot for John Stultz [this message]
2012-07-13 5:21 ` [PATCH 8/8] time: Rework timekeeping functions to take timekeeper ptr as argument John Stultz
2012-07-15 9:01 ` [tip:timers/core] " tip-bot for John Stultz
2012-07-13 6:05 ` [PATCH 0/8] Time fixes and cleanups for 3.6 Ingo Molnar
2012-07-13 20:49 ` John Stultz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-2a8c0883c3cfffcc148ea606e2a4e7453cd75e73@git.kernel.org \
--to=john.stultz@linaro.org \
--cc=a.p.zijlstra@chello.nl \
--cc=hpa@zytor.com \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=prarit@redhat.com \
--cc=richardcochran@gmail.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome