* [PATCH 1/4] time: Ensure we normalize the timekeeper in tk_xtime_add
2012-08-22 0:30 [PATCH 0/4] Time fixes for 3.6 John Stultz
@ 2012-08-22 0:30 ` John Stultz
2012-08-22 8:50 ` [tip:timers/urgent] " tip-bot for John Stultz
2012-08-22 0:30 ` [PATCH 2/4] time: Fix casting issue in timekeeping_forward_now John Stultz
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: John Stultz @ 2012-08-22 0:30 UTC (permalink / raw)
To: linux-kernel
Cc: John Stultz, Ingo Molnar, Prarit Bhargava, Thomas Gleixner,
Andreas Schwab
Andreas noticed problems with resume on specific hardware
after commit 1e75fa8be9fb61e1af46b5b3b176347a4c958ca1
combined with commit b44d50dcacea0d485ca2ff9140f8cc28ee22f28d
After some digging I realized we aren't normalizing
the timekeeper after the add. This patch to correct this
resolved the issue.
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Tested-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
kernel/time/timekeeping.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 898bef0..258164a 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -115,6 +115,7 @@ static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts)
{
tk->xtime_sec += ts->tv_sec;
tk->xtime_nsec += (u64)ts->tv_nsec << tk->shift;
+ tk_normalize_xtime(tk);
}
static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec wtm)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread* [tip:timers/urgent] time: Ensure we normalize the timekeeper in tk_xtime_add
2012-08-22 0:30 ` [PATCH 1/4] time: Ensure we normalize the timekeeper in tk_xtime_add John Stultz
@ 2012-08-22 8:50 ` tip-bot for John Stultz
0 siblings, 0 replies; 10+ messages in thread
From: tip-bot for John Stultz @ 2012-08-22 8:50 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, john.stultz, hpa, mingo, schwab, tglx, prarit
Commit-ID: 784ffcbb96c3a97b4c64fd48b1dfe12ef3fcbcda
Gitweb: http://git.kernel.org/tip/784ffcbb96c3a97b4c64fd48b1dfe12ef3fcbcda
Author: John Stultz <john.stultz@linaro.org>
AuthorDate: Tue, 21 Aug 2012 20:30:46 -0400
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 22 Aug 2012 10:42:12 +0200
time: Ensure we normalize the timekeeper in tk_xtime_add
Andreas noticed problems with resume on specific hardware after commit
1e75fa8b (time: Condense timekeeper.xtime into xtime_sec) combined
with commit b44d50dca (time: Fix casting issue in tk_set_xtime and
tk_xtime_add)
After some digging I realized we aren't normalizing the timekeeper
after the add. Add the missing normalize call.
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Tested-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1345595449-34965-2-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/time/timekeeping.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 898bef0..258164a 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -115,6 +115,7 @@ static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts)
{
tk->xtime_sec += ts->tv_sec;
tk->xtime_nsec += (u64)ts->tv_nsec << tk->shift;
+ tk_normalize_xtime(tk);
}
static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec wtm)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/4] time: Fix casting issue in timekeeping_forward_now
2012-08-22 0:30 [PATCH 0/4] Time fixes for 3.6 John Stultz
2012-08-22 0:30 ` [PATCH 1/4] time: Ensure we normalize the timekeeper in tk_xtime_add John Stultz
@ 2012-08-22 0:30 ` John Stultz
2012-08-22 8:51 ` [tip:timers/urgent] " tip-bot for Andreas Schwab
2012-08-22 0:30 ` [PATCH 3/4] time: Avoid potential shift-overflow with large shift values John Stultz
2012-08-22 0:30 ` [PATCH 4/4] time: Avoid making adjustments if we havne't accumulated anything John Stultz
3 siblings, 1 reply; 10+ messages in thread
From: John Stultz @ 2012-08-22 0:30 UTC (permalink / raw)
To: linux-kernel
Cc: Andreas Schwab, Ingo Molnar, Prarit Bhargava, Thomas Gleixner,
John Stultz
From: Andreas Schwab <schwab@linux-m68k.org>
arch_gettimeoffset returns a u32 value which when shifted by tk->shift can
overflow. Cast it to u64 first.
This issue was introduced with 1e75fa8be9fb61e1af46b5b3b176347a4c958ca1
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
kernel/time/timekeeping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 258164a..1dbf80e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -277,7 +277,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
tk->xtime_nsec += cycle_delta * tk->mult;
/* If arch requires, add in gettimeoffset() */
- tk->xtime_nsec += arch_gettimeoffset() << tk->shift;
+ tk->xtime_nsec += (u64)arch_gettimeoffset() << tk->shift;
tk_normalize_xtime(tk);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [tip:timers/urgent] time: Fix casting issue in timekeeping_forward_now
2012-08-22 0:30 ` [PATCH 2/4] time: Fix casting issue in timekeeping_forward_now John Stultz
@ 2012-08-22 8:51 ` tip-bot for Andreas Schwab
0 siblings, 0 replies; 10+ messages in thread
From: tip-bot for Andreas Schwab @ 2012-08-22 8:51 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, john.stultz, hpa, mingo, schwab, tglx, prarit
Commit-ID: 85dc8f05c93c8105987de9d7e7cebf15a72ff4ec
Gitweb: http://git.kernel.org/tip/85dc8f05c93c8105987de9d7e7cebf15a72ff4ec
Author: Andreas Schwab <schwab@linux-m68k.org>
AuthorDate: Tue, 21 Aug 2012 20:30:47 -0400
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 22 Aug 2012 10:42:13 +0200
time: Fix casting issue in timekeeping_forward_now
arch_gettimeoffset returns a u32 value which when shifted by tk->shift
can overflow. This issue was introduced with 1e75fa8be (time: Condense
timekeeper.xtime into xtime_sec)
Cast it to u64 first.
Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1345595449-34965-3-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/time/timekeeping.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 258164a..1dbf80e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -277,7 +277,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
tk->xtime_nsec += cycle_delta * tk->mult;
/* If arch requires, add in gettimeoffset() */
- tk->xtime_nsec += arch_gettimeoffset() << tk->shift;
+ tk->xtime_nsec += (u64)arch_gettimeoffset() << tk->shift;
tk_normalize_xtime(tk);
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/4] time: Avoid potential shift-overflow with large shift values
2012-08-22 0:30 [PATCH 0/4] Time fixes for 3.6 John Stultz
2012-08-22 0:30 ` [PATCH 1/4] time: Ensure we normalize the timekeeper in tk_xtime_add John Stultz
2012-08-22 0:30 ` [PATCH 2/4] time: Fix casting issue in timekeeping_forward_now John Stultz
@ 2012-08-22 0:30 ` John Stultz
2012-08-22 8:11 ` Geert Uytterhoeven
2012-08-22 8:52 ` [tip:timers/urgent] time: Avoid potential shift overflow " tip-bot for John Stultz
2012-08-22 0:30 ` [PATCH 4/4] time: Avoid making adjustments if we havne't accumulated anything John Stultz
3 siblings, 2 replies; 10+ messages in thread
From: John Stultz @ 2012-08-22 0:30 UTC (permalink / raw)
To: linux-kernel
Cc: John Stultz, Ingo Molnar, Prarit Bhargava, Thomas Gleixner,
Andreas Schwab
Andreas Schwab noted that the 1 << tk->shift could overflow
if the shift value was greater then 30, since 1 would be
a 32bit long on 32bit architectures.
This patch uses 1ULL instead to ensure we don't overflow on
the shift.
This issue was introduced by 1e75fa8be9fb61e1af46b5b3b176347a4c958ca1
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
kernel/time/timekeeping.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 1dbf80e..a5a9389 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1184,9 +1184,9 @@ static void update_wall_time(void)
* the vsyscall implementations are converted to use xtime_nsec
* (shifted nanoseconds), this can be killed.
*/
- remainder = tk->xtime_nsec & ((1 << tk->shift) - 1);
+ remainder = tk->xtime_nsec & ((1ULL << tk->shift) - 1);
tk->xtime_nsec -= remainder;
- tk->xtime_nsec += 1 << tk->shift;
+ tk->xtime_nsec += 1ULL << tk->shift;
tk->ntp_error += remainder << tk->ntp_error_shift;
/*
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 3/4] time: Avoid potential shift-overflow with large shift values
2012-08-22 0:30 ` [PATCH 3/4] time: Avoid potential shift-overflow with large shift values John Stultz
@ 2012-08-22 8:11 ` Geert Uytterhoeven
2012-08-22 8:52 ` [tip:timers/urgent] time: Avoid potential shift overflow " tip-bot for John Stultz
1 sibling, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2012-08-22 8:11 UTC (permalink / raw)
To: John Stultz
Cc: linux-kernel, Ingo Molnar, Prarit Bhargava, Thomas Gleixner,
Andreas Schwab
Hi John,
On Wed, Aug 22, 2012 at 2:30 AM, John Stultz <john.stultz@linaro.org> wrote:
> Andreas Schwab noted that the 1 << tk->shift could overflow
> if the shift value was greater then 30, since 1 would be
> a 32bit long on 32bit architectures.
This comment is not entirely correct: "1" is not a long, but an
(32-bit signed) int,
so it can overflow on 64-bit platforms, too.
> This patch uses 1ULL instead to ensure we don't overflow on
> the shift.
>
> This issue was introduced by 1e75fa8be9fb61e1af46b5b3b176347a4c958ca1
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Prarit Bhargava <prarit@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Andreas Schwab <schwab@linux-m68k.org>
> Reported-by: Andreas Schwab <schwab@linux-m68k.org>
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> ---
> kernel/time/timekeeping.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index 1dbf80e..a5a9389 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -1184,9 +1184,9 @@ static void update_wall_time(void)
> * the vsyscall implementations are converted to use xtime_nsec
> * (shifted nanoseconds), this can be killed.
> */
> - remainder = tk->xtime_nsec & ((1 << tk->shift) - 1);
> + remainder = tk->xtime_nsec & ((1ULL << tk->shift) - 1);
> tk->xtime_nsec -= remainder;
> - tk->xtime_nsec += 1 << tk->shift;
> + tk->xtime_nsec += 1ULL << tk->shift;
> tk->ntp_error += remainder << tk->ntp_error_shift;
>
> /*
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 10+ messages in thread* [tip:timers/urgent] time: Avoid potential shift overflow with large shift values
2012-08-22 0:30 ` [PATCH 3/4] time: Avoid potential shift-overflow with large shift values John Stultz
2012-08-22 8:11 ` Geert Uytterhoeven
@ 2012-08-22 8:52 ` tip-bot for John Stultz
1 sibling, 0 replies; 10+ messages in thread
From: tip-bot for John Stultz @ 2012-08-22 8:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, john.stultz, hpa, mingo, schwab, tglx, prarit
Commit-ID: 6ea565a9be32a3c8d1092017686f183b6d8c4514
Gitweb: http://git.kernel.org/tip/6ea565a9be32a3c8d1092017686f183b6d8c4514
Author: John Stultz <john.stultz@linaro.org>
AuthorDate: Tue, 21 Aug 2012 20:30:48 -0400
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 22 Aug 2012 10:42:13 +0200
time: Avoid potential shift overflow with large shift values
Andreas Schwab noticed that the 1 << tk->shift could overflow if the
shift value was greater than 30, since 1 would be a 32bit long on
32bit architectures. This issue was introduced by 1e75fa8be (time:
Condense timekeeper.xtime into xtime_sec)
Use 1ULL instead to ensure we don't overflow on the shift.
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1345595449-34965-4-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/time/timekeeping.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 1dbf80e..a5a9389 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1184,9 +1184,9 @@ static void update_wall_time(void)
* the vsyscall implementations are converted to use xtime_nsec
* (shifted nanoseconds), this can be killed.
*/
- remainder = tk->xtime_nsec & ((1 << tk->shift) - 1);
+ remainder = tk->xtime_nsec & ((1ULL << tk->shift) - 1);
tk->xtime_nsec -= remainder;
- tk->xtime_nsec += 1 << tk->shift;
+ tk->xtime_nsec += 1ULL << tk->shift;
tk->ntp_error += remainder << tk->ntp_error_shift;
/*
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/4] time: Avoid making adjustments if we havne't accumulated anything
2012-08-22 0:30 [PATCH 0/4] Time fixes for 3.6 John Stultz
` (2 preceding siblings ...)
2012-08-22 0:30 ` [PATCH 3/4] time: Avoid potential shift-overflow with large shift values John Stultz
@ 2012-08-22 0:30 ` John Stultz
2012-08-22 8:52 ` [tip:timers/urgent] time: Avoid making adjustments if we haven' t " tip-bot for John Stultz
3 siblings, 1 reply; 10+ messages in thread
From: John Stultz @ 2012-08-22 0:30 UTC (permalink / raw)
To: linux-kernel
Cc: John Stultz, Ingo Molnar, Prarit Bhargava, Thomas Gleixner,
stable
If update_wall_time() is called and the current offset isn't
large enough to accumulate, avoid re-calling timekeeping_adjust
which may change the clock freq and can cause 1ns inconsistencies
with CLOCK_REALTIME_COARSE/CLOCK_MONOTONIC_COARSE.
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
kernel/time/timekeeping.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index a5a9389..0c1485e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1152,6 +1152,10 @@ static void update_wall_time(void)
offset = (clock->read(clock) - clock->cycle_last) & clock->mask;
#endif
+ /* Check if there's really nothing to do */
+ if (offset < tk->cycle_interval)
+ goto out;
+
/*
* With NO_HZ we may have to accumulate many cycle_intervals
* (think "ticks") worth of time at once. To do this efficiently,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread* [tip:timers/urgent] time: Avoid making adjustments if we haven' t accumulated anything
2012-08-22 0:30 ` [PATCH 4/4] time: Avoid making adjustments if we havne't accumulated anything John Stultz
@ 2012-08-22 8:52 ` tip-bot for John Stultz
0 siblings, 0 replies; 10+ messages in thread
From: tip-bot for John Stultz @ 2012-08-22 8:52 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, john.stultz, hpa, mingo, tglx, prarit
Commit-ID: bf2ac312195155511a0f79325515cbb61929898a
Gitweb: http://git.kernel.org/tip/bf2ac312195155511a0f79325515cbb61929898a
Author: John Stultz <john.stultz@linaro.org>
AuthorDate: Tue, 21 Aug 2012 20:30:49 -0400
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 22 Aug 2012 10:42:13 +0200
time: Avoid making adjustments if we haven't accumulated anything
If update_wall_time() is called and the current offset isn't large
enough to accumulate, avoid re-calling timekeeping_adjust which may
change the clock freq and can cause 1ns inconsistencies with
CLOCK_REALTIME_COARSE/CLOCK_MONOTONIC_COARSE.
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1345595449-34965-5-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/time/timekeeping.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index a5a9389..0c1485e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1152,6 +1152,10 @@ static void update_wall_time(void)
offset = (clock->read(clock) - clock->cycle_last) & clock->mask;
#endif
+ /* Check if there's really nothing to do */
+ if (offset < tk->cycle_interval)
+ goto out;
+
/*
* With NO_HZ we may have to accumulate many cycle_intervals
* (think "ticks") worth of time at once. To do this efficiently,
^ permalink raw reply related [flat|nested] 10+ messages in thread