[20ab637] | 1 | #define _GNU_SOURCE |
---|
| 2 | |
---|
[5847d35] | 3 | #include <stdlib.h> |
---|
| 4 | #include <stdio.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | |
---|
| 7 | extern "C" { |
---|
| 8 | #include <locale.h> |
---|
| 9 | #include <getopt.h> |
---|
| 10 | #include <fcntl.h> |
---|
| 11 | #include <sys/uio.h> |
---|
| 12 | } |
---|
| 13 | |
---|
[920dca3] | 14 | #include <errno.h> |
---|
[5847d35] | 15 | #include <unistd.h> |
---|
| 16 | |
---|
| 17 | #include <clock.hfa> |
---|
[920dca3] | 18 | #include <iofwd.hfa> |
---|
[5847d35] | 19 | #include <kernel.hfa> |
---|
| 20 | #include <thread.hfa> |
---|
| 21 | #include <time.hfa> |
---|
[566fde0] | 22 | #include <stats.hfa> |
---|
[5847d35] | 23 | |
---|
[9791ab5] | 24 | #include "../benchcltr.hfa" |
---|
| 25 | |
---|
[1bcdeff] | 26 | extern bool traceHeapOn(); |
---|
[5847d35] | 27 | |
---|
| 28 | int fd; |
---|
| 29 | volatile bool run = false; |
---|
| 30 | volatile size_t count = 0; |
---|
| 31 | |
---|
[920dca3] | 32 | unsigned long int buflen = 512; |
---|
[20ab637] | 33 | bool fixed_file = false; |
---|
[5847d35] | 34 | |
---|
[9791ab5] | 35 | thread __attribute__((aligned(128))) Reader {}; |
---|
[4069faad] | 36 | void ?{}( Reader & this ) { |
---|
[9791ab5] | 37 | ((thread&)this){ "Reader Thread", *the_benchmark_cluster }; |
---|
[4069faad] | 38 | } |
---|
| 39 | |
---|
[20ab637] | 40 | int do_read(int fd, struct iovec * iov) { |
---|
[920dca3] | 41 | // extern ssize_t cfa_preadv2(int, const struct iovec *, int, off_t, int, int = 0, Duration = -1`s, io_cancellation * = 0p, io_context * = 0p); |
---|
| 42 | int sflags = 0; |
---|
[20ab637] | 43 | if(fixed_file) { |
---|
[920dca3] | 44 | sflags |= CFA_IO_FIXED_FD1; |
---|
[20ab637] | 45 | } |
---|
[920dca3] | 46 | return cfa_preadv2(fd, iov, 1, 0, 0, sflags, -1`s, 0p, 0p); |
---|
[20ab637] | 47 | } |
---|
| 48 | |
---|
[5847d35] | 49 | void main( Reader & ) { |
---|
[9791ab5] | 50 | park( __cfaabi_dbg_ctx ); |
---|
| 51 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) ); |
---|
[5847d35] | 52 | |
---|
[920dca3] | 53 | __attribute__((aligned(512))) char data[buflen]; |
---|
[5847d35] | 54 | struct iovec iov = { data, buflen }; |
---|
| 55 | |
---|
| 56 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) { |
---|
[20ab637] | 57 | int r = do_read(fd, &iov); |
---|
[920dca3] | 58 | if(r < 0) abort("%s\n", strerror(errno)); |
---|
[4069faad] | 59 | |
---|
[5847d35] | 60 | __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST ); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | int main(int argc, char * argv[]) { |
---|
[cb85603] | 65 | BENCH_DECL |
---|
[920dca3] | 66 | unsigned num_io = 1; |
---|
| 67 | io_context_params params; |
---|
[20ab637] | 68 | int file_flags = 0; |
---|
[dd4e2d7] | 69 | unsigned sublen = 16; |
---|
[5847d35] | 70 | |
---|
| 71 | arg_loop: |
---|
| 72 | for(;;) { |
---|
| 73 | static struct option options[] = { |
---|
[cb85603] | 74 | BENCH_OPT_LONG |
---|
[69237cd] | 75 | {"bufsize", required_argument, 0, 'b'}, |
---|
| 76 | {"submitthread", no_argument , 0, 's'}, |
---|
| 77 | {"eagersubmit", no_argument , 0, 'e'}, |
---|
| 78 | {"kpollsubmit", no_argument , 0, 'k'}, |
---|
| 79 | {"kpollcomplete", no_argument , 0, 'i'}, |
---|
[920dca3] | 80 | {"fixed-files", no_argument , 0, 'f'}, |
---|
| 81 | {"open-direct", no_argument , 0, 'o'}, |
---|
[69237cd] | 82 | {"submitlength", required_argument, 0, 'l'}, |
---|
[5847d35] | 83 | {0, 0, 0, 0} |
---|
| 84 | }; |
---|
| 85 | |
---|
| 86 | int idx = 0; |
---|
[920dca3] | 87 | int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:sekil:", options, &idx); |
---|
[5847d35] | 88 | |
---|
| 89 | const char * arg = optarg ? optarg : ""; |
---|
| 90 | char * end; |
---|
| 91 | switch(opt) { |
---|
| 92 | // Exit Case |
---|
| 93 | case -1: |
---|
| 94 | break arg_loop; |
---|
[cb85603] | 95 | BENCH_OPT_CASE |
---|
[5847d35] | 96 | case 'b': |
---|
| 97 | buflen = strtoul(arg, &end, 10); |
---|
| 98 | if(*end != '\0' && buflen < 10) { |
---|
| 99 | fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg); |
---|
| 100 | goto usage; |
---|
| 101 | } |
---|
| 102 | break; |
---|
[0335620] | 103 | case 's': |
---|
[920dca3] | 104 | params.poller_submits = true; |
---|
[0335620] | 105 | break; |
---|
[69237cd] | 106 | case 'e': |
---|
[920dca3] | 107 | params.eager_submits = true; |
---|
[69237cd] | 108 | break; |
---|
| 109 | case 'k': |
---|
[920dca3] | 110 | params.poll_submit = true; |
---|
| 111 | case 'f': |
---|
[20ab637] | 112 | fixed_file = true; |
---|
[69237cd] | 113 | break; |
---|
| 114 | case 'i': |
---|
[920dca3] | 115 | params.poll_complete = true; |
---|
| 116 | case 'o': |
---|
[20ab637] | 117 | file_flags |= O_DIRECT; |
---|
[69237cd] | 118 | break; |
---|
[dd4e2d7] | 119 | case 'l': |
---|
| 120 | sublen = strtoul(arg, &end, 10); |
---|
| 121 | if(*end != '\0' && sublen < 16) { |
---|
| 122 | fprintf(stderr, "Submit length must be at least 16, was %s\n", arg); |
---|
| 123 | goto usage; |
---|
| 124 | } |
---|
[920dca3] | 125 | // flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET); |
---|
[dd4e2d7] | 126 | break; |
---|
[5847d35] | 127 | default: /* ? */ |
---|
| 128 | fprintf(stderr, "%d\n", opt); |
---|
| 129 | usage: |
---|
[cb85603] | 130 | bench_usage( argv ); |
---|
[566fde0] | 131 | fprintf( stderr, " -b, --buflen=SIZE Number of bytes to read per request\n" ); |
---|
| 132 | fprintf( stderr, " -u, --userthread If set, cluster uses user-thread to poll I/O\n" ); |
---|
| 133 | fprintf( stderr, " -s, --submitthread If set, cluster uses polling thread to submit I/O\n" ); |
---|
[69237cd] | 134 | fprintf( stderr, " -e, --eagersubmit If set, cluster submits I/O eagerly but still aggregates submits\n" ); |
---|
| 135 | fprintf( stderr, " -k, --kpollsubmit If set, cluster uses IORING_SETUP_SQPOLL\n" ); |
---|
| 136 | fprintf( stderr, " -i, --kpollcomplete If set, cluster uses IORING_SETUP_IOPOLL\n" ); |
---|
| 137 | fprintf( stderr, " -l, --submitlength=LEN Max number of submitions that can be submitted together\n" ); |
---|
[5847d35] | 138 | exit(EXIT_FAILURE); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
[20ab637] | 142 | int lfd = open(__FILE__, file_flags); |
---|
| 143 | if(lfd < 0) { |
---|
[5847d35] | 144 | fprintf(stderr, "Could not open source file\n"); |
---|
| 145 | exit(EXIT_FAILURE); |
---|
| 146 | } |
---|
| 147 | |
---|
[cb85603] | 148 | printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration); |
---|
[5847d35] | 149 | |
---|
| 150 | { |
---|
[4069faad] | 151 | Time start, end; |
---|
[920dca3] | 152 | BenchCluster cl = { num_io, params, CFA_STATS_READY_Q | CFA_STATS_IO }; |
---|
[20ab637] | 153 | |
---|
| 154 | if(fixed_file) { |
---|
| 155 | fd = 0; |
---|
| 156 | register_fixed_files( cl.self, &lfd, 1 ); |
---|
| 157 | } |
---|
| 158 | else { |
---|
| 159 | fd = lfd; |
---|
| 160 | } |
---|
| 161 | |
---|
[5847d35] | 162 | { |
---|
[9791ab5] | 163 | BenchProc procs[nprocs]; |
---|
[4069faad] | 164 | { |
---|
| 165 | Reader threads[nthreads]; |
---|
| 166 | |
---|
| 167 | printf("Starting\n"); |
---|
[9791ab5] | 168 | bool is_tty = isatty(STDOUT_FILENO); |
---|
[8e27ac45] | 169 | start = getTimeNsec(); |
---|
[4069faad] | 170 | run = true; |
---|
[9791ab5] | 171 | |
---|
| 172 | for(i; nthreads) { |
---|
| 173 | unpark( threads[i] __cfaabi_dbg_ctx2 ); |
---|
| 174 | } |
---|
| 175 | wait(duration, start, end, is_tty); |
---|
| 176 | |
---|
[4069faad] | 177 | run = false; |
---|
[8e27ac45] | 178 | end = getTimeNsec(); |
---|
[9791ab5] | 179 | printf("\nDone\n"); |
---|
[4069faad] | 180 | } |
---|
[920dca3] | 181 | printf("Readers closed\n"); |
---|
[5847d35] | 182 | } |
---|
[b1ac7dd] | 183 | printf("Took %'ld ms\n", (end - start)`ms); |
---|
[cbabfd4] | 184 | printf("Total reads : %'15zu\n", count); |
---|
| 185 | printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s); |
---|
| 186 | printf("Total read size : %'15zu\n", buflen * count); |
---|
| 187 | printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s); |
---|
[5847d35] | 188 | } |
---|
| 189 | |
---|
[20ab637] | 190 | close(lfd); |
---|
[5847d35] | 191 | } |
---|