Ignore:
Timestamp:
Apr 24, 2021, 11:32:49 AM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
424dfc4, 986cb99
Parents:
fec63b2 (diff), 8edbe40 (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/concurrency
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/clib/cfathread.cfa

    rfec63b2 r50f6afb  
    5050
    5151cfathread_vtable _cfathread_vtable_instance;
     52
     53cfathread_vtable & const _default_vtable = _cfathread_vtable_instance;
    5254
    5355cfathread_vtable const & get_exception_vtable(cfathread_exception *) {
  • libcfa/src/concurrency/coroutine.cfa

    rfec63b2 r50f6afb  
    4646
    4747//-----------------------------------------------------------------------------
    48 EHM_VIRTUAL_TABLE(SomeCoroutineCancelled, std_coroutine_cancelled);
    49 
    5048forall(T &)
    5149void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) {
     
    6260// This code should not be inlined. It is the error path on resume.
    6361forall(T & | is_coroutine(T))
    64 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) {
     62void __cfaehm_cancelled_coroutine(
     63                T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ) {
    6564        verify( desc->cancellation );
    6665        desc->state = Cancelled;
     
    6867
    6968        // TODO: Remove explitate vtable set once trac#186 is fixed.
    70         SomeCoroutineCancelled except;
    71         except.virtual_table = &std_coroutine_cancelled;
     69        CoroutineCancelled(T) except;
     70        except.virtual_table = &_default_vtable;
    7271        except.the_coroutine = &cor;
    7372        except.the_exception = except;
    7473        // Why does this need a cast?
    75         throwResume (SomeCoroutineCancelled &)except;
     74        throwResume (CoroutineCancelled(T) &)except;
    7675
    7776        except->virtual_table->free( except );
     
    146145// Part of the Public API
    147146// Not inline since only ever called once per coroutine
    148 forall(T & | is_coroutine(T))
     147forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    149148void prime(T& cor) {
    150149        $coroutine* this = get_coroutine(cor);
  • libcfa/src/concurrency/coroutine.hfa

    rfec63b2 r50f6afb  
    2222//-----------------------------------------------------------------------------
    2323// Exception thrown from resume when a coroutine stack is cancelled.
    24 EHM_EXCEPTION(SomeCoroutineCancelled)(
    25         void * the_coroutine;
    26         exception_t * the_exception;
    27 );
    28 
    29 EHM_EXTERN_VTABLE(SomeCoroutineCancelled, std_coroutine_cancelled);
    30 
    3124EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) (
    3225        coroutine_t * the_coroutine;
     
    4437// Anything that implements this trait can be resumed.
    4538// Anything that is resumed is a coroutine.
    46 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(SomeCoroutineCancelled)) {
     39trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) {
    4740        void main(T & this);
    4841        $coroutine * get_coroutine(T & this);
     
    6760//-----------------------------------------------------------------------------
    6861// Public coroutine API
    69 forall(T & | is_coroutine(T))
     62forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    7063void prime(T & cor);
    7164
     
    137130
    138131forall(T & | is_coroutine(T))
    139 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc );
     132void __cfaehm_cancelled_coroutine(
     133        T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable );
    140134
    141135// Resume implementation inlined for performance
    142 forall(T & | is_coroutine(T))
     136forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    143137static inline T & resume(T & cor) {
    144138        // optimization : read TLS once and reuse it
     
    170164        $ctx_switch( src, dst );
    171165        if ( unlikely(dst->cancellation) ) {
    172                 __cfaehm_cancelled_coroutine( cor, dst );
     166                __cfaehm_cancelled_coroutine( cor, dst, _default_vtable );
    173167        }
    174168
  • libcfa/src/concurrency/locks.hfa

    rfec63b2 r50f6afb  
    197197static inline $thread * unlock( fast_lock & this ) __attribute__((artificial));
    198198static inline $thread * unlock( fast_lock & this ) {
    199         $thread * thrd = active_thread();
    200         /* paranoid */ verify(thrd == this.owner);
     199        /* paranoid */ verify(active_thread() == this.owner);
    201200
    202201        // open 'owner' before unlocking anyone
  • libcfa/src/concurrency/ready_queue.cfa

    rfec63b2 r50f6afb  
    413413                        unsigned it2  = proc->rdq.itr + 1;
    414414                        unsigned idx1 = proc->rdq.id + (it1 % READYQ_SHARD_FACTOR);
    415                         unsigned idx2 = proc->rdq.id + (it1 % READYQ_SHARD_FACTOR);
     415                        unsigned idx2 = proc->rdq.id + (it2 % READYQ_SHARD_FACTOR);
    416416                        unsigned long long tsc1 = ts(lanes.data[idx1]);
    417417                        unsigned long long tsc2 = ts(lanes.data[idx2]);
    418418                        proc->rdq.cutoff = min(tsc1, tsc2);
    419                 }
    420                 else if(lanes.tscs[proc->rdq.target].tv < proc->rdq.cutoff) {
    421                         $thread * t = try_pop(cltr, proc->rdq.target __STATS(, __tls_stats()->ready.pop.help));
     419                        if(proc->rdq.cutoff == 0) proc->rdq.cutoff = -1ull;
     420                }
     421                else {
     422                        unsigned target = proc->rdq.target;
    422423                        proc->rdq.target = -1u;
    423                         if(t) return t;
     424                        if(lanes.tscs[target].tv < proc->rdq.cutoff) {
     425                                $thread * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
     426                                if(t) return t;
     427                        }
    424428                }
    425429
  • libcfa/src/concurrency/stats.cfa

    rfec63b2 r50f6afb  
    126126                        double sExt_len = ready.push.extrn.success ? ((double)ready.push.extrn.attempt) / ready.push.extrn.success : 0;
    127127
    128                         double rLcl_len  = ready.pop.local .success ? ((double)ready.pop.local .attempt) / ready.pop.local .success : 0;
    129                         double rHlp_len  = ready.pop.help  .success ? ((double)ready.pop.help  .attempt) / ready.pop.help  .success : 0;
    130                         double rStl_len  = ready.pop.steal .success ? ((double)ready.pop.steal .attempt) / ready.pop.steal .success : 0;
    131                         double rSch_len  = ready.pop.search.success ? ((double)ready.pop.search.attempt) / ready.pop.search.success : 0;
     128                        uint64_t total = ready.pop.local.success + ready.pop.help.success + ready.pop.steal.success + ready.pop.search.success;
     129                        double rLcl_pc = (100.0 * (double)ready.pop.local .success) / total;
     130                        double rHlp_pc = (100.0 * (double)ready.pop.help  .success) / total;
     131                        double rStl_pc = (100.0 * (double)ready.pop.steal .success) / total;
     132                        double rSch_pc = (100.0 * (double)ready.pop.search.success) / total;
    132133
    133134                        __cfaabi_bits_print_safe( STDOUT_FILENO,
    134135                                "----- %s \"%s\" (%p) - Ready Q Stats -----\n"
    135136                                "- totals   : %'3" PRIu64 " run, %'3" PRIu64 " schd (%'" PRIu64 "ext, %'" PRIu64 "mig, %'" PRId64 " )\n"
    136                                 "- push avg : %'3.2lf (l: %'3.2lf/%'" PRIu64 ", s: %'3.2lf/%'" PRIu64 ", e: %'3.2lf : %'" PRIu64 "e)\n"
    137                                 "- local    : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    138                                 "- help     : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    139                                 "- steal    : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    140                                 "- search   : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     137                                "- push avg : %'3.0lf (l: %'3.2lf/%'" PRIu64 ", s: %'3.2lf/%'" PRIu64 ", e: %'3.2lf : %'" PRIu64 "e)\n"
     138                                "- local    : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     139                                "- help     : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     140                                "- steal    : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     141                                "- search   : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    141142                                "- Idle Slp : %'3" PRIu64 "h, %'3" PRIu64 "c, %'3" PRIu64 "w, %'3" PRIu64 "e\n"
    142143                                "\n"
    143144                                , type, name, id
    144                                 , ready.pop.local.success + ready.pop.help.success + ready.pop.steal.success + ready.pop.search.success
     145                                , total
    145146                                , ready.push.local.success + ready.push.share.success + ready.push.extrn.success
    146147                                , ready.push.extrn.success, ready.threads.migration, ready.threads.threads
    147148                                , push_len, sLcl_len, ready.push.local.attempt, sOth_len, ready.push.share.attempt, sExt_len, ready.push.extrn.attempt
    148                                 , rLcl_len, ready.pop.local .attempt, ready.pop.local .espec, ready.pop.local .elock, ready.pop.local .eempty
    149                                 , rHlp_len, ready.pop.help  .attempt, ready.pop.help  .espec, ready.pop.help  .elock, ready.pop.help  .eempty
    150                                 , rStl_len, ready.pop.steal .attempt, ready.pop.steal .espec, ready.pop.steal .elock, ready.pop.steal .eempty
    151                                 , rSch_len, ready.pop.search.attempt, ready.pop.search.espec, ready.pop.search.elock, ready.pop.search.eempty
     149                                , rLcl_pc, ready.pop.local .success, ready.pop.local .attempt, ready.pop.local .espec, ready.pop.local .elock, ready.pop.local .eempty
     150                                , rHlp_pc, ready.pop.help  .success, ready.pop.help  .attempt, ready.pop.help  .espec, ready.pop.help  .elock, ready.pop.help  .eempty
     151                                , rStl_pc, ready.pop.steal .success, ready.pop.steal .attempt, ready.pop.steal .espec, ready.pop.steal .elock, ready.pop.steal .eempty
     152                                , rSch_pc, ready.pop.search.success, ready.pop.search.attempt, ready.pop.search.espec, ready.pop.search.elock, ready.pop.search.eempty
    152153                                , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits
    153154                        );
  • libcfa/src/concurrency/thread.cfa

    rfec63b2 r50f6afb  
    6161}
    6262
    63 EHM_VIRTUAL_TABLE(SomeThreadCancelled, std_thread_cancelled);
    64 
    6563forall(T &)
    6664void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src) {
     
    8179}
    8280
    83 static void default_thread_cancel_handler(SomeThreadCancelled & ) {
    84         // Improve this error message, can I do formatting?
    85         abort( "Unhandled thread cancellation.\n" );
    86 }
    87 
    88 forall(T & | is_thread(T) | IS_EXCEPTION(SomeThreadCancelled))
     81forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))
     82    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })
    8983void ?{}( thread_dtor_guard_t & this,
    90                 T & thrd, void(*cancelHandler)(SomeThreadCancelled &)) {
     84                T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) {
    9185        $monitor * m = get_monitor(thrd);
    9286        $thread * desc = get_thread(thrd);
     
    9488        // Setup the monitor guard
    9589        void (*dtor)(T& mutex this) = ^?{};
    96         bool join = cancelHandler != (void(*)(SomeThreadCancelled&))0;
     90        bool join = cancelHandler != (void(*)(ThreadCancelled(T)&))0;
    9791        (this.mg){&m, (void(*)())dtor, join};
    9892
     
    108102        }
    109103        desc->state = Cancelled;
    110         void(*defaultResumptionHandler)(SomeThreadCancelled &) =
     104        void(*defaultResumptionHandler)(ThreadCancelled(T) &) =
    111105                join ? cancelHandler : default_thread_cancel_handler;
    112106
    113107        // TODO: Remove explitate vtable set once trac#186 is fixed.
    114         SomeThreadCancelled except;
    115         except.virtual_table = &std_thread_cancelled;
     108        ThreadCancelled(T) except;
     109        except.virtual_table = &_default_vtable;
    116110        except.the_thread = &thrd;
    117111        except.the_exception = __cfaehm_cancellation_exception( cancellation );
    118112        // Why is this cast required?
    119         throwResume (SomeThreadCancelled &)except;
     113        throwResume (ThreadCancelled(T) &)except;
    120114
    121115        except.the_exception->virtual_table->free( except.the_exception );
     
    164158
    165159//-----------------------------------------------------------------------------
    166 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled))
     160forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))
     161    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })
    167162T & join( T & this ) {
    168163        thread_dtor_guard_t guard = { this, defaultResumptionHandler };
  • libcfa/src/concurrency/thread.hfa

    rfec63b2 r50f6afb  
    3131        $thread* get_thread(T& this);
    3232};
    33 
    34 EHM_EXCEPTION(SomeThreadCancelled) (
    35         void * the_thread;
    36         exception_t * the_exception;
    37 );
    38 
    39 EHM_EXTERN_VTABLE(SomeThreadCancelled, std_thread_cancelled);
    4033
    4134EHM_FORALL_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) (
     
    8679};
    8780
    88 forall( T & | is_thread(T) | IS_EXCEPTION(SomeThreadCancelled) )
    89 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(SomeThreadCancelled &) );
     81forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))
     82    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } )
     83void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) );
    9084void ^?{}( thread_dtor_guard_t & this );
    9185
     
    132126//----------
    133127// join
    134 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled) )
     128forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))
     129    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } )
    135130T & join( T & this );
    136131
Note: See TracChangeset for help on using the changeset viewer.