diff options
author | Gabe Black <gabeblack@google.com> | 2018-09-11 00:59:56 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-09-11 21:39:28 +0000 |
commit | 544b136cbfbba53b6d97b763445e9f9b25eb2a7f (patch) | |
tree | 0b76d35afe78d373f25cd23c370ff6347219a7f3 | |
parent | 6c49198b7541eeddf648e210569e18eb0ab79303 (diff) | |
download | gem5-544b136cbfbba53b6d97b763445e9f9b25eb2a7f.tar.xz |
base: Avoid dividing by zero in Time::[gs]etTick.
Those functions used the value SimClock::Int::ns which, if the time
resolution is larger than 1ns, can/will be zero. That will make
getTick always return zero, and setTick divide by zero. This change
modifies those functions so that the math they do avoids using any
integer Ticks per time unit value except for Frequency. It seems
unlikely that the Ticks will increment at less than 1Hz.
Change-Id: I5cc9db14699c00dcbff48e4593b98522b13b4ccd
Reviewed-on: https://gem5-review.googlesource.com/12573
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r-- | src/base/time.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/base/time.cc b/src/base/time.cc index 6e9d7ccfb..80bc546e1 100644 --- a/src/base/time.cc +++ b/src/base/time.cc @@ -57,14 +57,17 @@ Time::_set(bool monotonic) void Time::setTick(Tick ticks) { - uint64_t nsecs = ticks / SimClock::Int::ns; - set(nsecs / NSEC_PER_SEC, nsecs % NSEC_PER_SEC); + uint64_t secs = ticks / SimClock::Frequency; + ticks -= secs * SimClock::Frequency; + uint64_t nsecs = static_cast<uint64_t>(ticks * SimClock::Float::GHz); + set(secs, nsecs); } Tick Time::getTick() const { - return (nsec() + sec() * NSEC_PER_SEC) * SimClock::Int::ns; + return sec() * SimClock::Frequency + + static_cast<uint64_t>(nsec() * SimClock::Float::ns); } string |