What time is it?

QNX Neutrino maintains two clocks in the system: one is a monotonic count of time since the system booted (CLOCK_MONOTONIC), and the other is a wall-clock time since January 1st, 1970 (CLOCK_REALTIME).

The OS actually just counts time since booting, and if asked for the current time, adds an adjustment value (SYSPAGE_ENTRY(qtime)->nsec_tod_adjust) to the monotonic time to get the current time. Any functions that change the current time simply modify the adjustment value.

There are several functions that you can use to determine the current time, for use in timestamps or for calculating execution times, including:

time()
Return the current time in seconds.
clock_gettime()
Return the current or monotonic time in seconds and nanoseconds since the last second.
ClockTime()
Set or get the current or monotonic time in 64-bit nanoseconds

QNX Neutrino uses unsigned 32-bit values for seconds since January 1st, 1970, allowing for time representations through approximately the year 2100 (rather than 2038). The internal time storage in 64-bit nanoseconds allows for time representations through the year 2500.

All the above methods have a precision that's based on the system timer tick. If you need more precision, you can use ClockCycles(). This function is implemented differently for each processor architecture, so there are tradeoffs. The implementation tries to be as quick as possible, so it tries to use a CPU register if possible.

Note: In QNX Neutrino 7.0.1 or later, we require 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. Using synchronized hardware means that you no longer have to use a runmask for threads to prevent them from migrating to other processors between calls to ClockCycles().

Some caveats for each processor:

x86
Reads from a 64-bit register.
ARM
Always faults, and the fault handler reads from an external clock chip to make a 64-bit value.

To convert the cycle number to real time, use SYSPAGE_ENTRY(qtime)->cycles_per_sec.