diff --git a/sys/kern/ktime.c b/sys/kern/ktime.c index 41fc445..3cb0103 100644 --- a/sys/kern/ktime.c +++ b/sys/kern/ktime.c @@ -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;