ClockCycles()

QNX SDP8.0C Library ReferenceAPIDeveloper

Get the number of clock cycles

Synopsis:

#include <sys/neutrino.h>
#include <inttypes.h>

uint64_t ClockCycles( void );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The ClockCycles() function returns the current value of a free-running 64-bit cycle counter. This 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).

You can use the SYSPAGE_ENTRY(qtime)->cycles_per_sec field to get the number of ClockCycles() increments in one second.

Note:
QNX OS requires that the hardware underlying ClockCycles() be synchronized across all processors on a multicore system. Here, synchronized means that the difference in time values (i.e., deltas) measured by different processors must be small enough to be not software observable. This requirement means that you don't have to call ThreadCtl( _NTO_TCTL_RUNMASK, ...) to prevent threads from migrating to another processor between calls to ClockCycles().

Unless you specify the frequency for ClockCycles() via the startup -f option, startup determines a frequency value on each target bootup. On AArch64 startup reads a hardware register that contains the frequency, thus it is correct and consistent across boots. On x86_64 the value determined is not exact and may vary from boot to boot. To ensure consistent results, we recommend that you query your x86_64 hardware for the frequency, or consult your target's documentation. Once you determine the frequency, you can either specify this value in your target configuration by using the startup -f option, or modify startup to hard-code the frequency.

Having a correct value is important to ensure proper OS behavior for time and timers. For more information, see startup-* options in the Utilities Reference guide.

Blocking states:

This call doesn't block.

Returns

The current value of a free-running 64-bit cycle counter.

Examples:

See SYSPAGE_ENTRY().

Classification:

QNX OS

Safety:
Cancellation pointNo
Signal handlerYes
ThreadYes
Page updated: