public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin Schwidefsky <schwidefsky@de.ibm.com>
To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>
Subject: [patch 17/21] nohz: Fix __udelay.
Date: Wed, 01 Oct 2008 10:33:34 +0200	[thread overview]
Message-ID: <20081001084129.581466549@de.ibm.com> (raw)
In-Reply-To: 20081001083317.782967473@de.ibm.com

[-- Attachment #1: 116-udelay-torture.diff --]
[-- Type: text/plain, Size: 4664 bytes --]

From: Heiko Carstens <heiko.carstens@de.ibm.com>

rcutorture reveals that our __udelay implementation is still buggy,
since it might schedule tasklets, but prevents their execution:

NOHZ: local_softirq_pending 42
NOHZ: local_softirq_pending 02
NOHZ: local_softirq_pending 142
NOHZ: local_softirq_pending 02

To fix this we make sure that only the clock comparator interrupt
is enabled when the enabled wait psw is loaded.
Also no code gets called anymore which might schedule tasklets.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---

 arch/s390/kernel/time.c |    2 +
 arch/s390/lib/delay.c   |   88 +++++++++++++++++++++++++++++-------------------
 2 files changed, 56 insertions(+), 34 deletions(-)

Index: quilt-2.6/arch/s390/kernel/time.c
===================================================================
--- quilt-2.6.orig/arch/s390/kernel/time.c
+++ quilt-2.6/arch/s390/kernel/time.c
@@ -169,6 +169,8 @@ void init_cpu_timer(void)
 
 static void clock_comparator_interrupt(__u16 code)
 {
+	if (S390_lowcore.clock_comparator == -1ULL)
+		set_clock_comparator(S390_lowcore.clock_comparator);
 }
 
 static void etr_timing_alert(struct etr_irq_parm *);
Index: quilt-2.6/arch/s390/lib/delay.c
===================================================================
--- quilt-2.6.orig/arch/s390/lib/delay.c
+++ quilt-2.6/arch/s390/lib/delay.c
@@ -1,14 +1,9 @@
 /*
- *  arch/s390/lib/delay.c
  *    Precise Delay Loops for S390
  *
- *  S390 version
- *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
- *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
- *
- *  Derived from "arch/i386/lib/delay.c"
- *    Copyright (C) 1993 Linus Torvalds
- *    Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *    Copyright IBM Corp. 1999,2008
+ *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
+ *		 Heiko Carstens <heiko.carstens@de.ibm.com>,
  */
 
 #include <linux/sched.h>
@@ -29,30 +24,31 @@ void __delay(unsigned long loops)
 	asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
 }
 
-/*
- * Waits for 'usecs' microseconds using the TOD clock comparator.
- */
-void __udelay(unsigned long usecs)
+static void __udelay_disabled(unsigned long usecs)
 {
-	u64 end, time, old_cc = 0;
-	unsigned long flags, cr0, mask, dummy;
-	int irq_context;
+	unsigned long mask, cr0, cr0_saved;
+	u64 clock_saved;
 
-	irq_context = in_interrupt();
-	if (!irq_context)
-		local_bh_disable();
-	local_irq_save(flags);
-	if (raw_irqs_disabled_flags(flags)) {
-		old_cc = local_tick_disable();
-		S390_lowcore.clock_comparator = -1ULL;
-		__ctl_store(cr0, 0, 0);
-		dummy = (cr0 & 0xffff00e0) | 0x00000800;
-		__ctl_load(dummy , 0, 0);
-		mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
-	} else
-		mask = psw_kernel_bits | PSW_MASK_WAIT |
-			PSW_MASK_EXT | PSW_MASK_IO;
+	clock_saved = local_tick_disable();
+	set_clock_comparator(get_clock() + ((u64) usecs << 12));
+	__ctl_store(cr0_saved, 0, 0);
+	cr0 = (cr0_saved & 0xffff00e0) | 0x00000800;
+	__ctl_load(cr0 , 0, 0);
+	mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
+	trace_hardirqs_on();
+	__load_psw_mask(mask);
+	local_irq_disable();
+	__ctl_load(cr0_saved, 0, 0);
+	local_tick_enable(clock_saved);
+	set_clock_comparator(S390_lowcore.clock_comparator);
+}
 
+static void __udelay_enabled(unsigned long usecs)
+{
+	unsigned long mask;
+	u64 end, time;
+
+	mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT | PSW_MASK_IO;
 	end = get_clock() + ((u64) usecs << 12);
 	do {
 		time = end < S390_lowcore.clock_comparator ?
@@ -62,13 +58,37 @@ void __udelay(unsigned long usecs)
 		__load_psw_mask(mask);
 		local_irq_disable();
 	} while (get_clock() < end);
+	set_clock_comparator(S390_lowcore.clock_comparator);
+}
 
-	if (raw_irqs_disabled_flags(flags)) {
-		__ctl_load(cr0, 0, 0);
-		local_tick_enable(old_cc);
+/*
+ * Waits for 'usecs' microseconds using the TOD clock comparator.
+ */
+void __udelay(unsigned long usecs)
+{
+	unsigned long flags;
+
+	preempt_disable();
+	local_irq_save(flags);
+	if (in_irq()) {
+		__udelay_disabled(usecs);
+		goto out;
+	}
+	if (in_softirq()) {
+		if (raw_irqs_disabled_flags(flags))
+			__udelay_disabled(usecs);
+		else
+			__udelay_enabled(usecs);
+		goto out;
 	}
-	if (!irq_context)
+	if (raw_irqs_disabled_flags(flags)) {
+		local_bh_disable();
+		__udelay_disabled(usecs);
 		_local_bh_enable();
-	set_clock_comparator(S390_lowcore.clock_comparator);
+		goto out;
+	}
+	__udelay_enabled(usecs);
+out:
 	local_irq_restore(flags);
+	preempt_enable();
 }

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.


  parent reply	other threads:[~2008-10-01  9:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-01  8:33 [patch 00/21] s390 patches for the 2.6.28 merge window Martin Schwidefsky
2008-10-01  8:33 ` [patch 01/21] qdio: speed up multicast traffic on full HiperSocket queue Martin Schwidefsky
2008-10-01  8:33 ` [patch 02/21] cio: move device unregistration to dedicated work queue Martin Schwidefsky
2008-10-01  8:33 ` [patch 03/21] cio: introduce purge function for /proc/cio_ignore Martin Schwidefsky
2008-10-01  8:33 ` [patch 04/21] cio: Update cio_ignore documentation Martin Schwidefsky
2008-10-01  8:33 ` [patch 05/21] cio: Exorcise cio_msg= from documentation Martin Schwidefsky
2008-10-01  8:33 ` [patch 06/21] bus_id -> dev_name conversions Martin Schwidefsky
2008-10-01  8:33 ` [patch 07/21] bus_id -> dev_set_name() changes Martin Schwidefsky
2008-10-01  8:33 ` [patch 08/21] more bus_id -> dev_name conversions Martin Schwidefsky
2008-10-01  8:33 ` [patch 09/21] Use s390_root_dev_* in kvm_virtio Martin Schwidefsky
2008-10-01  8:33 ` [patch 10/21] bus_id ->dev_name() conversions in qdio Martin Schwidefsky
2008-10-01  8:33 ` [patch 11/21] bus_id -> dev_set_name() for css and ccw busses Martin Schwidefsky
2008-10-01  8:33 ` [patch 12/21] cio: inline assembly cleanup Martin Schwidefsky
2008-10-01  8:33 ` [patch 13/21] qdio enhanced SIGA (iqdio) support Martin Schwidefsky
2008-10-01  8:33 ` [patch 14/21] s390: use sys_pause for 31bit pause entry point Martin Schwidefsky
2008-10-01  8:33 ` [patch 15/21] ptrace changes Martin Schwidefsky
2008-11-03 17:14   ` David Smith
2008-11-05 11:41     ` Martin Schwidefsky
2008-11-06 18:24       ` David Smith
2008-11-07  9:14         ` Martin Schwidefsky
2008-11-07 15:32         ` Martin Schwidefsky
2008-10-01  8:33 ` [patch 16/21] dcssblk: add >2G DCSSs support and stacked contiguous DCSSs support Martin Schwidefsky
2008-10-01  8:33 ` Martin Schwidefsky [this message]
2008-10-01  8:33 ` [patch 18/21] Move private simple udelay function to arch/s390/lib/delay.c Martin Schwidefsky
2008-10-01  8:33 ` [patch 19/21] dasd: fix message flood for unsolicited interrupts Martin Schwidefsky
2008-10-01  8:33 ` [patch 20/21] xpram: per device block request queues Martin Schwidefsky
2008-10-01  8:33 ` [patch 21/21] Add ioctl support for EMC Symmetrix Subsystem Control I/O Martin Schwidefsky
2008-10-01 11:03   ` Christoph Hellwig
2008-10-01 11:17     ` Martin Schwidefsky

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=20081001084129.581466549@de.ibm.com \
    --to=schwidefsky@de.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    /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