Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12573

Change subject: base: Avoid dividing by zero in Time::[gs]etTick.
......................................................................

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
---
M src/base/time.cc
1 file changed, 6 insertions(+), 3 deletions(-)



diff --git a/src/base/time.cc b/src/base/time.cc
index 6e9d7cc..80bc546 100644
--- a/src/base/time.cc
+++ b/src/base/time.cc
@@ -57,14 +57,17 @@
 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

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12573
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I5cc9db14699c00dcbff48e4593b98522b13b4ccd
Gerrit-Change-Number: 12573
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to