source: trunk/libs/newlib/src/libgloss/riscv/sys_times.c @ 480

Last change on this file since 480 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.2 KB
Line 
1#include <machine/syscall.h>
2#include <sys/types.h>
3#include <sys/times.h>
4#include <sys/time.h>
5#include "internal_syscall.h"
6
7extern int _gettimeofday(struct timeval *, void *);
8
9/* Timing information for current process. From
10   newlib/libc/include/sys/times.h the tms struct fields are as follows:
11
12   - clock_t tms_utime  : user clock ticks
13   - clock_t tms_stime  : system clock ticks
14   - clock_t tms_cutime : children's user clock ticks
15   - clock_t tms_cstime : children's system clock ticks
16
17   Since maven does not currently support processes we set both of the
18   children's times to zero. Eventually we might want to separately
19   account for user vs system time, but for now we just return the total
20   number of cycles since starting the program.  */
21clock_t
22_times(struct tms *buf)
23{
24  // when called for the first time, initialize t0
25  static struct timeval t0;
26  if (t0.tv_sec == 0)
27    _gettimeofday (&t0, 0);
28
29  struct timeval t;
30  _gettimeofday (&t, 0);
31
32  long long utime = (t.tv_sec - t0.tv_sec) * 1000000 + (t.tv_usec - t0.tv_usec);
33  buf->tms_utime = utime * CLOCKS_PER_SEC / 1000000;
34  buf->tms_stime = buf->tms_cstime = buf->tms_cutime = 0;
35
36  return -1;
37}
Note: See TracBrowser for help on using the repository browser.