
From: David Howells <dhowells@redhat.com>

The attached patch makes calibrate_delay() optional. In this architecture, it's
a waste of time since we can predict exactly what it's going to come up with
just by looking at the CPU's hardware clock registers. Thus far, we haven't
seen a board with any clock not dependent on the CPU's clock.

Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/alpha/Kconfig         |    4 +
 25-akpm/arch/arm/Kconfig           |    4 +
 25-akpm/arch/arm26/Kconfig         |    4 +
 25-akpm/arch/cris/Kconfig          |    4 +
 25-akpm/arch/h8300/Kconfig         |    4 +
 25-akpm/arch/i386/Kconfig          |    4 +
 25-akpm/arch/ia64/Kconfig          |    4 +
 25-akpm/arch/m68k/Kconfig          |    4 +
 25-akpm/arch/m68knommu/Kconfig     |    4 +
 25-akpm/arch/mips/Kconfig          |    4 +
 25-akpm/arch/parisc/Kconfig        |    4 +
 25-akpm/arch/ppc/Kconfig           |    4 +
 25-akpm/arch/ppc64/Kconfig         |    4 +
 25-akpm/arch/s390/Kconfig          |    4 +
 25-akpm/arch/sh/Kconfig            |    4 +
 25-akpm/arch/sh64/Kconfig          |    4 +
 25-akpm/arch/sparc/Kconfig         |    4 +
 25-akpm/arch/sparc64/Kconfig       |    4 +
 25-akpm/arch/um/Kconfig            |    4 +
 25-akpm/arch/v850/Kconfig          |    3 +
 25-akpm/arch/x86_64/Kconfig        |    4 +
 25-akpm/include/asm-m32r/smp.h     |    1 
 25-akpm/include/asm-x86_64/proto.h |    1 
 25-akpm/include/linux/delay.h      |    1 
 25-akpm/init/Makefile              |    2 
 25-akpm/init/calibrate.c           |   79 +++++++++++++++++++++++++++++++++++++
 25-akpm/init/main.c                |   70 --------------------------------
 27 files changed, 165 insertions(+), 72 deletions(-)

diff -puN arch/alpha/Kconfig~frv-make-calibrate_delay-optional arch/alpha/Kconfig
--- 25/arch/alpha/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.659446640 -0800
+++ 25-akpm/arch/alpha/Kconfig	2004-12-03 20:54:03.697440864 -0800
@@ -28,6 +28,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config GENERIC_ISA_DMA
 	bool
 	default y
diff -puN arch/arm26/Kconfig~frv-make-calibrate_delay-optional arch/arm26/Kconfig
--- 25/arch/arm26/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.660446488 -0800
+++ 25-akpm/arch/arm26/Kconfig	2004-12-03 20:54:03.698440712 -0800
@@ -45,6 +45,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config GENERIC_BUST_SPINLOCK
 	bool
 
diff -puN arch/arm/Kconfig~frv-make-calibrate_delay-optional arch/arm/Kconfig
--- 25/arch/arm/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.661446336 -0800
+++ 25-akpm/arch/arm/Kconfig	2004-12-03 20:54:03.698440712 -0800
@@ -57,6 +57,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config GENERIC_BUST_SPINLOCK
 	bool
 
diff -puN arch/cris/Kconfig~frv-make-calibrate_delay-optional arch/cris/Kconfig
--- 25/arch/cris/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.663446032 -0800
+++ 25-akpm/arch/cris/Kconfig	2004-12-03 20:54:03.699440560 -0800
@@ -20,6 +20,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config CRIS
 	bool
 	default y
diff -puN arch/h8300/Kconfig~frv-make-calibrate_delay-optional arch/h8300/Kconfig
--- 25/arch/h8300/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.664445880 -0800
+++ 25-akpm/arch/h8300/Kconfig	2004-12-03 20:54:03.699440560 -0800
@@ -33,6 +33,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default n
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config ISA
 	bool
 	default y
diff -puN arch/i386/Kconfig~frv-make-calibrate_delay-optional arch/i386/Kconfig
--- 25/arch/i386/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.666445576 -0800
+++ 25-akpm/arch/i386/Kconfig	2004-12-03 20:54:03.700440408 -0800
@@ -378,6 +378,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	depends on !M386
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config X86_PPRO_FENCE
 	bool
 	depends on M686 || M586MMX || M586TSC || M586 || M486 || M386
diff -puN arch/ia64/Kconfig~frv-make-calibrate_delay-optional arch/ia64/Kconfig
--- 25/arch/ia64/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.668445272 -0800
+++ 25-akpm/arch/ia64/Kconfig	2004-12-03 20:54:03.701440256 -0800
@@ -30,6 +30,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config TIME_INTERPOLATION
 	bool
 	default y
diff -puN arch/m68k/Kconfig~frv-make-calibrate_delay-optional arch/m68k/Kconfig
--- 25/arch/m68k/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.669445120 -0800
+++ 25-akpm/arch/m68k/Kconfig	2004-12-03 20:54:03.701440256 -0800
@@ -21,6 +21,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 mainmenu "Linux/68k Kernel Configuration"
 
 source "init/Kconfig"
diff -puN arch/m68knommu/Kconfig~frv-make-calibrate_delay-optional arch/m68knommu/Kconfig
--- 25/arch/m68knommu/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.671444816 -0800
+++ 25-akpm/arch/m68knommu/Kconfig	2004-12-03 20:54:03.702440104 -0800
@@ -29,6 +29,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default n
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 source "init/Kconfig"
 
 menu "Processor type and features"
diff -puN arch/mips/Kconfig~frv-make-calibrate_delay-optional arch/mips/Kconfig
--- 25/arch/mips/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.672444664 -0800
+++ 25-akpm/arch/mips/Kconfig	2004-12-03 20:54:03.703439952 -0800
@@ -852,6 +852,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config HAVE_DEC_LOCK
 	bool
 	default y
diff -puN arch/parisc/Kconfig~frv-make-calibrate_delay-optional arch/parisc/Kconfig
--- 25/arch/parisc/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.673444512 -0800
+++ 25-akpm/arch/parisc/Kconfig	2004-12-03 20:54:03.703439952 -0800
@@ -32,6 +32,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config GENERIC_ISA_DMA
 	bool
 
diff -puN arch/ppc64/Kconfig~frv-make-calibrate_delay-optional arch/ppc64/Kconfig
--- 25/arch/ppc64/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.675444208 -0800
+++ 25-akpm/arch/ppc64/Kconfig	2004-12-03 20:54:03.704439800 -0800
@@ -20,6 +20,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config GENERIC_ISA_DMA
 	bool
 	default y
diff -puN arch/ppc/Kconfig~frv-make-calibrate_delay-optional arch/ppc/Kconfig
--- 25/arch/ppc/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.676444056 -0800
+++ 25-akpm/arch/ppc/Kconfig	2004-12-03 20:54:03.705439648 -0800
@@ -22,6 +22,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config HAVE_DEC_LOCK
 	bool
 	default y
diff -puN arch/s390/Kconfig~frv-make-calibrate_delay-optional arch/s390/Kconfig
--- 25/arch/s390/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.678443752 -0800
+++ 25-akpm/arch/s390/Kconfig	2004-12-03 20:54:03.705439648 -0800
@@ -14,6 +14,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config GENERIC_BUST_SPINLOCK
 	bool
 
diff -puN arch/sh64/Kconfig~frv-make-calibrate_delay-optional arch/sh64/Kconfig
--- 25/arch/sh64/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.679443600 -0800
+++ 25-akpm/arch/sh64/Kconfig	2004-12-03 20:54:03.706439496 -0800
@@ -25,6 +25,10 @@ config RWSEM_GENERIC_SPINLOCK
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config LOG_BUF_SHIFT
 	int
 	default 14
diff -puN arch/sh/Kconfig~frv-make-calibrate_delay-optional arch/sh/Kconfig
--- 25/arch/sh/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.680443448 -0800
+++ 25-akpm/arch/sh/Kconfig	2004-12-03 20:54:03.706439496 -0800
@@ -25,6 +25,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 source "init/Kconfig"
 
 menu "System type"
diff -puN arch/sparc64/Kconfig~frv-make-calibrate_delay-optional arch/sparc64/Kconfig
--- 25/arch/sparc64/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.682443144 -0800
+++ 25-akpm/arch/sparc64/Kconfig	2004-12-03 20:54:03.707439344 -0800
@@ -186,6 +186,10 @@ config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 choice
 	prompt "SPARC64 Huge TLB Page Size"
 	depends on HUGETLB_PAGE
diff -puN arch/sparc/Kconfig~frv-make-calibrate_delay-optional arch/sparc/Kconfig
--- 25/arch/sparc/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.683442992 -0800
+++ 25-akpm/arch/sparc/Kconfig	2004-12-03 20:54:03.708439192 -0800
@@ -207,6 +207,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config SUN_PM
 	bool
 	default y
diff -puN arch/um/Kconfig~frv-make-calibrate_delay-optional arch/um/Kconfig
--- 25/arch/um/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.684442840 -0800
+++ 25-akpm/arch/um/Kconfig	2004-12-03 20:54:03.708439192 -0800
@@ -31,6 +31,10 @@ config RWSEM_GENERIC_SPINLOCK
 	bool
 	default y
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 menu "UML-specific options"
 
 config MODE_TT
diff -puN arch/v850/Kconfig~frv-make-calibrate_delay-optional arch/v850/Kconfig
--- 25/arch/v850/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.685442688 -0800
+++ 25-akpm/arch/v850/Kconfig	2004-12-03 20:54:03.708439192 -0800
@@ -19,6 +19,9 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default n
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
 
 # Turn off some random 386 crap that can affect device config
 config ISA
diff -puN arch/x86_64/Kconfig~frv-make-calibrate_delay-optional arch/x86_64/Kconfig
--- 25/arch/x86_64/Kconfig~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.687442384 -0800
+++ 25-akpm/arch/x86_64/Kconfig	2004-12-03 20:54:03.709439040 -0800
@@ -41,6 +41,10 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default y
+
 config X86_CMPXCHG
 	bool
 	default y
diff -puN include/asm-m32r/smp.h~frv-make-calibrate_delay-optional include/asm-m32r/smp.h
--- 25/include/asm-m32r/smp.h~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.688442232 -0800
+++ 25-akpm/include/asm-m32r/smp.h	2004-12-03 20:54:03.709439040 -0800
@@ -92,7 +92,6 @@ static __inline__ unsigned int num_booti
 }
 
 extern void smp_send_timer(void);
-extern void calibrate_delay(void);
 extern unsigned long send_IPI_mask_phys(cpumask_t, int, int);
 
 #endif	/* not __ASSEMBLY__ */
diff -puN include/asm-x86_64/proto.h~frv-make-calibrate_delay-optional include/asm-x86_64/proto.h
--- 25/include/asm-x86_64/proto.h~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.689442080 -0800
+++ 25-akpm/include/asm-x86_64/proto.h	2004-12-03 20:54:03.710438888 -0800
@@ -25,7 +25,6 @@ extern void ia32_syscall(void);
 extern void ia32_cstar_target(void); 
 extern void ia32_sysenter_target(void); 
 
-extern void calibrate_delay(void);
 extern void cpu_idle(void);
 extern void config_acpi_tables(void);
 extern void ia32_syscall(void);
diff -puN include/linux/delay.h~frv-make-calibrate_delay-optional include/linux/delay.h
--- 25/include/linux/delay.h~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.691441776 -0800
+++ 25-akpm/include/linux/delay.h	2004-12-03 20:54:03.710438888 -0800
@@ -38,6 +38,7 @@ extern unsigned long loops_per_jiffy;
 #define ndelay(x)	udelay(((x)+999)/1000)
 #endif
 
+void calibrate_delay(void);
 void msleep(unsigned int msecs);
 unsigned long msleep_interruptible(unsigned int msecs);
 
diff -puN /dev/null init/calibrate.c
--- /dev/null	2003-09-15 06:40:47.000000000 -0700
+++ 25-akpm/init/calibrate.c	2004-12-03 20:54:03.710438888 -0800
@@ -0,0 +1,79 @@
+/* calibrate.c: default delay calibration
+ *
+ * Excised from init/main.c
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ */
+
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+
+static unsigned long preset_lpj;
+static int __init lpj_setup(char *str)
+{
+	preset_lpj = simple_strtoul(str,NULL,0);
+	return 1;
+}
+
+__setup("lpj=", lpj_setup);
+
+/*
+ * This is the number of bits of precision for the loops_per_jiffy.  Each
+ * bit takes on average 1.5/HZ seconds.  This (like the original) is a little
+ * better than 1%
+ */
+#define LPS_PREC 8
+
+void __devinit calibrate_delay(void)
+{
+	unsigned long ticks, loopbit;
+	int lps_precision = LPS_PREC;
+
+	if (preset_lpj) {
+		loops_per_jiffy = preset_lpj;
+		printk("Calibrating delay loop (skipped)... "
+			"%lu.%02lu BogoMIPS preset\n",
+			loops_per_jiffy/(500000/HZ),
+			(loops_per_jiffy/(5000/HZ)) % 100);
+	} else {
+		loops_per_jiffy = (1<<12);
+
+		printk(KERN_DEBUG "Calibrating delay loop... ");
+		while ((loops_per_jiffy <<= 1) != 0) {
+			/* wait for "start of" clock tick */
+			ticks = jiffies;
+			while (ticks == jiffies)
+				/* nothing */;
+			/* Go .. */
+			ticks = jiffies;
+			__delay(loops_per_jiffy);
+			ticks = jiffies - ticks;
+			if (ticks)
+				break;
+		}
+
+		/*
+		 * Do a binary approximation to get loops_per_jiffy set to
+		 * equal one clock (up to lps_precision bits)
+		 */
+		loops_per_jiffy >>= 1;
+		loopbit = loops_per_jiffy;
+		while (lps_precision-- && (loopbit >>= 1)) {
+			loops_per_jiffy |= loopbit;
+			ticks = jiffies;
+			while (ticks == jiffies)
+				/* nothing */;
+			ticks = jiffies;
+			__delay(loops_per_jiffy);
+			if (jiffies != ticks)	/* longer than 1 tick */
+				loops_per_jiffy &= ~loopbit;
+		}
+
+		/* Round the value and print it */
+		printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
+			loops_per_jiffy/(500000/HZ),
+			(loops_per_jiffy/(5000/HZ)) % 100,
+			loops_per_jiffy);
+	}
+
+}
diff -puN init/main.c~frv-make-calibrate_delay-optional init/main.c
--- 25/init/main.c~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.692441624 -0800
+++ 25-akpm/init/main.c	2004-12-03 20:54:03.711438736 -0800
@@ -182,15 +182,6 @@ static int __init obsolete_checksetup(ch
 	return 0;
 }
 
-static unsigned long preset_lpj;
-static int __init lpj_setup(char *str)
-{
-	preset_lpj = simple_strtoul(str,NULL,0);
-	return 1;
-}
-
-__setup("lpj=", lpj_setup);
-
 /*
  * This should be approx 2 Bo*oMips to start (note initial shift), and will
  * still work even if initially too large, it will just take slightly longer
@@ -199,67 +190,6 @@ unsigned long loops_per_jiffy = (1<<12);
 
 EXPORT_SYMBOL(loops_per_jiffy);
 
-/*
- * This is the number of bits of precision for the loops_per_jiffy.  Each
- * bit takes on average 1.5/HZ seconds.  This (like the original) is a little
- * better than 1%
- */
-#define LPS_PREC 8
-
-void __devinit calibrate_delay(void)
-{
-	unsigned long ticks, loopbit;
-	int lps_precision = LPS_PREC;
-
-	if (preset_lpj) {
-		loops_per_jiffy = preset_lpj;
-		printk("Calibrating delay loop (skipped)... "
-			"%lu.%02lu BogoMIPS preset\n",
-			loops_per_jiffy/(500000/HZ),
-			(loops_per_jiffy/(5000/HZ)) % 100);
-	} else {
-		loops_per_jiffy = (1<<12);
-
-		printk(KERN_DEBUG "Calibrating delay loop... ");
-		while ((loops_per_jiffy <<= 1) != 0) {
-			/* wait for "start of" clock tick */
-			ticks = jiffies;
-			while (ticks == jiffies)
-				/* nothing */;
-			/* Go .. */
-			ticks = jiffies;
-			__delay(loops_per_jiffy);
-			ticks = jiffies - ticks;
-			if (ticks)
-				break;
-		}
-
-		/*
-		 * Do a binary approximation to get loops_per_jiffy set to
-		 * equal one clock (up to lps_precision bits)
-		 */
-		loops_per_jiffy >>= 1;
-		loopbit = loops_per_jiffy;
-		while (lps_precision-- && (loopbit >>= 1)) {
-			loops_per_jiffy |= loopbit;
-			ticks = jiffies;
-			while (ticks == jiffies)
-				/* nothing */;
-			ticks = jiffies;
-			__delay(loops_per_jiffy);
-			if (jiffies != ticks)	/* longer than 1 tick */
-				loops_per_jiffy &= ~loopbit;
-		}
-
-		/* Round the value and print it */
-		printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
-			loops_per_jiffy/(500000/HZ),
-			(loops_per_jiffy/(5000/HZ)) % 100,
-			loops_per_jiffy);
-	}
-
-}
-
 static int __init debug_kernel(char *str)
 {
 	if (*str)
diff -puN init/Makefile~frv-make-calibrate_delay-optional init/Makefile
--- 25/init/Makefile~frv-make-calibrate_delay-optional	2004-12-03 20:54:03.694441320 -0800
+++ 25-akpm/init/Makefile	2004-12-03 20:54:03.712438584 -0800
@@ -3,6 +3,8 @@
 #
 
 obj-y				:= main.o version.o mounts.o initramfs.o
+obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o
+
 mounts-y			:= do_mounts.o
 mounts-$(CONFIG_DEVFS_FS)	+= do_mounts_devfs.o
 mounts-$(CONFIG_BLK_DEV_RAM)	+= do_mounts_rd.o
_
