clock.c 899 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "io.h"
  7. #include "ureg.h"
  8. /*
  9. * this is called both by the mp's clock interrupt and
  10. * by the clockintr0 for the i8253
  11. */
  12. void
  13. clockintr(Ureg* ureg, void*)
  14. {
  15. /* this has to get called every tick or the 8253 timer will overflow */
  16. fastticks(nil);
  17. if(m->flushmmu){
  18. if(up)
  19. flushmmu();
  20. m->flushmmu = 0;
  21. }
  22. portclock(ureg);
  23. }
  24. void
  25. delay(int millisecs)
  26. {
  27. millisecs *= m->loopconst;
  28. if(millisecs <= 0)
  29. millisecs = 1;
  30. aamloop(millisecs);
  31. }
  32. void
  33. microdelay(int microsecs)
  34. {
  35. microsecs *= m->loopconst;
  36. microsecs /= 1000;
  37. if(microsecs <= 0)
  38. microsecs = 1;
  39. aamloop(microsecs);
  40. }
  41. /*
  42. * performance measurement ticks. must be low overhead.
  43. * doesn't have to count over a second.
  44. */
  45. ulong
  46. perfticks(void)
  47. {
  48. uvlong x;
  49. if(!m->havetsc)
  50. return ticks;
  51. rdtsc(&x);
  52. return x;
  53. }