Computer hardware timers

From Helpful
Jump to navigation Jump to search
This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Hardware perspective

The system's Real-Time clock (RTC)

  • IO based, therefore fairly expensive setup (not practical for some purposes)
  • Rate/resolution: depends on hardware. Approximately 30ms on a 32kHz crystal, and assume no better than 1 millisecond in the best case.(verify)

8254 PIT (Programmable Interval Timer)

  • Resolution/rate: configurable, 1 millisecond (at best) (verify)
  • Controls resolution of system timer (verify)

APIC timer

  • Resolution: Varies (microsecond scale?(verify))
  • Pauses under some conditions, so not directly useful for time-telling

ACPI Power Management Timer (PM, PMT)

  • Accurate (if hardware not buggy)

Time Stamp Counter: ticks since reset

  • rate/resolution depends on system (nanosecond scale?(verify))
  • handy high-resolution counter on i386 processors since the Pentium (there are similar features on other architectures)
  • ...but may be out of sync between cores on various processors - except those with constant-rate TSC (reported by the CPU)
  • ...may vary with CPU voltage/frequency control, so not ideal for timekeeping
  • readout with RDTSC opcode


Programming perspective


  • resolution depends on hardware as well as operating system. May be as precise as a few microseconds, and as rough as perhaps 10 milliseconds. (verify)
  • Often depends on PIT rate? (verify)

clock_gettime() / clock_gettime()

  • Resolution/rate: Varies, but better than gettimeofday (based on TSC)