source: benchmark/readyQ/cycle.cfa@ b35ab2d

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum stuck-waitfor-destruct
Last change on this file since b35ab2d was b35ab2d, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Added basic benchmark for readyQ that cycles among groups of threads.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include "rq_bench.hfa"
2
3thread Partner {
4 Partner * partner;
5 unsigned long long count;
6 bool first;
7};
8
9void ?{}( Partner & this ) {
10 ((thread&)this){ bench_cluster };
11}
12
13void main( Partner & this ) {
14 thread_loop {
15 park();
16 unpark( *this.partner );
17 }
18
19 __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
20
21 if(this.first) park();
22}
23
24int main(int argc, char * argv[]) {
25 unsigned ring_size = 2;
26 cfa_option opt[] = {
27 BENCH_OPT,
28 { 'r', "ringsize", "Number of threads in a cycle", ring_size }
29 };
30 BENCH_OPT_PARSE("cforall cycle benchmark");
31
32 {
33 unsigned long long global_counter = 0;
34 unsigned tthreads = nthreads * ring_size;
35 Time start, end;
36 BenchCluster bc = { nprocs };
37 {
38 threads_left = tthreads;
39 Partner threads[tthreads];
40 for(i; tthreads) {
41 unsigned pi = (i + nthreads) % tthreads;
42 threads[i].partner = &threads[pi];
43 threads[i].first = i < nthreads;
44 }
45 printf("Starting\n");
46
47 bool is_tty = isatty(STDOUT_FILENO);
48 start = getTimeNsec();
49
50 for(i; nthreads) {
51 unpark( threads[i] );
52 }
53 wait(start, end, is_tty);
54
55 stop = true;
56 end = getTimeNsec();
57 printf("\nDone\n");
58
59 for(i; tthreads) {
60 global_counter += join( threads[i] ).count;
61 }
62 }
63
64 printf("Took %'ld ms\n", (end - start)`ms);
65 printf("Yields per second : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
66 printf("ns per yields : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
67 printf("Total yields : %'15llu\n", global_counter);
68 printf("Yields per threads : %'15llu\n", global_counter / tthreads);
69 printf("Yields per procs : %'15llu\n", global_counter / nprocs);
70 printf("Yields/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
71 printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
72 fflush(stdout);
73 }
74
75 return 0;
76}
Note: See TracBrowser for help on using the repository browser.