3 #include <metal/timer.h>
6 extern int _gettimeofday(struct timeval *, void *);
8 /* Timing information for current process. From
9 newlib/libc/include/sys/times.h the tms struct fields are as follows:
11 - clock_t tms_utime : user clock ticks
12 - clock_t tms_stime : system clock ticks
13 - clock_t tms_cutime : children's user clock ticks
14 - clock_t tms_cstime : children's system clock ticks
16 Since maven does not currently support processes we set both of the
17 children's times to zero. Eventually we might want to separately
18 account for user vs system time, but for now we just return the total
19 number of cycles since starting the program. */
21 _times(struct tms *buf)
24 // when called for the first time, initialize t0
25 static struct timeval t0;
26 if (t0.tv_sec == 0 && t0.tv_usec == 0)
27 _gettimeofday (&t0, 0);
30 _gettimeofday (&t, 0);
32 unsigned long long timebase;
33 rv = metal_timer_get_timebase_frequency(0, &timebase);
38 long long utime = (t.tv_sec - t0.tv_sec) * 1000000 + (t.tv_usec - t0.tv_usec);
39 buf->tms_utime = utime * timebase / 1000000;
40 buf->tms_stime = buf->tms_cstime = buf->tms_cutime = 0;