Ignore:
Timestamp:
Jul 23, 2020, 3:37:05 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
f4ec4a90
Parents:
f0c3120 (diff), e262b5e (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

File:
1 edited

Legend:

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

    rf0c3120 r04b73b6  
    1717#include "filecache.hfa"
    1818#include "options.hfa"
    19 #include "parseargs.hfa"
    2019#include "worker.hfa"
    2120
     
    2322// Globals
    2423//=============================================================================================
    25 Options options @= {
    26         0,
    27         42u,
    28         0,
    29         false,
    30         false,
    31         0
    32 };
    33 
    3424channel & wait_connect;
    3525
     
    3929
    4030void ?{}( ServerProc & this ) {
    41         /* paranoid */ assert( options.the_cluster != 0p );
    42         (this.self){ "Benchmark Processor", *options.the_cluster };
     31        /* paranoid */ assert( options.clopts.instance != 0p );
     32        (this.self){ "Benchmark Processor", *options.clopts.instance };
    4333
    4434        #if !defined(__CFA_NO_STATISTICS__)
    45                 if( options.procstats ) {
    46                         print_stats_at_exit( this.self, options.the_cluster->print_stats );
     35                if( options.clopts.procstats ) {
     36                        print_stats_at_exit( this.self, options.clopts.instance->print_stats );
    4737                }
    48                 if( options.viewhalts ) {
     38                if( options.clopts.viewhalts ) {
    4939                        print_halts( this.self );
    5040                }
     
    5646//============================================================================================='
    5747int main( int argc, char * argv[] ) {
    58         int port      = 8080;
    59         int backlog   = 10;
    60         int nprocs    = 1;
    61         int nworkers  = 1;
    62         int cl_flags  = 0;
    63         int chan_size = 10;
    64         const char * path = ".";
    6548        //===================
    6649        // Parse args
    67         static cfa_option opt[] = {
    68                 {'p', "port", "Port the server will listen on", port},
    69                 {'c', "cpus", "Number of processors to use", nprocs},
    70                 {'t', "threads", "Number of worker threads to use", nworkers},
    71                 {'b', "accept-backlog", "Maximum number of pending accepts", backlog},
    72                 {'B', "channel-size", "Maximum number of accepted connection pending", chan_size}
    73         };
    74         int opt_cnt = sizeof(opt) / sizeof(cfa_option);
    75 
    76         char **left;
    77       parse_args( argc, argv, opt, opt_cnt, "[OPTIONS] [PATH]  -- cforall http server", left );
    78 
     50        const char * path = parse_options(argc, argv);
    7951
    8052        //===================
     
    8557        //===================
    8658        // Open Socket
    87         printf("Listening on port %d\n", port);
     59        printf("Listening on port %d\n", options.socket.port);
    8860        int server_fd = socket(AF_INET, SOCK_STREAM, 0);
    8961        if(server_fd < 0) {
     
    9769        address.sin_family = AF_INET;
    9870        address.sin_addr.s_addr = htonl(INADDR_ANY);
    99         address.sin_port = htons( port );
     71        address.sin_port = htons( options.socket.port );
    10072
    10173        ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) );
     
    10476        }
    10577
    106         ret = listen( server_fd, backlog );
     78        ret = listen( server_fd, options.socket.backlog );
    10779        if(ret < 0) {
    10880                abort( "listen error: (%d) %s\n", (int)errno, strerror(errno) );
     
    11284        // Run Server Cluster
    11385        {
    114                 cluster cl = { "Server Cluster", cl_flags };
     86                cluster cl = { "Server Cluster", options.clopts.flags };
    11587                #if !defined(__CFA_NO_STATISTICS__)
    11688                        print_stats_at_exit( cl, CFA_STATS_READY_Q | CFA_STATS_IO );
    11789                #endif
    118                 options.the_cluster = &cl;
     90                options.clopts.instance = &cl;
    11991
    120                 channel chan = { chan_size };
     92                channel chan = { options.clopts.chan_size };
    12193                &wait_connect = &chan;
    12294
     95                int pipe_cnt = options.clopts.nworkers * 2;
     96                int pipe_off;
     97                int * fds;
     98                [fds, pipe_off] = filefds( pipe_cnt );
     99                for(i; 0 ~ pipe_cnt ~ 2) {
     100                        int ret = pipe(&fds[pipe_off + i]);
     101                        if( ret < 0 ) { abort( "pipe error: (%d) %s\n", (int)errno, strerror(errno) ); }
     102                }
     103
    123104                {
    124                         ServerProc procs[nprocs];
     105                        ServerProc procs[options.clopts.nprocs];
    125106                        {
    126                                 Worker workers[nworkers];
    127                                 printf("%d workers started on %d processors\n", nworkers, nprocs);
     107                                Worker workers[options.clopts.nworkers];
     108                                for(i; options.clopts.nworkers) {
     109                                        if( options.file_cache.fixed_fds ) {
     110                                                workers[i].pipe[0] = pipe_off + (i * 2) + 0;
     111                                                workers[i].pipe[1] = pipe_off + (i * 2) + 1;
     112                                        }
     113                                        else {
     114                                                workers[i].pipe[0] = fds[pipe_off + (i * 2) + 0];
     115                                                workers[i].pipe[1] = fds[pipe_off + (i * 2) + 1];
     116                                        }
     117                                        unpark( workers[i] __cfaabi_dbg_ctx2 );
     118                                }
     119                                printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs);
    128120                                {
    129121                                        Acceptor acceptor = { server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen, 0 };
     122
     123                                        char buffer[128];
     124                                        while(!feof(stdin)) {
     125                                                fgets(buffer, 128, stdin);
     126                                        }
     127
     128                                        printf("Shutting Down\n");
    130129                                }
    131                                 printf("Shutting Down\n");
     130                                printf("Acceptor Closed\n");
    132131
    133132                                // Clean-up the workers
    134                                 for(nworkers) {
     133                                for(options.clopts.nworkers) {
    135134                                        put( wait_connect, -1 );
    136135                                }
    137136                        }
     137                        printf("Workers Closed\n");
    138138                }
     139
     140                for(i; pipe_cnt) {
     141                        ret = close( fds[pipe_off + i] );
     142                        if(ret < 0) {
     143                                abort( "close pipe error: (%d) %s\n", (int)errno, strerror(errno) );
     144                        }
     145                }
     146                free(fds);
    139147        }
    140148
Note: See TracChangeset for help on using the changeset viewer.