[2649ff9] | 1 | #pragma once |
---|
| 2 | |
---|
| 3 | #include <assert.h> |
---|
| 4 | #include <kernel.hfa> |
---|
| 5 | #include <thread.hfa> |
---|
[cb85603] | 6 | #include <stats.hfa> |
---|
[2649ff9] | 7 | |
---|
[ec21f13] | 8 | #define BENCH_OPT_SHORT "d:p:t:SPV" |
---|
[cb85603] | 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'}, \ |
---|
[ec21f13] | 14 | {"procstat", no_argument , 0, 'P'}, \ |
---|
| 15 | {"viewhalts", no_argument , 0, 'V'}, |
---|
[cb85603] | 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; \ |
---|
[ec21f13] | 49 | break; \ |
---|
| 50 | case 'V': \ |
---|
| 51 | viewhalts = true; \ |
---|
[cb85603] | 52 | break; |
---|
| 53 | |
---|
| 54 | bool silent = false; |
---|
| 55 | bool procstats = false; |
---|
[ec21f13] | 56 | bool viewhalts = false; |
---|
[2649ff9] | 57 | struct cluster * the_benchmark_cluster = 0p; |
---|
| 58 | struct BenchCluster { |
---|
[cb85603] | 59 | cluster self; |
---|
[2649ff9] | 60 | }; |
---|
| 61 | |
---|
[cb85603] | 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; |
---|
[2649ff9] | 67 | |
---|
[cb85603] | 68 | #if !defined(__CFA_NO_STATISTICS__) |
---|
| 69 | if( !silent ) { |
---|
| 70 | print_stats_at_exit( this.self, stats ); |
---|
| 71 | } |
---|
| 72 | #endif |
---|
[2649ff9] | 73 | } |
---|
| 74 | |
---|
| 75 | struct BenchProc { |
---|
| 76 | processor self; |
---|
| 77 | }; |
---|
| 78 | |
---|
| 79 | void ?{}( BenchProc & this ) { |
---|
[cb85603] | 80 | assert( the_benchmark_cluster != 0p ); |
---|
[2649ff9] | 81 | (this.self){ "Benchmark Processor", *the_benchmark_cluster }; |
---|
[cb85603] | 82 | |
---|
| 83 | #if !defined(__CFA_NO_STATISTICS__) |
---|
| 84 | if( procstats ) { |
---|
| 85 | print_stats_at_exit( this.self, the_benchmark_cluster->print_stats ); |
---|
| 86 | } |
---|
[ec21f13] | 87 | if( viewhalts ) { |
---|
| 88 | print_halts( this.self ); |
---|
| 89 | } |
---|
[cb85603] | 90 | #endif |
---|
[2649ff9] | 91 | } |
---|
| 92 | |
---|
[9791ab5] | 93 | void wait(double duration, Time & start, Time & end, bool is_tty) { |
---|
[cb85603] | 94 | for() { |
---|
| 95 | sleep(100`ms); |
---|
| 96 | end = getTimeNsec(); |
---|
| 97 | Duration delta = end - start; |
---|
[b813f53] | 98 | /*if(is_tty)*/ { |
---|
| 99 | printf(" %.1f\r", delta`ds); |
---|
[cb85603] | 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" ); |
---|
[9791ab5] | 116 | } |
---|