Changeset d95969a for benchmark


Ignore:
Timestamp:
Jan 25, 2021, 3:45:42 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c292244
Parents:
b6a8b31 (diff), 7158202 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
benchmark/io
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/filecache.cfa

    rb6a8b31 rd95969a  
    44#include <string.h>
    55
     6#include <fstream.hfa>
    67#include <stdlib.hfa>
    78
     
    182183                conflicts += put_file( raw[i], fd );
    183184        }
    184         printf("Filled cache from path \"%s\" with %zu files\n", path, fcount);
     185        sout | "Filled cache from path \"" | path | "\" with" | fcount | "files";
    185186        if( conflicts > 0 ) {
    186                 printf("Found %d conflicts (seed: %u)\n", conflicts, options.file_cache.hash_seed);
     187                sout | "Found" | conflicts | "conflicts (seed: " | options.file_cache.hash_seed | ")";
    187188                #if defined(REJECT_CONFLICTS)
    188189                        abort("Conflicts found in the cache");
     
    191192
    192193        if(options.file_cache.list) {
    193                 printf("Listing files and exiting\n");
     194                sout | "Listing files and exiting";
    194195                for(i; fcount) {
    195196                        int s; char u;
    196197                        [s, u] = human_size(raw[i].size);
    197                         printf("%4d%c - %s\n", s, u, raw[i].file);
     198                        sout | s | u | "-" | raw[i].file;
    198199                        free(raw[i].file);
    199200                }
     
    208209
    209210[int *, int] filefds(int extra) {
     211        if(!options.file_cache.path) {
     212                int * data = alloc(extra);
     213                return [data, 0];
     214        }
     215
    210216        if(!file_cache.entries) {
    211217                abort("File cache not filled!\n");
  • benchmark/io/http/main.cfa

    rb6a8b31 rd95969a  
    66#include <unistd.h>
    77extern "C" {
     8        #include <signal.h>
    89        #include <sys/socket.h>
    910        #include <netinet/in.h>
    1011}
    1112
     13#include <fstream.hfa>
    1214#include <kernel.hfa>
     15#include <iofwd.hfa>
    1316#include <stats.hfa>
    1417#include <time.hfa>
     
    5053
    5154//=============================================================================================
     55// Stats Printer
     56//============================================================================================='
     57
     58thread StatsPrinter {};
     59
     60void ?{}( StatsPrinter & this ) {
     61        ((thread&)this){ "Stats Printer Thread" };
     62}
     63
     64void main(StatsPrinter & this) {
     65        LOOP: for() {
     66                waitfor( ^?{} : this) {
     67                        break LOOP;
     68                }
     69                or else {}
     70
     71                sleep(10`s);
     72
     73                print_stats_now( *options.clopts.instance, CFA_STATS_READY_Q | CFA_STATS_IO );
     74        }
     75}
     76
     77//=============================================================================================
    5278// Main
    5379//============================================================================================='
    5480int main( int argc, char * argv[] ) {
     81        __sighandler_t s = 1p;
     82        signal(SIGPIPE, s);
     83
    5584        //===================
    5685        // Parse args
    57         const char * path = parse_options(argc, argv);
     86        parse_options(argc, argv);
    5887
    5988        //===================
    6089        // Open Files
    61         printf("Filling cache from %s\n", path);
    62         fill_cache( path );
     90        if( options.file_cache.path ) {
     91                sout | "Filling cache from" | options.file_cache.path;
     92                fill_cache( options.file_cache.path );
     93        }
    6394
    6495        //===================
    6596        // Open Socket
    66         printf("%ld : Listening on port %d\n", getpid(), options.socket.port);
     97        sout | getpid() | ": Listening on port" | options.socket.port;
    6798        int server_fd = socket(AF_INET, SOCK_STREAM, 0);
    6899        if(server_fd < 0) {
     
    84115                        if(errno == EADDRINUSE) {
    85116                                if(waited == 0) {
    86                                         printf("Waiting for port\n");
     117                                        sout | "Waiting for port";
    87118                                } else {
    88                                         printf("\r%d", waited);
    89                                         fflush(stdout);
     119                                        sout | "\r" | waited | nonl;
     120                                        flush( sout );
    90121                                }
    91122                                waited ++;
     
    122153                }
    123154
    124                 if(options.file_cache.fixed_fds) {
     155                if(options.file_cache.path && options.file_cache.fixed_fds) {
    125156                        register_fixed_files(cl, fds, pipe_off);
    126157                }
     
    128159                {
    129160                        ServerProc procs[options.clopts.nprocs];
     161                        StatsPrinter printer;
    130162
    131163                        init_protocol();
     
    148180                                        unpark( workers[i] );
    149181                                }
    150                                 printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs);
     182                                sout | options.clopts.nworkers | "workers started on" | options.clopts.nprocs | "processors";
    151183                                {
    152184                                        char buffer[128];
    153                                         while(!feof(stdin)) {
    154                                                 fgets(buffer, 128, stdin);
     185                                        while(int ret = cfa_read(0, buffer, 128, 0, -1`s, 0p, 0p); ret != 0) {
     186                                                if(ret < 0) abort( "main read error: (%d) %s\n", (int)errno, strerror(errno) );
    155187                                        }
    156188
    157                                         printf("Shutting Down\n");
    158                                 }
    159 
     189                                        sout | "Shutdown received";
     190                                }
     191
     192                                sout | "Notifying connections..." | nonl; flush( sout );
    160193                                for(i; options.clopts.nworkers) {
    161                                         printf("Cancelling %p\n", (void*)workers[i].cancel.target);
    162194                                        workers[i].done = true;
    163195                                        cancel(workers[i].cancel);
    164196                                }
    165 
    166                                 printf("Shutting down socket\n");
     197                                sout | "done";
     198
     199                                sout | "Shutting down socket..." | nonl; flush( sout );
    167200                                int ret = shutdown( server_fd, SHUT_RD );
    168                                 if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); }
     201                                if( ret < 0 ) {
     202                                        abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) );
     203                                }
     204                                sout | "done";
    169205
    170206                                //===================
    171207                                // Close Socket
    172                                 printf("Closing Socket\n");
     208                                sout | "Closing Socket..." | nonl; flush( sout );
    173209                                ret = close( server_fd );
    174210                                if(ret < 0) {
    175211                                        abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) );
    176212                                }
     213                                sout | "done";
     214
     215                                sout | "Stopping connection threads..." | nonl; flush( sout );
    177216                        }
    178                         printf("Workers Closed\n");
    179 
     217                        sout | "done";
     218
     219                        sout | "Stopping protocol threads..." | nonl; flush( sout );
    180220                        deinit_protocol();
    181                 }
    182 
     221                        sout | "done";
     222
     223                        sout | "Stopping processors..." | nonl; flush( sout );
     224                }
     225                sout | "done";
     226
     227                sout | "Closing splice fds..." | nonl; flush( sout );
    183228                for(i; pipe_cnt) {
    184229                        ret = close( fds[pipe_off + i] );
     
    188233                }
    189234                free(fds);
    190 
    191         }
     235                sout | "done";
     236
     237                sout | "Stopping processors..." | nonl; flush( sout );
     238        }
     239        sout | "done";
    192240
    193241        //===================
    194242        // Close Files
    195         printf("Closing Files\n");
    196         close_cache();
    197 }
     243        if( options.file_cache.path ) {
     244                sout | "Closing open files..." | nonl; flush( sout );
     245                close_cache();
     246                sout | "done";
     247        }
     248}
  • benchmark/io/http/options.cfa

    rb6a8b31 rd95969a  
    99}
    1010
     11#include <bitmanip.hfa>
     12#include <fstream.hfa>
    1113#include <kernel.hfa>
    1214#include <parseargs.hfa>
    1315
     16#include <stdlib.h>
    1417#include <string.h>
    1518
     
    1821
    1922        { // file_cache
     23                0,     // path
    2024                0,     // open_flags;
    2125                42u,   // hash_seed;
     
    3438                1,     // nprocs;
    3539                1,     // nworkers;
    36                 0,     // flags;
     40                {},     // params;
    3741                false, // procstats
    3842                false, // viewhalts
     
    4145};
    4246
    43 const char * parse_options( int argc, char * argv[] ) {
     47void parse_options( int argc, char * argv[] ) {
    4448        bool subthrd = false;
    4549        bool eagrsub = false;
     
    4852        bool iokpoll = false;
    4953        unsigned sublen = 16;
     54        unsigned nentries = 16;
     55
    5056
    5157        static cfa_option opt[] = {
    52                 {'p', "port",           "Port the server will listen on", options.socket.port},
    53                 {'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
    54                 {'L', "log",            "Enable logs", options.log, parse_settrue},
    55                 {'t', "threads",        "Number of worker threads to use", options.clopts.nworkers},
    56                 {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
    57                 {'r', "request_len",    "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen},
    58                 {'S', "seed",           "seed to use for hashing", options.file_cache.hash_seed },
    59                 {'C', "cache-size",     "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
    60                 {'l', "list-files",     "List the files in the specified path and exit", options.file_cache.list, parse_settrue },
    61                 {'s', "submitthread",   "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue },
    62                 {'e', "eagersubmit",    "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue},
    63                 {'f', "fixed-fds",      "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
    64                 {'k', "kpollsubmit",    "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
    65                 {'i', "kpollcomplete",  "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
    66                 {'L', "submitlength",   "Max number of submitions that can be submitted together", sublen },
     58                { 'p', "port",           "Port the server will listen on", options.socket.port},
     59                { 'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
     60                { 't', "threads",        "Number of worker threads to use", options.clopts.nworkers},
     61                {'\0', "log",            "Enable logs", options.log, parse_settrue},
     62                {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
     63                {'\0', "request_len",    "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen},
     64                {'\0', "seed",           "seed to use for hashing", options.file_cache.hash_seed },
     65                {'\0', "cache-size",     "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
     66                {'\0', "list-files",     "List the files in the specified path and exit", options.file_cache.list, parse_settrue },
     67                { 's', "submitthread",   "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue },
     68                { 'e', "eagersubmit",    "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue},
     69                { 'f', "fixed-fds",      "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
     70                { 'k', "kpollsubmit",    "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
     71                { 'i', "kpollcomplete",  "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
     72                {'\0', "submitlength",   "Max number of submitions that can be submitted together", sublen },
     73                {'\0', "numentries",     "Number of I/O entries", nentries },
    6774
    6875        };
     
    7178        char **left;
    7279        parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left );
     80
     81        if( !is_pow2(nentries) ) {
     82                unsigned v = nentries;
     83                v--;
     84                v |= v >> 1;
     85                v |= v >> 2;
     86                v |= v >> 4;
     87                v |= v >> 8;
     88                v |= v >> 16;
     89                v++;
     90                serr | "Warning: num_entries not a power of 2" | '(' | nentries | ')' | "raising to " | v;
     91                nentries = v;
     92        }
     93        options.clopts.params.num_entries = nentries;
    7394
    7495        options.clopts.params.poller_submits = subthrd;
     
    91112        options.clopts.params.num_ready = sublen;
    92113
    93         if( left[0] == 0p ) { return "."; }
     114        if( left[0] == 0p ) { return; }
    94115
    95116        const char * path = left[0];
     
    97118
    98119        if( left[0] != 0p ) {
    99                 abort("Too many trailing arguments!\n");
     120                serr | "Too many trailing arguments!" | '\'' | path | '\'';
     121                while(left[0] != 0p) {
     122                        serr | " - " | left[0];
     123                        left++;
     124                }
     125                exit(EXIT_FAILURE);
    100126        }
    101127
    102         return path;
     128        options.file_cache.path = path;
    103129}
  • benchmark/io/http/options.hfa

    rb6a8b31 rd95969a  
    1111
    1212        struct {
     13                const char * path;
    1314                int open_flags;
    1415                uint32_t hash_seed;
     
    3637extern Options options;
    3738
    38 const char * parse_options( int argc, char * argv[] );
     39void parse_options( int argc, char * argv[] );
  • benchmark/io/http/protocol.cfa

    rb6a8b31 rd95969a  
    55        #include <fcntl.h>
    66}
     7
     8#include <fstream.hfa>
    79#include <iofwd.hfa>
    810
     
    1113extern "C" {
    1214      int snprintf ( char * s, size_t n, const char * format, ... );
    13         #include <linux/io_uring.h>
     15        // #include <linux/io_uring.h>
    1416}
    1517#include <string.h>
     
    2426        "HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2527        "HTTP/1.1 404 Not Found\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
     28        "HTTP/1.1 405 Method Not Allowed\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
     29        "HTTP/1.1 408 Request Timeout\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2630        "HTTP/1.1 413 Payload Too Large\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2731        "HTTP/1.1 414 URI Too Long\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
     
    3438        400,
    3539        404,
     40        405,
     41        408,
    3642        413,
    3743        414,
     
    4955                int ret = cfa_write(fd, it, len, 0, -1`s, 0p, 0p);
    5056                // int ret = write(fd, it, len);
    51                 if( ret < 0 ) { if( errno != EAGAIN && errno != EWOULDBLOCK) abort( "'answer error' error: (%d) %s\n", (int)errno, strerror(errno) ); }
     57                if( ret < 0 ) {
     58                        if( errno == ECONNRESET || errno == EPIPE ) return -ECONNRESET;
     59                        if( errno == EAGAIN || errno == EWOULDBLOCK) return -EAGAIN;
     60
     61                        abort( "'answer error' error: (%d) %s\n", (int)errno, strerror(errno) );
     62                }
    5263
    5364                // update it/len
     
    94105                if(ret < 0 ) {
    95106                        if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ;
    96                         // if( errno == EINVAL ) return [E400, true, 0, 0];
     107                        if( errno == ECONNRESET ) return [E408, true, 0, 0];
     108                        if( errno == EPIPE ) return [E408, true, 0, 0];
    97109                        abort( "read error: (%d) %s\n", (int)errno, strerror(errno) );
    98110                }
     
    108120        }
    109121
    110         if( options.log ) printf("%.*s\n", rlen, buffer);
     122        if( options.log ) {
     123                write(sout, buffer, rlen);
     124                sout | nl;
     125        }
    111126
    112127        it = buffer;
     
    119134}
    120135
    121 void sendfile( int pipe[2], int fd, int ans_fd, size_t count ) {
     136int sendfile( int pipe[2], int fd, int ans_fd, size_t count ) {
    122137        unsigned sflags = SPLICE_F_MOVE; // | SPLICE_F_MORE;
    123138        off_t offset = 0;
     
    128143                if( ret < 0 ) {
    129144                        if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE1;
     145                        if( errno == ECONNRESET ) return -ECONNRESET;
     146                        if( errno == EPIPE ) return -EPIPE;
    130147                        abort( "splice [0] error: (%d) %s\n", (int)errno, strerror(errno) );
    131148                }
     
    139156                        if( ret < 0 ) {
    140157                                if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE2;
     158                                if( errno == ECONNRESET ) return -ECONNRESET;
     159                                if( errno == EPIPE ) return -EPIPE;
    141160                                abort( "splice [1] error: (%d) %s\n", (int)errno, strerror(errno) );
    142161                        }
     
    145164
    146165        }
     166        return count;
    147167}
    148168
  • benchmark/io/http/protocol.hfa

    rb6a8b31 rd95969a  
    77        E400,
    88        E404,
     9        E405,
     10        E408,
    911        E413,
    1012        E414,
     
    2123[HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len, io_cancellation *);
    2224
    23 void sendfile( int pipe[2], int fd, int ans_fd, size_t count );
     25int sendfile( int pipe[2], int fd, int ans_fd, size_t count );
  • benchmark/io/http/worker.cfa

    rb6a8b31 rd95969a  
    66#include <unistd.h>
    77
     8#include <fstream.hfa>
    89#include <iofwd.hfa>
    910
     
    3334        CONNECTION:
    3435        for() {
    35                 if( options.log ) printf("=== Accepting connection ===\n");
     36                if( options.log ) sout | "=== Accepting connection ===";
    3637                int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p );
    3738                // int fd = accept4( this.[sockfd, addr, addrlen, flags] );
    3839                if(fd < 0) {
    3940                        if( errno == ECONNABORTED ) break;
    40                         if( errno == EINVAL && this.done ) break;
     41                        if( this.done && (errno == EINVAL || errno == EBADF) ) break;
    4142                        abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    4243                }
    4344
    44                 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);
     45                if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ===";
    4546                REQUEST:
    4647                for() {
     
    5354                        size_t len = options.socket.buflen;
    5455                        char buffer[len];
    55                         if( options.log ) printf("=== Reading request ===\n");
     56                        if( options.log ) sout | "=== Reading request ===";
    5657                        [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel);
    5758
    5859                        // if we are done, break out of the loop
    59                         if( closed ) {
    60                                 if( options.log ) printf("=== Connection closed ===\n");
    61                                 close(fd);
    62                                 continue CONNECTION;
    63                         }
     60                        if( closed ) break REQUEST;
    6461
    6562                        // If this wasn't a request retrun 400
    6663                        if( code != OK200 ) {
    67                                 printf("=== Invalid Request : %d ===\n", code_val(code));
     64                                sout | "=== Invalid Request :" | code_val(code) | "===";
    6865                                answer_error(fd, code);
    6966                                continue REQUEST;
     
    7168
    7269                        if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    73                                 if( options.log ) printf("=== Request for /plaintext ===\n");
     70                                if( options.log ) sout | "=== Request for /plaintext ===";
    7471
    7572                                char text[] = "Hello, World!\n";
    7673
    7774                                // Send the header
    78                                 answer_plain(fd, text, sizeof(text));
     75                                int ret = answer_plain(fd, text, sizeof(text));
     76                                if( ret == -ECONNRESET ) break REQUEST;
    7977
    80                                 if( options.log ) printf("=== Answer sent ===\n");
     78                                if( options.log ) sout | "=== Answer sent ===";
    8179                                continue REQUEST;
    8280                        }
    8381
    8482                        if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) {
    85                                 if( options.log ) printf("=== Request for /ping ===\n");
     83                                if( options.log ) sout | "=== Request for /ping ===";
    8684
    8785                                // Send the header
    88                                 answer_empty(fd);
     86                                int ret = answer_empty(fd);
     87                                if( ret == -ECONNRESET ) break REQUEST;
    8988
    90                                 if( options.log ) printf("=== Answer sent ===\n");
     89                                if( options.log ) sout | "=== Answer sent ===";
    9190                                continue REQUEST;
    9291                        }
    9392
    94                         if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file);
     93                        if( options.log ) {
     94                                sout | "=== Request for file " | nonl;
     95                                write(sout, file, name_size);
     96                                sout | " ===";
     97                        }
     98
     99                        if( !options.file_cache.path ) {
     100                                if( options.log ) {
     101                                        sout | "=== File Not Found (" | nonl;
     102                                        write(sout, file, name_size);
     103                                        sout | ") ===";
     104                                }
     105                                answer_error(fd, E405);
     106                                continue REQUEST;
     107                        }
    95108
    96109                        // Get the fd from the file cache
     
    101114                        // If we can't find the file, return 404
    102115                        if( ans_fd < 0 ) {
    103                                 printf("=== File Not Found ===\n");
     116                                if( options.log ) {
     117                                        sout | "=== File Not Found (" | nonl;
     118                                        write(sout, file, name_size);
     119                                        sout | ") ===";
     120                                }
    104121                                answer_error(fd, E404);
    105122                                continue REQUEST;
     
    107124
    108125                        // Send the header
    109                         answer_header(fd, count);
     126                        int ret = answer_header(fd, count);
     127                        if( ret == -ECONNRESET ) break REQUEST;
    110128
    111129                        // Send the desired file
    112                         sendfile( this.pipe, fd, ans_fd, count);
     130                        ret = sendfile( this.pipe, fd, ans_fd, count);
     131                        if( ret == -ECONNRESET ) break REQUEST;
    113132
    114                         if( options.log ) printf("=== Answer sent ===\n");
     133                        if( options.log ) sout | "=== Answer sent ===";
    115134                }
     135
     136                if( options.log ) sout | "=== Connection closed ===";
     137                close(fd);
     138                continue CONNECTION;
    116139        }
    117140}
Note: See TracChangeset for help on using the changeset viewer.