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, so there are tradeoffs. The implementation tries to be as quick as possible, so it tries to use a CPU register if possible. Because of this, to get accurate times on SMP machines, you need to use thread affinity to lock the thread to a processor, because each processor can have a ClockCycles() base value that may not be synchronized with the values on other processors.

Some caveats for each processor:

x86
Reads from a 64-bit register, except for 486s, where it causes a fault and the fault handler reads from an external clock chip.
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.