This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
There are several functions that you can use to determine the current time, for use in timestamps or for calculating execution times:
All the above methods have an accuracy based on the system timer tick. If you need more accuracy, 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 synchronized with the values on other processors.
Some caveats for each processor:
To convert the cycle number to real time, use SYSPAGE_ENTRY(qtime)->cycles_per_sec.
SH and MIPS are based on a 32-bit clock, so they can wrap around. You should use ClockCycles() only for short durations. |
If you need a pause, use delay() or the POSIX clock_nanosleep().
If you need a very short delay (e.g. for accessing hardware), you should look at the nanospin* functions. They basically do a while loop to a calibrated number of iterations to delay the proper amount of time (see http://cvs.qnx.com/cgi-bin/cvsweb.cgi/lib/c/qnx/nanospin_count.c and http://cvs.qnx.com/cgi-bin/cvsweb.cgi/lib/c/qnx/nanospin_ns_to_count.c) This wastes CPU, so you should use it only if necessary.