1 | #include "rq_bench.hfa"
|
---|
2 |
|
---|
3 | #include <locks.hfa>
|
---|
4 |
|
---|
5 | unsigned spot_cnt = 2;
|
---|
6 | semaphore * spots;
|
---|
7 |
|
---|
8 | thread BThrd {
|
---|
9 | unsigned long long count;
|
---|
10 | unsigned long long blocks;
|
---|
11 | bool skip;
|
---|
12 | };
|
---|
13 |
|
---|
14 | void ?{}( BThrd & this ) {
|
---|
15 | ((thread&)this){ bench_cluster };
|
---|
16 | this.count = 0;
|
---|
17 | this.blocks = 0;
|
---|
18 | this.skip = false;
|
---|
19 | }
|
---|
20 |
|
---|
21 | void ^?{}( BThrd & mutex this ) {}
|
---|
22 |
|
---|
23 | void main( BThrd & this ) with( this ) {
|
---|
24 | park();
|
---|
25 | for() {
|
---|
26 | uint32_t r = prng(this);
|
---|
27 | semaphore & sem = spots[r % spot_cnt];
|
---|
28 | if(!skip) V( sem );
|
---|
29 | blocks += P( sem );
|
---|
30 | skip = false;
|
---|
31 |
|
---|
32 | count ++;
|
---|
33 | if( clock_mode && stop) break;
|
---|
34 | if(!clock_mode && count >= stop_count) break;
|
---|
35 | }
|
---|
36 |
|
---|
37 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | int main(int argc, char * argv[]) {
|
---|
42 | cfa_option opt[] = {
|
---|
43 | BENCH_OPT,
|
---|
44 | { 's', "spots", "Number of spots in the system", spot_cnt }
|
---|
45 | };
|
---|
46 | BENCH_OPT_PARSE("cforall churn benchmark");
|
---|
47 |
|
---|
48 | {
|
---|
49 | unsigned long long global_counter = 0;
|
---|
50 | unsigned long long global_blocks = 0;
|
---|
51 | Time start, end;
|
---|
52 | BenchCluster bc = { nprocs };
|
---|
53 | {
|
---|
54 | spots = aalloc(spot_cnt);
|
---|
55 | for(i; spot_cnt) {
|
---|
56 | (spots[i]){ 0 };
|
---|
57 | }
|
---|
58 |
|
---|
59 | threads_left = nthreads;
|
---|
60 | BThrd ** threads = alloc(nthreads);
|
---|
61 | for(i; nthreads ) {
|
---|
62 | BThrd & t = *(threads[i] = malloc());
|
---|
63 | (t){};
|
---|
64 | t.skip = i < spot_cnt;
|
---|
65 | }
|
---|
66 | printf("Starting\n");
|
---|
67 |
|
---|
68 | bool is_tty = isatty(STDOUT_FILENO);
|
---|
69 | start = timeHiRes();
|
---|
70 |
|
---|
71 | for(i; nthreads) {
|
---|
72 | unpark( *threads[i] );
|
---|
73 | }
|
---|
74 | wait(start, is_tty);
|
---|
75 |
|
---|
76 | stop = true;
|
---|
77 | end = timeHiRes();
|
---|
78 | printf("\nDone\n");
|
---|
79 |
|
---|
80 | for(i; spot_cnt) {
|
---|
81 | for(10000) V( spots[i] );
|
---|
82 | }
|
---|
83 |
|
---|
84 | for(i; nthreads) {
|
---|
85 | BThrd & thrd = join( *threads[i] );
|
---|
86 | global_counter += thrd.count;
|
---|
87 | global_blocks += thrd.blocks;
|
---|
88 | delete(threads[i]);
|
---|
89 | }
|
---|
90 |
|
---|
91 | free(spots);
|
---|
92 | free(threads);
|
---|
93 | }
|
---|
94 |
|
---|
95 | printf("Duration (ms) : %'lf\n", (end - start)`dms);
|
---|
96 | printf("Number of processors : %'d\n", nprocs);
|
---|
97 | printf("Number of threads : %'d\n", nthreads);
|
---|
98 | printf("Number of spots : %'d\n", spot_cnt);
|
---|
99 | printf("Total Operations(ops): %'15llu\n", global_counter);
|
---|
100 | printf("Total blocks : %'15llu\n", global_blocks);
|
---|
101 | printf("Ops per second : %'18.2lf\n", ((double)global_counter) / (end - start)`ds);
|
---|
102 | printf("ns per ops : %'18.2lf\n", (end - start)`dns / global_counter);
|
---|
103 | printf("Ops per threads : %'15llu\n", global_counter / nthreads);
|
---|
104 | printf("Ops per procs : %'15llu\n", global_counter / nprocs);
|
---|
105 | printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`ds);
|
---|
106 | printf("ns per ops/procs : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
|
---|
107 | fflush(stdout);
|
---|
108 | }
|
---|
109 |
|
---|
110 | return 0;
|
---|
111 | }
|
---|