| 1 | #include <stdlib.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 |
|
|---|
| 5 | extern "C" {
|
|---|
| 6 | #include <locale.h>
|
|---|
| 7 | #include <getopt.h>
|
|---|
| 8 | #include <fcntl.h>
|
|---|
| 9 | #include <sys/uio.h>
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | #include <unistd.h>
|
|---|
| 13 |
|
|---|
| 14 | #include <clock.hfa>
|
|---|
| 15 | #include <kernel.hfa>
|
|---|
| 16 | #include <thread.hfa>
|
|---|
| 17 | #include <time.hfa>
|
|---|
| 18 | #include <stats.hfa>
|
|---|
| 19 |
|
|---|
| 20 | #include "../benchcltr.hfa"
|
|---|
| 21 |
|
|---|
| 22 | extern bool traceHeapOn();
|
|---|
| 23 | extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
|
|---|
| 24 |
|
|---|
| 25 | int fd;
|
|---|
| 26 | volatile bool run = false;
|
|---|
| 27 | volatile size_t count = 0;
|
|---|
| 28 |
|
|---|
| 29 | unsigned long int buflen = 50;
|
|---|
| 30 |
|
|---|
| 31 | thread __attribute__((aligned(128))) Reader {};
|
|---|
| 32 | void ?{}( Reader & this ) {
|
|---|
| 33 | ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | void main( Reader & ) {
|
|---|
| 37 | park( __cfaabi_dbg_ctx );
|
|---|
| 38 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
|
|---|
| 39 |
|
|---|
| 40 | char data[buflen];
|
|---|
| 41 | struct iovec iov = { data, buflen };
|
|---|
| 42 |
|
|---|
| 43 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
|
|---|
| 44 | int r = cfa_preadv2(fd, &iov, 1, 0, 0);
|
|---|
| 45 | if(r < 0) abort("%s\n", strerror(-r));
|
|---|
| 46 |
|
|---|
| 47 | __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | int main(int argc, char * argv[]) {
|
|---|
| 52 | double duration = 5.0;
|
|---|
| 53 | unsigned long int nthreads = 2;
|
|---|
| 54 | unsigned long int nprocs = 1;
|
|---|
| 55 | bool silent = false;
|
|---|
| 56 | bool procstats = false;
|
|---|
| 57 | unsigned flags = 0;
|
|---|
| 58 | unsigned sublen = 16;
|
|---|
| 59 |
|
|---|
| 60 | arg_loop:
|
|---|
| 61 | for(;;) {
|
|---|
| 62 | static struct option options[] = {
|
|---|
| 63 | {"duration", required_argument, 0, 'd'},
|
|---|
| 64 | {"nthreads", required_argument, 0, 't'},
|
|---|
| 65 | {"nprocs", required_argument, 0, 'p'},
|
|---|
| 66 | {"nostats", no_argument , 0, 'S'},
|
|---|
| 67 | {"procstat", no_argument , 0, 'P'},
|
|---|
| 68 | {"bufsize", required_argument, 0, 'b'},
|
|---|
| 69 | {"userthread", no_argument , 0, 'u'},
|
|---|
| 70 | {"submitthread", no_argument , 0, 's'},
|
|---|
| 71 | {"submitlength", required_argument, 0, 'l'},
|
|---|
| 72 | {0, 0, 0, 0}
|
|---|
| 73 | };
|
|---|
| 74 |
|
|---|
| 75 | int idx = 0;
|
|---|
| 76 | int opt = getopt_long(argc, argv, "d:t:p:SPb:usl:", options, &idx);
|
|---|
| 77 |
|
|---|
| 78 | const char * arg = optarg ? optarg : "";
|
|---|
| 79 | char * end;
|
|---|
| 80 | switch(opt) {
|
|---|
| 81 | // Exit Case
|
|---|
| 82 | case -1:
|
|---|
| 83 | break arg_loop;
|
|---|
| 84 | // Numeric Arguments
|
|---|
| 85 | case 'd':
|
|---|
| 86 | duration = strtod(arg, &end);
|
|---|
| 87 | if(*end != '\0') {
|
|---|
| 88 | fprintf(stderr, "Duration must be a valid double, was %s\n", arg);
|
|---|
| 89 | goto usage;
|
|---|
| 90 | }
|
|---|
| 91 | break;
|
|---|
| 92 | case 't':
|
|---|
| 93 | nthreads = strtoul(arg, &end, 10);
|
|---|
| 94 | if(*end != '\0' || nthreads < 1) {
|
|---|
| 95 | fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg);
|
|---|
| 96 | goto usage;
|
|---|
| 97 | }
|
|---|
| 98 | break;
|
|---|
| 99 | case 'p':
|
|---|
| 100 | nprocs = strtoul(arg, &end, 10);
|
|---|
| 101 | if(*end != '\0' || nprocs < 1) {
|
|---|
| 102 | fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg);
|
|---|
| 103 | goto usage;
|
|---|
| 104 | }
|
|---|
| 105 | break;
|
|---|
| 106 | case 'S':
|
|---|
| 107 | silent = true;
|
|---|
| 108 | break;
|
|---|
| 109 | case 'P':
|
|---|
| 110 | procstats = true;
|
|---|
| 111 | break;
|
|---|
| 112 | case 'b':
|
|---|
| 113 | buflen = strtoul(arg, &end, 10);
|
|---|
| 114 | if(*end != '\0' && buflen < 10) {
|
|---|
| 115 | fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
|
|---|
| 116 | goto usage;
|
|---|
| 117 | }
|
|---|
| 118 | break;
|
|---|
| 119 | case 'u':
|
|---|
| 120 | flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
|
|---|
| 121 | break;
|
|---|
| 122 | case 's':
|
|---|
| 123 | flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS;
|
|---|
| 124 | break;
|
|---|
| 125 | case 'l':
|
|---|
| 126 | sublen = strtoul(arg, &end, 10);
|
|---|
| 127 | if(*end != '\0' && sublen < 16) {
|
|---|
| 128 | fprintf(stderr, "Submit length must be at least 16, was %s\n", arg);
|
|---|
| 129 | goto usage;
|
|---|
| 130 | }
|
|---|
| 131 | flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
|
|---|
| 132 | break;
|
|---|
| 133 | // Other cases
|
|---|
| 134 | default: /* ? */
|
|---|
| 135 | fprintf(stderr, "%d\n", opt);
|
|---|
| 136 | usage:
|
|---|
| 137 | fprintf( stderr, "Usage: %s : [options]\n", argv[0] );
|
|---|
| 138 | fprintf( stderr, "\n" );
|
|---|
| 139 | fprintf( stderr, " -d, --duration=DURATION Duration of the experiment, in seconds\n" );
|
|---|
| 140 | fprintf( stderr, " -t, --nthreads=NTHREADS Number of user threads\n" );
|
|---|
| 141 | fprintf( stderr, " -p, --nprocs=NPROCS Number of kernel threads\n" );
|
|---|
| 142 | fprintf( stderr, " -S, --nostats Don't print cluster stats\n" );
|
|---|
| 143 | fprintf( stderr, " -P, --procstat Print processor stats" );
|
|---|
| 144 | fprintf( stderr, " -b, --buflen=SIZE Number of bytes to read per request\n" );
|
|---|
| 145 | fprintf( stderr, " -u, --userthread If set, cluster uses user-thread to poll I/O\n" );
|
|---|
| 146 | fprintf( stderr, " -s, --submitthread If set, cluster uses polling thread to submit I/O\n" );
|
|---|
| 147 | exit(EXIT_FAILURE);
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | fd = open(__FILE__, 0);
|
|---|
| 152 | if(fd < 0) {
|
|---|
| 153 | fprintf(stderr, "Could not open source file\n");
|
|---|
| 154 | exit(EXIT_FAILURE);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | printf("Running %lu threads, reading %lu bytes each, over %lu processors for %lf seconds\n", nthreads, buflen, nprocs, duration);
|
|---|
| 158 |
|
|---|
| 159 | {
|
|---|
| 160 | Time start, end;
|
|---|
| 161 | BenchCluster cl = { flags };
|
|---|
| 162 | #if !defined(__CFA_NO_STATISTICS__)
|
|---|
| 163 | if( !silent ) {
|
|---|
| 164 | print_stats_at_exit( cl.self, CFA_STATS_READY_Q | CFA_STATS_IO );
|
|---|
| 165 | }
|
|---|
| 166 | #endif
|
|---|
| 167 | {
|
|---|
| 168 | BenchProc procs[nprocs];
|
|---|
| 169 | #if !defined(__CFA_NO_STATISTICS__)
|
|---|
| 170 | if( procstats ) {
|
|---|
| 171 | for(i; nprocs) {
|
|---|
| 172 | print_stats_at_exit( procs[i].self, CFA_STATS_READY_Q | CFA_STATS_IO );
|
|---|
| 173 | }
|
|---|
| 174 | }
|
|---|
| 175 | #endif
|
|---|
| 176 | {
|
|---|
| 177 | Reader threads[nthreads];
|
|---|
| 178 |
|
|---|
| 179 | printf("Starting\n");
|
|---|
| 180 | bool is_tty = isatty(STDOUT_FILENO);
|
|---|
| 181 | start = getTimeNsec();
|
|---|
| 182 | run = true;
|
|---|
| 183 |
|
|---|
| 184 | for(i; nthreads) {
|
|---|
| 185 | unpark( threads[i] __cfaabi_dbg_ctx2 );
|
|---|
| 186 | }
|
|---|
| 187 | wait(duration, start, end, is_tty);
|
|---|
| 188 |
|
|---|
| 189 | run = false;
|
|---|
| 190 | end = getTimeNsec();
|
|---|
| 191 | printf("\nDone\n");
|
|---|
| 192 | }
|
|---|
| 193 | }
|
|---|
| 194 | printf("Took %'ld ms\n", (end - start)`ms);
|
|---|
| 195 | printf("Total reads : %'15zu\n", count);
|
|---|
| 196 | printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
|
|---|
| 197 | printf("Total read size : %'15zu\n", buflen * count);
|
|---|
| 198 | printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | close(fd);
|
|---|
| 202 | }
|
|---|