Changeset 77ff383 for libcfa


Ignore:
Timestamp:
Jan 15, 2021, 3:22:50 PM (5 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
02b73ea
Parents:
03ecdcf (diff), d46bdac (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:
libcfa/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/io.cfa

    r03ecdcf r77ff383  
    390390                        block++;
    391391
    392                         abort( "Kernel I/O : all submit queue entries used, yielding\n" );
    393 
    394392                        yield();
    395393                }
  • libcfa/src/concurrency/io/setup.cfa

    r03ecdcf r77ff383  
    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

    r03ecdcf r77ff383  
    140140                preemption_scope scope = { this };
    141141
     142                #if !defined(__CFA_NO_STATISTICS__)
     143                        unsigned long long last_tally = rdtscl();
     144                #endif
     145
     146
    142147                __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this);
    143148
     
    206211                        // Are we done?
    207212                        if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP;
     213
     214                        #if !defined(__CFA_NO_STATISTICS__)
     215                                unsigned long long curr = rdtscl();
     216                                if(curr > (last_tally + 500000000)) {
     217                                        __tally_stats(this->cltr->stats, __cfaabi_tls.this_stats);
     218                                        last_tally = curr;
     219                                }
     220                        #endif
    208221                }
    209222
     
    611624// Unexpected Terminating logic
    612625//=============================================================================================
    613 static __spinlock_t kernel_abort_lock;
    614 static bool kernel_abort_called = false;
     626
     627extern "C" {
     628        extern void __cfaabi_real_abort(void);
     629}
     630static volatile bool kernel_abort_called = false;
    615631
    616632void * kernel_abort(void) __attribute__ ((__nothrow__)) {
    617633        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
    618634        // the globalAbort flag is true.
    619         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        }
    620643
    621644        // disable interrupts, it no longer makes sense to try to interrupt this processor
    622645        disable_interrupts();
    623 
    624         // first task to abort ?
    625         if ( kernel_abort_called ) {                    // not first task to abort ?
    626                 unlock( kernel_abort_lock );
    627 
    628                 sigset_t mask;
    629                 sigemptyset( &mask );
    630                 sigaddset( &mask, SIGALRM );            // block SIGALRM signals
    631                 sigaddset( &mask, SIGUSR1 );            // block SIGALRM signals
    632                 sigsuspend( &mask );                            // block the processor to prevent further damage during abort
    633                 _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it
    634         }
    635         else {
    636                 kernel_abort_called = true;
    637                 unlock( kernel_abort_lock );
    638         }
    639646
    640647        return __cfaabi_tls.this_thread;
  • libcfa/src/concurrency/stats.hfa

    r03ecdcf r77ff383  
    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

    r03ecdcf r77ff383  
    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

    r03ecdcf r77ff383  
    3030
    3131static void usage(char * cmd, cfa_option options[], size_t opt_count, const char * usage, FILE * out)  __attribute__ ((noreturn));
    32 
     32//-----------------------------------------------------------------------------
     33// checking
     34static void check_args(cfa_option options[], size_t opt_count) {
     35        for(i; opt_count) {
     36                for(j; opt_count) {
     37                        if(i == j) continue;
     38
     39                        if( options[i].short_name != '\0'
     40                        && options[i].short_name == options[j].short_name)
     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);
     44                }
     45        }
     46}
     47
     48
     49//-----------------------------------------------------------------------------
     50// Parsing args
    3351void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left ) {
    3452        if( 0p != &cfa_args_argc ) {
     
    4159}
    4260
    43 //-----------------------------------------------------------------------------
    44 // getopt_long wrapping
    4561void parse_args(
    4662        int argc,
     
    5167        char ** & left
    5268) {
     69        check_args(options, opt_count);
     70
     71        int maxv = 'h';
     72        char optstring[opt_count * 3] = { '\0' };
     73        {
     74                int idx = 0;
     75                for(i; opt_count) {
     76                        if (options[i].short_name) {
     77                                maxv = max(options[i].short_name, maxv);
     78                                optstring[idx] = options[i].short_name;
     79                                idx++;
     80                                if(    ((intptr_t)options[i].parse) != ((intptr_t)parse_settrue)
     81                                && ((intptr_t)options[i].parse) != ((intptr_t)parse_setfalse) ) {
     82                                        optstring[idx] = ':';
     83                                        idx++;
     84                                }
     85                        }
     86                }
     87                optstring[idx+0] = 'h';
     88                optstring[idx+1] = '\0';
     89        }
     90
    5391        struct option optarr[opt_count + 2];
    5492        {
     
    5694                for(i; opt_count) {
    5795                        if(options[i].long_name) {
     96                                options[i].val = (options[i].short_name != '\0') ? ((int)options[i].short_name) : ++maxv;
    5897                                optarr[idx].name = options[i].long_name;
    5998                                optarr[idx].flag = 0p;
    60                                 optarr[idx].val  = options[i].short_name;
     99                                optarr[idx].val  = options[i].val;
    61100                                if(    ((intptr_t)options[i].parse) == ((intptr_t)parse_settrue)
    62101                                    || ((intptr_t)options[i].parse) == ((intptr_t)parse_setfalse) ) {
     
    70109                optarr[idx+0].[name, has_arg, flag, val] = ["help", no_argument, 0, 'h'];
    71110                optarr[idx+1].[name, has_arg, flag, val] = [0, no_argument, 0, 0];
    72         }
    73 
    74         char optstring[opt_count * 3] = { '\0' };
    75         {
    76                 int idx = 0;
    77                 for(i; opt_count) {
    78                         optstring[idx] = options[i].short_name;
    79                         idx++;
    80                         if(    ((intptr_t)options[i].parse) != ((intptr_t)parse_settrue)
    81                             && ((intptr_t)options[i].parse) != ((intptr_t)parse_setfalse) ) {
    82                                 optstring[idx] = ':';
    83                                 idx++;
    84                         }
    85                 }
    86                 optstring[idx+0] = 'h';
    87                 optstring[idx+1] = '\0';
    88111        }
    89112
     
    103126                        default:
    104127                                for(i; opt_count) {
    105                                         if(opt == options[i].short_name) {
     128                                        if(opt == options[i].val) {
    106129                                                const char * arg = optarg ? optarg : "";
    107130                                                if( arg[0] == '=' ) { arg++; }
  • libcfa/src/parseargs.hfa

    r03ecdcf r77ff383  
    22
    33struct cfa_option {
     4      int val; // reserved
    45      char short_name;
    56      const char * long_name;
     
    1516forall(dtype T | { bool parse(const char *, T & ); })
    1617static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) {
     18      this.val        = 0;
    1719      this.short_name = short_name;
    1820      this.long_name  = long_name;
     
    2426forall(dtype T)
    2527static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) {
     28      this.val        = 0;
    2629      this.short_name = short_name;
    2730      this.long_name  = long_name;
Note: See TracChangeset for help on using the changeset viewer.