From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Prarit Bhargava <prarit@redhat.com>,
John Stultz <johnstul@us.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Salman Qazi <sqazi@google.com>,
stable@kernel.org
Subject: [PATCH] clocksource, prevent overflow in clocksource_cyc2ns
Date: Wed, 4 Apr 2012 11:11:00 -0400 [thread overview]
Message-ID: <1333552260-1170-1-git-send-email-prarit@redhat.com> (raw)
The clocksource code has a watchdog which runs once a minute. The
clocksource watchdog calculates the number of nanoseconds since the last
time the watchdog ran and compares that value to the number of nanoseconds
that have passed on another clocksource. If these values do not match (to
within .0625s) then the watchdog marks the current clocksource as unstable
and switches to another clocksource.
This works so long as the delta between calls of the watchdog is small
(maximum delta is ~18 seconds with the tsc). After that, the
clocksource_cyc2ns() calculation will overflow and the calculated number
of ns returned is incorrect.
This causes the watchdog to erroneously mark the tsc as unstable and
switch to the hpet.
A long delay on the system is not usual, however, it can be reproduced
simply by doing
echo 1 > /proc/sys/kernel/sysrq
for i in `seq 10000`; do sleep 1000 & done
echo t > /proc/sysrq-trigger
on a 32-cpu system (which is not an unusual number of processes for this
size of system). This floods the printk buffer and results in a
pause of approximately 600 seconds which prevents the clocksource watchdog
from running during that time. On the next call, the watchdog erroneously
marks the tsc as unstable and switches to the hpet because the checked
values for the tsc overflow.
Fixing this is simple -- use mult_frac() in clocksource_cyc2ns().
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: John Stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Salman Qazi <sqazi@google.com>
Cc: stable@kernel.org
---
include/linux/clocksource.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index fbe89e1..1625ddb 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -273,7 +273,7 @@ static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant)
*/
static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
{
- return ((u64) cycles * mult) >> shift;
+ return mult_frac(cycles, mult, (1UL << shift));
}
--
1.7.1
next reply other threads:[~2012-04-04 15:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-04 15:11 Prarit Bhargava [this message]
2012-04-04 18:00 ` John Stultz
2012-04-04 18:33 ` Prarit Bhargava
2012-04-05 1:08 ` John Stultz
2012-04-05 11:00 ` Prarit Bhargava
2012-04-05 16:23 ` John Stultz
2012-04-05 12:27 ` Prarit Bhargava
2012-04-05 16:45 ` John Stultz
2012-04-06 23:29 ` Thomas Gleixner
2012-04-07 13:47 ` Prarit Bhargava
2012-04-18 23:20 ` John Stultz
2012-04-18 23:59 ` Prarit Bhargava
2012-04-19 0:18 ` John Stultz
2012-04-19 11:56 ` Prarit Bhargava
2012-04-19 12:50 ` Thomas Gleixner
2012-04-19 12:52 ` Thomas Gleixner
2012-04-19 13:06 ` Prarit Bhargava
2012-04-19 13:18 ` Thomas Gleixner
2012-04-19 18:12 ` John Stultz
2012-04-25 12:29 ` Prarit Bhargava
2012-04-19 12:37 ` Thomas Gleixner
2012-04-19 12:51 ` Thomas Gleixner
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=1333552260-1170-1-git-send-email-prarit@redhat.com \
--to=prarit@redhat.com \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sqazi@google.com \
--cc=stable@kernel.org \
--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