Changeset d46bdac


Ignore:
Timestamp:
Jan 15, 2021, 3:01:31 PM (3 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
77ff383
Parents:
2d63023 (diff), b7664a0 (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

Files:
9 edited

Legend:

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

    r2d63023 rd46bdac  
    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                }
  • benchmark/io/http/main.cfa

    r2d63023 rd46bdac  
    1010}
    1111
     12#include <fstream.hfa>
    1213#include <kernel.hfa>
    1314#include <iofwd.hfa>
     
    8384        //===================
    8485        // Open Files
    85         printf("Filling cache from %s\n", path);
     86        sout | "Filling cache from" | path;
    8687        fill_cache( path );
    8788
    8889        //===================
    8990        // Open Socket
    90         printf("%ld : Listening on port %d\n", getpid(), options.socket.port);
     91        sout | getpid() | ": Listening on port" | options.socket.port;
    9192        int server_fd = socket(AF_INET, SOCK_STREAM, 0);
    9293        if(server_fd < 0) {
     
    108109                        if(errno == EADDRINUSE) {
    109110                                if(waited == 0) {
    110                                         printf("Waiting for port\n");
     111                                        sout | "Waiting for port";
    111112                                } else {
    112                                         printf("\r%d", waited);
    113                                         fflush(stdout);
     113                                        sout | "\r" | waited | nonl;
     114                                        flush( sout );
    114115                                }
    115116                                waited ++;
     
    173174                                        unpark( workers[i] );
    174175                                }
    175                                 printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs);
     176                                sout | options.clopts.nworkers | "workers started on" | options.clopts.nprocs | "processors";
    176177                                {
    177178                                        char buffer[128];
     
    180181                                        }
    181182
    182                                         printf("Shutting Down\n");
    183                                 }
    184 
     183                                        sout | "Shutdown received";
     184                                }
     185
     186                                sout | "Notifying connections";
    185187                                for(i; options.clopts.nworkers) {
    186188                                        workers[i].done = true;
     
    188190                                }
    189191
    190                                 printf("Shutting down socket\n");
     192                                sout | "Shutting down socket";
    191193                                int ret = shutdown( server_fd, SHUT_RD );
    192194                                if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); }
     
    194196                                //===================
    195197                                // Close Socket
    196                                 printf("Closing Socket\n");
     198                                sout | "Closing Socket";
    197199                                ret = close( server_fd );
    198200                                if(ret < 0) {
    199201                                        abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) );
    200202                                }
     203                                sout | "Stopping connection threads..." | nonl;
    201204                        }
    202                         printf("Workers Closed\n");
    203 
     205                        sout | "done";
     206
     207                        sout | "Stopping protocol threads..." | nonl;
    204208                        deinit_protocol();
    205                 }
    206 
     209                        sout | "done";
     210
     211                        sout | "Stopping processors..." | nonl;
     212                }
     213                sout | "done";
     214
     215                sout | "Closing splice fds..." | nonl;
    207216                for(i; pipe_cnt) {
    208217                        ret = close( fds[pipe_off + i] );
     
    212221                }
    213222                free(fds);
    214 
    215         }
     223                sout | "done";
     224
     225                sout | "Stopping processors..." | nonl;
     226        }
     227        sout | "done";
    216228
    217229        //===================
    218230        // Close Files
    219         printf("Closing Files\n");
     231        sout | "Closing open files..." | nonl;
    220232        close_cache();
    221 }
     233        sout | "done";
     234}
  • benchmark/io/http/protocol.cfa

    r2d63023 rd46bdac  
    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>
     
    115117        }
    116118
    117         if( options.log ) printf("%.*s\n", rlen, buffer);
     119        if( options.log ) {
     120                write(sout, buffer, rlen);
     121                sout | nl;
     122        }
    118123
    119124        it = buffer;
  • benchmark/io/http/worker.cfa

    r2d63023 rd46bdac  
    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] );
     
    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
     
    6162                        // If this wasn't a request retrun 400
    6263                        if( code != OK200 ) {
    63                                 printf("=== Invalid Request : %d ===\n", code_val(code));
     64                                sout | "=== Invalid Request :" | code_val(code) | "===";
    6465                                answer_error(fd, code);
    6566                                continue REQUEST;
     
    6768
    6869                        if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    69                                 if( options.log ) printf("=== Request for /plaintext ===\n");
     70                                if( options.log ) sout | "=== Request for /plaintext ===";
    7071
    7172                                char text[] = "Hello, World!\n";
     
    7576                                if( ret == -ECONNRESET ) break REQUEST;
    7677
    77                                 if( options.log ) printf("=== Answer sent ===\n");
     78                                if( options.log ) sout | "=== Answer sent ===";
    7879                                continue REQUEST;
    7980                        }
    8081
    8182                        if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) {
    82                                 if( options.log ) printf("=== Request for /ping ===\n");
     83                                if( options.log ) sout | "=== Request for /ping ===";
    8384
    8485                                // Send the header
     
    8687                                if( ret == -ECONNRESET ) break REQUEST;
    8788
    88                                 if( options.log ) printf("=== Answer sent ===\n");
     89                                if( options.log ) sout | "=== Answer sent ===";
    8990                                continue REQUEST;
    9091                        }
    9192
    92                         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                        }
    9398
    9499                        // Get the fd from the file cache
     
    99104                        // If we can't find the file, return 404
    100105                        if( ans_fd < 0 ) {
    101                                 printf("=== File Not Found ===\n");
     106                                sout | "=== File Not Found (" | nonl;
     107                                write(sout, file, name_size);
     108                                sout | ") ===";
    102109                                answer_error(fd, E404);
    103110                                continue REQUEST;
     
    112119                        if( ret == -ECONNRESET ) break REQUEST;
    113120
    114                         if( options.log ) printf("=== Answer sent ===\n");
     121                        if( options.log ) sout | "=== Answer sent ===";
    115122                }
    116123
    117                 if( options.log ) printf("=== Connection closed ===\n");
     124                if( options.log ) sout | "=== Connection closed ===";
    118125                close(fd);
    119126                continue CONNECTION;
  • libcfa/src/concurrency/io/setup.cfa

    r2d63023 rd46bdac  
    4242        void ^?{}(io_context & this, bool cluster_context) {}
    4343
     44        void register_fixed_files( io_context &, int *, unsigned ) {}
     45        void register_fixed_files( cluster    &, int *, unsigned ) {}
     46
    4447#else
    4548        #include <errno.h>
  • libcfa/src/concurrency/kernel.cfa

    r2d63023 rd46bdac  
    624624// Unexpected Terminating logic
    625625//=============================================================================================
    626 static __spinlock_t kernel_abort_lock;
    627 static bool kernel_abort_called = false;
     626
     627extern "C" {
     628        extern void __cfaabi_real_abort(void);
     629}
     630static volatile bool kernel_abort_called = false;
    628631
    629632void * kernel_abort(void) __attribute__ ((__nothrow__)) {
    630633        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
    631634        // the globalAbort flag is true.
    632         lock( kernel_abort_lock __cfaabi_dbg_ctx2 );
     635        bool first = __atomic_test_and_set( &kernel_abort_called, __ATOMIC_SEQ_CST);
     636
     637        // first task to abort ?
     638        if ( !first ) {
     639                // We aren't the first to abort.
     640                // I give up, just let C handle it
     641                __cfaabi_real_abort();
     642        }
    633643
    634644        // disable interrupts, it no longer makes sense to try to interrupt this processor
    635645        disable_interrupts();
    636 
    637         // first task to abort ?
    638         if ( kernel_abort_called ) {                    // not first task to abort ?
    639                 unlock( kernel_abort_lock );
    640 
    641                 sigset_t mask;
    642                 sigemptyset( &mask );
    643                 sigaddset( &mask, SIGALRM );            // block SIGALRM signals
    644                 sigaddset( &mask, SIGUSR1 );            // block SIGALRM signals
    645                 sigsuspend( &mask );                            // block the processor to prevent further damage during abort
    646                 _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it
    647         }
    648         else {
    649                 kernel_abort_called = true;
    650                 unlock( kernel_abort_lock );
    651         }
    652646
    653647        return __cfaabi_tls.this_thread;
  • libcfa/src/concurrency/stats.hfa

    r2d63023 rd46bdac  
    22
    33#include <stdint.h>
     4
     5enum {
     6        CFA_STATS_READY_Q  = 0x01,
     7        CFA_STATS_IO = 0x02,
     8};
    49
    510#if defined(__CFA_NO_STATISTICS__)
     
    914        static inline void __print_stats( struct __stats_t *, int, const char *, const char *, void * ) {}
    1015#else
    11         enum {
    12                 CFA_STATS_READY_Q  = 0x01,
    13                 #if defined(CFA_HAVE_LINUX_IO_URING_H)
    14                         CFA_STATS_IO = 0x02,
    15                 #endif
    16         };
    1716
    1817        struct __attribute__((aligned(64))) __stats_readQ_t {
  • libcfa/src/interpose.cfa

    r2d63023 rd46bdac  
    284284}
    285285
     286extern "C" {
     287        void __cfaabi_real_abort(void) {
     288                __cabi_libc.abort();
     289        }
     290}
     291
    286292void sigHandler_segv( __CFA_SIGPARMS__ ) {
    287293                if ( sfp->si_addr == 0p ) {
  • libcfa/src/parseargs.cfa

    r2d63023 rd46bdac  
    3939                        if( options[i].short_name != '\0'
    4040                        && options[i].short_name == options[j].short_name)
    41                                 abort("Parse Args error: two options have short name '%c' (%d & %d)", options[i].short_name, i, j);
    42 
    43                         if(0 == strcmp(options[i].long_name, options[j].long_name)) abort("Parse Args error: two options have long name '%s' (%d & %d)", options[i].long_name, i, j);
     41                                abort("Parse Args error: two options have short name '%c' (%zu & %zu)", options[i].short_name, i, j);
     42
     43                        if(0 == strcmp(options[i].long_name, options[j].long_name)) abort("Parse Args error: two options have long name '%s' (%zu & %zu)", options[i].long_name, i, j);
    4444                }
    4545        }
Note: See TracChangeset for help on using the changeset viewer.