source: benchmark/io/readv.cfa @ 61dd73d

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

Moved io_uring data to io.cfa and create it using dynamic allocation.

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