Fix overflow in KTime_GetEpochNS

This commit is contained in:
Ali Mashtizadeh 2015-01-16 17:08:29 -08:00
parent c408b47966
commit 114b35bbbc

View File

@ -194,7 +194,12 @@ KTime_GetEpochNS()
Spinlock_Lock(&ktimeLock);
tscDiff = Time_GetTSC() - ktimeLastTSC;
epoch = (ktimeLastEpoch * 1000000000) + (tscDiff * 1000000000 / ticksPerSecond);
/*
* This is ugly but it avoids overflowing tscDiff to time computation.
* Note that the bottom bits of ticksPerSecond are not significant so it is
* okay to discard them.
*/
epoch = (ktimeLastEpoch * 1000000000ULL) + (tscDiff * 1000000ULL / ticksPerSecond * 1000ULL);
Spinlock_Unlock(&ktimeLock);
return epoch;