Changeset 22f94a4 for benchmark/io/readv.cfa
- Timestamp:
- Aug 11, 2020, 4:40:15 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0d070ca
- Parents:
- 07d867b (diff), 129674b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
benchmark/io/readv.cfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/readv.cfa
r07d867b r22f94a4 1 #define _GNU_SOURCE 2 1 3 #include <stdlib.h> 2 4 #include <stdio.h> … … 10 12 } 11 13 14 #include <errno.h> 12 15 #include <unistd.h> 13 16 14 17 #include <clock.hfa> 18 #include <iofwd.hfa> 15 19 #include <kernel.hfa> 16 20 #include <thread.hfa> 17 21 #include <time.hfa> 22 #include <stats.hfa> 23 24 #include "../benchcltr.hfa" 18 25 19 26 extern bool traceHeapOn(); 20 extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);21 27 22 28 int fd; … … 24 30 volatile size_t count = 0; 25 31 26 unsigned long int buflen = 50; 32 unsigned long int buflen = 512; 33 bool fixed_file = false; 27 34 28 cluster * the_cluster; 29 30 thread Reader {}; 35 thread __attribute__((aligned(128))) Reader {}; 31 36 void ?{}( Reader & this ) { 32 ((thread&)this){ "Reader Thread", *the_ cluster };37 ((thread&)this){ "Reader Thread", *the_benchmark_cluster }; 33 38 } 34 39 35 struct my_processor { 36 processor p; 37 }; 38 39 void ?{}( my_processor & this ) { 40 (this.p){ "I/O Processor", *the_cluster }; 40 int do_read(int fd, struct iovec * iov) { 41 // extern ssize_t cfa_preadv2(int, const struct iovec *, int, off_t, int, int = 0, Duration = -1`s, io_cancellation * = 0p, io_context * = 0p); 42 int sflags = 0; 43 if(fixed_file) { 44 sflags |= CFA_IO_FIXED_FD1; 45 } 46 return cfa_preadv2(fd, iov, 1, 0, 0, sflags, -1`s, 0p, 0p); 41 47 } 42 48 43 49 void main( Reader & ) { 44 while(!__atomic_load_n(&run, __ATOMIC_RELAXED)) yield(); 50 park( __cfaabi_dbg_ctx ); 51 /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) ); 45 52 46 char data[buflen];53 __attribute__((aligned(512))) char data[buflen]; 47 54 struct iovec iov = { data, buflen }; 48 55 49 56 while(__atomic_load_n(&run, __ATOMIC_RELAXED)) { 50 int r = cfa_preadv2(fd, &iov, 1, 0, 0);51 if(r < 0) abort("%s\n", strerror( -r));57 int r = do_read(fd, &iov); 58 if(r < 0) abort("%s\n", strerror(errno)); 52 59 53 60 __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST ); … … 56 63 57 64 int main(int argc, char * argv[]) { 58 double duration = 5.0; 59 unsigned long int nthreads = 2; 60 unsigned long int nprocs = 1; 61 int flags = 0; 65 BENCH_DECL 66 unsigned num_io = 1; 67 io_context_params params; 68 int file_flags = 0; 69 unsigned sublen = 16; 62 70 63 71 arg_loop: 64 72 for(;;) { 65 73 static struct option options[] = { 66 {"duration", required_argument, 0, 'd'}, 67 {"nthreads", required_argument, 0, 't'}, 68 {"nprocs", required_argument, 0, 'p'}, 69 {"bufsize", required_argument, 0, 'b'}, 70 {"userthread", no_argument , 0, 'u'}, 74 BENCH_OPT_LONG 75 {"bufsize", required_argument, 0, 'b'}, 76 {"submitthread", no_argument , 0, 's'}, 77 {"eagersubmit", no_argument , 0, 'e'}, 78 {"kpollsubmit", no_argument , 0, 'k'}, 79 {"kpollcomplete", no_argument , 0, 'i'}, 80 {"fixed-files", no_argument , 0, 'f'}, 81 {"open-direct", no_argument , 0, 'o'}, 82 {"submitlength", required_argument, 0, 'l'}, 71 83 {0, 0, 0, 0} 72 84 }; 73 85 74 86 int idx = 0; 75 int opt = getopt_long(argc, argv, "d:t:p:b:u", options, &idx);87 int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:sekil:", options, &idx); 76 88 77 89 const char * arg = optarg ? optarg : ""; … … 81 93 case -1: 82 94 break arg_loop; 83 // Numeric Arguments 84 case 'd': 85 duration = strtod(arg, &end); 86 if(*end != '\0') { 87 fprintf(stderr, "Duration must be a valid double, was %s\n", arg); 88 goto usage; 89 } 90 break; 91 case 't': 92 nthreads = strtoul(arg, &end, 10); 93 if(*end != '\0' || nthreads < 1) { 94 fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg); 95 goto usage; 96 } 97 break; 98 case 'p': 99 nprocs = strtoul(arg, &end, 10); 100 if(*end != '\0' || nprocs < 1) { 101 fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg); 102 goto usage; 103 } 104 break; 95 BENCH_OPT_CASE 105 96 case 'b': 106 97 buflen = strtoul(arg, &end, 10); … … 110 101 } 111 102 break; 112 case ' u':113 flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;103 case 's': 104 params.poller_submits = true; 114 105 break; 115 // Other cases 106 case 'e': 107 params.eager_submits = true; 108 break; 109 case 'k': 110 params.poll_submit = true; 111 case 'f': 112 fixed_file = true; 113 break; 114 case 'i': 115 params.poll_complete = true; 116 case 'o': 117 file_flags |= O_DIRECT; 118 break; 119 case 'l': 120 sublen = strtoul(arg, &end, 10); 121 if(*end != '\0' && sublen < 16) { 122 fprintf(stderr, "Submit length must be at least 16, was %s\n", arg); 123 goto usage; 124 } 125 // flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET); 126 break; 116 127 default: /* ? */ 117 128 fprintf(stderr, "%d\n", opt); 118 129 usage: 119 fprintf(stderr, "Usage: %s : [options]\n", argv[0]); 120 fprintf(stderr, "\n"); 121 fprintf(stderr, " -d, --duration=DURATION Duration of the experiment, in seconds\n"); 122 fprintf(stderr, " -t, --nthreads=NTHREADS Number of user threads\n"); 123 fprintf(stderr, " -p, --nprocs=NPROCS Number of kernel threads\n"); 124 fprintf(stderr, " -b, --buflen=SIZE Number of bytes to read per request\n"); 130 bench_usage( argv ); 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 fprintf( stderr, " -e, --eagersubmit If set, cluster submits I/O eagerly but still aggregates submits\n" ); 135 fprintf( stderr, " -k, --kpollsubmit If set, cluster uses IORING_SETUP_SQPOLL\n" ); 136 fprintf( stderr, " -i, --kpollcomplete If set, cluster uses IORING_SETUP_IOPOLL\n" ); 137 fprintf( stderr, " -l, --submitlength=LEN Max number of submitions that can be submitted together\n" ); 125 138 exit(EXIT_FAILURE); 126 139 } 127 140 } 128 141 129 fd = open(__FILE__, 0);130 if( fd < 0) {142 int lfd = open(__FILE__, file_flags); 143 if(lfd < 0) { 131 144 fprintf(stderr, "Could not open source file\n"); 132 145 exit(EXIT_FAILURE); 133 146 } 134 147 135 printf("Running % lu threads, reading %lu bytes each, over %lu processors for %lf seconds\n", nthreads, buflen, nprocs, duration);148 printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration); 136 149 137 150 { 138 151 Time start, end; 139 cluster cl = { "IO Cluster", flags }; 140 the_cluster = &cl; 141 #if !defined(__CFA_NO_STATISTICS__) 142 print_stats_at_exit( cl ); 143 #endif 152 BenchCluster cl = { num_io, params, CFA_STATS_READY_Q | CFA_STATS_IO }; 153 154 if(fixed_file) { 155 fd = 0; 156 register_fixed_files( cl.self, &lfd, 1 ); 157 } 158 else { 159 fd = lfd; 160 } 161 144 162 { 145 my_processorprocs[nprocs];163 BenchProc procs[nprocs]; 146 164 { 147 165 Reader threads[nthreads]; 148 166 149 167 printf("Starting\n"); 150 start = getTime(); 168 bool is_tty = isatty(STDOUT_FILENO); 169 start = getTimeNsec(); 151 170 run = true; 152 do { 153 sleep(500`ms); 154 end = getTime(); 155 } while( (end - start) < duration`s ); 171 172 for(i; nthreads) { 173 unpark( threads[i] __cfaabi_dbg_ctx2 ); 174 } 175 wait(duration, start, end, is_tty); 176 156 177 run = false; 157 end = getTime ();158 printf(" Done\n");178 end = getTimeNsec(); 179 printf("\nDone\n"); 159 180 } 181 printf("Readers closed\n"); 160 182 } 161 183 printf("Took %'ld ms\n", (end - start)`ms); … … 166 188 } 167 189 168 close( fd);190 close(lfd); 169 191 }
Note:
See TracChangeset
for help on using the changeset viewer.