source: benchmark/io/readv.cfa@ 7f6e9eb

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 7f6e9eb was 01c6256, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Adjsuted benchmarks to new io_ctxs

  • Property mode set to 100644
File size: 5.0 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 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
55void main( Reader & ) {
56 park( __cfaabi_dbg_ctx );
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
70int main(int argc, char * argv[]) {
71 BENCH_DECL
72 unsigned num_io = 1;
73 io_context_params params;
74 int file_flags = 0;
75 unsigned sublen = 16;
76
77 arg_loop:
78 for(;;) {
79 static struct option options[] = {
80 BENCH_OPT_LONG
81 {"bufsize", required_argument, 0, 'b'},
82 {"submitthread", no_argument , 0, 's'},
83 {"eagersubmit", no_argument , 0, 'e'},
84 {"kpollsubmit", no_argument , 0, 'k'},
85 {"kpollcomplete", no_argument , 0, 'i'},
86 {"fixed-files", no_argument , 0, 'f'},
87 {"open-direct", no_argument , 0, 'o'},
88 {"submitlength", required_argument, 0, 'l'},
89 {0, 0, 0, 0}
90 };
91
92 int idx = 0;
93 int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:sekil:", options, &idx);
94
95 const char * arg = optarg ? optarg : "";
96 char * end;
97 switch(opt) {
98 // Exit Case
99 case -1:
100 break arg_loop;
101 BENCH_OPT_CASE
102 case 'b':
103 buflen = strtoul(arg, &end, 10);
104 if(*end != '\0' && buflen < 10) {
105 fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
106 goto usage;
107 }
108 break;
109 case 's':
110 params.poller_submits = true;
111 break;
112 case 'e':
113 params.eager_submits = true;
114 break;
115 case 'k':
116 params.poll_submit = true;
117 case 'f':
118 fixed_file = true;
119 break;
120 case 'i':
121 params.poll_complete = true;
122 case 'o':
123 file_flags |= O_DIRECT;
124 break;
125 case 'l':
126 sublen = strtoul(arg, &end, 10);
127 if(*end != '\0' && sublen < 16) {
128 fprintf(stderr, "Submit length must be at least 16, was %s\n", arg);
129 goto usage;
130 }
131 // flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
132 break;
133 default: /* ? */
134 fprintf(stderr, "%d\n", opt);
135 usage:
136 bench_usage( argv );
137 fprintf( stderr, " -b, --buflen=SIZE Number of bytes to read per request\n" );
138 fprintf( stderr, " -s, --submitthread If set, cluster uses polling thread to submit I/O\n" );
139 fprintf( stderr, " -e, --eagersubmit If set, cluster submits I/O eagerly but still aggregates submits\n" );
140 fprintf( stderr, " -k, --kpollsubmit If set, cluster uses IORING_SETUP_SQPOLL\n" );
141 fprintf( stderr, " -i, --kpollcomplete If set, cluster uses IORING_SETUP_IOPOLL\n" );
142 fprintf( stderr, " -l, --submitlength=LEN Max number of submitions that can be submitted together\n" );
143 exit(EXIT_FAILURE);
144 }
145 }
146
147 if(params.poll_submit ) fixed_file = true;
148 if(params.poll_complete) file_flags |= O_DIRECT;
149
150 int lfd = open(__FILE__, file_flags);
151 if(lfd < 0) {
152 fprintf(stderr, "Could not open source file\n");
153 exit(EXIT_FAILURE);
154 }
155
156 printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration);
157
158 {
159 Time start, end;
160 BenchCluster cl = { num_io, params, CFA_STATS_READY_Q | CFA_STATS_IO };
161
162 if(fixed_file) {
163 fd = 0;
164 register_fixed_files( cl.self, &lfd, 1 );
165 }
166 else {
167 fd = lfd;
168 }
169
170 {
171 BenchProc procs[nprocs];
172 {
173 Reader threads[nthreads];
174
175 printf("Starting\n");
176 bool is_tty = isatty(STDOUT_FILENO);
177 start = getTimeNsec();
178 run = true;
179
180 for(i; nthreads) {
181 unpark( threads[i] __cfaabi_dbg_ctx2 );
182 }
183 wait(duration, start, end, is_tty);
184
185 run = false;
186 end = getTimeNsec();
187 printf("\nDone\n");
188 }
189 printf("Readers closed\n");
190 }
191 printf("Took %'ld ms\n", (end - start)`ms);
192 printf("Total reads : %'15zu\n", count);
193 printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
194 printf("Total read size : %'15zu\n", buflen * count);
195 printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
196 }
197
198 close(lfd);
199}
Note: See TracBrowser for help on using the repository browser.