source: benchmark/readyQ/yield.cfa @ a633f6f

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since a633f6f was 6dc2db9, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Change benchmarks to consistently print duration in ms.

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[2649ff9]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>
[566fde0]15#include <stats.hfa>
[2649ff9]16
17#include "../benchcltr.hfa"
18
19extern bool traceHeapOn();
20
21
22volatile bool run = false;
23volatile unsigned long long global_counter;
24
[04b5cef]25thread __attribute__((aligned(128))) Yielder {
[2649ff9]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 ) {
[e235429]34        park();
[2649ff9]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[]) {
[01c6256]45        unsigned num_io = 1;
46        io_context_params params;
[2649ff9]47
[5bcdc8c]48        cfa_option opt[] = {
49                BENCH_OPT_CFA
50        };
51        int opt_cnt = sizeof(opt) / sizeof(cfa_option);
[2649ff9]52
[5bcdc8c]53        char **left;
54        parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]...\ncforall yield benchmark", left );
[2649ff9]55
56        {
[cb85603]57                printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration);
[2649ff9]58
59                Time start, end;
[01c6256]60                BenchCluster cl = { num_io, params, CFA_STATS_READY_Q };
[2649ff9]61                {
62                        BenchProc procs[nprocs];
63                        {
64                                Yielder threads[nthreads];
65                                printf("Starting\n");
[9791ab5]66
67                                bool is_tty = isatty(STDOUT_FILENO);
[e54d0c3]68                                start = timeHiRes();
[2649ff9]69                                run = true;
70
71                                for(i; nthreads) {
[e235429]72                                        unpark( threads[i] );
[2649ff9]73                                }
[9791ab5]74                                wait(duration, start, end, is_tty);
[2649ff9]75
76                                run = false;
[e54d0c3]77                                end = timeHiRes();
[9791ab5]78                                printf("\nDone\n");
[2649ff9]79                        }
80                }
81
[6dc2db9]82                printf("Duration (ms)       : %'ld\n", (end - start)`dms);
[2c7d0e8]83                printf("Number of processors: %'d\n", nprocs);
84                printf("Number of threads   : %'d\n", nthreads);
85                printf("Total yields        : %'15llu\n", global_counter);
[564148f]86                printf("Yields per second   : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
87                printf("ns per yields       : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
[2073d207]88                printf("Yields per procs    : %'15llu\n", global_counter / nprocs);
89                printf("Yields/sec/procs    : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
90                printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
[b813f53]91                fflush(stdout);
[2649ff9]92        }
[e54d0c3]93}
Note: See TracBrowser for help on using the repository browser.