blob: 74c2fb40c791b2515f3a7ad820784b96e8075d43 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include "litmus.h"
/* CPU time consumed so far in seconds */
double cputime(void)
{
struct timespec ts;
int err;
err = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
if (err != 0)
perror("clock_gettime");
return (ts.tv_sec + 1E-9 * ts.tv_nsec);
}
/* wall-clock time in seconds */
double wctime(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec + 1E-6 * tv.tv_usec);
}
int lt_sleep(lt_t timeout)
{
struct timespec delay;
delay.tv_sec = timeout / 1000000000L;
delay.tv_nsec = timeout % 1000000000L;
return nanosleep(&delay, NULL);
}
|