source: benchmark/readyQ/yield.cfa @ 42f1d739

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 42f1d739 was b813f53, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Improvement of handling of \r processing halts

  • 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
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}
Note: See TracBrowser for help on using the repository browser.