2004-11-01 19:34:49

by David Howells

[permalink] [raw]
Subject: [PATCH 10/14] FRV: Make calibrate_delay() optional

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
seem a board with any clock not dependent on the CPU's clock.

Signed-Off-By: [email protected]
---
diffstat frv-calibrate-2610rc1bk10.diff
init/main.c | 70 ---------------------------------------------
lib/Makefile | 3 +
lib/calibrate.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 88 insertions(+), 71 deletions(-)

diff -uNr /warthog/kernels/linux-2.6.10-rc1-bk10/init/main.c linux-2.6.10-rc1-bk10-frv/init/main.c
--- /warthog/kernels/linux-2.6.10-rc1-bk10/init/main.c 2004-11-01 11:45:34.000000000 +0000
+++ linux-2.6.10-rc1-bk10-frv/init/main.c 2004-11-01 11:47:05.147633905 +0000
@@ -182,15 +178,6 @@
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 @@

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 -uNr /warthog/kernels/linux-2.6.10-rc1-bk10/lib/calibrate.c linux-2.6.10-rc1-bk10-frv/lib/calibrate.c
--- /warthog/kernels/linux-2.6.10-rc1-bk10/lib/calibrate.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.10-rc1-bk10-frv/lib/calibrate.c 2004-11-01 11:47:05.186630659 +0000
@@ -0,0 +1,86 @@
+/* calibrate.c: default delay calibration
+ *
+ * Excised from init/main.c
+ *
+ * Copyright (C) 1991, 1992 Linus Torvalds
+ *
+ * GK 2/5/95 - Changed to support mounting root fs via NFS
+ * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96
+ * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96
+ * Simplified starting of init: Michael A. Griffith <[email protected]>
+ *
+ */
+
+#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 -uNr /warthog/kernels/linux-2.6.10-rc1-bk10/lib/Makefile linux-2.6.10-rc1-bk10-frv/lib/Makefile
--- /warthog/kernels/linux-2.6.10-rc1-bk10/lib/Makefile 2004-11-01 11:45:34.000000000 +0000
+++ linux-2.6.10-rc1-bk10-frv/lib/Makefile 2004-11-01 12:00:25.742993383 +0000
@@ -5,7 +5,8 @@
lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
kobject.o kref.o idr.o div64.o parser.o int_sqrt.o \
- bitmap.o extable.o kobject_uevent.o find_next_bit.o
+ bitmap.o extable.o kobject_uevent.o find_next_bit.o \
+ calibrate.o

ifeq ($(CONFIG_DEBUG_KOBJECT),y)
CFLAGS_kobject.o += -DDEBUG


2004-11-02 00:38:10

by john stultz

[permalink] [raw]
Subject: Re: [PATCH 10/14] FRV: Make calibrate_delay() optional

On Mon, 2004-11-01 at 11:30, [email protected] wrote:
> 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
> seem a board with any clock not dependent on the CPU's clock.

Just doing a quick skim, the patch looks good. Making a whole new file
for just one function is a bit heavy handed, but I don't feel that code
needed to be in main.c

My only nit would be to save the tabs and switch the code from:

if (preset_lpj) {
newstuff
} else {
oldstuff
}

to

if (preset_lpj) {
newstuff
return
}
oldstuff


thanks
-john

2004-11-02 07:20:57

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 10/14] FRV: Make calibrate_delay() optional



init/main.c: In function `start_kernel':
init/main.c:494: warning: implicit declaration of function `calibrate_delay'

Move the calibrate_delay() prototype into linux/delay.h

Signed-off-by: Andrew Morton <[email protected]>
---

25-akpm/include/asm-frv/delay.h | 1 -
25-akpm/include/asm-m32r/smp.h | 1 -
25-akpm/include/asm-x86_64/proto.h | 1 -
25-akpm/include/linux/delay.h | 1 +
4 files changed, 1 insertion(+), 3 deletions(-)

diff -puN include/linux/delay.h~frv-make-calibrate_delay-optional-warning-fix include/linux/delay.h
--- 25/include/linux/delay.h~frv-make-calibrate_delay-optional-warning-fix 2004-11-01 23:20:40.736445936 -0800
+++ 25-akpm/include/linux/delay.h 2004-11-01 23:21:09.070138560 -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 include/asm-m32r/smp.h~frv-make-calibrate_delay-optional-warning-fix include/asm-m32r/smp.h
--- 25/include/asm-m32r/smp.h~frv-make-calibrate_delay-optional-warning-fix 2004-11-01 23:20:40.752443504 -0800
+++ 25-akpm/include/asm-m32r/smp.h 2004-11-01 23:20:54.544346816 -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-warning-fix include/asm-x86_64/proto.h
--- 25/include/asm-x86_64/proto.h~frv-make-calibrate_delay-optional-warning-fix 2004-11-01 23:20:40.769440920 -0800
+++ 25-akpm/include/asm-x86_64/proto.h 2004-11-01 23:21:13.197511104 -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/asm-frv/delay.h~frv-make-calibrate_delay-optional-warning-fix include/asm-frv/delay.h
--- 25/include/asm-frv/delay.h~frv-make-calibrate_delay-optional-warning-fix 2004-11-01 23:20:40.785438488 -0800
+++ 25-akpm/include/asm-frv/delay.h 2004-11-01 23:21:19.580540736 -0800
@@ -18,7 +18,6 @@
* delay loop - runs at __core_clock_speed_HZ / 2 [there are 2 insns in the loop]
*/
extern unsigned long __delay_loops_MHz;
-extern void calibrate_delay(void);

static inline void __delay(unsigned long loops)
{
_

2004-11-02 09:36:39

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 10/14] FRV: Make calibrate_delay() optional

> + * GK 2/5/95 - Changed to support mounting root fs via NFS
> + * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96
> + * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96
> + * Simplified starting of init: Michael A. Griffith <[email protected]>

this changelog certainly does not apply to the delay loop calibration.

> lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
> bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
> kobject.o kref.o idr.o div64.o parser.o int_sqrt.o \
> - bitmap.o extable.o kobject_uevent.o find_next_bit.o
> + bitmap.o extable.o kobject_uevent.o find_next_bit.o \
> + calibrate.o

any reason it's in lib? Better move this to kernel and properly compile
it conditionally.

2004-11-02 11:01:45

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 10/14] FRV: Make calibrate_delay() optional


> Just doing a quick skim, the patch looks good. Making a whole new file
> for just one function is a bit heavy handed, but I don't feel that code
> needed to be in main.c

Doing it this way means that we can use the linker's handling of archive
libraries to decide whether to actually use this function or not.

> My only nit would be to save the tabs and switch the code from:

And then it'll be argued that I should switch it back... Different people have
different opinions on how this should be arranged (of course, they're wrong if
they don't agree with my opinion:-).

David

2004-11-02 16:33:04

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 10/14] FRV: Make calibrate_delay() optional


> this changelog certainly does not apply to the delay loop calibration.

I just duplicated the banners from init/main.c and tacked some extra bits on
the front.

> any reason it's in lib? Better move this to kernel and properly compile
> it conditionally.

So that it get built and placed in an archive library, thus allowing the
linker to decide whether to include it or not, without having to use
conditional stuff and without having to change every other arch to enable it.

I suppose I could do something like this in init/Makefile:

if ($(CONFIG_DISABLE_GENERIC_CALIBRATE_DELAY),y)
obj-y += calibrate.o
endif

That would allow me to avoid having to change all the archs.

David

2004-11-03 10:40:28

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 10/14] FRV: Make calibrate_delay() optional

On Tue, Nov 02, 2004 at 04:29:39PM +0000, David Howells wrote:
>
> > this changelog certainly does not apply to the delay loop calibration.
>
> I just duplicated the banners from init/main.c and tacked some extra bits on
> the front.
>
> > any reason it's in lib? Better move this to kernel and properly compile
> > it conditionally.
>
> So that it get built and placed in an archive library, thus allowing the
> linker to decide whether to include it or not, without having to use
> conditional stuff and without having to change every other arch to enable it.
>
> I suppose I could do something like this in init/Makefile:
>
> if ($(CONFIG_DISABLE_GENERIC_CALIBRATE_DELAY),y)
> obj-y += calibrate.o
> endif
>
> That would allow me to avoid having to change all the archs.

Use CONFIG_CALIBRATE_DELAY and add it to all other ports. Remember Linux
is not about least intrusive changes but about what's easiest maintainable.