1 /* calibrate.c: default delay calibration
3 * Excised from init/main.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
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);
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
27 void __devinit
calibrate_delay(void)
29 unsigned long ticks
, loopbit
;
30 int lps_precision
= LPS_PREC
;
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);
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 */
45 while (ticks
== jiffies
)
49 __delay(loops_per_jiffy
);
50 ticks
= jiffies
- ticks
;
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
;
64 while (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,