Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jeremy Fitzhardinge and committed by
Linus Torvalds
966812dc 8524070b

+29 -6
+29 -6
kernel/softlockup.c
··· 34 34 .notifier_call = softlock_panic, 35 35 }; 36 36 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 + 37 47 void touch_softlockup_watchdog(void) 38 48 { 39 - __raw_get_cpu_var(touch_timestamp) = jiffies; 49 + __raw_get_cpu_var(touch_timestamp) = get_timestamp(); 40 50 } 41 51 EXPORT_SYMBOL(touch_softlockup_watchdog); 42 52 ··· 58 48 { 59 49 int this_cpu = smp_processor_id(); 60 50 unsigned long touch_timestamp = per_cpu(touch_timestamp, this_cpu); 51 + unsigned long print_timestamp; 52 + unsigned long now; 61 53 62 - /* prevent double reports: */ 63 - if (per_cpu(print_timestamp, this_cpu) == touch_timestamp || 54 + /* watchdog task hasn't updated timestamp yet */ 55 + if (touch_timestamp == 0) 56 + return; 57 + 58 + print_timestamp = per_cpu(print_timestamp, this_cpu); 59 + 60 + /* report at most once a second */ 61 + if (print_timestamp < (touch_timestamp + 1) || 64 62 did_panic || 65 63 !per_cpu(watchdog_task, this_cpu)) 66 64 return; ··· 79 61 return; 80 62 } 81 63 64 + now = get_timestamp(); 65 + 82 66 /* Wake up the high-prio watchdog task every second: */ 83 - if (time_after(jiffies, touch_timestamp + HZ)) 67 + if (now > (touch_timestamp + 1)) 84 68 wake_up_process(per_cpu(watchdog_task, this_cpu)); 85 69 86 70 /* Warn about unreasonable 10+ seconds delays: */ 87 - if (time_after(jiffies, touch_timestamp + 10*HZ)) { 71 + if (now > (touch_timestamp + 10)) { 88 72 per_cpu(print_timestamp, this_cpu) = touch_timestamp; 89 73 90 74 spin_lock(&print_lock); ··· 106 86 107 87 sched_setscheduler(current, SCHED_FIFO, &param); 108 88 current->flags |= PF_NOFREEZE; 89 + 90 + /* initialize timestamp */ 91 + touch_softlockup_watchdog(); 109 92 110 93 /* 111 94 * Run briefly once per second to reset the softlockup timestamp. ··· 141 118 printk("watchdog for %i failed\n", hotcpu); 142 119 return NOTIFY_BAD; 143 120 } 144 - per_cpu(touch_timestamp, hotcpu) = jiffies; 121 + per_cpu(touch_timestamp, hotcpu) = 0; 145 122 per_cpu(watchdog_task, hotcpu) = p; 146 123 kthread_bind(p, hotcpu); 147 124 break;