Changes in / [0cc43e1:78a8440]


Ignore:
Files:
13 edited

Legend:

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

    r0cc43e1 r78a8440  
    209209
    210210[int *, int] filefds(int extra) {
     211        if(!options.file_cache.path) {
     212                int * data = alloc(extra);
     213                return [data, 0];
     214        }
     215
    211216        if(!file_cache.entries) {
    212217                abort("File cache not filled!\n");
  • benchmark/io/http/main.cfa

    r0cc43e1 r78a8440  
    8080        //===================
    8181        // Parse args
    82         const char * path = parse_options(argc, argv);
     82        parse_options(argc, argv);
    8383
    8484        //===================
    8585        // Open Files
    86         sout | "Filling cache from" | path;
    87         fill_cache( path );
     86        if( options.file_cache.path ) {
     87                sout | "Filling cache from" | options.file_cache.path;
     88                fill_cache( options.file_cache.path );
     89        }
    8890
    8991        //===================
     
    147149                }
    148150
    149                 if(options.file_cache.fixed_fds) {
     151                if(options.file_cache.path && options.file_cache.fixed_fds) {
    150152                        register_fixed_files(cl, fds, pipe_off);
    151153                }
     
    184186                                }
    185187
    186                                 sout | "Notifying connections";
     188                                sout | "Notifying connections..." | nonl; flush( sout );
    187189                                for(i; options.clopts.nworkers) {
    188190                                        workers[i].done = true;
    189191                                        cancel(workers[i].cancel);
    190192                                }
    191 
    192                                 sout | "Shutting down socket";
     193                                sout | "done";
     194
     195                                sout | "Shutting down socket..." | nonl; flush( sout );
    193196                                int ret = shutdown( server_fd, SHUT_RD );
    194                                 if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); }
     197                                if( ret < 0 ) {
     198                                        abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) );
     199                                }
     200                                sout | "done";
    195201
    196202                                //===================
    197203                                // Close Socket
    198                                 sout | "Closing Socket";
     204                                sout | "Closing Socket..." | nonl; flush( sout );
    199205                                ret = close( server_fd );
    200206                                if(ret < 0) {
    201207                                        abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) );
    202208                                }
    203                                 sout | "Stopping connection threads..." | nonl;
     209                                sout | "done";
     210
     211                                sout | "Stopping connection threads..." | nonl; flush( sout );
    204212                        }
    205213                        sout | "done";
    206214
    207                         sout | "Stopping protocol threads..." | nonl;
     215                        sout | "Stopping protocol threads..." | nonl; flush( sout );
    208216                        deinit_protocol();
    209217                        sout | "done";
    210218
    211                         sout | "Stopping processors..." | nonl;
     219                        sout | "Stopping processors..." | nonl; flush( sout );
    212220                }
    213221                sout | "done";
    214222
    215                 sout | "Closing splice fds..." | nonl;
     223                sout | "Closing splice fds..." | nonl; flush( sout );
    216224                for(i; pipe_cnt) {
    217225                        ret = close( fds[pipe_off + i] );
     
    223231                sout | "done";
    224232
    225                 sout | "Stopping processors..." | nonl;
     233                sout | "Stopping processors..." | nonl; flush( sout );
    226234        }
    227235        sout | "done";
     
    229237        //===================
    230238        // Close Files
    231         sout | "Closing open files..." | nonl;
    232         close_cache();
    233         sout | "done";
    234 }
     239        if( options.file_cache.path ) {
     240                sout | "Closing open files..." | nonl; flush( sout );
     241                close_cache();
     242                sout | "done";
     243        }
     244}
  • benchmark/io/http/options.cfa

    r0cc43e1 r78a8440  
    99}
    1010
     11#include <fstream.hfa>
    1112#include <kernel.hfa>
    1213#include <parseargs.hfa>
    1314
     15#include <stdlib.h>
    1416#include <string.h>
    1517
     
    1820
    1921        { // file_cache
     22                0,     // path
    2023                0,     // open_flags;
    2124                42u,   // hash_seed;
     
    3437                1,     // nprocs;
    3538                1,     // nworkers;
    36                 0,     // flags;
     39                {},     // params;
    3740                false, // procstats
    3841                false, // viewhalts
     
    4144};
    4245
    43 const char * parse_options( int argc, char * argv[] ) {
     46void parse_options( int argc, char * argv[] ) {
    4447        bool subthrd = false;
    4548        bool eagrsub = false;
     
    97100
    98101        if( left[0] != 0p ) {
    99                 abort("Too many trailing arguments!\n");
     102                serr | "Too many trailing arguments!";
     103                exit(EXIT_FAILURE);
    100104        }
    101105
    102         return path;
     106        options.file_cache.path = path;
    103107}
  • benchmark/io/http/options.hfa

    r0cc43e1 r78a8440  
    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

    r0cc43e1 r78a8440  
    2626        "HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2727        "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",
    2829        "HTTP/1.1 408 Request Timeout\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    2930        "HTTP/1.1 413 Payload Too Large\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
     
    3738        400,
    3839        404,
     40        405,
    3941        408,
    4042        413,
     
    104106                        if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ;
    105107                        if( errno == ECONNRESET ) return [E408, true, 0, 0];
     108                        if( errno == EPIPE ) return [E408, true, 0, 0];
    106109                        abort( "read error: (%d) %s\n", (int)errno, strerror(errno) );
    107110                }
  • benchmark/io/http/protocol.hfa

    r0cc43e1 r78a8440  
    77        E400,
    88        E404,
     9        E405,
    910        E408,
    1011        E413,
  • benchmark/io/http/worker.cfa

    r0cc43e1 r78a8440  
    9797                        }
    9898
     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                        }
     108
    99109                        // Get the fd from the file cache
    100110                        int ans_fd;
     
    104114                        // If we can't find the file, return 404
    105115                        if( ans_fd < 0 ) {
    106                                 sout | "=== File Not Found (" | nonl;
    107                                 write(sout, file, name_size);
    108                                 sout | ") ===";
     116                                if( options.log ) {
     117                                        sout | "=== File Not Found (" | nonl;
     118                                        write(sout, file, name_size);
     119                                        sout | ") ===";
     120                                }
    109121                                answer_error(fd, E404);
    110122                                continue REQUEST;
  • libcfa/src/concurrency/io.cfa

    r0cc43e1 r78a8440  
    318318
    319319                __cfadbg_print_safe(io_core, "Kernel I/O : Fast poller %d (%p) stopping\n", this.ring->fd, &this);
     320
     321                __ioctx_unregister( this );
    320322        }
    321323
  • libcfa/src/concurrency/io/setup.cfa

    r0cc43e1 r78a8440  
    113113
    114114        static struct {
    115                 pthread_t     thrd;    // pthread handle to io poller thread
    116                 void *        stack;   // pthread stack for io poller thread
    117                 int           epollfd; // file descriptor to the epoll instance
    118                 volatile bool run;     // Whether or not to continue
     115                pthread_t       thrd;    // pthread handle to io poller thread
     116                void *          stack;   // pthread stack for io poller thread
     117                int             epollfd; // file descriptor to the epoll instance
     118                volatile bool   run;     // Whether or not to continue
     119                volatile size_t epoch;   // Epoch used for memory reclamation
    119120        } iopoll;
    120121
     
    131132                iopoll.run = true;
    132133                iopoll.stack = __create_pthread( &iopoll.thrd, iopoll_loop, 0p );
     134                iopoll.epoch = 0;
    133135        }
    134136
     
    174176                while( iopoll.run ) {
    175177                        __cfadbg_print_safe(io_core, "Kernel I/O - epoll : waiting on io_uring contexts\n");
     178
     179                        // increment the epoch to notify any deleters we are starting a new cycle
     180                        __atomic_fetch_add(&iopoll.epoch, 1, __ATOMIC_SEQ_CST);
    176181
    177182                        // Wait for events
     
    496501// I/O Context Sleep
    497502//=============================================================================================
    498         #define IOEVENTS EPOLLIN | EPOLLONESHOT
    499 
    500503        static inline void __ioctx_epoll_ctl($io_ctx_thread & ctx, int op, const char * error) {
    501504                struct epoll_event ev;
    502                 ev.events = IOEVENTS;
     505                ev.events = EPOLLIN | EPOLLONESHOT;
    503506                ev.data.u64 = (__u64)&ctx;
    504507                int ret = epoll_ctl(iopoll.epollfd, op, ctx.ring->efd, &ev);
     
    517520        }
    518521
     522        void __ioctx_unregister($io_ctx_thread & ctx) {
     523                // Read the current epoch so we know when to stop
     524                size_t curr = __atomic_load_n(&iopoll.epoch, __ATOMIC_SEQ_CST);
     525
     526                // Remove the fd from the iopoller
     527                __ioctx_epoll_ctl(ctx, EPOLL_CTL_DEL, "REMOVE");
     528
     529                // Notify the io poller thread of the shutdown
     530                iopoll.run = false;
     531                sigval val = { 1 };
     532                pthread_sigqueue( iopoll.thrd, SIGUSR1, val );
     533
     534                // Make sure all this is done
     535                __atomic_thread_fence(__ATOMIC_SEQ_CST);
     536
     537                // Wait for the next epoch
     538                while(curr == __atomic_load_n(&iopoll.epoch, __ATOMIC_RELAXED)) yield();
     539        }
     540
    519541//=============================================================================================
    520542// I/O Context Misc Setup
  • libcfa/src/concurrency/io/types.hfa

    r0cc43e1 r78a8440  
    133133        struct $io_ctx_thread;
    134134        void __ioctx_register($io_ctx_thread & ctx);
     135        void __ioctx_unregister($io_ctx_thread & ctx);
    135136        void __ioctx_prepare_block($io_ctx_thread & ctx);
    136137        void __sqe_clean( volatile struct io_uring_sqe * sqe );
  • libcfa/src/concurrency/kernel.cfa

    r0cc43e1 r78a8440  
    633633        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
    634634        // the globalAbort flag is true.
    635         bool first = __atomic_test_and_set( &kernel_abort_called, __ATOMIC_SEQ_CST);
     635        bool first = !__atomic_test_and_set( &kernel_abort_called, __ATOMIC_SEQ_CST);
    636636
    637637        // first task to abort ?
  • libcfa/src/concurrency/mutex.hfa

    r0cc43e1 r78a8440  
    4242};
    4343
    44 void ?{}(mutex_lock & this);
    45 void ^?{}(mutex_lock & this);
    46 void lock(mutex_lock & this);
    47 bool try_lock(mutex_lock & this);
    48 void unlock(mutex_lock & this);
     44void ?{}(mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     45void ^?{}(mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     46void lock(mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     47bool try_lock(mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     48void unlock(mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    4949
    5050// Exclusive lock - recursive
     
    6464};
    6565
    66 void ?{}(recursive_mutex_lock & this);
    67 void ^?{}(recursive_mutex_lock & this);
    68 void lock(recursive_mutex_lock & this);
    69 bool try_lock(recursive_mutex_lock & this);
    70 void unlock(recursive_mutex_lock & this);
     66void ?{}(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     67void ^?{}(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     68void lock(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     69bool try_lock(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     70void unlock(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    7171
    7272trait is_lock(dtype L | sized(L)) {
     
    8686};
    8787
    88 void ?{}(condition_variable & this);
    89 void ^?{}(condition_variable & this);
     88void ?{}(condition_variable & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     89void ^?{}(condition_variable & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    9090
    91 void notify_one(condition_variable & this);
    92 void notify_all(condition_variable & this);
     91void notify_one(condition_variable & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
     92void notify_all(condition_variable & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    9393
    94 void wait(condition_variable & this);
     94void wait(condition_variable & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    9595
    9696forall(dtype L | is_lock(L))
    97 void wait(condition_variable & this, L & l);
     97void wait(condition_variable & this, L & l) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    9898
    9999//-----------------------------------------------------------------------------
  • libcfa/src/parseargs.cfa

    r0cc43e1 r78a8440  
    148148        if(hwidth <= 0) hwidth = max;
    149149
    150         fprintf(out, "  -%c, --%-*s   %.*s\n", sn, width, ln, hwidth, help);
     150        char sname[4] = { ' ', ' ', ' ', '\0' };
     151        if(sn != '\0') {
     152                sname[0] = '-';
     153                sname[1] = sn;
     154                sname[2] = ',';
     155        }
     156
     157        fprintf(out, "  %s --%-*s   %.*s\n", sname, width, ln, hwidth, help);
    151158        for() {
    152159                help += min(strlen(help), hwidth);
Note: See TracChangeset for help on using the changeset viewer.