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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.