What time is it?
QNX OS maintains two clocks in the system: one is a monotonic count of time since the kernel was initialized (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
Previous releases used an unsigned 32-bit value for seconds since the start of January 1st, 1970, allowing for time representations through approximately the year 2100. This release of QNX OS uses a signed 64-bit value for seconds since January 1st, 1970. This supports a time range that can be considered infinite.
For a high resolution timestamp without the overhead of a kernel call, you can use ClockCycles().
Some information for each processor:
- x86_64
- Uses the RDTSC instruction.
- aarch64
- Reads from a 64-bit CNTVCT_EL0 register.
To convert a
ClockCycles() delta to seconds, use
SYSPAGE_ENTRY(qtime)->cycles_per_sec
.