Guardian Programmer's Guide

Table Of Contents
Guardian Programmer’s Guide 421922-014
18 - 1
18
Managing Time
Time management involves two related concepts:
Creating and manipulating timestamps—that is, finding out what the time is
Performing timing operations—that is, finding out how much time it takes to
perform a given task
This section begins by describing how timestamps are generated, what kind of
timestamps are available, and the different ways in which the time of day can be
represented; see How the System Keeps Time. The subsection Using the Time
Management Procedures introduces the system procedures that you can use to
manipulate timestamps. The subsection Time and Date Manipulation goes on to
describe the procedures that form the programmatic interface to system timekeeping.
Timing information is described in Timing in Elapsed Time and Timing in Process Time.
This subsection explains the difference between elapsed time and process time and
describes the tasks you can perform with the related procedures.
The last subsection, Managing System Time, describes the procedures you can use to
manipulate system timekeeping. Specifically, this includes getting and setting the
system time.
How the System Keeps Time
The basis of all timing performed on the system is a hardware clock that increments
every clock cycle. This clock represents the number of microseconds since the last
time the node was cold loaded. All other time values are derived from this clock.
Clock Averaging and System Time
Each CPU in the system has its own CPU clock that keeps the time for that CPU.
Typically, each CPU clock in the system runs at a slightly different speed. The system
determines system time by taking the average of the various CPU times; it then
establishes an adjustment value for each CPU clock. The adjustment value, which is
periodically updated, enables each CPU to provide the correct system time when
queried. Thus, when you ask for a timestamp, what you get is the CPU time corrected
by the adjustment value, In this way, the CPU clocks are effectively synchronized.
While the clock-averaging algorithm keeps CPU clocks synchronized with each other, it
does not necessarily keep system time consistent with the real time of day. For this
purpose, the SYSTEMCLOCK_SET_ or SETSYSTEMCLOCK procedure provides a
means for periodically adjusting the system time, adjusting the system time rate, or
setting the system time. Managing System Time at the end of this section provides
details.
Synchronizing system time to any standard time requires some program, such as a
Network Time Protocol (NTP) client, to set or adjust the time and clock rate to match