SlideServe
Menu
Préférences
© SlideServe · v2026

Enhancing Clock Accuracy in PC Systems: RTC, Interrupts, and High-Performance Counters

clarke-lambert avatar
11 diapositives · 268 Views · Nov 19, 2014

This document by Dr. Hugh Melvin from NUI Galway explores the intricacies of timing systems in typical PC clock systems. It discusses Real-Time Clocks (RTC), low-frequency oscillators, and their role in minimizing battery consumption while achieving second-level accuracy. The paper examines how counters are incremented via interrupts and how the counter value is translated into time standards like UTC. It also highlights the importance of system clock granularity and resolution, particularly for real-time applications, alongside practical solutions for improving timing fidelity in both Windows and Unix/Linux platforms.

Enhancing Clock Accuracy in PC Systems: RTC, Interrupts, and High-Performance Counters - slide 1
01 / 11Enhancing Clock Accuracy in PC Systems: RTC, Interrupts, and High-Performance Counters
1 / 17

Télécharger la présentation

Enhancing Clock Accuracy in PC Systems: RTC, Interrupts, and High-Performance Counters
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. OS Timing Services Dr. Hugh Melvin, Dept. of IT, NUI,G

  2. Typical PC Clock System • RTC (Real Time Clock) • Low freq oscillator (Eg. 32 kHz) • Minimises Battery Consumption • Second-level accuracy • Software Clock (System Clock) • Counter • Interrupt driven: ticks are added to counter value • Counter value translated into time standard eg. UTC • At system startup, counter value taken from RTC • Interrupts generated by separate oscillator • Eg. Intel 8254 1.193182 MHz Clock is commonly used Interrupt rate determines granularity or resolution Dr. Hugh Melvin, Dept. of IT, NUI,G

  3. System Clock • Interrupt rate  tick size  system clock resolution • Note: Little point in implementing NTP for msec accuracy if timing services have poor resolution • Unix/Linux platforms • Interrupt rate upgraded to 1000 Hz (1msec) from 100Hz (10 msec) in recent releases • Windows Platforms • 10 15 msec ticksize still common • Eg. GetSystemTimeAsFileTime() Dr. Hugh Melvin, Dept. of IT, NUI,G

  4. Granularity/Resolution • System Clock Granularity • Significant restriction for precision timing requirements of many RTS applications • Process timeslice also typically set by timer interrupts • Further restriction on Real Time applications • Limits responsiveness • Windows • Not yet implemented • Manual workarounds available • See notes • NTP workaround based on interpolation eg. using 8254 clock counter Dr. Hugh Melvin, Dept. of IT, NUI,G

  5. Granularity/Resolution • Unix/Linux • gettimeofday() circumvents clock granularity (100/1000Hz) by interpolating between ticks using main CPU processor counter • gettimeofday() • Stores time in timeval structure (sec + usec) • struct timeval{ time_t tv_sec; time_t tv_usec; } • time_t is long integer Dr. Hugh Melvin, Dept. of IT, NUI,G

  6. Windows Resolution //File handler ofstream outFile( argv[1],ios::out); SYSTEMTIME st; int i=0; while (i<5000) { ::GetSystemTime(&st); outFile<< st.wHour << ':'<< st.wMinute << ':'<< st.wSecond << '.' << st.wMilliseconds << '\n'; i++; } • Indicates granularity See http://msdn.microsoft.com/msdnmag/issues/04/03/HighResolutionTimer/ Dr. Hugh Melvin, Dept. of IT, NUI,G

  7. Windows Resolution • See Code Extract • Store 5000 intervals • Examine distribution • Not all equal to fundamental resolution! • OS issue process preempted  time has advanced by > 1 tick 5000 samples. Smallest delta: 15.625ms; Largest delta: 46.875ms; Sum of Delta: 78234.4ms; Average: 15.6469ms Distribution: 156250: 4993 312500: 4 468750: 2 Total Runtime was : 78.2656 seconds Exercise: Load up OS .. Examine distribution Dr. Hugh Melvin, Dept. of IT, NUI,G

  8. Windows Resolution: Workaround • Improve resolution via separate High Performance/ Resolution Counter (HPRC) • ::QueryPerformanceCounter(&li); • Can access its frequency • ::QueryPerformanceFrequency(&frequency); • 3.57 MHz Clock • Interpolate between ticks of system clock • Need to establish baseline ‘synchronise’ with system clock • Baseline or reference has • System clock at instant of change • Corresponding HPRC value • Use baseline for interpolation Dr. Hugh Melvin, Dept. of IT, NUI,G

  9. void simplistic_synchronize(reference_point& ref_point) { FILETIME ft0 = { 0, 0 }, ft1 = { 0, 0 }; LARGE_INTEGER li; // // Spin waiting for a change in system time. Get the matching // performance counter value for that time. // ::GetSystemTimeAsFileTime(&ft0); do { ::GetSystemTimeAsFileTime(&ft1); ::QueryPerformanceCounter(&li); } while ((ft0.dwHighDateTime == ft1.dwHighDateTime) && (ft0.dwLowDateTime == ft1.dwLowDateTime)); ref_point.file_time = ft1; ref_point.counter = li; } Dr. Hugh Melvin, Dept. of IT, NUI,G

  10. Skew System Clock : Ref Sys Time + ΔHPRC Actual System Clock Reference Point (Ref Sys Time, Ref HPRC) Dr. Hugh Melvin, Dept. of IT, NUI,G

  11. Unix/Linux Timing • gettimeofday() • Microsec granularity • Process timeslice can however impact on timing services • Eg. usleep( ) .. microsec level argument • In practice, limited by timeslice Dr. Hugh Melvin, Dept. of IT, NUI,G