[2649ff9] | 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> |
---|
[566fde0] | 15 | #include <stats.hfa> |
---|
[2649ff9] | 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 | |
---|
[04b5cef] | 25 | thread __attribute__((aligned(128))) Yielder { |
---|
[2649ff9] | 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[]) { |
---|
[cb85603] | 45 | BENCH_DECL |
---|
[2649ff9] | 46 | |
---|
| 47 | for(;;) { |
---|
| 48 | static struct option options[] = { |
---|
[cb85603] | 49 | BENCH_OPT_LONG |
---|
[2649ff9] | 50 | {0, 0, 0, 0} |
---|
| 51 | }; |
---|
| 52 | |
---|
| 53 | int idx = 0; |
---|
[cb85603] | 54 | int opt = getopt_long(argc, argv, BENCH_OPT_SHORT, options, &idx); |
---|
[2649ff9] | 55 | |
---|
[cb85603] | 56 | const char * arg = optarg ? optarg : ""; |
---|
[2649ff9] | 57 | char * end; |
---|
| 58 | switch(opt) { |
---|
| 59 | case -1: |
---|
| 60 | goto run; |
---|
[cb85603] | 61 | BENCH_OPT_CASE |
---|
[2649ff9] | 62 | default: /* ? */ |
---|
| 63 | fprintf( stderr, "Unkown option '%c'\n", opt); |
---|
| 64 | usage: |
---|
[cb85603] | 65 | bench_usage( argv ); |
---|
[2649ff9] | 66 | exit(1); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | run: |
---|
| 70 | |
---|
| 71 | { |
---|
[cb85603] | 72 | printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration); |
---|
[2649ff9] | 73 | |
---|
| 74 | Time start, end; |
---|
[cb85603] | 75 | BenchCluster cl = { 0, CFA_STATS_READY_Q }; |
---|
[2649ff9] | 76 | { |
---|
| 77 | BenchProc procs[nprocs]; |
---|
| 78 | { |
---|
| 79 | Yielder threads[nthreads]; |
---|
| 80 | printf("Starting\n"); |
---|
[9791ab5] | 81 | |
---|
| 82 | bool is_tty = isatty(STDOUT_FILENO); |
---|
[8e27ac45] | 83 | start = getTimeNsec(); |
---|
[2649ff9] | 84 | run = true; |
---|
| 85 | |
---|
| 86 | for(i; nthreads) { |
---|
| 87 | unpark( threads[i] __cfaabi_dbg_ctx2 ); |
---|
| 88 | } |
---|
[9791ab5] | 89 | wait(duration, start, end, is_tty); |
---|
[2649ff9] | 90 | |
---|
| 91 | run = false; |
---|
[8e27ac45] | 92 | end = getTimeNsec(); |
---|
[9791ab5] | 93 | printf("\nDone\n"); |
---|
[2649ff9] | 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | printf("Took %'ld ms\n", (end - start)`ms); |
---|
[564148f] | 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); |
---|
[2073d207] | 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)); |
---|
[b813f53] | 104 | fflush(stdout); |
---|
[2649ff9] | 105 | } |
---|
| 106 | } |
---|