source: benchmark/readyQ/churn.cfa @ c715e5f

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since c715e5f was 12bb5ab1, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Implemented the churn benchmark for libfibre.
Trivial change to the cfa version.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#include "rq_bench.hfa"
2
3#include <locks.hfa>
4
5unsigned spot_cnt = 2;
6semaphore * spots;
7
8thread BThrd {
9        unsigned long long count;
10        unsigned long long blocks;
11        bool skip;
12};
13
14void ?{}( BThrd & this ) {
15        ((thread&)this){ bench_cluster };
16        this.count  = 0;
17        this.blocks = 0;
18        this.skip = false;
19}
20
21void ^?{}( BThrd & mutex this ) {}
22
23void main( BThrd & this ) with( this ) {
24        park();
25        for() {
26                uint32_t r = prng(this);
27                semaphore & sem = spots[r % spot_cnt];
28                if(!skip) V( sem );
29                blocks += P( sem );
30                skip = false;
31
32                count ++;
33                if( clock_mode && stop) break;
34                if(!clock_mode && count >= stop_count) break;
35        }
36
37        __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
38}
39
40
41int main(int argc, char * argv[]) {
42        cfa_option opt[] = {
43                BENCH_OPT,
44                { 's', "spots", "Number of spots in the system", spot_cnt }
45        };
46        BENCH_OPT_PARSE("cforall churn benchmark");
47
48        {
49                unsigned long long global_counter = 0;
50                unsigned long long global_blocks  = 0;
51                Time start, end;
52                BenchCluster bc = { nprocs };
53                {
54                        spots = aalloc(spot_cnt);
55                        for(i; spot_cnt) {
56                                (spots[i]){ 0 };
57                        }
58
59                        threads_left = nthreads;
60                        BThrd * threads[nthreads];
61                        for(i; nthreads ) {
62                                BThrd & t = *(threads[i] = malloc());
63                                (t){};
64                                t.skip = i < spot_cnt;
65                        }
66                        printf("Starting\n");
67
68                        bool is_tty = isatty(STDOUT_FILENO);
69                        start = timeHiRes();
70
71                        for(i; nthreads) {
72                                unpark( *threads[i] );
73                        }
74                        wait(start, is_tty);
75
76                        stop = true;
77                        end = timeHiRes();
78                        printf("\nDone\n");
79
80                        for(i; spot_cnt) {
81                                for(10000) V( spots[i] );
82                        }
83
84                        for(i; nthreads) {
85                                BThrd & thrd = join( *threads[i] );
86                                global_counter += thrd.count;
87                                global_blocks  += thrd.blocks;
88                                delete(threads[i]);
89                        }
90
91                        free(spots);
92                }
93
94                printf("Duration (ms)        : %'lf\n", (end - start)`dms);
95                printf("Number of processors : %'d\n", nprocs);
96                printf("Number of threads    : %'d\n", nthreads);
97                printf("Number of spots      : %'d\n", spot_cnt);
98                printf("Total Operations(ops): %'15llu\n", global_counter);
99                printf("Total blocks         : %'15llu\n", global_blocks);
100                printf("Ops per second       : %'18.2lf\n", ((double)global_counter) / (end - start)`ds);
101                printf("ns per ops           : %'18.2lf\n", (end - start)`dns / global_counter);
102                printf("Ops per threads      : %'15llu\n", global_counter / nthreads);
103                printf("Ops per procs        : %'15llu\n", global_counter / nprocs);
104                printf("Ops/sec/procs        : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`ds);
105                printf("ns per ops/procs     : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
106                fflush(stdout);
107        }
108
109        return 0;
110}
Note: See TracBrowser for help on using the repository browser.