]> git.hungrycats.org Git - linux/commitdiff
[SPARC64]: Fix delay with HZ==1000.
authorDavid S. Miller <davem@nuts.davemloft.net>
Fri, 27 Aug 2004 09:12:23 +0000 (02:12 -0700)
committerDavid S. Miller <davem@nuts.davemloft.net>
Fri, 27 Aug 2004 09:12:23 +0000 (02:12 -0700)
When I moved sparc64 over to HZ==1000 this added some
problems to the udelay() handling.  Specifically, with
slower cpus we could now get underflows to zero for
things like udelay(1) due to the order of multiplies
and shifts.

Fix this, and move it out to arch/sparc64/lib/delay.c
so it is easier to tinker with this in the future and
also to optimize away one of the multiplies for the
constant delay case just like other platforms do.

Signed-off-by: David S. Miller <davem@davemloft.net>
arch/sparc64/kernel/sparc64_ksyms.c
arch/sparc64/lib/Makefile
arch/sparc64/lib/delay.c [new file with mode: 0644]
include/asm-sparc64/delay.h

index 46df529607b3f9467ad16bf26d1becfe65bac4ac..7bf82ab43c7d0221587d68b4d99c181d4466b139 100644 (file)
@@ -372,6 +372,12 @@ EXPORT_SYMBOL_NOVERS(memset);
 EXPORT_SYMBOL_NOVERS(memmove);
 EXPORT_SYMBOL_NOVERS(strncmp);
 
+/* Delay routines. */
+EXPORT_SYMBOL(__udelay);
+EXPORT_SYMBOL(__ndelay);
+EXPORT_SYMBOL(__const_udelay);
+EXPORT_SYMBOL(__delay);
+
 void VISenter(void);
 /* RAID code needs this */
 EXPORT_SYMBOL_NOVERS(VISenter);
index 5f2270f343bd8595669576bd26567845314b806c..22c5b59fd8b97dc551efada1dba2b481411ec918 100644 (file)
@@ -12,7 +12,7 @@ lib-y := PeeCeeI.o copy_page.o clear_page.o strlen.o strncmp.o \
         U1memcpy.o U1copy_from_user.o U1copy_to_user.o \
         U3memcpy.o U3copy_from_user.o U3copy_to_user.o U3patch.o \
         copy_in_user.o user_fixup.o memmove.o \
-        mcount.o ipcsum.o rwsem.o xor.o splock.o find_bit.o
+        mcount.o ipcsum.o rwsem.o xor.o splock.o find_bit.o delay.o
 
 lib-$(CONFIG_DEBUG_SPINLOCK) += debuglocks.o
 lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o
diff --git a/arch/sparc64/lib/delay.c b/arch/sparc64/lib/delay.c
new file mode 100644 (file)
index 0000000..f55f528
--- /dev/null
@@ -0,0 +1,49 @@
+/* delay.c: Delay loops for sparc64
+ *
+ * Copyright (C) 2004 David S. Miller <davem@redhat.com>
+ *
+ * Based heavily upon x86 variant which is:
+ *     Copyright (C) 1993 Linus Torvalds
+ *     Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ */
+
+#include <linux/delay.h>
+
+void __delay(unsigned long loops)
+{
+       __asm__ __volatile__(
+"      b,pt    %%xcc, 1f\n"
+"       cmp    %0, 0\n"
+"      .align  32\n"
+"1:\n"
+"      bne,pt  %%xcc, 1b\n"
+"       subcc  %0, 1, %0\n"
+       : "=&r" (loops)
+       : "0" (loops)
+       : "cc");
+}
+
+/* We used to multiply by HZ after shifting down by 32 bits
+ * but that runs into problems for higher values of HZ and
+ * slow cpus.
+ */
+void __const_udelay(unsigned long n)
+{
+       n *= 4;
+
+       n *= (cpu_data(smp_processor_id()).udelay_val * (HZ/4));
+       n >>= 32;
+
+       __delay(n + 1);
+}
+
+void __udelay(unsigned long n)
+{
+       __const_udelay(n * 0x10c7UL);
+}
+
+
+void __ndelay(unsigned long n)
+{
+       __const_udelay(n * 0x5UL);
+}
index 13de4b10f70954c717c17498c37bae3f5804b6ce..2901ea0c342d9a231147ee1d1ebdb7e4c6ba772b 100644 (file)
@@ -1,7 +1,11 @@
-/* $Id: delay.h,v 1.13 2002/02/02 03:33:48 kanoj Exp $
- * delay.h: Linux delay routines on the V9.
+/* delay.h: Linux delay routines on sparc64.
  *
- * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu).
+ * Copyright (C) 1996, 2004 David S. Miller (davem@davemloft.net).
+ *
+ * Based heavily upon x86 variant which is:
+ * Copyright (C) 1993 Linus Torvalds
+ *
+ * Delay routines calling functions in arch/sparc64/lib/delay.c
  */
 
 #ifndef __SPARC64_DELAY_H
 
 #ifndef __ASSEMBLY__
 
-static __inline__ void __delay(unsigned long loops)
-{
-       __asm__ __volatile__(
-"      b,pt    %%xcc, 1f\n"
-"       cmp    %0, 0\n"
-"      .align  32\n"
-"1:\n"
-"      bne,pt  %%xcc, 1b\n"
-"       subcc  %0, 1, %0\n"
-       : "=&r" (loops)
-       : "0" (loops)
-       : "cc");
-}
-
-static __inline__ void __udelay(unsigned long usecs, unsigned long lps)
-{
-       usecs *= 0x00000000000010c6UL;          /* 2**32 / 1000000 */
-
-       __asm__ __volatile__(
-"      mulx    %1, %2, %0\n"
-"      srlx    %0, 32, %0\n"
-       : "=r" (usecs)
-       : "r" (usecs), "r" (lps));
-
-       __delay(usecs * HZ);
-}
-
-extern __inline__ void __ndelay(unsigned long usecs, unsigned long lps)
-{
-       usecs *= 0x0000000000000005UL;          /* 2**32 / 10000 */
-
-       __asm__ __volatile__(
-"      mulx    %1, %2, %0\n"
-"      srlx    %0, 32, %0\n"
-       : "=r" (usecs)
-       : "r" (usecs), "r" (lps));
-
-       __delay(usecs * HZ);
-}
-
-#define __udelay_val cpu_data(smp_processor_id()).udelay_val
-
-#define udelay(usecs) __udelay((usecs),__udelay_val)
-#define ndelay(usecs) __ndelay((usecs),__udelay_val)
+extern void __bad_udelay(void);
+extern void __bad_ndelay(void);
+
+extern void __udelay(unsigned long usecs);
+extern void __ndelay(unsigned long nsecs);
+extern void __const_udelay(unsigned long usecs);
+extern void __delay(unsigned long loops);
+
+#define udelay(n) (__builtin_constant_p(n) ? \
+       ((n) > 20000 ? __bad_udelay() : __const_udelay((n) * 0x10c7ul)) : \
+       __udelay(n))
+       
+#define ndelay(n) (__builtin_constant_p(n) ? \
+       ((n) > 20000 ? __bad_ndelay() : __const_udelay((n) * 5ul)) : \
+       __ndelay(n))
 
 #endif /* !__ASSEMBLY__ */