1 | #include <stdlib.h> |
---|
2 | #include <stdio.h> |
---|
3 | #include <string.h> |
---|
4 | #include <limits.h> |
---|
5 | |
---|
6 | extern "C" { |
---|
7 | #include <locale.h> |
---|
8 | #include <getopt.h> |
---|
9 | } |
---|
10 | |
---|
11 | #include <unistd.h> |
---|
12 | |
---|
13 | #include <clock.hfa> |
---|
14 | #include <time.hfa> |
---|
15 | #include <stats.hfa> |
---|
16 | |
---|
17 | #include "../benchcltr.hfa" |
---|
18 | |
---|
19 | extern bool traceHeapOn(); |
---|
20 | |
---|
21 | |
---|
22 | volatile bool run = false; |
---|
23 | volatile unsigned long long global_counter; |
---|
24 | |
---|
25 | thread __attribute__((aligned(128))) Yielder { |
---|
26 | unsigned long long counter; |
---|
27 | }; |
---|
28 | void ?{}( Yielder & this ) { |
---|
29 | this.counter = 0; |
---|
30 | ((thread&)this){ "Yielder Thread", *the_benchmark_cluster }; |
---|
31 | } |
---|
32 | |
---|
33 | void main( Yielder & this ) { |
---|
34 | park( __cfaabi_dbg_ctx ); |
---|
35 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) ); |
---|
36 | |
---|
37 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) { |
---|
38 | yield(); |
---|
39 | this.counter++; |
---|
40 | } |
---|
41 | __atomic_fetch_add(&global_counter, this.counter, __ATOMIC_SEQ_CST); |
---|
42 | } |
---|
43 | |
---|
44 | int main(int argc, char * argv[]) { |
---|
45 | BENCH_DECL |
---|
46 | |
---|
47 | for(;;) { |
---|
48 | static struct option options[] = { |
---|
49 | BENCH_OPT_LONG |
---|
50 | {0, 0, 0, 0} |
---|
51 | }; |
---|
52 | |
---|
53 | int idx = 0; |
---|
54 | int opt = getopt_long(argc, argv, BENCH_OPT_SHORT, options, &idx); |
---|
55 | |
---|
56 | const char * arg = optarg ? optarg : ""; |
---|
57 | char * end; |
---|
58 | switch(opt) { |
---|
59 | case -1: |
---|
60 | goto run; |
---|
61 | BENCH_OPT_CASE |
---|
62 | default: /* ? */ |
---|
63 | fprintf( stderr, "Unkown option '%c'\n", opt); |
---|
64 | usage: |
---|
65 | bench_usage( argv ); |
---|
66 | exit(1); |
---|
67 | } |
---|
68 | } |
---|
69 | run: |
---|
70 | |
---|
71 | { |
---|
72 | printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration); |
---|
73 | |
---|
74 | Time start, end; |
---|
75 | BenchCluster cl = { 0, CFA_STATS_READY_Q }; |
---|
76 | { |
---|
77 | BenchProc procs[nprocs]; |
---|
78 | { |
---|
79 | Yielder threads[nthreads]; |
---|
80 | printf("Starting\n"); |
---|
81 | |
---|
82 | bool is_tty = isatty(STDOUT_FILENO); |
---|
83 | start = getTimeNsec(); |
---|
84 | run = true; |
---|
85 | |
---|
86 | for(i; nthreads) { |
---|
87 | unpark( threads[i] __cfaabi_dbg_ctx2 ); |
---|
88 | } |
---|
89 | wait(duration, start, end, is_tty); |
---|
90 | |
---|
91 | run = false; |
---|
92 | end = getTimeNsec(); |
---|
93 | printf("\nDone\n"); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | printf("Took %'ld ms\n", (end - start)`ms); |
---|
98 | printf("Yields per second : %'18.2lf\n", ((double)global_counter) / (end - start)`s); |
---|
99 | printf("ns per yields : %'18.2lf\n", ((double)(end - start)`ns) / global_counter); |
---|
100 | printf("Total yields : %'15llu\n", global_counter); |
---|
101 | printf("Yields per procs : %'15llu\n", global_counter / nprocs); |
---|
102 | printf("Yields/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s); |
---|
103 | printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs)); |
---|
104 | fflush(stdout); |
---|
105 | } |
---|
106 | } |
---|