1 | #include <stdlib.h>
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <string.h>
|
---|
4 |
|
---|
5 | extern "C" {
|
---|
6 | #include <locale.h>
|
---|
7 | #include <getopt.h>
|
---|
8 | #include <fcntl.h>
|
---|
9 | #include <sys/uio.h>
|
---|
10 | }
|
---|
11 |
|
---|
12 | #include <unistd.h>
|
---|
13 |
|
---|
14 | #include <clock.hfa>
|
---|
15 | #include <kernel.hfa>
|
---|
16 | #include <thread.hfa>
|
---|
17 | #include <time.hfa>
|
---|
18 | #include <stats.hfa>
|
---|
19 |
|
---|
20 | #include "../benchcltr.hfa"
|
---|
21 |
|
---|
22 | extern bool traceHeapOn();
|
---|
23 | extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
|
---|
24 |
|
---|
25 | int fd;
|
---|
26 | volatile bool run = false;
|
---|
27 | volatile size_t count = 0;
|
---|
28 |
|
---|
29 | unsigned long int buflen = 50;
|
---|
30 |
|
---|
31 | thread __attribute__((aligned(128))) Reader {};
|
---|
32 | void ?{}( Reader & this ) {
|
---|
33 | ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
|
---|
34 | }
|
---|
35 |
|
---|
36 | void main( Reader & ) {
|
---|
37 | park( __cfaabi_dbg_ctx );
|
---|
38 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
|
---|
39 |
|
---|
40 | char data[buflen];
|
---|
41 | struct iovec iov = { data, buflen };
|
---|
42 |
|
---|
43 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
|
---|
44 | int r = cfa_preadv2(fd, &iov, 1, 0, 0);
|
---|
45 | if(r < 0) abort("%s\n", strerror(-r));
|
---|
46 |
|
---|
47 | __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | int main(int argc, char * argv[]) {
|
---|
52 | BENCH_DECL
|
---|
53 | unsigned flags = 0;
|
---|
54 | unsigned sublen = 16;
|
---|
55 |
|
---|
56 | arg_loop:
|
---|
57 | for(;;) {
|
---|
58 | static struct option options[] = {
|
---|
59 | BENCH_OPT_LONG
|
---|
60 | {"bufsize", required_argument, 0, 'b'},
|
---|
61 | {"userthread", no_argument , 0, 'u'},
|
---|
62 | {"submitthread", no_argument , 0, 's'},
|
---|
63 | {"eagersubmit", no_argument , 0, 'e'},
|
---|
64 | {"kpollsubmit", no_argument , 0, 'k'},
|
---|
65 | {"kpollcomplete", no_argument , 0, 'i'},
|
---|
66 | {"submitlength", required_argument, 0, 'l'},
|
---|
67 | {0, 0, 0, 0}
|
---|
68 | };
|
---|
69 |
|
---|
70 | int idx = 0;
|
---|
71 | int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:usekil:", options, &idx);
|
---|
72 |
|
---|
73 | const char * arg = optarg ? optarg : "";
|
---|
74 | char * end;
|
---|
75 | switch(opt) {
|
---|
76 | // Exit Case
|
---|
77 | case -1:
|
---|
78 | break arg_loop;
|
---|
79 | BENCH_OPT_CASE
|
---|
80 | case 'b':
|
---|
81 | buflen = strtoul(arg, &end, 10);
|
---|
82 | if(*end != '\0' && buflen < 10) {
|
---|
83 | fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
|
---|
84 | goto usage;
|
---|
85 | }
|
---|
86 | break;
|
---|
87 | case 'u':
|
---|
88 | flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
|
---|
89 | break;
|
---|
90 | case 's':
|
---|
91 | flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS;
|
---|
92 | break;
|
---|
93 | case 'e':
|
---|
94 | flags |= CFA_CLUSTER_IO_EAGER_SUBMITS;
|
---|
95 | break;
|
---|
96 | case 'k':
|
---|
97 | flags |= CFA_CLUSTER_IO_KERNEL_POLL_SUBMITS;
|
---|
98 | break;
|
---|
99 | case 'i':
|
---|
100 | flags |= CFA_CLUSTER_IO_KERNEL_POLL_COMPLETES;
|
---|
101 | break;
|
---|
102 | case 'l':
|
---|
103 | sublen = strtoul(arg, &end, 10);
|
---|
104 | if(*end != '\0' && sublen < 16) {
|
---|
105 | fprintf(stderr, "Submit length must be at least 16, was %s\n", arg);
|
---|
106 | goto usage;
|
---|
107 | }
|
---|
108 | flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
|
---|
109 | break;
|
---|
110 | default: /* ? */
|
---|
111 | fprintf(stderr, "%d\n", opt);
|
---|
112 | usage:
|
---|
113 | bench_usage( argv );
|
---|
114 | fprintf( stderr, " -b, --buflen=SIZE Number of bytes to read per request\n" );
|
---|
115 | fprintf( stderr, " -u, --userthread If set, cluster uses user-thread to poll I/O\n" );
|
---|
116 | fprintf( stderr, " -s, --submitthread If set, cluster uses polling thread to submit I/O\n" );
|
---|
117 | fprintf( stderr, " -e, --eagersubmit If set, cluster submits I/O eagerly but still aggregates submits\n" );
|
---|
118 | fprintf( stderr, " -k, --kpollsubmit If set, cluster uses IORING_SETUP_SQPOLL\n" );
|
---|
119 | fprintf( stderr, " -i, --kpollcomplete If set, cluster uses IORING_SETUP_IOPOLL\n" );
|
---|
120 | fprintf( stderr, " -l, --submitlength=LEN Max number of submitions that can be submitted together\n" );
|
---|
121 | exit(EXIT_FAILURE);
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | fd = open(__FILE__, 0);
|
---|
126 | if(fd < 0) {
|
---|
127 | fprintf(stderr, "Could not open source file\n");
|
---|
128 | exit(EXIT_FAILURE);
|
---|
129 | }
|
---|
130 |
|
---|
131 | printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration);
|
---|
132 |
|
---|
133 | {
|
---|
134 | Time start, end;
|
---|
135 | BenchCluster cl = { flags, CFA_STATS_READY_Q | CFA_STATS_IO };
|
---|
136 | {
|
---|
137 | BenchProc procs[nprocs];
|
---|
138 | {
|
---|
139 | Reader threads[nthreads];
|
---|
140 |
|
---|
141 | printf("Starting\n");
|
---|
142 | bool is_tty = isatty(STDOUT_FILENO);
|
---|
143 | start = getTimeNsec();
|
---|
144 | run = true;
|
---|
145 |
|
---|
146 | for(i; nthreads) {
|
---|
147 | unpark( threads[i] __cfaabi_dbg_ctx2 );
|
---|
148 | }
|
---|
149 | wait(duration, start, end, is_tty);
|
---|
150 |
|
---|
151 | run = false;
|
---|
152 | end = getTimeNsec();
|
---|
153 | printf("\nDone\n");
|
---|
154 | }
|
---|
155 | }
|
---|
156 | printf("Took %'ld ms\n", (end - start)`ms);
|
---|
157 | printf("Total reads : %'15zu\n", count);
|
---|
158 | printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
|
---|
159 | printf("Total read size : %'15zu\n", buflen * count);
|
---|
160 | printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
|
---|
161 | }
|
---|
162 |
|
---|
163 | close(fd);
|
---|
164 | }
|
---|