Clock and timer services
Clock services are used to maintain the time of day, which is in turn used by the kernel timer calls to implement interval timers.
The ClockTime() kernel call allows you to get or set the value of the system clock specified by an ID (CLOCK_REALTIME), which maintains the system time. The system time is based on ClockCycles(), which returns the current value of the 64-bit nanoseconds counter; the time is no longer incremented based on the resolution of a timer tick or a clock.
Within the system page, an in-memory data
structure, there's a 64-bit field (nsec) that
holds the number of nanoseconds since the system was booted.
This field is always monotonically increasing
and is never affected by setting the current time of day via
ClockTime() or
ClockAdjust().
You can access this field via the
SYSPAGE_ENTRY(qtime)->nsec
macro command.
The ClockCycles() function returns the current value of a free-running 64-bit cycle counter. This is implemented on each processor as a high-performance mechanism for timing short intervals. For example, on Intel x86 processors, an opcode that reads the processor's time-stamp counter is used. Other CPU architectures have similar instructions.
The SYSPAGE_ENTRY(qtime)->cycles_per_sec
field gives the number of ClockCycles() increments
in one second.
The ClockId()
function returns a special clock ID that you can use to track the CPU time that a process or thread uses.
For more information, see
Monitoring execution times
in the Understanding the Microkernel's Concept of Time
chapter of the
QNX OS Programmer's Guide.
Microkernel call | POSIX call | Description |
---|---|---|
ClockTime() | clock_gettime(), clock_settime() | Get or set the time of day (using a 64-bit value in nanoseconds ranging from 1970 to 2554) |
ClockAdjust() | N/A | Apply small time adjustments to synchronize clocks. |
ClockCycles() | N/A | Read a 64-bit free-running high-precision counter |
ClockPeriod() | clock_getres() | Get the period of the clock that gives the resolution for system timers |
ClockId() | clock_getcpuclockid(), pthread_getcpuclockid() | Get a clock ID for a process or thread CPU-time clock |