Clock and timer services

QNX SDP8.0System ArchitectureDeveloperUser

Clock services are used to maintain the time of day, which is in turn used by the kernel timer calls to implement interval timers.

Note:
The kernel itself uses unsigned 64-bit numbers to count the nanoseconds since the start of January 1st, 1970. This design supports a time range that can be considered infinite for developers of QNX OS systems. Unlike with signed 32-bit time values, there's no risk of rollover in 2038 or, if unsigned values were used, in 2106.

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.

Note:
QNX OS requires that the hardware underlying ClockCycles() be synchronized across all processors on an SMP system. If it isn't, you might encounter some unexpected behavior, such as drifting times and timers.

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
Page updated: