source: benchmark/readyQ/yield.cfa @ 566fde0

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

Updated benchmark Stats options

  • Property mode set to 100644
File size: 4.1 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        double duration = 5;
46        int nprocs = 1;
47        int nthreads = 1;
48        bool silent = false;
49        bool procstats = false;
50
51        for(;;) {
52                static struct option options[] = {
53                        {"duration",  required_argument, 0, 'd'},
54                        {"nprocs",    required_argument, 0, 'p'},
55                        {"nthreads",  required_argument, 0, 't'},
56                        {"nostats",   no_argument      , 0, 'S'},
57                        {"procstat",  no_argument      , 0, 'P'},
58                        {0, 0, 0, 0}
59                };
60
61                int idx = 0;
62                int opt = getopt_long(argc, argv, "d:p:t:SP", options, &idx);
63
64                char * arg = optarg ? optarg : "";
65                size_t len = 0;
66                char * end;
67                switch(opt) {
68                        case -1:
69                                goto run;
70                        // Numeric Arguments
71                        case 'd':
72                                duration = strtod(arg, &end);
73                                if(*end != '\0') {
74                                        fprintf(stderr, "Duration must be a valid double, was %s\n", arg);
75                                        goto usage;
76                                }
77                                break;
78                        case 't':
79                                nthreads = strtoul(arg, &end, 10);
80                                if(*end != '\0' || nthreads < 1) {
81                                        fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg);
82                                        goto usage;
83                                }
84                                break;
85                        case 'p':
86                                nprocs = strtoul(arg, &end, 10);
87                                if(*end != '\0' || nprocs < 1) {
88                                        fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg);
89                                        goto usage;
90                                }
91                                break;
92                        case 'S':
93                                silent = true;
94                                break;
95                        case 'P':
96                                procstats = true;
97                                break;
98                        // Other cases
99                        default: /* ? */
100                                fprintf( stderr, "Unkown option '%c'\n", opt);
101                        usage:
102                                fprintf( stderr, "Usage: %s [options]\n", argv[0]);
103                                fprintf( stderr, "\n" );
104                                fprintf( stderr, "  -d, --duration=DURATION  Duration of the experiment, in seconds\n" );
105                                fprintf( stderr, "  -t, --nthreads=NTHREADS  Number of kernel threads\n" );
106                                fprintf( stderr, "  -q, --nqueues=NQUEUES    Number of queues per threads\n" );
107                                fprintf( stderr, "  -S, --nostats            Don't print cluster stats\n" );
108                                fprintf( stderr, "  -P, --procstat           Print processor stats" );
109                                exit(1);
110                }
111        }
112        run:
113
114        {
115                printf("Running %d threads on %d processors for %lf seconds\n", nthreads, nprocs, duration);
116
117                Time start, end;
118                BenchCluster cl = { 0 };
119                #if !defined(__CFA_NO_STATISTICS__)
120                        if( !silent ) {
121                                print_stats_at_exit( cl.self, CFA_STATS_READY_Q );
122                        }
123                #endif
124                {
125                        BenchProc procs[nprocs];
126                        #if !defined(__CFA_NO_STATISTICS__)
127                                if( procstats ) {
128                                        for(i; nprocs) {
129                                                print_stats_at_exit( procs[i].self, CFA_STATS_READY_Q );
130                                        }
131                                }
132                        #endif
133                        {
134                                Yielder threads[nthreads];
135                                printf("Starting\n");
136
137                                bool is_tty = isatty(STDOUT_FILENO);
138                                start = getTimeNsec();
139                                run = true;
140
141                                for(i; nthreads) {
142                                        unpark( threads[i] __cfaabi_dbg_ctx2 );
143                                }
144                                wait(duration, start, end, is_tty);
145
146                                run = false;
147                                end = getTimeNsec();
148                                printf("\nDone\n");
149                        }
150                }
151
152                printf("Took %'ld ms\n", (end - start)`ms);
153                printf("Yields per second   : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
154                printf("ns per yields       : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
155                printf("Total yields        : %'15llu\n", global_counter);
156                printf("Yields per procs    : %'15llu\n", global_counter / nprocs);
157                printf("Yields/sec/procs    : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
158                printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
159
160        }
161}
Note: See TracBrowser for help on using the repository browser.