]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/gloss/sys_times.c
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / gloss / sys_times.c
1 #include <sys/times.h>
2 #include <sys/time.h>
3 #include <metal/timer.h>
4 #include <errno.h>
5
6 extern int _gettimeofday(struct timeval *, void *);
7
8 /* Timing information for current process. From
9    newlib/libc/include/sys/times.h the tms struct fields are as follows:
10
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
15
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.  */
20 clock_t
21 _times(struct tms *buf)
22 {
23     int rv;
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);
28
29     struct timeval t;
30     _gettimeofday (&t, 0);
31
32     unsigned long long timebase;
33     rv = metal_timer_get_timebase_frequency(0, &timebase);
34     if (rv != 0) {
35         return -1;
36     }
37
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;
41     return 0;
42 }