source: benchmark/io/readv.cfa @ 42f1d739

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

Fixed readv after io_context re-work

  • Property mode set to 100644
File size: 4.9 KB
Line 
1#define _GNU_SOURCE
2
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 <errno.h>
15#include <unistd.h>
16
17#include <clock.hfa>
18#include <iofwd.hfa>
19#include <kernel.hfa>
20#include <thread.hfa>
21#include <time.hfa>
22#include <stats.hfa>
23
24#include "../benchcltr.hfa"
25
26extern bool traceHeapOn();
27
28int fd;
29volatile bool run = false;
30volatile size_t count = 0;
31
32unsigned long int buflen = 512;
33bool fixed_file = false;
34
35thread __attribute__((aligned(128))) Reader {};
36void ?{}( Reader & this ) {
37        ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
38}
39
40int do_read(int fd, struct iovec * iov) {
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;
43        if(fixed_file) {
44                sflags |= CFA_IO_FIXED_FD1;
45        }
46        return cfa_preadv2(fd, iov, 1, 0, 0, sflags, -1`s, 0p, 0p);
47}
48
49void main( Reader & ) {
50        park( __cfaabi_dbg_ctx );
51        /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
52
53        __attribute__((aligned(512)))  char data[buflen];
54        struct iovec iov = { data, buflen };
55
56        while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
57                int r = do_read(fd, &iov);
58                if(r < 0) abort("%s\n", strerror(errno));
59
60                __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
61        }
62}
63
64int main(int argc, char * argv[]) {
65        BENCH_DECL
66        unsigned num_io = 1;
67        io_context_params params;
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                        {"submitthread",  no_argument      , 0, 's'},
77                        {"eagersubmit",   no_argument      , 0, 'e'},
78                        {"kpollsubmit",   no_argument      , 0, 'k'},
79                        {"kpollcomplete", no_argument      , 0, 'i'},
80                        {"fixed-files",   no_argument      , 0, 'f'},
81                        {"open-direct",   no_argument      , 0, 'o'},
82                        {"submitlength",  required_argument, 0, 'l'},
83                        {0, 0, 0, 0}
84                };
85
86                int idx = 0;
87                int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:sekil:", options, &idx);
88
89                const char * arg = optarg ? optarg : "";
90                char * end;
91                switch(opt) {
92                        // Exit Case
93                        case -1:
94                                break arg_loop;
95                        BENCH_OPT_CASE
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;
103                        case 's':
104                                params.poller_submits = true;
105                                break;
106                        case 'e':
107                                params.eager_submits = true;
108                                break;
109                        case 'k':
110                                params.poll_submit = true;
111                        case 'f':
112                                fixed_file = true;
113                                break;
114                        case 'i':
115                                params.poll_complete = true;
116                        case 'o':
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 = { num_io, params, 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                        printf("Readers closed\n");
182                }
183                printf("Took %'ld ms\n", (end - start)`ms);
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);
188        }
189
190        close(lfd);
191}
Note: See TracBrowser for help on using the repository browser.