source: benchmark/io/readv.cfa@ 13099a8b

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 13099a8b was 1bcdeff, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Small fixes to the io benchmark

  • Property mode set to 100644
File size: 3.4 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 async_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
28thread Reader {};
29void main( Reader & ) {
30 while(!__atomic_load_n(&run, __ATOMIC_RELAXED)) yield();
31
32 char data[buflen];
33 struct iovec iov = { data, buflen };
34
35 while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
36 async_preadv2(fd, &iov, 1, 0, 0);
37 __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
38 }
39}
40
41int main(int argc, char * argv[]) {
42 double duration = 5.0;
43 unsigned long int nthreads = 2;
44 unsigned long int nprocs = 1;
45
46 printf("Setting local\n");
47 setlocale(LC_NUMERIC, "");
48
49
50 arg_loop:
51 for(;;) {
52 static struct option options[] = {
53 {"duration", required_argument, 0, 'd'},
54 {"nthreads", required_argument, 0, 't'},
55 {"nprocs", required_argument, 0, 'p'},
56 {"bufsize", required_argument, 0, 'b'},
57 {0, 0, 0, 0}
58 };
59
60 int idx = 0;
61 int opt = getopt_long(argc, argv, "d:t:p:b:", options, &idx);
62
63 const char * arg = optarg ? optarg : "";
64 char * end;
65 switch(opt) {
66 // Exit Case
67 case -1:
68 break arg_loop;
69 // Numeric Arguments
70 case 'd':
71 duration = strtod(arg, &end);
72 if(*end != '\0') {
73 fprintf(stderr, "Duration must be a valid double, was %s\n", arg);
74 goto usage;
75 }
76 break;
77 case 't':
78 nthreads = strtoul(arg, &end, 10);
79 if(*end != '\0' || nthreads < 1) {
80 fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg);
81 goto usage;
82 }
83 break;
84 case 'p':
85 nprocs = strtoul(arg, &end, 10);
86 if(*end != '\0' || nprocs < 1) {
87 fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg);
88 goto usage;
89 }
90 break;
91 case 'b':
92 buflen = strtoul(arg, &end, 10);
93 if(*end != '\0' && buflen < 10) {
94 fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
95 goto usage;
96 }
97 break;
98 // Other cases
99 default: /* ? */
100 fprintf(stderr, "%d\n", opt);
101 usage:
102 fprintf(stderr, "Usage: %s : [options]\n", argv[0]);
103 fprintf(stderr, "\n");
104 fprintf(stderr, " -d, --duration=DURATION Duration of the experiment, in seconds\n");
105 fprintf(stderr, " -t, --nthreads=NTHREADS Number of user threads\n");
106 fprintf(stderr, " -p, --nprocs=NPROCS Number of kernel threads\n");
107 fprintf(stderr, " -b, --buflen=SIZE Number of bytes to read per request\n");
108 exit(EXIT_FAILURE);
109 }
110 }
111
112 int fd = open(__FILE__, 0);
113 if(fd < 0) {
114 fprintf(stderr, "Could not open source file\n");
115 exit(EXIT_FAILURE);
116 }
117
118 printf("Running %lu threads over %lu processors for %lf seconds\n", nthreads, nprocs, duration);
119
120 Time start, end;
121 {
122 processor procs[nprocs - 1];
123 {
124 Reader threads[nthreads];
125
126 printf("Starting\n");
127 start = getTime();
128 run = true;
129 do {
130 sleep(500`ms);
131 end = getTime();
132 } while( (end - start) < duration`s );
133 run = false;
134 end = getTime();
135 }
136 }
137 printf("Took %ld ms\n", (end - start)`ms);
138 printf("Total reads: %'zu\n", count);
139 printf("Reads per second: %'lf\n", ((double)count) / (end - start)`s);
140
141 close(fd);
142 printf("Done\n");
143}
Note: See TracBrowser for help on using the repository browser.