- if( freq == I64C(-1) )
- {
- /* Extract from the Tcl source code:
- * (http://www.cs.man.ac.uk/fellowsd-bin/TIP/7.html)
- *
- * Some hardware abstraction layers use the CPU clock
- * in place of the real-time clock as a performance counter
- * reference. This results in:
- * - inconsistent results among the processors on
- * multi-processor systems.
- * - unpredictable changes in performance counter frequency
- * on "gearshift" processors such as Transmeta and
- * SpeedStep.
- * There seems to be no way to test whether the performance
- * counter is reliable, but a useful heuristic is that
- * if its frequency is 1.193182 MHz or 3.579545 MHz, it's
- * derived from a colorburst crystal and is therefore
- * the RTC rather than the TSC. If it's anything else, we
- * presume that the performance counter is unreliable.
- */
- LARGE_INTEGER buf;
-
- freq = ( QueryPerformanceFrequency( &buf ) &&
- (buf.QuadPart == I64C(1193182) || buf.QuadPart == I64C(3579545) ) )
- ? buf.QuadPart : 0;
- }
-
- if( freq != 0 )
- {
- LARGE_INTEGER counter;
- QueryPerformanceCounter (&counter);
+ /* Convert to from (1/freq) to microsecond resolution */
+ /* We need to split the division to avoid 63-bits overflow */
+ lldiv_t d = lldiv (counter.QuadPart, freq.QuadPart);