Skip to content

Commit 966812d

Browse files
jsgfLinus Torvalds
authored andcommitted
Ignore stolen time in the softlockup watchdog
The softlockup watchdog is currently a nuisance in a virtual machine, since the whole system could have the CPU stolen from it for a long period of time. While it would be unlikely for a guest domain to be denied timer interrupts for over 10s, it could happen and any softlockup message would be completely spurious. Earlier I proposed that sched_clock() return time in unstolen nanoseconds, which is how Xen and VMI currently implement it. If the softlockup watchdog uses sched_clock() to measure time, it would automatically ignore stolen time, and therefore only report when the guest itself locked up. When running native, sched_clock() returns real-time nanoseconds, so the behaviour would be unchanged. Note that sched_clock() used this way is inherently per-cpu, so this patch makes sure that the per-processor watchdog thread initialized its own timestamp. Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: john stultz <johnstul@us.ibm.com> Cc: Zachary Amsden <zach@vmware.com> Cc: James Morris <jmorris@namei.org> Cc: Dan Hecht <dhecht@vmware.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Chris Lalancette <clalance@redhat.com> Cc: Rick Lindsley <ricklind@us.ibm.com> Cc: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8524070 commit 966812d

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

‎kernel/softlockup.c‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@ static struct notifier_block panic_block = {
3434
.notifier_call = softlock_panic,
3535
};
3636

37+
/*
38+
* Returns seconds, approximately. We don't need nanosecond
39+
* resolution, and we don't need to waste time with a big divide when
40+
* 2^30ns == 1.074s.
41+
*/
42+
static unsigned long get_timestamp(void)
43+
{
44+
return sched_clock() >> 30; /* 2^30 ~= 10^9 */
45+
}
46+
3747
void touch_softlockup_watchdog(void)
3848
{
39-
__raw_get_cpu_var(touch_timestamp) = jiffies;
49+
__raw_get_cpu_var(touch_timestamp) = get_timestamp();
4050
}
4151
EXPORT_SYMBOL(touch_softlockup_watchdog);
4252

@@ -48,9 +58,17 @@ void softlockup_tick(void)
4858
{
4959
int this_cpu = smp_processor_id();
5060
unsigned long touch_timestamp = per_cpu(touch_timestamp, this_cpu);
61+
unsigned long print_timestamp;
62+
unsigned long now;
5163

52-
/* prevent double reports: */
53-
if (per_cpu(print_timestamp, this_cpu) == touch_timestamp ||
64+
/* watchdog task hasn't updated timestamp yet */
65+
if (touch_timestamp == 0)
66+
return;
67+
68+
print_timestamp = per_cpu(print_timestamp, this_cpu);
69+
70+
/* report at most once a second */
71+
if (print_timestamp < (touch_timestamp + 1) ||
5472
did_panic ||
5573
!per_cpu(watchdog_task, this_cpu))
5674
return;
@@ -61,12 +79,14 @@ void softlockup_tick(void)
6179
return;
6280
}
6381

82+
now = get_timestamp();
83+
6484
/* Wake up the high-prio watchdog task every second: */
65-
if (time_after(jiffies, touch_timestamp + HZ))
85+
if (now > (touch_timestamp + 1))
6686
wake_up_process(per_cpu(watchdog_task, this_cpu));
6787

6888
/* Warn about unreasonable 10+ seconds delays: */
69-
if (time_after(jiffies, touch_timestamp + 10*HZ)) {
89+
if (now > (touch_timestamp + 10)) {
7090
per_cpu(print_timestamp, this_cpu) = touch_timestamp;
7191

7292
spin_lock(&print_lock);
@@ -87,6 +107,9 @@ static int watchdog(void * __bind_cpu)
87107
sched_setscheduler(current, SCHED_FIFO, &param);
88108
current->flags |= PF_NOFREEZE;
89109

110+
/* initialize timestamp */
111+
touch_softlockup_watchdog();
112+
90113
/*
91114
* Run briefly once per second to reset the softlockup timestamp.
92115
* If this gets delayed for more than 10 seconds then the
@@ -118,7 +141,7 @@ cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
118141
printk("watchdog for %i failed\n", hotcpu);
119142
return NOTIFY_BAD;
120143
}
121-
per_cpu(touch_timestamp, hotcpu) = jiffies;
144+
per_cpu(touch_timestamp, hotcpu) = 0;
122145
per_cpu(watchdog_task, hotcpu) = p;
123146
kthread_bind(p, hotcpu);
124147
break;

0 commit comments

Comments
 (0)