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 |
|
---|
54 | bool silent = false;
|
---|
55 | bool procstats = false;
|
---|
56 | bool viewhalts = false;
|
---|
57 | struct cluster * the_benchmark_cluster = 0p;
|
---|
58 | struct BenchCluster {
|
---|
59 | cluster self;
|
---|
60 | };
|
---|
61 |
|
---|
62 | void ?{}( 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 |
|
---|
75 | struct BenchProc {
|
---|
76 | processor self;
|
---|
77 | };
|
---|
78 |
|
---|
79 | void ?{}( 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 |
|
---|
93 | void 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 |
|
---|
108 | void 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 | }
|
---|