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 <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 |
|
---|
26 | extern bool traceHeapOn();
|
---|
27 |
|
---|
28 | int fd;
|
---|
29 | volatile bool run = false;
|
---|
30 | volatile size_t count = 0;
|
---|
31 |
|
---|
32 | unsigned long int buflen = 512;
|
---|
33 | bool fixed_file = false;
|
---|
34 |
|
---|
35 | thread __attribute__((aligned(128))) Reader {};
|
---|
36 | void ?{}( Reader & this ) {
|
---|
37 | ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
|
---|
38 | }
|
---|
39 |
|
---|
40 | int 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 defined(CFA_HAVE_IOSQE_ASYNC)
|
---|
44 | | CFA_IO_ASYNC
|
---|
45 | #else
|
---|
46 | #warning no CFA_IO_ASYNC support
|
---|
47 | #endif
|
---|
48 | ;
|
---|
49 | if(fixed_file) {
|
---|
50 | sflags |= CFA_IO_FIXED_FD1;
|
---|
51 | }
|
---|
52 | return cfa_preadv2(fd, iov, 1, 0, 0, sflags, -1`s, 0p, 0p);
|
---|
53 | }
|
---|
54 |
|
---|
55 | void main( Reader & ) {
|
---|
56 | park();
|
---|
57 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
|
---|
58 |
|
---|
59 | __attribute__((aligned(512))) char data[buflen];
|
---|
60 | struct iovec iov = { data, buflen };
|
---|
61 |
|
---|
62 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
|
---|
63 | int r = do_read(fd, &iov);
|
---|
64 | if(r < 0) abort("%s\n", strerror(errno));
|
---|
65 |
|
---|
66 | __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | int main(int argc, char * argv[]) {
|
---|
71 | int file_flags = 0;
|
---|
72 | unsigned num_io = 1;
|
---|
73 | unsigned sublen = 16;
|
---|
74 | unsigned nentries = 0;
|
---|
75 |
|
---|
76 | bool subthrd = false;
|
---|
77 | bool subeagr = false;
|
---|
78 | bool odirect = false;
|
---|
79 | bool kpollsb = false;
|
---|
80 | bool kpollcp = false;
|
---|
81 |
|
---|
82 | cfa_option opt[] = {
|
---|
83 | BENCH_OPT_CFA
|
---|
84 | {'b', "bufsize", "Number of bytes to read per request", buflen},
|
---|
85 | {'s', "submitthread", "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue},
|
---|
86 | {'e', "eagersubmit", "If set, cluster submits I/O eagerly but still aggregates submits", subeagr, parse_settrue},
|
---|
87 | {'f', "fixed-files", "Pre-register files with the io_contexts", fixed_file, parse_settrue},
|
---|
88 | {'o', "open-direct", "Open files with O_DIRECT flag, bypassing the file cache", odirect, parse_settrue},
|
---|
89 | {'k', "kpollsubmit", "If set, cluster uses an in kernel thread to poll submission, implies -f, requires elevated permissions", kpollsb, parse_settrue},
|
---|
90 | {'i', "kpollcomplete", "If set, cluster polls fds for completions instead of relying on interrupts to get notifications, implies -o", kpollcp, parse_settrue},
|
---|
91 | {'l', "submitlength", "Size of the buffer that stores ready submissions", sublen},
|
---|
92 | {'r', "numentries", "Number of entries each of the io_context have", nentries},
|
---|
93 | {'n', "numcontexts", "Number of io_contexts to the cluster", num_io},
|
---|
94 | };
|
---|
95 | int opt_cnt = sizeof(opt) / sizeof(cfa_option);
|
---|
96 |
|
---|
97 | char **left;
|
---|
98 | parse_args( opt, opt_cnt, "[OPTIONS]...\ncforall readv benchmark", left );
|
---|
99 |
|
---|
100 | if(kpollcp || odirect) {
|
---|
101 | if( (buflen % 512) != 0 ) {
|
---|
102 | fprintf(stderr, "Buffer length must be a multiple of 512 when using O_DIRECT, was %lu\n\n", buflen);
|
---|
103 | print_args_usage(opt, opt_cnt, "[OPTIONS]...\ncforall readv benchmark", true);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | io_context_params params;
|
---|
108 |
|
---|
109 | if( subthrd ) params.poller_submits = true;
|
---|
110 | if( subeagr ) params.eager_submits = true;
|
---|
111 | if( kpollsb ) params.poll_submit = true;
|
---|
112 | if( kpollcp ) params.poll_complete = true;
|
---|
113 |
|
---|
114 | if(params.poll_submit ) fixed_file = true;
|
---|
115 | if(params.poll_complete) odirect = true;
|
---|
116 |
|
---|
117 | params.num_ready = sublen;
|
---|
118 | params.num_entries = nentries;
|
---|
119 |
|
---|
120 | if(odirect) file_flags |= O_DIRECT;
|
---|
121 |
|
---|
122 | int lfd = open(__FILE__, file_flags);
|
---|
123 | if(lfd < 0) {
|
---|
124 | fprintf(stderr, "Could not open source file\n");
|
---|
125 | exit(EXIT_FAILURE);
|
---|
126 | }
|
---|
127 |
|
---|
128 | printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration);
|
---|
129 |
|
---|
130 | {
|
---|
131 | Time start, end;
|
---|
132 | BenchCluster cl = { num_io, params, CFA_STATS_READY_Q | CFA_STATS_IO };
|
---|
133 |
|
---|
134 | if(fixed_file) {
|
---|
135 | fd = 0;
|
---|
136 | register_fixed_files( cl.self, &lfd, 1 );
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | fd = lfd;
|
---|
140 | }
|
---|
141 |
|
---|
142 | {
|
---|
143 | BenchProc procs[nprocs];
|
---|
144 | {
|
---|
145 | Reader threads[nthreads];
|
---|
146 |
|
---|
147 | printf("Starting\n");
|
---|
148 | bool is_tty = isatty(STDOUT_FILENO);
|
---|
149 | start = timeHiRes();
|
---|
150 | run = true;
|
---|
151 |
|
---|
152 | for(i; nthreads) {
|
---|
153 | unpark( threads[i] );
|
---|
154 | }
|
---|
155 | wait(duration, start, end, is_tty);
|
---|
156 |
|
---|
157 | run = false;
|
---|
158 | end = timeHiRes();
|
---|
159 | printf("\nDone\n");
|
---|
160 | }
|
---|
161 | printf("Readers closed\n");
|
---|
162 | }
|
---|
163 | printf("Took %'ld ms\n", (end - start)`ms);
|
---|
164 | printf("Total reads : %'15zu\n", count);
|
---|
165 | printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
|
---|
166 | printf("Total read size : %'15zu\n", buflen * count);
|
---|
167 | printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
|
---|
168 | }
|
---|
169 |
|
---|
170 | close(lfd);
|
---|
171 | }
|
---|