What time is it?
The 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.
- clock_gettime_mon_ns()
- Return the monotonic time in nanoseconds.
- clock_gettime_rt_ns()
- Return the current time in 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 the start of 1970. This supports a time range that can be considered infinite.
In QNX OS, you can access the free-running cycle counter in hardware via the ClockCycles() function which, despite its spelling, is not actually a kernel call.
Here's some information for each supported architecture:
- 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
.