summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/syscall_emul.hh43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index bb73e1fd2..8c1a21a65 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012-2013 ARM Limited
+ * Copyright (c) 2015 Advanced Micro Devices, Inc.
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -397,6 +398,8 @@ SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
/// A readable name for 1,000,000, for converting microseconds to seconds.
const int one_million = 1000000;
+/// A readable name for 1,000,000,000, for converting nanoseconds to seconds.
+const int one_billion = 1000000000;
/// Approximate seconds since the epoch (1/1/1970). About a billion,
/// by my reckoning. We want to keep this a constant (not use the
@@ -407,13 +410,24 @@ const unsigned seconds_since_epoch = 1000000000;
/// microseconds.
template <class T1, class T2>
void
-getElapsedTime(T1 &sec, T2 &usec)
+getElapsedTimeMicro(T1 &sec, T2 &usec)
{
- int elapsed_usecs = curTick() / SimClock::Int::us;
+ uint64_t elapsed_usecs = curTick() / SimClock::Int::us;
sec = elapsed_usecs / one_million;
usec = elapsed_usecs % one_million;
}
+/// Helper function to convert current elapsed time to seconds and
+/// nanoseconds.
+template <class T1, class T2>
+void
+getElapsedTimeNano(T1 &sec, T2 &nsec)
+{
+ uint64_t elapsed_nsecs = curTick() / SimClock::Int::ns;
+ sec = elapsed_nsecs / one_billion;
+ nsec = elapsed_nsecs % one_billion;
+}
+
//////////////////////////////////////////////////////////////////////
//
// The following emulation functions are generic, but need to be
@@ -1283,6 +1297,25 @@ getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
return 0;
}
+/// Target clock_gettime() function.
+template <class OS>
+SyscallReturn
+clock_gettimeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
+{
+ int index = 1;
+ //int clk_id = p->getSyscallArg(tc, index);
+ TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
+
+ getElapsedTimeNano(tp->tv_sec, tp->tv_nsec);
+ tp->tv_sec += seconds_since_epoch;
+ tp->tv_sec = TheISA::htog(tp->tv_sec);
+ tp->tv_nsec = TheISA::htog(tp->tv_nsec);
+
+ tp.copyOut(tc->getMemProxy());
+
+ return 0;
+}
+
/// Target gettimeofday() handler.
template <class OS>
SyscallReturn
@@ -1292,7 +1325,7 @@ gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
int index = 0;
TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
- getElapsedTime(tp->tv_sec, tp->tv_usec);
+ getElapsedTimeMicro(tp->tv_sec, tp->tv_usec);
tp->tv_sec += seconds_since_epoch;
tp->tv_sec = TheISA::htog(tp->tv_sec);
tp->tv_usec = TheISA::htog(tp->tv_usec);
@@ -1369,7 +1402,7 @@ getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
switch (who) {
case OS::TGT_RUSAGE_SELF:
- getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
+ getElapsedTimeMicro(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
rup->ru_utime.tv_sec = TheISA::htog(rup->ru_utime.tv_sec);
rup->ru_utime.tv_usec = TheISA::htog(rup->ru_utime.tv_usec);
break;
@@ -1423,7 +1456,7 @@ timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
typename OS::time_t sec, usec;
- getElapsedTime(sec, usec);
+ getElapsedTimeMicro(sec, usec);
sec += seconds_since_epoch;
int index = 0;