Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / init / calibrate.c
blobc698e04a3dbe37745b9b32cb696b1f5deb3f3acb
1 /* calibrate.c: default delay calibration
3 * Excised from init/main.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
7 #include <linux/sched.h>
8 #include <linux/delay.h>
9 #include <linux/init.h>
11 static unsigned long preset_lpj;
12 static int __init lpj_setup(char *str)
14 preset_lpj = simple_strtoul(str,NULL,0);
15 return 1;
18 __setup("lpj=", lpj_setup);
21 * This is the number of bits of precision for the loops_per_jiffy. Each
22 * bit takes on average 1.5/HZ seconds. This (like the original) is a little
23 * better than 1%
25 #define LPS_PREC 8
27 void __devinit calibrate_delay(void)
29 unsigned long ticks, loopbit;
30 int lps_precision = LPS_PREC;
32 if (preset_lpj) {
33 loops_per_jiffy = preset_lpj;
34 printk("Calibrating delay loop (skipped)... "
35 "%lu.%02lu BogoMIPS preset\n",
36 loops_per_jiffy/(500000/HZ),
37 (loops_per_jiffy/(5000/HZ)) % 100);
38 } else {
39 loops_per_jiffy = (1<<12);
41 printk(KERN_DEBUG "Calibrating delay loop... ");
42 while ((loops_per_jiffy <<= 1) != 0) {
43 /* wait for "start of" clock tick */
44 ticks = jiffies;
45 while (ticks == jiffies)
46 /* nothing */;
47 /* Go .. */
48 ticks = jiffies;
49 __delay(loops_per_jiffy);
50 ticks = jiffies - ticks;
51 if (ticks)
52 break;
56 * Do a binary approximation to get loops_per_jiffy set to
57 * equal one clock (up to lps_precision bits)
59 loops_per_jiffy >>= 1;
60 loopbit = loops_per_jiffy;
61 while (lps_precision-- && (loopbit >>= 1)) {
62 loops_per_jiffy |= loopbit;
63 ticks = jiffies;
64 while (ticks == jiffies)
65 /* nothing */;
66 ticks = jiffies;
67 __delay(loops_per_jiffy);
68 if (jiffies != ticks) /* longer than 1 tick */
69 loops_per_jiffy &= ~loopbit;
72 /* Round the value and print it */
73 printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
74 loops_per_jiffy/(500000/HZ),
75 (loops_per_jiffy/(5000/HZ)) % 100,
76 loops_per_jiffy);