All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Kropelin <akropel1@rochester.rr.com>
To: Tim Bird <tim.bird@am.sony.com>
Cc: linux kernel <linux-kernel@vger.kernel.org>,
	CE Linux Developers List <celinux-dev@tree.celinuxforum.org>
Subject: Re: [PATCH] preset loops_per_jiffy for faster booting
Date: Fri, 9 Jul 2004 22:01:42 -0400	[thread overview]
Message-ID: <20040709220142.B29198@mail.kroptech.com> (raw)
In-Reply-To: <40EF3637.4090105@am.sony.com>; from tim.bird@am.sony.com on Fri, Jul 09, 2004 at 05:20:07PM -0700

On Fri, Jul 09, 2004 at 05:20:07PM -0700, Tim Bird wrote:
> Adam Kropelin wrote:
> > crashes due to a bogus preset. The only problem I can think of with
> > this approach is if there is a system out there so slow that lpj=0 is
> > actually a valid setting.
> It's hard to imagine this case, but that would merely result in
> a calibration, right?  For a machine that slow, calibrating the
> delay is the least of their worries. :-)

Good point. ;)

> > be a problem. Perhaps this is worth mentioning in the help text as well.
> I hadn't considered this.  (Too much "embedded" on the brain.)
> By help text, do you mean the config text, or something on the wiki page,
> or some other file (in Documentation?).

I meant the config text.

> On the subject of help text, is there a Documentation file I should modify
> or someone I should notify about the addition of a new kernel command line
> option?

Indeed, there is: Documentation/kernel-parameters.txt. You're right; we
should update it.

> > While we're on the topic: Should FASTBOOT perhaps depend on EMBEDDED? I
> > can imagine a user with a massively MP system perhaps finding this
> > option useful, so maybe not.
> 
> I had it there originally, then changed my mind.  I know some server
> guys are interested in fastboot.  This particular change might not
> be that interesting, but some of the other changes we are thinking of
> might not be specific to just embedded.

Ok, let's leave it as-is, then.

> I will do some runtime testing on your patch, but I probably won't be
> able to report back until Monday.

I've made an updated patch below that incorporates the items we just
discussed as well as a couple of things Andreas Dilger sent to me
privately.

> Thanks very much!

No problem. This was a nice little self-contained project to play with
this evening.


Signed-off-by: Adam Kropelin <akropel1@rochester.rr.com>

--- linux-2.6.7/init/main.c.orig	Mon Jun 21 17:55:09 2004
+++ linux-2.6.7/init/main.c	Fri Jul  9 21:07:44 2004
@@ -167,6 +167,15 @@
 	return 0;
 }
 
+static unsigned long preset_lpj = CONFIG_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 */
 unsigned long loops_per_jiffy = (1<<12);
@@ -183,40 +192,49 @@
 	unsigned long ticks, loopbit;
 	int lps_precision = LPS_PREC;
 
-	loops_per_jiffy = (1<<12);
+	if (preset_lpj) {
+		loops_per_jiffy = preset_lpj;
+		printk("Calibrating delay loop (skipped)... ");
+	} else {
+		loops_per_jiffy = (1<<12);
+
+		printk("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\n",
+			loops_per_jiffy/(500000/HZ),
+			(loops_per_jiffy/(5000/HZ)) % 100);
+		printk("Set 'Preset loops_per_jiffy'=%lu for preset lpj.\n",
+			loops_per_jiffy);
 
-	printk("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);
-		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\n",
-		loops_per_jiffy/(500000/HZ),
-		(loops_per_jiffy/(5000/HZ)) % 100);
 }
 
 static int __init debug_kernel(char *str)
--- linux-2.6.7/init/Kconfig.orig	Mon Jun 21 17:55:09 2004
+++ linux-2.6.7/init/Kconfig	Fri Jul  9 21:12:21 2004
@@ -218,6 +218,44 @@
 	  This option enables access to kernel configuration file and build
 	  information through /proc/config.gz.
 
+menuconfig FASTBOOT
+	bool "Fast boot options"
+	help
+	  Say Y here to select among various options that can decrease
+	  kernel boot time. These options commonly involve providing
+	  hardcoded values for some parameters that the kernel usually
+	  determines automatically.
+	
+	  This option is useful primarily on embedded systems.
+	
+	  If unsure, say N.
+
+config PRESET_LPJ
+	int "Preset loops_per_jiffy" if FASTBOOT
+	default 0
+	help
+	  This is the number of loops used by delay() to achieve a single
+	  jiffy of delay inside the kernel.  It is normally calculated at
+	  boot time, but that calculation can take up to 250 ms per CPU.
+	  Specifying a constant value here will eliminate that delay.
+	  
+	  loops_per_jiffy is roughly BogoMips * 5000. To determine the correct
+	  value for your kernel, first turn off the fast booting option,
+	  compile and boot the kernel on your target hardware, then see what
+	  value is printed during the kernel boot.  Use that value here.
+
+	  A value of 0 results in the normal autodetect behavior at boot.
+	  
+	  The kernel command line parameter "lpj=" can be used to override
+	  the value configured here.
+	  
+	  Note that on SMP systems the preset will be applied to all CPUs
+	  which will cause problems if for some reason your CPUs need
+	  significantly divergent settings.
+
+	  If unsure, set this to 0. An incorrect value will cause delays in
+	  the kernel to be incorrect.  Although unlikely, in the extreme case
+	  this might damage your hardware.
 
 menuconfig EMBEDDED
 	bool "Configure standard kernel features (for small systems)"
--- linux-2.6.7/Documentation/kernel-parameters.txt.orig	Fri Jul  9 21:20:16 2004
+++ linux-2.6.7/Documentation/kernel-parameters.txt	Fri Jul  9 21:17:11 2004
@@ -576,6 +576,12 @@
 				so, the driver will manage that printer.
 				See also header of drivers/char/lp.c.
 
+	lpj=n		[KNL]
+			Sets loops_per_jiffy to given constant, thus avoiding
+			time-consuming boot-time autodetection.
+			0 enables autodetection (default). See Kconfig help text
+			for PRESET_LPJ for details.
+
 	ltpc=		[NET]
 			Format: <io>,<irq>,<dma>
 

  reply	other threads:[~2004-07-10  1:28 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-09 19:25 [PATCH] preset loops_per_jiffy for faster booting Tim Bird
2004-07-09 22:24 ` Adam Kropelin
2004-07-09 23:35 ` Adam Kropelin
2004-07-10  0:20   ` Tim Bird
2004-07-10  2:01     ` Adam Kropelin [this message]
2004-07-10  2:01       ` Todd Poynor
2004-07-10 15:42         ` Adam Kropelin
2004-07-10 14:41       ` [Celinux-dev] " Geert Uytterhoeven
2004-07-10 15:22         ` Adam Kropelin
2004-07-10 15:54     ` Adam Kropelin
2004-07-10 18:28       ` Adam Kropelin
2004-07-10 18:19         ` Dmitry Torokhov
2004-07-10 20:14           ` Adam Kropelin
2004-07-11  1:25             ` Andrew Morton
2004-07-11  3:44               ` Adam Kropelin
2004-07-11  4:38                 ` Andrew Morton
2004-07-12 17:31                   ` Tim Bird
2004-07-11  4:51                 ` Dmitry Torokhov
2004-07-11  4:58                   ` Karim Yaghmour
2004-07-11  5:19                     ` Dmitry Torokhov
2004-07-11  5:27                       ` Andrew Morton
2004-07-11  7:46                         ` Geert Uytterhoeven
2004-07-11  7:51                           ` Andrew Morton
2004-07-11 13:41                             ` Adam Kropelin
2004-07-12 18:52                               ` Tim Bird
2004-07-12 19:32                                 ` Adam Kropelin
2004-07-12 22:41                                   ` Tim Bird
2004-07-13 19:24                                     ` Bartlomiej Zolnierkiewicz
2004-07-12 17:50               ` Tim Bird

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=20040709220142.B29198@mail.kroptech.com \
    --to=akropel1@rochester.rr.com \
    --cc=celinux-dev@tree.celinuxforum.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tim.bird@am.sony.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.