source: benchmark/io/readv.cfa @ 4069faad

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 4069faad was 4069faad, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Fix error in benchmark where the wrong fd was used.
Changed behcnmark to use seperate cluster for I/O.
Changed some debug prints to use new versions with groups.
Fixed halting race condition leading to deadlock.

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