source: benchmark/benchcltr.hfa @ 9cf2b0f

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 9cf2b0f was e54d0c3, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

Fixed benchmarks after another change to getTimeNsec()

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[2649ff9]1#pragma once
2#include <assert.h>
[01c6256]3#include <stdint.h>
4
5#ifdef __cforall
6        #include <kernel.hfa>
7        #include <thread.hfa>
8        #include <stats.hfa>
9#else
10#include <time.h>                                                                               // timespec
11#include <sys/time.h>                                                                   // timeval
12
13enum { TIMEGRAN = 1000000000LL };                                       // nanosecond granularity, except for timeval
14#endif
[2649ff9]15
[ec21f13]16#define BENCH_OPT_SHORT "d:p:t:SPV"
[cb85603]17#define BENCH_OPT_LONG \
18        {"duration",     required_argument, 0, 'd'}, \
19        {"nthreads",     required_argument, 0, 't'}, \
20        {"nprocs",       required_argument, 0, 'p'}, \
21        {"nostats",      no_argument      , 0, 'S'}, \
[ec21f13]22        {"procstat",     no_argument      , 0, 'P'}, \
23        {"viewhalts",    no_argument      , 0, 'V'},
[cb85603]24
25#define BENCH_OPT_CASE \
26        case 'd': \
27                duration = strtod(arg, &end); \
28                if(*end != '\0') { \
29                        fprintf(stderr, "Duration must be a valid double, was %s\n", arg); \
30                        goto usage; \
31                } \
32                break; \
33        case 't': \
34                nthreads = strtoul(arg, &end, 10); \
35                if(*end != '\0' || nthreads < 1) { \
36                        fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg); \
37                        goto usage; \
38                } \
39                break; \
40        case 'p': \
41                nprocs = strtoul(arg, &end, 10); \
42                if(*end != '\0' || nprocs < 1) { \
43                        fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg); \
44                        goto usage; \
45                } \
46                break; \
47        case 'S': \
48                silent = true; \
49                break; \
50        case 'P': \
51                procstats = true; \
[ec21f13]52                break; \
53        case 'V': \
54                viewhalts = true; \
[cb85603]55                break;
56
[5bcdc8c]57double duration = 5;
58int nprocs = 1;
59int nthreads = 1;
[cb85603]60bool silent = false;
[5bcdc8c]61bool continuous = false;
[cb85603]62bool procstats = false;
[ec21f13]63bool viewhalts = false;
[01c6256]64
[5bcdc8c]65#define BENCH_OPT_CFA \
66        {'d', "duration",  "Duration of the experiments in seconds", duration }, \
67        {'t', "nthreads",  "Number of threads to use", nthreads }, \
68        {'p', "nprocs",    "Number of processors to use", nprocs }, \
69        {'S', "nostats",   "Don't print statistics", silent, parse_settrue }, \
70        {'C', "constats",  "Regularly print statistics", continuous, parse_settrue }, \
71        {'P', "procstat",  "Print statistics for each processors", procstats, parse_settrue }, \
72        {'V', "viewhalts", "Visualize halts, prints timestamp and Processor id for each halt.", viewhalts, parse_settrue },
73
[01c6256]74#ifdef __cforall
[5bcdc8c]75#include <parseargs.hfa>
76
[2649ff9]77struct cluster * the_benchmark_cluster = 0p;
78struct BenchCluster {
[cb85603]79        cluster self;
[2649ff9]80};
81
[01c6256]82void ?{}( BenchCluster & this, int num_io, const io_context_params & io_params, int stats ) {
83        (this.self){ "Benchmark Cluster", num_io, io_params };
[cb85603]84
85        assert( the_benchmark_cluster == 0p );
86        the_benchmark_cluster = &this.self;
[2649ff9]87
[cb85603]88        #if !defined(__CFA_NO_STATISTICS__)
89                if( !silent ) {
90                        print_stats_at_exit( this.self, stats );
91                }
92        #endif
[2649ff9]93}
94
95struct BenchProc {
96        processor self;
97};
98
99void ?{}( BenchProc & this ) {
[cb85603]100        assert( the_benchmark_cluster != 0p );
[2649ff9]101        (this.self){ "Benchmark Processor", *the_benchmark_cluster };
[cb85603]102
103        #if !defined(__CFA_NO_STATISTICS__)
104                if( procstats ) {
105                        print_stats_at_exit( this.self, the_benchmark_cluster->print_stats );
106                }
[ec21f13]107                if( viewhalts ) {
108                        print_halts( this.self );
109                }
[cb85603]110        #endif
[2649ff9]111}
112
[9791ab5]113void wait(double duration, Time & start, Time & end, bool is_tty) {
[cb85603]114        for() {
115                sleep(100`ms);
[e54d0c3]116                end = timeHiRes();
[cb85603]117                Duration delta = end - start;
[b813f53]118                /*if(is_tty)*/ {
119                        printf(" %.1f\r", delta`ds);
[cb85603]120                        fflush(stdout);
121                }
122                if( delta >= duration`s ) {
123                        break;
124                }
125        }
126}
[01c6256]127#else
[e54d0c3]128uint64_t timeHiRes() {
[01c6256]129        timespec curr;
130        clock_gettime( CLOCK_REALTIME, &curr );
131        return (int64_t)curr.tv_sec * TIMEGRAN + curr.tv_nsec;
132}
133
134uint64_t to_miliseconds( uint64_t durtn ) { return durtn / (TIMEGRAN / 1000LL); }
135double to_fseconds(uint64_t durtn ) { return durtn / (double)TIMEGRAN; }
136uint64_t from_fseconds(double sec) { return sec * TIMEGRAN; }
137
138
139void wait_duration(double duration, uint64_t & start, uint64_t & end, bool is_tty) {
140        for(;;) {
141                usleep(100000);
[e54d0c3]142                end = timeHiRes();
[01c6256]143                uint64_t delta = end - start;
144                /*if(is_tty)*/ {
145                        printf(" %.1f\r", to_fseconds(delta));
146                        fflush(stdout);
147                }
148                if( delta >= from_fseconds(duration) ) {
149                        break;
150                }
151        }
152}
153#endif
154
[cb85603]155
156void bench_usage( char * argv [] ) {
157        fprintf( stderr, "Usage: %s : [options]\n", argv[0] );
158        fprintf( stderr, "\n" );
159        fprintf( stderr, "  -d, --duration=DURATION  Duration of the experiment, in seconds\n" );
160        fprintf( stderr, "  -t, --nthreads=NTHREADS  Number of user threads\n" );
161        fprintf( stderr, "  -p, --nprocs=NPROCS      Number of kernel threads\n" );
162        fprintf( stderr, "  -S, --nostats            Don't print cluster stats\n" );
163        fprintf( stderr, "  -P, --procstat           Print processor stats" );
[9791ab5]164}
Note: See TracBrowser for help on using the repository browser.