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, including CLOCK_REALTIME and CLOCK_MONOTONIC, which maintain the system time. The system time is based on ClockCycles(), which returns the current value of a free-running 64-bit cycle counter, operating at the frequency read from the SYSPAGE_ENTRY(qtime)->cycles_per_sec field. For more information about this field and the other time-related fields in the system page data structure, go to the qtime reference in the System Page chapter in the Building Embedded Systems guide.

The ClockCycles() function is implemented on each processor architecture as a high-performance mechanism for timing short intervals. On x86 systems, ClockCycles() reads the Time Stamp Counter (RDTSC); on ARM systems, it reads the Generic Timer (CNTVCT_EL0 register).

Note:
QNX OS requires that the hardware underlying ClockCycles() be synchronized across all processors on a multicore 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)
ClockCycles() N/A Read a 64-bit free-running high-precision counter
ClockId() clock_getcpuclockid(), pthread_getcpuclockid() Get a clock ID for a process or thread CPU-time clock
Page updated: