#pragma once #include #include #include #include #define BENCH_OPT_SHORT "d:p:t:SPV" #define BENCH_OPT_LONG \ {"duration", required_argument, 0, 'd'}, \ {"nthreads", required_argument, 0, 't'}, \ {"nprocs", required_argument, 0, 'p'}, \ {"nostats", no_argument , 0, 'S'}, \ {"procstat", no_argument , 0, 'P'}, \ {"viewhalts", no_argument , 0, 'V'}, #define BENCH_DECL \ double duration = 5; \ int nprocs = 1; \ int nthreads = 1; #define BENCH_OPT_CASE \ case 'd': \ duration = strtod(arg, &end); \ if(*end != '\0') { \ fprintf(stderr, "Duration must be a valid double, was %s\n", arg); \ goto usage; \ } \ break; \ case 't': \ nthreads = strtoul(arg, &end, 10); \ if(*end != '\0' || nthreads < 1) { \ fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg); \ goto usage; \ } \ break; \ case 'p': \ nprocs = strtoul(arg, &end, 10); \ if(*end != '\0' || nprocs < 1) { \ fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg); \ goto usage; \ } \ break; \ case 'S': \ silent = true; \ break; \ case 'P': \ procstats = true; \ break; \ case 'V': \ viewhalts = true; \ break; bool silent = false; bool procstats = false; bool viewhalts = false; struct cluster * the_benchmark_cluster = 0p; struct BenchCluster { cluster self; }; void ?{}( BenchCluster & this, int flags, int stats ) { (this.self){ "Benchmark Cluster", flags }; assert( the_benchmark_cluster == 0p ); the_benchmark_cluster = &this.self; #if !defined(__CFA_NO_STATISTICS__) if( !silent ) { print_stats_at_exit( this.self, stats ); } #endif } struct BenchProc { processor self; }; void ?{}( BenchProc & this ) { assert( the_benchmark_cluster != 0p ); (this.self){ "Benchmark Processor", *the_benchmark_cluster }; #if !defined(__CFA_NO_STATISTICS__) if( procstats ) { print_stats_at_exit( this.self, the_benchmark_cluster->print_stats ); } if( viewhalts ) { print_halts( this.self ); } #endif } void wait(double duration, Time & start, Time & end, bool is_tty) { for() { sleep(100`ms); end = getTimeNsec(); Duration delta = end - start; /*if(is_tty)*/ { printf(" %.1f\r", delta`ds); fflush(stdout); } if( delta >= duration`s ) { break; } } } void bench_usage( char * argv [] ) { fprintf( stderr, "Usage: %s : [options]\n", argv[0] ); fprintf( stderr, "\n" ); fprintf( stderr, " -d, --duration=DURATION Duration of the experiment, in seconds\n" ); fprintf( stderr, " -t, --nthreads=NTHREADS Number of user threads\n" ); fprintf( stderr, " -p, --nprocs=NPROCS Number of kernel threads\n" ); fprintf( stderr, " -S, --nostats Don't print cluster stats\n" ); fprintf( stderr, " -P, --procstat Print processor stats" ); }