calibrate.c 1.8 KB

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