diff options
-rw-r--r-- | src/kern/linux/linux.hh | 11 | ||||
-rw-r--r-- | src/sim/syscall_emul.hh | 24 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/kern/linux/linux.hh b/src/kern/linux/linux.hh index 7c16228ea..2df323712 100644 --- a/src/kern/linux/linux.hh +++ b/src/kern/linux/linux.hh @@ -136,6 +136,17 @@ class Linux : public OperatingSystem int64_t tv_usec; //!< microseconds }; + /// Clock ticks per second, for times(). + static const int _SC_CLK_TCK = 100; + + /// For times(). + struct tms { + int64_t tms_utime; //!< user time + int64_t tms_stime; //!< system time + int64_t tms_cutime; //!< user time of children + int64_t tms_cstime; //!< system time of children + }; + // For writev/readv struct tgt_iovec { uint64_t iov_base; // void * diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index e45a6c797..ce7c7fa87 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -1131,6 +1131,30 @@ getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process, return 0; } +/// Target times() function. +template <class OS> +SyscallReturn +timesFunc(SyscallDesc *desc, int callnum, LiveProcess *process, + ThreadContext *tc) +{ + TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, 0)); + + // Fill in the time structure (in clocks) + int64_t clocks = curTick * OS::_SC_CLK_TCK / Clock::Int::s; + bufp->tms_utime = clocks; + bufp->tms_stime = 0; + bufp->tms_cutime = 0; + bufp->tms_cstime = 0; + + // Convert to host endianness + bufp->tms_utime = htog(bufp->tms_utime); + + // Write back + bufp.copyOut(tc->getMemPort()); + + // Return clock ticks since system boot + return clocks; +} |