- Timestamp:
- Jan 14, 2021, 12:23:14 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8e4aa05
- Parents:
- 4468a70 (diff), ec19b21 (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. - Location:
- benchmark
- Files:
-
- 3 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/creation/node_cor.js
r4468a70 r342af53 6 6 function * coroutine() { yield } 7 7 8 for ( var i = 0; i < times; i += 1 ) { // warm jit8 for ( var i = 0; i < times; i += 1 ) { // warm JIT 9 9 cor = coroutine() 10 10 } -
benchmark/ctxswitch/node_cor.js
r4468a70 r342af53 11 11 cor = coroutine() 12 12 13 for ( var i = 0; i < times; i += 1 ) { // warm git13 for ( var i = 0; i < times; i += 1 ) { // warm JIT 14 14 cor.next(); 15 15 } -
benchmark/io/http/Makefile.am
r4468a70 r342af53 29 29 EXTRA_PROGRAMS = httpforall .dummy_hack 30 30 31 CLEANFILES = httpforall 32 31 33 nodist_httpforall_SOURCES = \ 32 34 filecache.cfa \ -
benchmark/io/http/main.cfa
r4468a70 r342af53 46 46 } 47 47 48 extern void init_protocol(void); 49 extern void deinit_protocol(void); 50 48 51 //============================================================================================= 49 52 // Main … … 61 64 //=================== 62 65 // Open Socket 63 printf(" Listening on port %d\n", options.socket.port);66 printf("%ld : Listening on port %d\n", getpid(), options.socket.port); 64 67 int server_fd = socket(AF_INET, SOCK_STREAM, 0); 65 68 if(server_fd < 0) { … … 79 82 ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) ); 80 83 if(ret < 0) { 81 if(errno == 98) {84 if(errno == EADDRINUSE) { 82 85 if(waited == 0) { 83 86 printf("Waiting for port\n"); … … 109 112 options.clopts.instance = &cl; 110 113 114 111 115 int pipe_cnt = options.clopts.nworkers * 2; 112 116 int pipe_off; … … 124 128 { 125 129 ServerProc procs[options.clopts.nprocs]; 130 131 init_protocol(); 126 132 { 127 133 Worker workers[options.clopts.nworkers]; … … 151 157 printf("Shutting Down\n"); 152 158 } 159 160 for(i; options.clopts.nworkers) { 161 printf("Cancelling %p\n", (void*)workers[i].cancel.target); 162 workers[i].done = true; 163 cancel(workers[i].cancel); 164 } 165 166 printf("Shutting down socket\n"); 167 int ret = shutdown( server_fd, SHUT_RD ); 168 if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); } 169 170 //=================== 171 // Close Socket 172 printf("Closing Socket\n"); 173 ret = close( server_fd ); 174 if(ret < 0) { 175 abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) ); 176 } 153 177 } 154 178 printf("Workers Closed\n"); 179 180 deinit_protocol(); 155 181 } 156 182 … … 162 188 } 163 189 free(fds); 164 }165 190 166 //===================167 // Close Socket168 printf("Closing Socket\n");169 ret = close( server_fd );170 if(ret < 0) {171 abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) );172 191 } 173 192 -
benchmark/io/http/options.cfa
r4468a70 r342af53 12 12 #include <parseargs.hfa> 13 13 14 #include <string.h> 15 14 16 Options options @= { 17 false, // log 18 15 19 { // file_cache 16 20 0, // open_flags; … … 48 52 {'p', "port", "Port the server will listen on", options.socket.port}, 49 53 {'c', "cpus", "Number of processors to use", options.clopts.nprocs}, 54 {'L', "log", "Enable logs", options.log, parse_settrue}, 50 55 {'t', "threads", "Number of worker threads to use", options.clopts.nworkers}, 51 56 {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog}, -
benchmark/io/http/options.hfa
r4468a70 r342af53 8 8 9 9 struct Options { 10 bool log; 11 10 12 struct { 11 13 int open_flags; -
benchmark/io/http/protocol.cfa
r4468a70 r342af53 18 18 #include "options.hfa" 19 19 20 const char * volatile date = 0p; 21 20 22 const char * http_msgs[] = { 21 "HTTP/1.1 200 OK\n Content-Type: text/plain\nContent-Length: %zu\n\n",22 "HTTP/1.1 400 Bad Request\n Content-Type: text/plain\nContent-Length: 0\n\n",23 "HTTP/1.1 404 Not Found\n Content-Type: text/plain\nContent-Length: 0\n\n",24 "HTTP/1.1 413 Payload Too Large\n Content-Type: text/plain\nContent-Length: 0\n\n",25 "HTTP/1.1 414 URI Too Long\n Content-Type: text/plain\nContent-Length: 0\n\n",23 "HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: %zu \n\n", 24 "HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 25 "HTTP/1.1 404 Not Found\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 26 "HTTP/1.1 413 Payload Too Large\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 27 "HTTP/1.1 414 URI Too Long\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n", 26 28 }; 27 29 … … 45 47 while(len > 0) { 46 48 // Call write 47 int ret = write(fd, it, len); 49 int ret = cfa_write(fd, it, len, 0, -1`s, 0p, 0p); 50 // int ret = write(fd, it, len); 48 51 if( ret < 0 ) { if( errno != EAGAIN && errno != EWOULDBLOCK) abort( "'answer error' error: (%d) %s\n", (int)errno, strerror(errno) ); } 49 52 … … 63 66 int answer_header( int fd, size_t size ) { 64 67 const char * fmt = http_msgs[OK200]; 65 int len = 100;68 int len = 200; 66 69 char buffer[len]; 67 len = snprintf(buffer, len, fmt, size);70 len = snprintf(buffer, len, fmt, date, size); 68 71 return answer( fd, buffer, len ); 69 72 } 70 73 71 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len) { 74 int answer_plain( int fd, char buffer[], size_t size ) { 75 int ret = answer_header(fd, size); 76 if( ret < 0 ) return ret; 77 return answer(fd, buffer, size); 78 } 79 80 int answer_empty( int fd ) { 81 return answer_header(fd, 0); 82 } 83 84 85 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len, io_cancellation * cancel) { 72 86 char * it = buffer; 73 87 size_t count = len - 1; … … 75 89 READ: 76 90 for() { 77 int ret = cfa_read(fd, (void*)it, count, 0, -1`s, 0p, 0p); 91 int ret = cfa_read(fd, (void*)it, count, 0, -1`s, cancel, 0p); 92 // int ret = read(fd, (void*)it, count); 78 93 if(ret == 0 ) return [OK200, true, 0, 0]; 79 94 if(ret < 0 ) { 80 95 if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ; 96 // if( errno == EINVAL ) return [E400, true, 0, 0]; 81 97 abort( "read error: (%d) %s\n", (int)errno, strerror(errno) ); 82 98 } … … 92 108 } 93 109 94 printf("%.*s\n", rlen, buffer);110 if( options.log ) printf("%.*s\n", rlen, buffer); 95 111 96 112 it = buffer; … … 104 120 105 121 void sendfile( int pipe[2], int fd, int ans_fd, size_t count ) { 122 unsigned sflags = SPLICE_F_MOVE; // | SPLICE_F_MORE; 106 123 off_t offset = 0; 107 124 ssize_t ret; 108 125 SPLICE1: while(count > 0) { 109 ret = cfa_splice(ans_fd, &offset, pipe[1], 0p, count, SPLICE_F_MOVE | SPLICE_F_MORE, 0, -1`s, 0p, 0p); 126 ret = cfa_splice(ans_fd, &offset, pipe[1], 0p, count, sflags, 0, -1`s, 0p, 0p); 127 // ret = splice(ans_fd, &offset, pipe[1], 0p, count, sflags); 110 128 if( ret < 0 ) { 111 129 if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE1; … … 117 135 size_t in_pipe = ret; 118 136 SPLICE2: while(in_pipe > 0) { 119 ret = cfa_splice(pipe[0], 0p, fd, 0p, in_pipe, SPLICE_F_MOVE | SPLICE_F_MORE, 0, -1`s, 0p, 0p); 137 ret = cfa_splice(pipe[0], 0p, fd, 0p, in_pipe, sflags, 0, -1`s, 0p, 0p); 138 // ret = splice(pipe[0], 0p, fd, 0p, in_pipe, sflags); 120 139 if( ret < 0 ) { 121 140 if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE2; … … 127 146 } 128 147 } 148 149 //============================================================================================= 150 151 #include <clock.hfa> 152 #include <time.hfa> 153 #include <thread.hfa> 154 155 struct date_buffer { 156 char buff[100]; 157 }; 158 159 thread DateFormater { 160 int idx; 161 date_buffer buffers[2]; 162 }; 163 164 void ?{}( DateFormater & this ) { 165 ((thread&)this){ "Server Date Thread", *options.clopts.instance }; 166 this.idx = 0; 167 memset( this.buffers[0].buff, 0, sizeof(this.buffers[0]) ); 168 memset( this.buffers[1].buff, 0, sizeof(this.buffers[1]) ); 169 } 170 171 void main(DateFormater & this) { 172 LOOP: for() { 173 waitfor( ^?{} : this) { 174 break LOOP; 175 } 176 or else {} 177 178 Time now = getTimeNsec(); 179 180 strftime( this.buffers[this.idx].buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now ); 181 182 char * next = this.buffers[this.idx].buff; 183 __atomic_exchange_n((char * volatile *)&date, next, __ATOMIC_SEQ_CST); 184 this.idx = (this.idx + 1) % 2; 185 186 sleep(1`s); 187 } 188 } 189 190 //============================================================================================= 191 DateFormater * the_date_formatter; 192 193 void init_protocol(void) { 194 the_date_formatter = alloc(); 195 (*the_date_formatter){}; 196 } 197 198 void deinit_protocol(void) { 199 ^(*the_date_formatter){}; 200 free( the_date_formatter ); 201 } -
benchmark/io/http/protocol.hfa
r4468a70 r342af53 1 1 #pragma once 2 3 struct io_cancellation; 2 4 3 5 enum HttpCode { … … 14 16 int answer_error( int fd, HttpCode code ); 15 17 int answer_header( int fd, size_t size ); 18 int answer_plain( int fd, char buffer [], size_t size ); 19 int answer_empty( int fd ); 16 20 17 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len );21 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len, io_cancellation *); 18 22 19 23 void sendfile( int pipe[2], int fd, int ans_fd, size_t count ); -
benchmark/io/http/worker.cfa
r4468a70 r342af53 19 19 this.pipe[0] = -1; 20 20 this.pipe[1] = -1; 21 this.done = false; 22 } 23 24 extern "C" { 25 extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); 21 26 } 22 27 … … 28 33 CONNECTION: 29 34 for() { 30 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, 0p, 0p ); 35 if( options.log ) printf("=== Accepting connection ===\n"); 36 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p ); 37 // int fd = accept4( this.[sockfd, addr, addrlen, flags] ); 31 38 if(fd < 0) { 32 39 if( errno == ECONNABORTED ) break; 40 if( errno == EINVAL && this.done ) break; 33 41 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 34 42 } 35 43 36 printf("New connection %d, waiting for requests\n", fd);44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd); 37 45 REQUEST: 38 46 for() { … … 45 53 size_t len = options.socket.buflen; 46 54 char buffer[len]; 47 printf("Reading request\n");48 [code, closed, file, name_size] = http_read(fd, buffer, len );55 if( options.log ) printf("=== Reading request ===\n"); 56 [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel); 49 57 50 58 // if we are done, break out of the loop 51 59 if( closed ) { 52 printf("Connection closed\n"); 60 if( options.log ) printf("=== Connection closed ===\n"); 61 close(fd); 53 62 continue CONNECTION; 54 63 } … … 56 65 // If this wasn't a request retrun 400 57 66 if( code != OK200 ) { 58 printf(" Invalid Request : %d\n", code_val(code));67 printf("=== Invalid Request : %d ===\n", code_val(code)); 59 68 answer_error(fd, code); 60 69 continue REQUEST; 61 70 } 62 71 63 printf("Request for file %.*s\n", (int)name_size, file); 72 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 73 if( options.log ) printf("=== Request for /plaintext ===\n"); 74 75 char text[] = "Hello, World!\n"; 76 77 // Send the header 78 answer_plain(fd, text, sizeof(text)); 79 80 if( options.log ) printf("=== Answer sent ===\n"); 81 continue REQUEST; 82 } 83 84 if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) { 85 if( options.log ) printf("=== Request for /ping ===\n"); 86 87 // Send the header 88 answer_empty(fd); 89 90 if( options.log ) printf("=== Answer sent ===\n"); 91 continue REQUEST; 92 } 93 94 if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file); 64 95 65 96 // Get the fd from the file cache … … 70 101 // If we can't find the file, return 404 71 102 if( ans_fd < 0 ) { 72 printf(" File Not Found\n");103 printf("=== File Not Found ===\n"); 73 104 answer_error(fd, E404); 74 105 continue REQUEST; … … 81 112 sendfile( this.pipe, fd, ans_fd, count); 82 113 83 printf("File sent\n");114 if( options.log ) printf("=== Answer sent ===\n"); 84 115 } 85 116 } -
benchmark/io/http/worker.hfa
r4468a70 r342af53 17 17 socklen_t * addrlen; 18 18 int flags; 19 io_cancellation cancel; 20 volatile bool done; 19 21 }; 20 22 void ?{}( Worker & this); -
benchmark/io/readv.cfa
r4468a70 r342af53 96 96 97 97 char **left; 98 parse_args( opt, opt_cnt, "[OPTIONS]...\ncforall yieldbenchmark", left );98 parse_args( opt, opt_cnt, "[OPTIONS]...\ncforall readv benchmark", left ); 99 99 100 100 if(kpollcp || odirect) { 101 101 if( (buflen % 512) != 0 ) { 102 102 fprintf(stderr, "Buffer length must be a multiple of 512 when using O_DIRECT, was %lu\n\n", buflen); 103 print_args_usage(opt, opt_cnt, "[OPTIONS]...\ncforall yieldbenchmark", true);103 print_args_usage(opt, opt_cnt, "[OPTIONS]...\ncforall readv benchmark", true); 104 104 } 105 105 }
Note: See TracChangeset
for help on using the changeset viewer.