Changeset a554e5f4 for libcfa


Ignore:
Timestamp:
Feb 9, 2022, 3:33:42 PM (4 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
850aff1
Parents:
21a99cc (diff), c4f81702 (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:
5 edited

Legend:

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

    r21a99cc ra554e5f4  
    251251        bool enabled = __cfaabi_tls.preemption_state.enabled;
    252252
     253        // Check if there is a pending preemption
     254        processor   * proc = __cfaabi_tls.this_processor;
     255        bool pending = proc ? proc->pending_preemption : false;
     256        if( enabled && pending ) proc->pending_preemption = false;
     257
    253258        // create a assembler label after
    254259        // marked as clobber all to avoid movement
    255260        __cfaasm_label(check, after);
     261
     262        // If we can preempt and there is a pending one
     263        // this is a good time to yield
     264        if( enabled && pending ) {
     265                force_yield( __POLL_PREEMPTION );
     266        }
    256267        return enabled;
    257268}
     
    282293        // marked as clobber all to avoid movement
    283294        __cfaasm_label(get, after);
     295
     296        // This is used everywhere, to avoid cost, we DO NOT poll pending preemption
    284297        return val;
    285298}
     
    358371        if(!ready) { abort("Preemption should be ready"); }
    359372
    360         __cfaasm_label(debug, before);
    361 
    362                 sigset_t oldset;
    363                 int ret;
    364                 ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    365                 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    366 
    367                 ret = sigismember(&oldset, SIGUSR1);
    368                 if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
    369                 if(ret == 1) { abort("ERROR SIGUSR1 is disabled"); }
    370 
    371                 ret = sigismember(&oldset, SIGALRM);
    372                 if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
    373                 if(ret == 0) { abort("ERROR SIGALRM is enabled"); }
    374 
    375                 ret = sigismember(&oldset, SIGTERM);
    376                 if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
    377                 if(ret == 1) { abort("ERROR SIGTERM is disabled"); }
    378 
    379         __cfaasm_label(debug, after);
     373        sigset_t oldset;
     374        int ret;
     375        ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
     376        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
     377
     378        ret = sigismember(&oldset, SIGUSR1);
     379        if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
     380        if(ret == 1) { abort("ERROR SIGUSR1 is disabled"); }
     381
     382        ret = sigismember(&oldset, SIGALRM);
     383        if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
     384        if(ret == 0) { abort("ERROR SIGALRM is enabled"); }
     385
     386        ret = sigismember(&oldset, SIGTERM);
     387        if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
     388        if(ret == 1) { abort("ERROR SIGTERM is disabled"); }
    380389}
    381390
     
    548557        __cfaasm_label( check  );
    549558        __cfaasm_label( dsable );
    550         __cfaasm_label( debug  );
     559        // __cfaasm_label( debug  );
    551560
    552561        // Check if preemption is safe
     
    555564        if( __cfaasm_in( ip, check  ) ) { ready = false; goto EXIT; };
    556565        if( __cfaasm_in( ip, dsable ) ) { ready = false; goto EXIT; };
    557         if( __cfaasm_in( ip, debug  ) ) { ready = false; goto EXIT; };
     566        // if( __cfaasm_in( ip, debug  ) ) { ready = false; goto EXIT; };
    558567        if( !__cfaabi_tls.preemption_state.enabled) { ready = false; goto EXIT; };
    559568        if( __cfaabi_tls.preemption_state.in_progress ) { ready = false; goto EXIT; };
     
    661670
    662671        // Check if it is safe to preempt here
    663         if( !preemption_ready( ip ) ) { return; }
     672        if( !preemption_ready( ip ) ) {
     673                #if !defined(__CFA_NO_STATISTICS__)
     674                        __cfaabi_tls.this_stats->ready.threads.preempt.rllfwd++;
     675                #endif
     676                return;
     677        }
    664678
    665679        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p @ %p).\n", __cfaabi_tls.this_processor, __cfaabi_tls.this_thread, (void *)(cxt->uc_mcontext.CFA_REG_IP) );
     
    680694
    681695        // Preemption can occur here
     696
     697        #if !defined(__CFA_NO_STATISTICS__)
     698                __cfaabi_tls.this_stats->ready.threads.preempt.yield++;
     699        #endif
    682700
    683701        force_yield( __ALARM_PREEMPTION ); // Do the actual __cfactx_switch
  • libcfa/src/concurrency/stats.cfa

    r21a99cc ra554e5f4  
    2929                stats->ready.threads.threads   = 0;
    3030                stats->ready.threads.cthreads  = 0;
     31                stats->ready.threads.preempt.yield  = 0;
     32                stats->ready.threads.preempt.rllfwd = 0;
    3133                stats->ready.sleep.halts   = 0;
    3234                stats->ready.sleep.cancels = 0;
     
    7779
    7880        void __tally_stats( struct __stats_t * cltr, struct __stats_t * proc ) {
    79                 tally_one( &cltr->ready.push.local.attempt, &proc->ready.push.local.attempt );
    80                 tally_one( &cltr->ready.push.local.success, &proc->ready.push.local.success );
    81                 tally_one( &cltr->ready.push.share.attempt, &proc->ready.push.share.attempt );
    82                 tally_one( &cltr->ready.push.share.success, &proc->ready.push.share.success );
    83                 tally_one( &cltr->ready.push.extrn.attempt, &proc->ready.push.extrn.attempt );
    84                 tally_one( &cltr->ready.push.extrn.success, &proc->ready.push.extrn.success );
    85                 tally_one( &cltr->ready.pop.local .attempt, &proc->ready.pop.local .attempt );
    86                 tally_one( &cltr->ready.pop.local .success, &proc->ready.pop.local .success );
    87                 tally_one( &cltr->ready.pop.help  .attempt, &proc->ready.pop.help  .attempt );
    88                 tally_one( &cltr->ready.pop.help  .success, &proc->ready.pop.help  .success );
    89                 tally_one( &cltr->ready.pop.steal .attempt, &proc->ready.pop.steal .attempt );
    90                 tally_one( &cltr->ready.pop.steal .success, &proc->ready.pop.steal .success );
    91                 tally_one( &cltr->ready.pop.search.attempt, &proc->ready.pop.search.attempt );
    92                 tally_one( &cltr->ready.pop.search.success, &proc->ready.pop.search.success );
    93                 tally_one( &cltr->ready.threads.migration , &proc->ready.threads.migration  );
    94                 tally_one( &cltr->ready.threads.extunpark , &proc->ready.threads.extunpark  );
    95                 tally_one( &cltr->ready.threads.threads   , &proc->ready.threads.threads    );
    96                 tally_one( &cltr->ready.threads.cthreads  , &proc->ready.threads.cthreads   );
    97                 tally_one( &cltr->ready.sleep.halts       , &proc->ready.sleep.halts        );
    98                 tally_one( &cltr->ready.sleep.cancels     , &proc->ready.sleep.cancels      );
    99                 tally_one( &cltr->ready.sleep.early       , &proc->ready.sleep.early        );
    100                 tally_one( &cltr->ready.sleep.wakes       , &proc->ready.sleep.wakes        );
    101                 tally_one( &cltr->ready.sleep.seen        , &proc->ready.sleep.wakes        );
    102                 tally_one( &cltr->ready.sleep.exits       , &proc->ready.sleep.exits        );
     81                tally_one( &cltr->ready.push.local.attempt    , &proc->ready.push.local.attempt     );
     82                tally_one( &cltr->ready.push.local.success    , &proc->ready.push.local.success     );
     83                tally_one( &cltr->ready.push.share.attempt    , &proc->ready.push.share.attempt     );
     84                tally_one( &cltr->ready.push.share.success    , &proc->ready.push.share.success     );
     85                tally_one( &cltr->ready.push.extrn.attempt    , &proc->ready.push.extrn.attempt     );
     86                tally_one( &cltr->ready.push.extrn.success    , &proc->ready.push.extrn.success     );
     87                tally_one( &cltr->ready.pop.local .attempt    , &proc->ready.pop.local .attempt     );
     88                tally_one( &cltr->ready.pop.local .success    , &proc->ready.pop.local .success     );
     89                tally_one( &cltr->ready.pop.help  .attempt    , &proc->ready.pop.help  .attempt     );
     90                tally_one( &cltr->ready.pop.help  .success    , &proc->ready.pop.help  .success     );
     91                tally_one( &cltr->ready.pop.steal .attempt    , &proc->ready.pop.steal .attempt     );
     92                tally_one( &cltr->ready.pop.steal .success    , &proc->ready.pop.steal .success     );
     93                tally_one( &cltr->ready.pop.search.attempt    , &proc->ready.pop.search.attempt     );
     94                tally_one( &cltr->ready.pop.search.success    , &proc->ready.pop.search.success     );
     95                tally_one( &cltr->ready.threads.migration     , &proc->ready.threads.migration      );
     96                tally_one( &cltr->ready.threads.extunpark     , &proc->ready.threads.extunpark      );
     97                tally_one( &cltr->ready.threads.threads       , &proc->ready.threads.threads        );
     98                tally_one( &cltr->ready.threads.cthreads      , &proc->ready.threads.cthreads       );
     99                tally_one( &cltr->ready.threads.preempt.yield , &proc->ready.threads.preempt.yield  );
     100                tally_one( &cltr->ready.threads.preempt.rllfwd, &proc->ready.threads.preempt.rllfwd );
     101                tally_one( &cltr->ready.sleep.halts           , &proc->ready.sleep.halts            );
     102                tally_one( &cltr->ready.sleep.cancels         , &proc->ready.sleep.cancels          );
     103                tally_one( &cltr->ready.sleep.early           , &proc->ready.sleep.early            );
     104                tally_one( &cltr->ready.sleep.wakes           , &proc->ready.sleep.wakes            );
     105                tally_one( &cltr->ready.sleep.seen            , &proc->ready.sleep.wakes            );
     106                tally_one( &cltr->ready.sleep.exits           , &proc->ready.sleep.exits            );
    103107
    104108                #if defined(CFA_HAVE_LINUX_IO_URING_H)
     
    168172                             | eng3(ready.sleep.wakes + ready.sleep.early) | '(' | eng3(ready.sleep.early) | ',' | eng3(ready.sleep.seen) | ')' | " wake(early, seen),"
    169173                             | eng3(ready.sleep.exits) | "exit";
     174                        sstr | "- Preemption : " | eng3(ready.threads.preempt.yield) | "yields," | eng3(ready.threads.preempt.rllfwd) | "delayed";
    170175                        sstr | nl;
    171176                }
  • libcfa/src/concurrency/stats.hfa

    r21a99cc ra554e5f4  
    6565                        volatile  int64_t threads;  // number of threads in the system, includes only local change
    6666                        volatile  int64_t cthreads; // number of threads in the system, includes only local change
     67                        struct {
     68                                volatile uint64_t yield;
     69                                volatile uint64_t rllfwd;
     70                        } preempt;
    6771                } threads;
    6872                struct {
  • libcfa/src/stdhdr/pthread.h

    r21a99cc ra554e5f4  
    1010// Created On       : Wed Jun 16 13:39:06 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 16 13:39:42 2021
    13 // Update Count     : 1
     12// Last Modified On : Thu Feb  3 21:53:26 2022
     13// Update Count     : 13
    1414//
    1515
     16// pthread.h and setjmp.h cannot agree on the type of __sigsetjmp:
     17//
     18//   extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __attribute__ ((__nothrow__));
     19//   extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __attribute__ ((__nothrow__));
     20//
     21// With -Wall, gcc-11 warns about the disagreement unless the CPP directive
     22//
     23//    # 1 "/usr/include/pthread.h" 1 3 4
     24//
     25// appears, which appears to be witchcraft. Unfortunately, this directive is removed by the CFA preprocessor, so the
     26// batchtest fails because of the spurious warning message. Hence, the warning is elided.
     27
    1628extern "C" {
     29#if defined(__GNUC__) && __GNUC__ == 11
     30        #pragma GCC diagnostic push
     31        #pragma GCC diagnostic ignored "-Warray-parameter"
     32#endif // defined(__GNUC__) && __GNUC__ == 11
     33
    1734#include_next <pthread.h>                                                               // has internal check for multiple expansion
     35
     36#if defined(__GNUC__) && __GNUC__ == 11
     37        #pragma GCC diagnostic pop
     38#endif // defined(__GNUC__) && __GNUC__ == 11
    1839} // extern "C"
    1940
    2041// Local Variables: //
    21 // tab-width: 4 //
    2242// mode: c++ //
    23 // compile-command: "make install" //
    2443// End: //
  • libcfa/src/stdhdr/setjmp.h

    r21a99cc ra554e5f4  
    1010// Created On       : Mon Jul  4 23:25:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul  5 20:38:33 2016
    13 // Update Count     : 12
     12// Last Modified On : Thu Feb  3 21:53:28 2022
     13// Update Count     : 18
    1414//
    1515
     16// pthread.h and setjmp.h cannot agree on the type of __sigsetjmp:
     17//
     18//   extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __attribute__ ((__nothrow__));
     19//   extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __attribute__ ((__nothrow__));
     20//
     21// With -Wall, gcc-11 warns about the disagreement unless the CPP directive
     22//
     23//    # 1 "/usr/include/pthread.h" 1 3 4
     24//
     25// appears, which appears to be witchcraft. Unfortunately, this directive is removed by the CFA preprocessor, so the
     26// batchtest fails because of the spurious warning message. Hence, the warning is elided.
     27
    1628extern "C" {
     29#if defined(__GNUC__) && __GNUC__ == 11
     30        #pragma GCC diagnostic push
     31        #pragma GCC diagnostic ignored "-Warray-parameter"
     32#endif // defined(__GNUC__) && __GNUC__ == 11
     33
    1734#include_next <setjmp.h>                                                                // has internal check for multiple expansion
     35
     36#if defined(__GNUC__) && __GNUC__ == 11
     37        #pragma GCC diagnostic pop
     38#endif // defined(__GNUC__) && __GNUC__ == 11
    1839} // extern "C"
    1940
    2041// Local Variables: //
    21 // tab-width: 4 //
    2242// mode: c++ //
    23 // compile-command: "make install" //
    2443// End: //
Note: See TracChangeset for help on using the changeset viewer.