source: benchmark/readyQ/yield.cfa @ 9cf2b0f

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 9cf2b0f was 9cf2b0f, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Updated yield benchmarks to be more consistents.

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[9cf2b0f]1#include "rq_bench.hfa"
[2649ff9]2
3extern bool traceHeapOn();
4
5
6volatile bool run = false;
7volatile unsigned long long global_counter;
8
[04b5cef]9thread __attribute__((aligned(128))) Yielder {
[2649ff9]10        unsigned long long counter;
11};
12void ?{}( Yielder & this ) {
13        this.counter = 0;
[9cf2b0f]14        ((thread&)this){ "Yielder Thread" };
[2649ff9]15}
16
17void main( Yielder & this ) {
[e235429]18        park();
[2649ff9]19        /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
20
21        while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
22                yield();
23                this.counter++;
24        }
25        __atomic_fetch_add(&global_counter, this.counter, __ATOMIC_SEQ_CST);
26}
27
28int main(int argc, char * argv[]) {
[5bcdc8c]29        cfa_option opt[] = {
[9cf2b0f]30                BENCH_OPT
[5bcdc8c]31        };
[9cf2b0f]32        BENCH_OPT_PARSE("cforall yield benchmark");
[2649ff9]33
34        {
[cb85603]35                printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration);
[2649ff9]36
37                Time start, end;
[9cf2b0f]38                BenchCluster bc = { nprocs };
[2649ff9]39                {
[9cf2b0f]40                        Yielder threads[nthreads];
41                        printf("Starting\n");
[9791ab5]42
[9cf2b0f]43                        bool is_tty = isatty(STDOUT_FILENO);
44                        start = timeHiRes();
45                        run = true;
[2649ff9]46
[9cf2b0f]47                        for(i; nthreads) {
48                                unpark( threads[i] );
[2649ff9]49                        }
[9cf2b0f]50                        wait(start, is_tty);
51
52                        run = false;
53                        end = timeHiRes();
54                        printf("\nDone\n");
[2649ff9]55                }
56
[9cf2b0f]57                printf("Duration (ms)        : %'ld\n", (end - start)`dms);
58                printf("Number of processors : %'d\n", nprocs);
59                printf("Number of threads    : %'d\n", nthreads);
60                printf("Total Operations(ops): %'15llu\n", global_counter);
61                printf("Ops per second       : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
62                printf("ns per ops           : %'18.2lf\n", (end - start)`dns / global_counter);
63                printf("Ops per threads      : %'15llu\n", global_counter / nthreads);
64                printf("Ops per procs        : %'15llu\n", global_counter / nprocs);
65                printf("Ops/sec/procs        : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
66                printf("ns per ops/procs     : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
[b813f53]67                fflush(stdout);
[2649ff9]68        }
[e54d0c3]69}
Note: See TracBrowser for help on using the repository browser.