timer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _ASMi386_TIMER_H
  2. #define _ASMi386_TIMER_H
  3. #include <linux/init.h>
  4. #include <linux/pm.h>
  5. #define TICK_SIZE (tick_nsec / 1000)
  6. void setup_pit_timer(void);
  7. unsigned long long native_sched_clock(void);
  8. unsigned long native_calculate_cpu_khz(void);
  9. extern int timer_ack;
  10. extern int no_timer_check;
  11. extern int no_sync_cmos_clock;
  12. extern int recalibrate_cpu_khz(void);
  13. #ifndef CONFIG_PARAVIRT
  14. #define calculate_cpu_khz() native_calculate_cpu_khz()
  15. #endif
  16. /* Accellerators for sched_clock()
  17. * convert from cycles(64bits) => nanoseconds (64bits)
  18. * basic equation:
  19. * ns = cycles / (freq / ns_per_sec)
  20. * ns = cycles * (ns_per_sec / freq)
  21. * ns = cycles * (10^9 / (cpu_khz * 10^3))
  22. * ns = cycles * (10^6 / cpu_khz)
  23. *
  24. * Then we use scaling math (suggested by george@mvista.com) to get:
  25. * ns = cycles * (10^6 * SC / cpu_khz) / SC
  26. * ns = cycles * cyc2ns_scale / SC
  27. *
  28. * And since SC is a constant power of two, we can convert the div
  29. * into a shift.
  30. *
  31. * We can use khz divisor instead of mhz to keep a better percision, since
  32. * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
  33. * (mathieu.desnoyers@polymtl.ca)
  34. *
  35. * -johnstul@us.ibm.com "math is hard, lets go shopping!"
  36. */
  37. extern unsigned long cyc2ns_scale __read_mostly;
  38. #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */
  39. static inline unsigned long long cycles_2_ns(unsigned long long cyc)
  40. {
  41. return (cyc * cyc2ns_scale) >> CYC2NS_SCALE_FACTOR;
  42. }
  43. #endif