syscall: Implementation of the times system call
authorTimothy M. Jones <tjones1@inf.ed.ac.uk>
Sat, 24 Oct 2009 17:53:57 +0000 (10:53 -0700)
committerTimothy M. Jones <tjones1@inf.ed.ac.uk>
Sat, 24 Oct 2009 17:53:57 +0000 (10:53 -0700)
src/kern/linux/linux.hh
src/sim/syscall_emul.hh

index 7c16228ea194288e786d3f0bc9962dcc6bb586b8..2df323712c555a3c5264f96fc5286b86758e825d 100644 (file)
@@ -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 *
index e45a6c79755470086767cfaaf938ac6a393f373c..ce7c7fa8789f9beac2ba211168dd02e4a124c437 100644 (file)
@@ -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;
+}