[5847d35] | 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> |
---|
[566fde0] | 18 | #include <stats.hfa> |
---|
[5847d35] | 19 | |
---|
[9791ab5] | 20 | #include "../benchcltr.hfa" |
---|
| 21 | |
---|
[1bcdeff] | 22 | extern bool traceHeapOn(); |
---|
[2489d31] | 23 | extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); |
---|
[5847d35] | 24 | |
---|
| 25 | int fd; |
---|
| 26 | volatile bool run = false; |
---|
| 27 | volatile size_t count = 0; |
---|
| 28 | |
---|
| 29 | unsigned long int buflen = 50; |
---|
| 30 | |
---|
[9791ab5] | 31 | thread __attribute__((aligned(128))) Reader {}; |
---|
[4069faad] | 32 | void ?{}( Reader & this ) { |
---|
[9791ab5] | 33 | ((thread&)this){ "Reader Thread", *the_benchmark_cluster }; |
---|
[4069faad] | 34 | } |
---|
| 35 | |
---|
[5847d35] | 36 | void main( Reader & ) { |
---|
[9791ab5] | 37 | park( __cfaabi_dbg_ctx ); |
---|
| 38 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) ); |
---|
[5847d35] | 39 | |
---|
| 40 | char data[buflen]; |
---|
| 41 | struct iovec iov = { data, buflen }; |
---|
| 42 | |
---|
| 43 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) { |
---|
[4069faad] | 44 | int r = cfa_preadv2(fd, &iov, 1, 0, 0); |
---|
[b1ac7dd] | 45 | if(r < 0) abort("%s\n", strerror(-r)); |
---|
[4069faad] | 46 | |
---|
[5847d35] | 47 | __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST ); |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | int main(int argc, char * argv[]) { |
---|
[cb85603] | 52 | BENCH_DECL |
---|
[dd4e2d7] | 53 | unsigned flags = 0; |
---|
| 54 | unsigned sublen = 16; |
---|
[5847d35] | 55 | |
---|
| 56 | arg_loop: |
---|
| 57 | for(;;) { |
---|
| 58 | static struct option options[] = { |
---|
[cb85603] | 59 | BENCH_OPT_LONG |
---|
[0335620] | 60 | {"bufsize", required_argument, 0, 'b'}, |
---|
| 61 | {"userthread", no_argument , 0, 'u'}, |
---|
| 62 | {"submitthread", no_argument , 0, 's'}, |
---|
[dd4e2d7] | 63 | {"submitlength", required_argument, 0, 'l'}, |
---|
[5847d35] | 64 | {0, 0, 0, 0} |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | int idx = 0; |
---|
[cb85603] | 68 | int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:usl:", options, &idx); |
---|
[5847d35] | 69 | |
---|
| 70 | const char * arg = optarg ? optarg : ""; |
---|
| 71 | char * end; |
---|
| 72 | switch(opt) { |
---|
| 73 | // Exit Case |
---|
| 74 | case -1: |
---|
| 75 | break arg_loop; |
---|
[cb85603] | 76 | BENCH_OPT_CASE |
---|
[5847d35] | 77 | case 'b': |
---|
| 78 | buflen = strtoul(arg, &end, 10); |
---|
| 79 | if(*end != '\0' && buflen < 10) { |
---|
| 80 | fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg); |
---|
| 81 | goto usage; |
---|
| 82 | } |
---|
| 83 | break; |
---|
[b6f2b21] | 84 | case 'u': |
---|
| 85 | flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD; |
---|
| 86 | break; |
---|
[0335620] | 87 | case 's': |
---|
| 88 | flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS; |
---|
| 89 | break; |
---|
[dd4e2d7] | 90 | case 'l': |
---|
| 91 | sublen = strtoul(arg, &end, 10); |
---|
| 92 | if(*end != '\0' && sublen < 16) { |
---|
| 93 | fprintf(stderr, "Submit length must be at least 16, was %s\n", arg); |
---|
| 94 | goto usage; |
---|
| 95 | } |
---|
| 96 | flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET); |
---|
| 97 | break; |
---|
[5847d35] | 98 | default: /* ? */ |
---|
| 99 | fprintf(stderr, "%d\n", opt); |
---|
| 100 | usage: |
---|
[cb85603] | 101 | bench_usage( argv ); |
---|
[566fde0] | 102 | fprintf( stderr, " -b, --buflen=SIZE Number of bytes to read per request\n" ); |
---|
| 103 | fprintf( stderr, " -u, --userthread If set, cluster uses user-thread to poll I/O\n" ); |
---|
| 104 | fprintf( stderr, " -s, --submitthread If set, cluster uses polling thread to submit I/O\n" ); |
---|
[5847d35] | 105 | exit(EXIT_FAILURE); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
[4069faad] | 109 | fd = open(__FILE__, 0); |
---|
[5847d35] | 110 | if(fd < 0) { |
---|
| 111 | fprintf(stderr, "Could not open source file\n"); |
---|
| 112 | exit(EXIT_FAILURE); |
---|
| 113 | } |
---|
| 114 | |
---|
[cb85603] | 115 | printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration); |
---|
[5847d35] | 116 | |
---|
| 117 | { |
---|
[4069faad] | 118 | Time start, end; |
---|
[cb85603] | 119 | BenchCluster cl = { flags, CFA_STATS_READY_Q | CFA_STATS_IO }; |
---|
[5847d35] | 120 | { |
---|
[9791ab5] | 121 | BenchProc procs[nprocs]; |
---|
[4069faad] | 122 | { |
---|
| 123 | Reader threads[nthreads]; |
---|
| 124 | |
---|
| 125 | printf("Starting\n"); |
---|
[9791ab5] | 126 | bool is_tty = isatty(STDOUT_FILENO); |
---|
[8e27ac45] | 127 | start = getTimeNsec(); |
---|
[4069faad] | 128 | run = true; |
---|
[9791ab5] | 129 | |
---|
| 130 | for(i; nthreads) { |
---|
| 131 | unpark( threads[i] __cfaabi_dbg_ctx2 ); |
---|
| 132 | } |
---|
| 133 | wait(duration, start, end, is_tty); |
---|
| 134 | |
---|
[4069faad] | 135 | run = false; |
---|
[8e27ac45] | 136 | end = getTimeNsec(); |
---|
[9791ab5] | 137 | printf("\nDone\n"); |
---|
[4069faad] | 138 | } |
---|
[5847d35] | 139 | } |
---|
[b1ac7dd] | 140 | printf("Took %'ld ms\n", (end - start)`ms); |
---|
[cbabfd4] | 141 | printf("Total reads : %'15zu\n", count); |
---|
| 142 | printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s); |
---|
| 143 | printf("Total read size : %'15zu\n", buflen * count); |
---|
| 144 | printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s); |
---|
[5847d35] | 145 | } |
---|
| 146 | |
---|
| 147 | close(fd); |
---|
| 148 | } |
---|