source: benchmark/io/readv.cfa @ 463cb33

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 463cb33 was 20ab637, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Added quick and dirty support for fixed files reads.
Added support for kernel side polling.

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[20ab637]1#define _GNU_SOURCE
2
[5847d35]3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6
7extern "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>
[566fde0]20#include <stats.hfa>
[5847d35]21
[9791ab5]22#include "../benchcltr.hfa"
23
[1bcdeff]24extern bool traceHeapOn();
[2489d31]25extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
[20ab637]26extern ssize_t cfa_preadv2_fixed(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
27extern void register_fixed_files( cluster &, int *, unsigned count );
[5847d35]28
29int fd;
30volatile bool run = false;
31volatile size_t count = 0;
32
33unsigned long int buflen = 50;
[20ab637]34bool fixed_file = false;
[5847d35]35
[9791ab5]36thread __attribute__((aligned(128))) Reader {};
[4069faad]37void ?{}( Reader & this ) {
[9791ab5]38        ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
[4069faad]39}
40
[20ab637]41int 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
[5847d35]50void main( Reader & ) {
[9791ab5]51        park( __cfaabi_dbg_ctx );
52        /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
[5847d35]53
54        char data[buflen];
55        struct iovec iov = { data, buflen };
56
57        while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
[20ab637]58                int r = do_read(fd, &iov);
[b1ac7dd]59                if(r < 0) abort("%s\n", strerror(-r));
[4069faad]60
[5847d35]61                __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
62        }
63}
64
65int main(int argc, char * argv[]) {
[cb85603]66        BENCH_DECL
[dd4e2d7]67        unsigned flags = 0;
[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                        {"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'},
[5847d35]82                        {0, 0, 0, 0}
83                };
84
85                int idx = 0;
[69237cd]86                int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:usekil:", options, &idx);
[5847d35]87
88                const char * arg = optarg ? optarg : "";
89                char * end;
90                switch(opt) {
91                        // Exit Case
92                        case -1:
93                                break arg_loop;
[cb85603]94                        BENCH_OPT_CASE
[5847d35]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;
[b6f2b21]102                        case 'u':
103                                flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
104                                break;
[0335620]105                        case 's':
106                                flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS;
107                                break;
[69237cd]108                        case 'e':
109                                flags |= CFA_CLUSTER_IO_EAGER_SUBMITS;
110                                break;
111                        case 'k':
112                                flags |= CFA_CLUSTER_IO_KERNEL_POLL_SUBMITS;
[20ab637]113                                fixed_file = true;
[69237cd]114                                break;
115                        case 'i':
116                                flags |= CFA_CLUSTER_IO_KERNEL_POLL_COMPLETES;
[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                                }
125                                flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
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;
[cb85603]152                BenchCluster cl = { flags, 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                        }
[5847d35]181                }
[b1ac7dd]182                printf("Took %'ld ms\n", (end - start)`ms);
[cbabfd4]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);
[5847d35]187        }
188
[20ab637]189        close(lfd);
[5847d35]190}
Note: See TracBrowser for help on using the repository browser.