source: benchmark/io/readv.cfa@ be91ab4

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

Several fixes to prints in the io readv benchmark

  • Property mode set to 100644
File size: 4.1 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
19extern bool traceHeapOn();
20extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
21
22int fd;
23volatile bool run = false;
24volatile size_t count = 0;
25
26unsigned long int buflen = 50;
27
28cluster * the_cluster;
29
30thread Reader {};
31void ?{}( Reader & this ) {
32 ((thread&)this){ "Reader Thread", *the_cluster };
33}
34
35struct my_processor {
36 processor p;
37};
38
39void ?{}( my_processor & this ) {
40 (this.p){ "I/O Processor", *the_cluster };
41}
42
43void main( Reader & ) {
44 while(!__atomic_load_n(&run, __ATOMIC_RELAXED)) yield();
45
46 char data[buflen];
47 struct iovec iov = { data, buflen };
48
49 while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
50 int r = cfa_preadv2(fd, &iov, 1, 0, 0);
51 if(r < 0) abort("%s\n", strerror(-r));
52
53 __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
54 }
55}
56
57int main(int argc, char * argv[]) {
58 double duration = 5.0;
59 unsigned long int nthreads = 2;
60 unsigned long int nprocs = 1;
61 int flags = 0;
62
63 arg_loop:
64 for(;;) {
65 static struct option options[] = {
66 {"duration", required_argument, 0, 'd'},
67 {"nthreads", required_argument, 0, 't'},
68 {"nprocs", required_argument, 0, 'p'},
69 {"bufsize", required_argument, 0, 'b'},
70 {"userthread", no_argument , 0, 'u'},
71 {0, 0, 0, 0}
72 };
73
74 int idx = 0;
75 int opt = getopt_long(argc, argv, "d:t:p:b:u", options, &idx);
76
77 const char * arg = optarg ? optarg : "";
78 char * end;
79 switch(opt) {
80 // Exit Case
81 case -1:
82 break arg_loop;
83 // Numeric Arguments
84 case 'd':
85 duration = strtod(arg, &end);
86 if(*end != '\0') {
87 fprintf(stderr, "Duration must be a valid double, was %s\n", arg);
88 goto usage;
89 }
90 break;
91 case 't':
92 nthreads = strtoul(arg, &end, 10);
93 if(*end != '\0' || nthreads < 1) {
94 fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg);
95 goto usage;
96 }
97 break;
98 case 'p':
99 nprocs = strtoul(arg, &end, 10);
100 if(*end != '\0' || nprocs < 1) {
101 fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg);
102 goto usage;
103 }
104 break;
105 case 'b':
106 buflen = strtoul(arg, &end, 10);
107 if(*end != '\0' && buflen < 10) {
108 fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
109 goto usage;
110 }
111 break;
112 case 'u':
113 flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
114 break;
115 // Other cases
116 default: /* ? */
117 fprintf(stderr, "%d\n", opt);
118 usage:
119 fprintf(stderr, "Usage: %s : [options]\n", argv[0]);
120 fprintf(stderr, "\n");
121 fprintf(stderr, " -d, --duration=DURATION Duration of the experiment, in seconds\n");
122 fprintf(stderr, " -t, --nthreads=NTHREADS Number of user threads\n");
123 fprintf(stderr, " -p, --nprocs=NPROCS Number of kernel threads\n");
124 fprintf(stderr, " -b, --buflen=SIZE Number of bytes to read per request\n");
125 exit(EXIT_FAILURE);
126 }
127 }
128
129 fd = open(__FILE__, 0);
130 if(fd < 0) {
131 fprintf(stderr, "Could not open source file\n");
132 exit(EXIT_FAILURE);
133 }
134
135 printf("Running %lu threads, reading %lu bytes each, over %lu processors for %lf seconds\n", nthreads, buflen, nprocs, duration);
136
137 {
138 Time start, end;
139 cluster cl = { "IO Cluster", flags };
140 the_cluster = &cl;
141 #if !defined(__CFA_NO_STATISTICS__)
142 print_stats_at_exit( cl );
143 #endif
144 {
145 my_processor procs[nprocs];
146 {
147 Reader threads[nthreads];
148
149 printf("Starting\n");
150 start = getTime();
151 run = true;
152 do {
153 sleep(500`ms);
154 end = getTime();
155 } while( (end - start) < duration`s );
156 run = false;
157 end = getTime();
158 printf("Done\n");
159 }
160 }
161 printf("Took %'ld ms\n", (end - start)`ms);
162 printf("Total reads : %'15zu\n", count);
163 printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
164 printf("Total read size : %'15zu\n", buflen * count);
165 printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
166 }
167
168 close(fd);
169}
Note: See TracBrowser for help on using the repository browser.