Updated: May 06, 2022 |
Get the number of clock cycles
#include <sys/neutrino.h> #include <inttypes.h> uint64_t ClockCycles( void );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The ClockCycles() kernel call returns the current value of a free-running 64-bit cycle counter. This is implemented on each processor as a high-performance mechanism for timing short intervals. On Intel, ClockCycles() reads the Time Stamp Counter (RDTSC) and on an ARM 64-bit system, it reads the Generic Timer.
You can use the SYSPAGE_ENTRY(qtime)->cycles_per_sec field to get the number of ClockCycles() increments in one second.
(~(uint64_t)0) / SYSPAGE_ENTRY(qtime)->cycles_per_sec
For example, a 6 GHz system will take 97 years for ClockCycles() to roll over.
We require that the hardware underlying ClockCycles() be synchronized across all processors on an SMP system. This means that you no longer have to call ThreadCtl( _NTO_TCTL_RUNMASK, ...) to prevent threads from migrating to another processor between calls to ClockCycles().
Blocking states:
This call doesn't block.
See SYSPAGE_ENTRY().
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |