forked from nikitadanilov/usched
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlmain.c
71 lines (66 loc) · 1.33 KB
/
lmain.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
65
66
67
68
69
70
71
#include "ll.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#include <inttypes.h>
static int n;
static int r;
static int m;
static int d;
static struct ll_thread **t;
static void loop(void *arg)
{
int idx = (long)arg;
int next = idx / n * n + (idx + 1) % n;
int i;
for (i = 0; i < m; ++i) {
if (idx % n == i % n) {
ll_wake(t[next]);
ll_wait();
} else {
ll_wait();
ll_wake(t[next]);
}
}
ll_done();
}
static
#if defined(__clang__)
__attribute__((optnone))
#else
__attribute__((optimize("O0"))) /* keep pad[] */
#endif
void f(void *arg)
{
char pad[d];
memset(pad, '#', d);
loop(arg);
}
int main(int argc, char **argv)
{
uint64_t start;
uint64_t end;
struct timeval tt;
int p = atoi(argv[5]);
n = atoi(argv[1]); /* Cycle length. */
r = atoi(argv[2]); /* Number of cycles. */
m = atoi(argv[3]); /* Number of rounds. */
d = atoi(argv[4]); /* Additional stack depth. */
t = calloc(n * r, sizeof t[0]);
if (p > r)
p = r;
ll_init(p /* processors */, n * r /* threads */);
for (int i = 0; i < n * r; ++i) {
t[i] = ll_thread_init(f, (void *)(long)i, i / n);
}
gettimeofday(&tt, NULL);
start = 1000000 * tt.tv_sec + tt.tv_usec;
ll_start();
ll_fini();
gettimeofday(&tt, NULL);
end = 1000000 * tt.tv_sec + tt.tv_usec;
printf("%f\n", (end - start) / 1000000.);
free(t);
return 0;
}