source: benchmark/readyQ/yield.cfa @ d72c074

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

Added BIAS option to ready_queue
Added yield test for LibFibre?
Fixed some alignments and minor optimizations

  • Property mode set to 100644
File size: 3.6 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
16#include "../benchcltr.hfa"
17
18extern bool traceHeapOn();
19
20
21volatile bool run = false;
22volatile unsigned long long global_counter;
23
24thread __attribute__((aligned(128))) Yielder {
25        unsigned long long counter;
26};
27void ?{}( Yielder & this ) {
28        this.counter = 0;
29        ((thread&)this){ "Yielder Thread", *the_benchmark_cluster };
30}
31
32void main( Yielder & this ) {
33        park( __cfaabi_dbg_ctx );
34        /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
35
36        while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
37                yield();
38                this.counter++;
39        }
40        __atomic_fetch_add(&global_counter, this.counter, __ATOMIC_SEQ_CST);
41}
42
43int main(int argc, char * argv[]) {
44        double duration = 5;
45        int nprocs = 1;
46        int nthreads = 1;
47
48
49
50        for(;;) {
51                static struct option options[] = {
52                        {"duration",  required_argument, 0, 'd'},
53                        {"nprocs",    required_argument, 0, 'p'},
54                        {"nthreads",  required_argument, 0, 't'},
55                        {0, 0, 0, 0}
56                };
57
58                int idx = 0;
59                int opt = getopt_long(argc, argv, "d:p:t:", options, &idx);
60
61                char * arg = optarg ? optarg : "";
62                size_t len = 0;
63                char * end;
64                switch(opt) {
65                        case -1:
66                                goto run;
67                        // Numeric Arguments
68                        case 'd':
69                                duration = strtod(arg, &end);
70                                if(*end != '\0') {
71                                        fprintf(stderr, "Duration must be a valid double, was %s\n", arg);
72                                        goto usage;
73                                }
74                                break;
75                        case 't':
76                                nthreads = strtoul(arg, &end, 10);
77                                if(*end != '\0' || nthreads < 1) {
78                                        fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg);
79                                        goto usage;
80                                }
81                                break;
82                        case 'p':
83                                nprocs = strtoul(arg, &end, 10);
84                                if(*end != '\0' || nprocs < 1) {
85                                        fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg);
86                                        goto usage;
87                                }
88                                break;
89                        // Other cases
90                        default: /* ? */
91                                fprintf( stderr, "Unkown option '%c'\n", opt);
92                        usage:
93                                fprintf( stderr, "Usage: %s [options]\n", argv[0]);
94                                fprintf( stderr, "\n" );
95                                fprintf( stderr, "  -d, --duration=DURATION  Duration of the experiment, in seconds\n" );
96                                fprintf( stderr, "  -t, --nthreads=NTHREADS  Number of kernel threads\n" );
97                                fprintf( stderr, "  -q, --nqueues=NQUEUES    Number of queues per threads\n" );
98                                exit(1);
99                }
100        }
101        run:
102
103        {
104                printf("Running %d threads on %d processors for %lf seconds\n", nthreads, nprocs, duration);
105
106                Time start, end;
107                BenchCluster cl;
108                #if !defined(__CFA_NO_STATISTICS__)
109                        print_stats_at_exit( cl.self );
110                #endif
111                {
112                        BenchProc procs[nprocs];
113                        {
114                                Yielder threads[nthreads];
115                                bool is_tty = isatty(STDOUT_FILENO);
116                                printf("Starting\n");
117                                start = getTime();
118                                run = true;
119
120                                for(i; nthreads) {
121                                        unpark( threads[i] __cfaabi_dbg_ctx2 );
122                                }
123                                for() {
124                                        sleep(500`ms);
125                                        end = getTime();
126                                        if( (end - start) >= duration`s ) {
127                                                break;
128                                        }
129                                        if(is_tty) {
130                                                printf("\r%.4lf", (double)(end - start)`s);
131                                                fflush(stdout);
132                                        }
133                                }
134
135                                run = false;
136                                end = getTime();
137                                printf("Done\n");
138                        }
139                }
140
141                printf("Took %'ld ms\n", (end - start)`ms);
142                printf("Total yields        : %'15llu\n", global_counter);
143                printf("Yields per procs    : %'15llu\n", global_counter / nprocs);
144                printf("Yields per second   : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
145                printf("Yields/sec/procs    : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
146                printf("ns per yields       : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
147                printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
148
149        }
150}
Note: See TracBrowser for help on using the repository browser.