-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinden_common.c
64 lines (51 loc) · 1.15 KB
/
linden_common.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#define _GNU_SOURCE
#include "linden_common.h"
#if defined(__linux__)
pid_t
gettid(void)
{
return (pid_t) syscall(SYS_gettid);
}
#ifdef LINDEN_PIN // defined in test.c
void
pin(pid_t t, int cpu)
{
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
E_en(sched_setaffinity(t, sizeof(cpu_set_t), &cpuset));
}
#endif // PIN
void
gettime(struct timespec *ts)
{
E(clock_gettime(CLOCK_MONOTONIC, ts));
}
#endif
#if defined(__APPLE__)
void
gettime(struct timespec *ts)
{
uint64_t time = mach_absolute_time();
static mach_timebase_info_data_t info = {0,0};
if (info.denom == 0) {
mach_timebase_info(&info);
}
uint64_t elapsed = time * (info.numer / info.denom);
ts->tv_sec = elapsed * 1e-9;
ts->tv_nsec = elapsed - (ts->tv_sec * 1e9);
}
#endif
struct timespec
timediff (struct timespec begin, struct timespec end)
{
struct timespec tmp;
if ((end.tv_nsec - begin.tv_nsec) < 0) {
tmp.tv_sec = end.tv_sec - begin.tv_sec - 1;
tmp.tv_nsec = 1000000000 + end.tv_nsec - begin.tv_nsec;
} else {
tmp.tv_sec = end.tv_sec - begin.tv_sec;
tmp.tv_nsec = end.tv_nsec - begin.tv_nsec;
}
return tmp;
}