From: Gabe Black Date: Thu, 20 Jan 2011 00:22:15 +0000 (-0800) Subject: Time: Add setTick and getTick functions to the Time class. X-Git-Tag: stable_2012_02_02~634 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=23bab6783b8fb4401543941983c36c41cd24b4ef;p=gem5.git Time: Add setTick and getTick functions to the Time class. --- diff --git a/src/base/time.cc b/src/base/time.cc index b9bbb0830..0fab938a4 100644 --- a/src/base/time.cc +++ b/src/base/time.cc @@ -33,6 +33,7 @@ #include "base/time.hh" #include "config/use_posix_clock.hh" +#include "sim/core.hh" using namespace std; @@ -48,6 +49,19 @@ Time::_set(bool monotonic) #endif } +void +Time::setTick(Tick ticks) +{ + uint64_t nsecs = ticks / SimClock::Int::ns; + set(nsecs / NSEC_PER_SEC, nsecs % NSEC_PER_SEC); +} + +Tick +Time::getTick() const +{ + return (nsec() + sec() * NSEC_PER_SEC) * SimClock::Int::ns; +} + string Time::date(const string &format) const { diff --git a/src/base/time.hh b/src/base/time.hh index 2c54f2675..4fc3dd3ef 100644 --- a/src/base/time.hh +++ b/src/base/time.hh @@ -42,6 +42,8 @@ #include #include +#include "base/types.hh" + class Time { protected: @@ -99,6 +101,18 @@ class Time */ void set(time_t _sec, long _nsec) { sec(_sec); nsec(_nsec); } + /** + * Set the current time from a value measured in Ticks + * @param ticks Number of ticks to convert into a time. + */ + void setTick(Tick ticks); + + /** + * Get the current time from a value measured in Ticks + * @return Time value measured in Ticks. + */ + Tick getTick() const; + const Time & operator=(const Time &other) {