From: Jeremy Fitzhardinge Subject: [patch 1/4] Ignore stolen time in the softlockup watchdog Date: Tue, 27 Mar 2007 14:49:20 -0700 Message-ID: <20070327215827.871954359@goop.org> References: <20070327214919.800272641@goop.org> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline; filename=softlockup-ignore-stolen-time.patch List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: Ingo Molnar Cc: Prarit Bhargava , Rick Lindsley , john stultz , Eric Dumazet , virtualization@lists.osdl.org, Paul Mackerras , Martin Schwidefsky , Andrew Morton , Thomas Gleixner , Linux Kernel List-Id: virtualization@lists.linuxfoundation.org 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 Cc: Ingo Molnar Cc: Thomas Gleixner Cc: john stultz Cc: Zachary Amsden Cc: James Morris Cc: Dan Hecht Cc: Paul Mackerras Cc: Martin Schwidefsky Cc: Prarit Bhargava Cc: Chris Lalancette Cc: Rick Lindsley Cc: Eric Dumazet --- kernel/softlockup.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- a/kernel/softlockup.c +++ b/kernel/softlockup.c @@ -35,9 +35,19 @@ static struct notifier_block panic_block .notifier_call =3D softlock_panic, }; = +/* + * Returns seconds, approximately. We don't need nanosecond + * resolution, and we don't need to waste time with a big divide when + * 2^30ns =3D=3D 1.074s. + */ +static unsigned long get_timestamp(void) +{ + return sched_clock() >> 30; /* 2^30 ~=3D 10^9 */ +} + void touch_softlockup_watchdog(void) { - __raw_get_cpu_var(touch_timestamp) =3D jiffies; + __raw_get_cpu_var(touch_timestamp) =3D get_timestamp(); } EXPORT_SYMBOL(touch_softlockup_watchdog); = @@ -48,10 +58,18 @@ void softlockup_tick(void) void softlockup_tick(void) { int this_cpu =3D smp_processor_id(); - unsigned long touch_timestamp =3D per_cpu(touch_timestamp, this_cpu); + unsigned long touch_timestamp =3D __get_cpu_var(touch_timestamp); + unsigned long print_timestamp; + unsigned long now; = - /* prevent double reports: */ - if (per_cpu(print_timestamp, this_cpu) =3D=3D touch_timestamp || + /* watchdog task hasn't updated timestamp yet */ + if (touch_timestamp =3D=3D 0) + return; + + print_timestamp =3D __get_cpu_var(print_timestamp); + + /* report at most once a second */ + if (print_timestamp < (touch_timestamp + 1) || did_panic || !per_cpu(watchdog_task, this_cpu)) return; @@ -62,12 +80,14 @@ void softlockup_tick(void) return; } = + now =3D get_timestamp(); + /* Wake up the high-prio watchdog task every second: */ - if (time_after(jiffies, touch_timestamp + HZ)) + if (now > (touch_timestamp + 1)) wake_up_process(per_cpu(watchdog_task, this_cpu)); = /* Warn about unreasonable 10+ seconds delays: */ - if (time_after(jiffies, touch_timestamp + 10*HZ)) { + if (now > (touch_timestamp + 10)) { per_cpu(print_timestamp, this_cpu) =3D touch_timestamp; = spin_lock(&print_lock); @@ -87,6 +107,9 @@ static int watchdog(void * __bind_cpu) = sched_setscheduler(current, SCHED_FIFO, ¶m); current->flags |=3D PF_NOFREEZE; + + /* initialize timestamp */ + touch_softlockup_watchdog(); = /* * Run briefly once per second to reset the softlockup timestamp. @@ -120,7 +143,7 @@ cpu_callback(struct notifier_block *nfb, printk("watchdog for %i failed\n", hotcpu); return NOTIFY_BAD; } - per_cpu(touch_timestamp, hotcpu) =3D jiffies; + per_cpu(touch_timestamp, hotcpu) =3D 0; per_cpu(watchdog_task, hotcpu) =3D p; kthread_bind(p, hotcpu); break; -- =