gettime: fix overflow in cycle to usec conversion
authorJens Axboe <axboe@fb.com>
Wed, 17 Dec 2014 05:40:37 +0000 (22:40 -0700)
committerJens Axboe <axboe@fb.com>
Wed, 17 Dec 2014 05:40:37 +0000 (22:40 -0700)
commitb3fa625b38a638cd1783e9fdcac1b958e37e48fa
tree5f4509ceae403f0c6e300b7c4bf5e18b0a8412a3
parent79c896a122a7a39b840257215e622bdeff8272f1
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 <axboe@fb.com>
gettime.c