source: benchmark/io/readv.cfa @ f6660520

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

Added new implementation of io_uring that uses user-thread

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