gettime: fix overflow in cycle to usec conversion

If this multiplication overflows:

usecs = (t * inv_cycles_per_usec) / 16777216UL;

then usecs is 2^64/2^24, which is 1099511627776. Divide that by
10^6 to get seconds, and that is 1099511. Since we cached the
old value previously, we'd get stuck with this amount of seconds.

To avoid turning this into an expensive division, have a check
and only divide if we have to. This avoids the overflow.

Signed-off-by: Jens Axboe <>
1 file changed