source: benchmark/readyQ/rq_bench.hfa @ b35ab2d

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

Added basic benchmark for readyQ that cycles among groups of threads.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#include <clock.hfa>
2#include <kernel.hfa>
3#include <parseargs.hfa>
4#include <stdio.h>
5#include <stdlib.hfa>
6#include <thread.hfa>
7#include <time.hfa>
8#include <unistd.h>
9
10volatile bool stop = false;
11bool clock_mode;
12double duration = -1;
13unsigned long long stop_count = 0;
14unsigned nprocs = 1;
15unsigned nthreads = 1;
16
17volatile unsigned long long threads_left;
18
19#define thread_loop for(this.count = 0; this.count < stop_count && !stop; this.count++)
20
21#define BENCH_OPT \
22        {'d', "duration",  "Duration of the experiments in seconds", duration }, \
23        {'i', "iterations",  "Number of iterations of the experiments", stop_count }, \
24        {'t', "nthreads",  "Number of threads to use", nthreads }, \
25        {'p', "nprocs",    "Number of processors to use", nprocs }
26
27#define BENCH_OPT_PARSE(name) \
28        { \
29                int opt_cnt = sizeof(opt) / sizeof(cfa_option); \
30                char **left; \
31                parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]...\n" name, left ); \
32                if(duration > 0 && stop_count > 0) { \
33                        fprintf(stderr, "--duration and --iterations cannot be used together\n"); \
34                        print_args_usage(argc, argv, opt, opt_cnt, "[OPTIONS]...\n" name, true); \
35                } else if(duration > 0) { \
36                        clock_mode = true; \
37                        stop_count = 0xFFFFFFFFFFFFFFFF; \
38                } else if(stop_count > 0) { \
39                        clock_mode = false; \
40                } else { \
41                        duration = 5; clock_mode = true;\
42                } \
43        }
44
45struct cluster & bench_cluster;
46
47struct BenchCluster {
48        cluster cl;
49        processor * procs;
50        unsigned nprocs;
51};
52
53void ?{}( BenchCluster & this, unsigned nprocs ) {
54        (this.cl){ "Benchmark Cluster" };
55        &bench_cluster = &this.cl;
56        this.nprocs = nprocs;
57        this.procs  = alloc( this.nprocs );
58        for(i; this.nprocs){
59                processor * p = &this.procs[i];
60                (*p){ "Benchmark Processor", this.cl };
61        }
62}
63
64void ^?{}( BenchCluster & this ) {
65        adelete( this.nprocs, this.procs );
66        ^(this.cl){};
67}
68
69void wait(Time & start, Time & end, bool is_tty) {
70        for() {
71                sleep(100`ms);
72                end = getTimeNsec();
73                Duration delta = end - start;
74                if(is_tty) {
75                        printf(" %.1f\r", delta`ds);
76                        fflush(stdout);
77                }
78                if( clock_mode && delta >= duration`s ) {
79                        break;
80                }
81                else if( !clock_mode && threads_left == 0 ) {
82                        break;
83                }
84        }
85}
Note: See TracBrowser for help on using the repository browser.