source: benchmark/io/readv.cfa@ 8291293

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 8291293 was cb85603, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Moved common code of benchmarks to benchcltr.hfa

  • Property mode set to 100644
File size: 3.6 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4
5extern "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
22extern bool traceHeapOn();
23extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
24
25int fd;
26volatile bool run = false;
27volatile size_t count = 0;
28
29unsigned long int buflen = 50;
30
31thread __attribute__((aligned(128))) Reader {};
32void ?{}( Reader & this ) {
33 ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
34}
35
36void 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
51int 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 {"submitlength", required_argument, 0, 'l'},
64 {0, 0, 0, 0}
65 };
66
67 int idx = 0;
68 int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:usl:", options, &idx);
69
70 const char * arg = optarg ? optarg : "";
71 char * end;
72 switch(opt) {
73 // Exit Case
74 case -1:
75 break arg_loop;
76 BENCH_OPT_CASE
77 case 'b':
78 buflen = strtoul(arg, &end, 10);
79 if(*end != '\0' && buflen < 10) {
80 fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
81 goto usage;
82 }
83 break;
84 case 'u':
85 flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
86 break;
87 case 's':
88 flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS;
89 break;
90 case 'l':
91 sublen = strtoul(arg, &end, 10);
92 if(*end != '\0' && sublen < 16) {
93 fprintf(stderr, "Submit length must be at least 16, was %s\n", arg);
94 goto usage;
95 }
96 flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
97 break;
98 default: /* ? */
99 fprintf(stderr, "%d\n", opt);
100 usage:
101 bench_usage( argv );
102 fprintf( stderr, " -b, --buflen=SIZE Number of bytes to read per request\n" );
103 fprintf( stderr, " -u, --userthread If set, cluster uses user-thread to poll I/O\n" );
104 fprintf( stderr, " -s, --submitthread If set, cluster uses polling thread to submit I/O\n" );
105 exit(EXIT_FAILURE);
106 }
107 }
108
109 fd = open(__FILE__, 0);
110 if(fd < 0) {
111 fprintf(stderr, "Could not open source file\n");
112 exit(EXIT_FAILURE);
113 }
114
115 printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration);
116
117 {
118 Time start, end;
119 BenchCluster cl = { flags, CFA_STATS_READY_Q | CFA_STATS_IO };
120 {
121 BenchProc procs[nprocs];
122 {
123 Reader threads[nthreads];
124
125 printf("Starting\n");
126 bool is_tty = isatty(STDOUT_FILENO);
127 start = getTimeNsec();
128 run = true;
129
130 for(i; nthreads) {
131 unpark( threads[i] __cfaabi_dbg_ctx2 );
132 }
133 wait(duration, start, end, is_tty);
134
135 run = false;
136 end = getTimeNsec();
137 printf("\nDone\n");
138 }
139 }
140 printf("Took %'ld ms\n", (end - start)`ms);
141 printf("Total reads : %'15zu\n", count);
142 printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
143 printf("Total read size : %'15zu\n", buflen * count);
144 printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
145 }
146
147 close(fd);
148}
Note: See TracBrowser for help on using the repository browser.