source: benchmark/benchcltr.hfa @ 9bbbc8e

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

Improvement of handling of \r processing halts

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