From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934025AbXC0FtB (ORCPT ); Tue, 27 Mar 2007 01:49:01 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S934030AbXC0FtA (ORCPT ); Tue, 27 Mar 2007 01:49:00 -0400 Received: from gw.goop.org ([64.81.55.164]:59347 "EHLO mail.goop.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934025AbXC0Fs7 (ORCPT ); Tue, 27 Mar 2007 01:48:59 -0400 Message-Id: <20070327054106.664262413@goop.org> References: <20070327053816.881735237@goop.org> User-Agent: quilt/0.46-1 Date: Mon, 26 Mar 2007 22:38:17 -0700 From: Jeremy Fitzhardinge To: Andrew Morton Cc: Linux Kernel , virtualization@lists.osdl.org, Ingo Molnar , Thomas Gleixner , john stultz , Zachary Amsden , James Morris , Dan Hecht , Paul Mackerras , Martin Schwidefsky , Prarit Bhargava , Chris Lalancette , Rick Lindsley Subject: [patch 1/2] Ignore stolen time in the softlockup watchdog Content-Disposition: inline; filename=softlockup-ignore-stolen-time.patch Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.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 --- kernel/softlockup.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) =================================================================== --- a/kernel/softlockup.c +++ b/kernel/softlockup.c @@ -17,8 +17,8 @@ static DEFINE_SPINLOCK(print_lock); -static DEFINE_PER_CPU(unsigned long, touch_timestamp); -static DEFINE_PER_CPU(unsigned long, print_timestamp); +static DEFINE_PER_CPU(unsigned long long, touch_timestamp); +static DEFINE_PER_CPU(unsigned long long, print_timestamp); static DEFINE_PER_CPU(struct task_struct *, watchdog_task); static int did_panic = 0; @@ -37,7 +37,7 @@ static struct notifier_block panic_block void touch_softlockup_watchdog(void) { - __raw_get_cpu_var(touch_timestamp) = jiffies; + __raw_get_cpu_var(touch_timestamp) = sched_clock(); } EXPORT_SYMBOL(touch_softlockup_watchdog); @@ -48,10 +48,15 @@ void softlockup_tick(void) void softlockup_tick(void) { int this_cpu = smp_processor_id(); - unsigned long touch_timestamp = per_cpu(touch_timestamp, this_cpu); + unsigned long long touch_timestamp = per_cpu(touch_timestamp, this_cpu); + unsigned long long now; - /* prevent double reports: */ - if (per_cpu(print_timestamp, this_cpu) == touch_timestamp || + /* watchdog task hasn't updated timestamp yet */ + if (touch_timestamp == 0) + return; + + /* report at most once a second */ + if (per_cpu(print_timestamp, this_cpu) < (touch_timestamp + NSEC_PER_SEC) || did_panic || !per_cpu(watchdog_task, this_cpu)) return; @@ -62,12 +67,14 @@ void softlockup_tick(void) return; } + now = sched_clock(); + /* Wake up the high-prio watchdog task every second: */ - if (time_after(jiffies, touch_timestamp + HZ)) + if (now > (touch_timestamp + NSEC_PER_SEC)) 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 + 10ull*NSEC_PER_SEC)) { per_cpu(print_timestamp, this_cpu) = touch_timestamp; spin_lock(&print_lock); @@ -87,6 +94,9 @@ static int watchdog(void * __bind_cpu) sched_setscheduler(current, SCHED_FIFO, ¶m); current->flags |= PF_NOFREEZE; + + /* initialize timestamp */ + touch_softlockup_watchdog(); /* * Run briefly once per second to reset the softlockup timestamp. @@ -120,7 +130,7 @@ cpu_callback(struct notifier_block *nfb, printk("watchdog for %i failed\n", hotcpu); return NOTIFY_BAD; } - per_cpu(touch_timestamp, hotcpu) = jiffies; + per_cpu(touch_timestamp, hotcpu) = 0; per_cpu(watchdog_task, hotcpu) = p; kthread_bind(p, hotcpu); break; --