| 1 | #define _GNU_SOURCE
|
|---|
| 2 |
|
|---|
| 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 |
|
|---|
| 14 | #include <unistd.h>
|
|---|
| 15 |
|
|---|
| 16 | #include <clock.hfa>
|
|---|
| 17 | #include <kernel.hfa>
|
|---|
| 18 | #include <thread.hfa>
|
|---|
| 19 | #include <time.hfa>
|
|---|
| 20 | #include <stats.hfa>
|
|---|
| 21 |
|
|---|
| 22 | #include "../benchcltr.hfa"
|
|---|
| 23 |
|
|---|
| 24 | extern bool traceHeapOn();
|
|---|
| 25 | extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
|
|---|
| 26 | extern ssize_t cfa_preadv2_fixed(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
|
|---|
| 27 | extern void register_fixed_files( cluster &, int *, unsigned count );
|
|---|
| 28 |
|
|---|
| 29 | int fd;
|
|---|
| 30 | volatile bool run = false;
|
|---|
| 31 | volatile size_t count = 0;
|
|---|
| 32 |
|
|---|
| 33 | unsigned long int buflen = 50;
|
|---|
| 34 | bool fixed_file = false;
|
|---|
| 35 |
|
|---|
| 36 | thread __attribute__((aligned(128))) Reader {};
|
|---|
| 37 | void ?{}( Reader & this ) {
|
|---|
| 38 | ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | int do_read(int fd, struct iovec * iov) {
|
|---|
| 42 | if(fixed_file) {
|
|---|
| 43 | return cfa_preadv2_fixed(fd, iov, 1, 0, 0);
|
|---|
| 44 | }
|
|---|
| 45 | else {
|
|---|
| 46 | return cfa_preadv2(fd, iov, 1, 0, 0);
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | void main( Reader & ) {
|
|---|
| 51 | park( __cfaabi_dbg_ctx );
|
|---|
| 52 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
|
|---|
| 53 |
|
|---|
| 54 | char data[buflen];
|
|---|
| 55 | struct iovec iov = { data, buflen };
|
|---|
| 56 |
|
|---|
| 57 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
|
|---|
| 58 | int r = do_read(fd, &iov);
|
|---|
| 59 | if(r < 0) abort("%s\n", strerror(-r));
|
|---|
| 60 |
|
|---|
| 61 | __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | int main(int argc, char * argv[]) {
|
|---|
| 66 | BENCH_DECL
|
|---|
| 67 | unsigned flags = 0;
|
|---|
| 68 | int file_flags = 0;
|
|---|
| 69 | unsigned sublen = 16;
|
|---|
| 70 |
|
|---|
| 71 | arg_loop:
|
|---|
| 72 | for(;;) {
|
|---|
| 73 | static struct option options[] = {
|
|---|
| 74 | BENCH_OPT_LONG
|
|---|
| 75 | {"bufsize", required_argument, 0, 'b'},
|
|---|
| 76 | {"userthread", no_argument , 0, 'u'},
|
|---|
| 77 | {"submitthread", no_argument , 0, 's'},
|
|---|
| 78 | {"eagersubmit", no_argument , 0, 'e'},
|
|---|
| 79 | {"kpollsubmit", no_argument , 0, 'k'},
|
|---|
| 80 | {"kpollcomplete", no_argument , 0, 'i'},
|
|---|
| 81 | {"submitlength", required_argument, 0, 'l'},
|
|---|
| 82 | {0, 0, 0, 0}
|
|---|
| 83 | };
|
|---|
| 84 |
|
|---|
| 85 | int idx = 0;
|
|---|
| 86 | int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:usekil:", options, &idx);
|
|---|
| 87 |
|
|---|
| 88 | const char * arg = optarg ? optarg : "";
|
|---|
| 89 | char * end;
|
|---|
| 90 | switch(opt) {
|
|---|
| 91 | // Exit Case
|
|---|
| 92 | case -1:
|
|---|
| 93 | break arg_loop;
|
|---|
| 94 | BENCH_OPT_CASE
|
|---|
| 95 | case 'b':
|
|---|
| 96 | buflen = strtoul(arg, &end, 10);
|
|---|
| 97 | if(*end != '\0' && buflen < 10) {
|
|---|
| 98 | fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
|
|---|
| 99 | goto usage;
|
|---|
| 100 | }
|
|---|
| 101 | break;
|
|---|
| 102 | case 'u':
|
|---|
| 103 | flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
|
|---|
| 104 | break;
|
|---|
| 105 | case 's':
|
|---|
| 106 | flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS;
|
|---|
| 107 | break;
|
|---|
| 108 | case 'e':
|
|---|
| 109 | flags |= CFA_CLUSTER_IO_EAGER_SUBMITS;
|
|---|
| 110 | break;
|
|---|
| 111 | case 'k':
|
|---|
| 112 | flags |= CFA_CLUSTER_IO_KERNEL_POLL_SUBMITS;
|
|---|
| 113 | fixed_file = true;
|
|---|
| 114 | break;
|
|---|
| 115 | case 'i':
|
|---|
| 116 | flags |= CFA_CLUSTER_IO_KERNEL_POLL_COMPLETES;
|
|---|
| 117 | file_flags |= O_DIRECT;
|
|---|
| 118 | break;
|
|---|
| 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 | }
|
|---|
| 125 | flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
|
|---|
| 126 | break;
|
|---|
| 127 | default: /* ? */
|
|---|
| 128 | fprintf(stderr, "%d\n", opt);
|
|---|
| 129 | usage:
|
|---|
| 130 | bench_usage( argv );
|
|---|
| 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" );
|
|---|
| 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" );
|
|---|
| 138 | exit(EXIT_FAILURE);
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | int lfd = open(__FILE__, file_flags);
|
|---|
| 143 | if(lfd < 0) {
|
|---|
| 144 | fprintf(stderr, "Could not open source file\n");
|
|---|
| 145 | exit(EXIT_FAILURE);
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration);
|
|---|
| 149 |
|
|---|
| 150 | {
|
|---|
| 151 | Time start, end;
|
|---|
| 152 | BenchCluster cl = { flags, CFA_STATS_READY_Q | CFA_STATS_IO };
|
|---|
| 153 |
|
|---|
| 154 | if(fixed_file) {
|
|---|
| 155 | fd = 0;
|
|---|
| 156 | register_fixed_files( cl.self, &lfd, 1 );
|
|---|
| 157 | }
|
|---|
| 158 | else {
|
|---|
| 159 | fd = lfd;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | {
|
|---|
| 163 | BenchProc procs[nprocs];
|
|---|
| 164 | {
|
|---|
| 165 | Reader threads[nthreads];
|
|---|
| 166 |
|
|---|
| 167 | printf("Starting\n");
|
|---|
| 168 | bool is_tty = isatty(STDOUT_FILENO);
|
|---|
| 169 | start = getTimeNsec();
|
|---|
| 170 | run = true;
|
|---|
| 171 |
|
|---|
| 172 | for(i; nthreads) {
|
|---|
| 173 | unpark( threads[i] __cfaabi_dbg_ctx2 );
|
|---|
| 174 | }
|
|---|
| 175 | wait(duration, start, end, is_tty);
|
|---|
| 176 |
|
|---|
| 177 | run = false;
|
|---|
| 178 | end = getTimeNsec();
|
|---|
| 179 | printf("\nDone\n");
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 | printf("Took %'ld ms\n", (end - start)`ms);
|
|---|
| 183 | printf("Total reads : %'15zu\n", count);
|
|---|
| 184 | printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
|
|---|
| 185 | printf("Total read size : %'15zu\n", buflen * count);
|
|---|
| 186 | printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | close(lfd);
|
|---|
| 190 | }
|
|---|