source: benchmark/benchcltr.hfa @ cb85603

arm-ehenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since cb85603 was cb85603, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Moved common code of benchmarks to benchcltr.hfa

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#pragma once
2
3#include <assert.h>
4#include <kernel.hfa>
5#include <thread.hfa>
6#include <stats.hfa>
7
8#define BENCH_OPT_SHORT "d:p:t:SP"
9#define BENCH_OPT_LONG \
10        {"duration",     required_argument, 0, 'd'}, \
11        {"nthreads",     required_argument, 0, 't'}, \
12        {"nprocs",       required_argument, 0, 'p'}, \
13        {"nostats",      no_argument      , 0, 'S'}, \
14        {"procstat",     no_argument      , 0, 'P'},
15
16#define BENCH_DECL \
17        double duration = 5; \
18        int nprocs = 1; \
19        int nthreads = 1;
20
21#define BENCH_OPT_CASE \
22        case 'd': \
23                duration = strtod(arg, &end); \
24                if(*end != '\0') { \
25                        fprintf(stderr, "Duration must be a valid double, was %s\n", arg); \
26                        goto usage; \
27                } \
28                break; \
29        case 't': \
30                nthreads = strtoul(arg, &end, 10); \
31                if(*end != '\0' || nthreads < 1) { \
32                        fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg); \
33                        goto usage; \
34                } \
35                break; \
36        case 'p': \
37                nprocs = strtoul(arg, &end, 10); \
38                if(*end != '\0' || nprocs < 1) { \
39                        fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg); \
40                        goto usage; \
41                } \
42                break; \
43        case 'S': \
44                silent = true; \
45                break; \
46        case 'P': \
47                procstats = true; \
48                break;
49
50bool silent = false;
51bool procstats = false;
52struct cluster * the_benchmark_cluster = 0p;
53struct BenchCluster {
54        cluster self;
55};
56
57void ?{}( BenchCluster & this, int flags, int stats ) {
58        (this.self){ "Benchmark Cluster", flags };
59
60        assert( the_benchmark_cluster == 0p );
61        the_benchmark_cluster = &this.self;
62
63        #if !defined(__CFA_NO_STATISTICS__)
64                if( !silent ) {
65                        print_stats_at_exit( this.self, stats );
66                }
67        #endif
68}
69
70struct BenchProc {
71        processor self;
72};
73
74void ?{}( BenchProc & this ) {
75        assert( the_benchmark_cluster != 0p );
76        (this.self){ "Benchmark Processor", *the_benchmark_cluster };
77
78        #if !defined(__CFA_NO_STATISTICS__)
79                if( procstats ) {
80                        print_stats_at_exit( this.self, the_benchmark_cluster->print_stats );
81                }
82        #endif
83}
84
85void wait(double duration, Time & start, Time & end, bool is_tty) {
86        for() {
87                sleep(100`ms);
88                end = getTimeNsec();
89                Duration delta = end - start;
90                if(is_tty) {
91                        printf("\r%.1f", delta`ds);
92                        fflush(stdout);
93                }
94                if( delta >= duration`s ) {
95                        break;
96                }
97        }
98}
99
100void bench_usage( char * argv [] ) {
101        fprintf( stderr, "Usage: %s : [options]\n", argv[0] );
102        fprintf( stderr, "\n" );
103        fprintf( stderr, "  -d, --duration=DURATION  Duration of the experiment, in seconds\n" );
104        fprintf( stderr, "  -t, --nthreads=NTHREADS  Number of user threads\n" );
105        fprintf( stderr, "  -p, --nprocs=NPROCS      Number of kernel threads\n" );
106        fprintf( stderr, "  -S, --nostats            Don't print cluster stats\n" );
107        fprintf( stderr, "  -P, --procstat           Print processor stats" );
108}
Note: See TracBrowser for help on using the repository browser.