source: benchmark/io/readv.cfa@ 44aad8f

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 44aad8f was 038be32, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

added defines and bool for whether or not to print statistics

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