source: benchmark/io/readv.cfa @ 8e27ac45

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

Fixed benchmark to use getTimeNsec

  • Property mode set to 100644
File size: 4.7 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#include "../benchcltr.hfa"
20
21extern bool traceHeapOn();
22extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
23
24int fd;
25volatile bool run = false;
26volatile size_t count = 0;
27
28unsigned long int buflen = 50;
29
30thread __attribute__((aligned(128))) Reader {};
31void ?{}( Reader & this ) {
32        ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
33}
34
35void main( Reader & ) {
36        park( __cfaabi_dbg_ctx );
37        /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
38
39        char data[buflen];
40        struct iovec iov = { data, buflen };
41
42        while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
43                int r = cfa_preadv2(fd, &iov, 1, 0, 0);
44                if(r < 0) abort("%s\n", strerror(-r));
45
46                __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
47        }
48}
49
50int main(int argc, char * argv[]) {
51        double duration   = 5.0;
52        unsigned long int nthreads = 2;
53        unsigned long int nprocs   = 1;
54        unsigned flags = 0;
55        unsigned sublen = 16;
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                        {"userthread",   no_argument      , 0, 'u'},
65                        {"submitthread", no_argument      , 0, 's'},
66                        {"submitlength", required_argument, 0, 'l'},
67                        {0, 0, 0, 0}
68                };
69
70                int idx = 0;
71                int opt = getopt_long(argc, argv, "d:t:p:b:usl:", options, &idx);
72
73                const char * arg = optarg ? optarg : "";
74                char * end;
75                switch(opt) {
76                        // Exit Case
77                        case -1:
78                                break arg_loop;
79                        // Numeric Arguments
80                        case 'd':
81                                duration = strtod(arg, &end);
82                                if(*end != '\0') {
83                                        fprintf(stderr, "Duration must be a valid double, was %s\n", arg);
84                                        goto usage;
85                                }
86                                break;
87                        case 't':
88                                nthreads = strtoul(arg, &end, 10);
89                                if(*end != '\0' || nthreads < 1) {
90                                        fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg);
91                                        goto usage;
92                                }
93                                break;
94                        case 'p':
95                                nprocs = strtoul(arg, &end, 10);
96                                if(*end != '\0' || nprocs < 1) {
97                                        fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg);
98                                        goto usage;
99                                }
100                                break;
101                        case 'b':
102                                buflen = strtoul(arg, &end, 10);
103                                if(*end != '\0' && buflen < 10) {
104                                        fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
105                                        goto usage;
106                                }
107                                break;
108                        case 'u':
109                                flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
110                                break;
111                        case 's':
112                                flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS;
113                                break;
114                        case 'l':
115                                sublen = strtoul(arg, &end, 10);
116                                if(*end != '\0' && sublen < 16) {
117                                        fprintf(stderr, "Submit length must be at least 16, was %s\n", arg);
118                                        goto usage;
119                                }
120                                flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
121                                break;
122                        // Other cases
123                        default: /* ? */
124                                fprintf(stderr, "%d\n", opt);
125                        usage:
126                                fprintf(stderr, "Usage: %s : [options]\n", argv[0]);
127                                fprintf(stderr, "\n");
128                                fprintf(stderr, "  -d, --duration=DURATION  Duration of the experiment, in seconds\n");
129                                fprintf(stderr, "  -t, --nthreads=NTHREADS  Number of user threads\n");
130                                fprintf(stderr, "  -p, --nprocs=NPROCS      Number of kernel threads\n");
131                                fprintf(stderr, "  -b, --buflen=SIZE        Number of bytes to read per request\n");
132                                fprintf(stderr, "  -u, --userthread         If set, cluster uses user-thread to poll I/O\n");
133                                fprintf(stderr, "  -s, --submitthread       If set, cluster uses polling thread to submit I/O\n");
134                                exit(EXIT_FAILURE);
135                }
136        }
137
138        fd = open(__FILE__, 0);
139        if(fd < 0) {
140                fprintf(stderr, "Could not open source file\n");
141                exit(EXIT_FAILURE);
142        }
143
144        printf("Running %lu threads, reading %lu bytes each, over %lu processors for %lf seconds\n", nthreads, buflen, nprocs, duration);
145
146        {
147                Time start, end;
148                BenchCluster cl = { flags };
149                #if !defined(__CFA_NO_STATISTICS__)
150                        print_stats_at_exit( cl.self );
151                #endif
152                {
153                        BenchProc procs[nprocs];
154                        {
155                                Reader threads[nthreads];
156
157                                printf("Starting\n");
158                                bool is_tty = isatty(STDOUT_FILENO);
159                                start = getTimeNsec();
160                                run = true;
161
162                                for(i; nthreads) {
163                                        unpark( threads[i] __cfaabi_dbg_ctx2 );
164                                }
165                                wait(duration, start, end, is_tty);
166
167                                run = false;
168                                end = getTimeNsec();
169                                printf("\nDone\n");
170                        }
171                }
172                printf("Took %'ld ms\n", (end - start)`ms);
173                printf("Total reads      : %'15zu\n", count);
174                printf("Reads per second : %'18.2lf\n", ((double)count) / (end - start)`s);
175                printf("Total read size  : %'15zu\n", buflen * count);
176                printf("Bytes per second : %'18.2lf\n", ((double)count * buflen) / (end - start)`s);
177        }
178
179        close(fd);
180}
Note: See TracBrowser for help on using the repository browser.