source: benchmark/readyQ/yield.cfa@ 01c6256

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

Adjsuted benchmarks to new io_ctxs

  • Property mode set to 100644
File size: 2.4 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <limits.h>
5
6extern "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
19extern bool traceHeapOn();
20
21
22volatile bool run = false;
23volatile unsigned long long global_counter;
24
25thread __attribute__((aligned(128))) Yielder {
26 unsigned long long counter;
27};
28void ?{}( Yielder & this ) {
29 this.counter = 0;
30 ((thread&)this){ "Yielder Thread", *the_benchmark_cluster };
31}
32
33void 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
44int main(int argc, char * argv[]) {
45 BENCH_DECL
46 unsigned num_io = 1;
47 io_context_params params;
48
49 for(;;) {
50 static struct option options[] = {
51 BENCH_OPT_LONG
52 {0, 0, 0, 0}
53 };
54
55 int idx = 0;
56 int opt = getopt_long(argc, argv, BENCH_OPT_SHORT, options, &idx);
57
58 const char * arg = optarg ? optarg : "";
59 char * end;
60 switch(opt) {
61 case -1:
62 goto run;
63 BENCH_OPT_CASE
64 default: /* ? */
65 fprintf( stderr, "Unkown option '%c'\n", opt);
66 usage:
67 bench_usage( argv );
68 exit(1);
69 }
70 }
71 run:
72
73 {
74 printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration);
75
76 Time start, end;
77 BenchCluster cl = { num_io, params, CFA_STATS_READY_Q };
78 {
79 BenchProc procs[nprocs];
80 {
81 Yielder threads[nthreads];
82 printf("Starting\n");
83
84 bool is_tty = isatty(STDOUT_FILENO);
85 start = getTimeNsec();
86 run = true;
87
88 for(i; nthreads) {
89 unpark( threads[i] __cfaabi_dbg_ctx2 );
90 }
91 wait(duration, start, end, is_tty);
92
93 run = false;
94 end = getTimeNsec();
95 printf("\nDone\n");
96 }
97 }
98
99 printf("Took %'ld ms\n", (end - start)`ms);
100 printf("Yields per second : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
101 printf("ns per yields : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
102 printf("Total yields : %'15llu\n", global_counter);
103 printf("Yields per procs : %'15llu\n", global_counter / nprocs);
104 printf("Yields/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
105 printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
106 fflush(stdout);
107 }
108}
Note: See TracBrowser for help on using the repository browser.