Changeset 50f6afb for libcfa/src/concurrency
- Timestamp:
- Apr 24, 2021, 11:32:49 AM (3 years ago)
- 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. - Location:
- libcfa/src/concurrency
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/clib/cfathread.cfa
rfec63b2 r50f6afb 50 50 51 51 cfathread_vtable _cfathread_vtable_instance; 52 53 cfathread_vtable & const _default_vtable = _cfathread_vtable_instance; 52 54 53 55 cfathread_vtable const & get_exception_vtable(cfathread_exception *) { -
libcfa/src/concurrency/coroutine.cfa
rfec63b2 r50f6afb 46 46 47 47 //----------------------------------------------------------------------------- 48 EHM_VIRTUAL_TABLE(SomeCoroutineCancelled, std_coroutine_cancelled);49 50 48 forall(T &) 51 49 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) { … … 62 60 // This code should not be inlined. It is the error path on resume. 63 61 forall(T & | is_coroutine(T)) 64 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) { 62 void __cfaehm_cancelled_coroutine( 63 T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ) { 65 64 verify( desc->cancellation ); 66 65 desc->state = Cancelled; … … 68 67 69 68 // TODO: Remove explitate vtable set once trac#186 is fixed. 70 SomeCoroutineCancelledexcept;71 except.virtual_table = & std_coroutine_cancelled;69 CoroutineCancelled(T) except; 70 except.virtual_table = &_default_vtable; 72 71 except.the_coroutine = &cor; 73 72 except.the_exception = except; 74 73 // Why does this need a cast? 75 throwResume ( SomeCoroutineCancelled&)except;74 throwResume (CoroutineCancelled(T) &)except; 76 75 77 76 except->virtual_table->free( except ); … … 146 145 // Part of the Public API 147 146 // Not inline since only ever called once per coroutine 148 forall(T & | is_coroutine(T) )147 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; }) 149 148 void prime(T& cor) { 150 149 $coroutine* this = get_coroutine(cor); -
libcfa/src/concurrency/coroutine.hfa
rfec63b2 r50f6afb 22 22 //----------------------------------------------------------------------------- 23 23 // 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 31 24 EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) ( 32 25 coroutine_t * the_coroutine; … … 44 37 // Anything that implements this trait can be resumed. 45 38 // Anything that is resumed is a coroutine. 46 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION( SomeCoroutineCancelled)) {39 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) { 47 40 void main(T & this); 48 41 $coroutine * get_coroutine(T & this); … … 67 60 //----------------------------------------------------------------------------- 68 61 // Public coroutine API 69 forall(T & | is_coroutine(T) )62 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; }) 70 63 void prime(T & cor); 71 64 … … 137 130 138 131 forall(T & | is_coroutine(T)) 139 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ); 132 void __cfaehm_cancelled_coroutine( 133 T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ); 140 134 141 135 // Resume implementation inlined for performance 142 forall(T & | is_coroutine(T) )136 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; }) 143 137 static inline T & resume(T & cor) { 144 138 // optimization : read TLS once and reuse it … … 170 164 $ctx_switch( src, dst ); 171 165 if ( unlikely(dst->cancellation) ) { 172 __cfaehm_cancelled_coroutine( cor, dst );166 __cfaehm_cancelled_coroutine( cor, dst, _default_vtable ); 173 167 } 174 168 -
libcfa/src/concurrency/locks.hfa
rfec63b2 r50f6afb 197 197 static inline $thread * unlock( fast_lock & this ) __attribute__((artificial)); 198 198 static inline $thread * unlock( fast_lock & this ) { 199 $thread * thrd = active_thread(); 200 /* paranoid */ verify(thrd == this.owner); 199 /* paranoid */ verify(active_thread() == this.owner); 201 200 202 201 // open 'owner' before unlocking anyone -
libcfa/src/concurrency/ready_queue.cfa
rfec63b2 r50f6afb 413 413 unsigned it2 = proc->rdq.itr + 1; 414 414 unsigned idx1 = proc->rdq.id + (it1 % READYQ_SHARD_FACTOR); 415 unsigned idx2 = proc->rdq.id + (it 1% READYQ_SHARD_FACTOR);415 unsigned idx2 = proc->rdq.id + (it2 % READYQ_SHARD_FACTOR); 416 416 unsigned long long tsc1 = ts(lanes.data[idx1]); 417 417 unsigned long long tsc2 = ts(lanes.data[idx2]); 418 418 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; 422 423 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 } 424 428 } 425 429 -
libcfa/src/concurrency/stats.cfa
rfec63b2 r50f6afb 126 126 double sExt_len = ready.push.extrn.success ? ((double)ready.push.extrn.attempt) / ready.push.extrn.success : 0; 127 127 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; 132 133 133 134 __cfaabi_bits_print_safe( STDOUT_FILENO, 134 135 "----- %s \"%s\" (%p) - Ready Q Stats -----\n" 135 136 "- 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" 141 142 "- Idle Slp : %'3" PRIu64 "h, %'3" PRIu64 "c, %'3" PRIu64 "w, %'3" PRIu64 "e\n" 142 143 "\n" 143 144 , type, name, id 144 , ready.pop.local.success + ready.pop.help.success + ready.pop.steal.success + ready.pop.search.success145 , total 145 146 , ready.push.local.success + ready.push.share.success + ready.push.extrn.success 146 147 , ready.push.extrn.success, ready.threads.migration, ready.threads.threads 147 148 , 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 .eempty149 , rHlp_ len, ready.pop.help .attempt, ready.pop.help .espec, ready.pop.help .elock, ready.pop.help .eempty150 , rStl_ len, ready.pop.steal .attempt, ready.pop.steal .espec, ready.pop.steal .elock, ready.pop.steal .eempty151 , rSch_ len, ready.pop.search.attempt, ready.pop.search.espec, ready.pop.search.elock, ready.pop.search.eempty149 , 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 152 153 , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits 153 154 ); -
libcfa/src/concurrency/thread.cfa
rfec63b2 r50f6afb 61 61 } 62 62 63 EHM_VIRTUAL_TABLE(SomeThreadCancelled, std_thread_cancelled);64 65 63 forall(T &) 66 64 void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src) { … … 81 79 } 82 80 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)) 81 forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) 82 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; }) 89 83 void ?{}( thread_dtor_guard_t & this, 90 T & thrd, void(*cancelHandler)( SomeThreadCancelled&)) {84 T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) { 91 85 $monitor * m = get_monitor(thrd); 92 86 $thread * desc = get_thread(thrd); … … 94 88 // Setup the monitor guard 95 89 void (*dtor)(T& mutex this) = ^?{}; 96 bool join = cancelHandler != (void(*)( SomeThreadCancelled&))0;90 bool join = cancelHandler != (void(*)(ThreadCancelled(T)&))0; 97 91 (this.mg){&m, (void(*)())dtor, join}; 98 92 … … 108 102 } 109 103 desc->state = Cancelled; 110 void(*defaultResumptionHandler)( SomeThreadCancelled&) =104 void(*defaultResumptionHandler)(ThreadCancelled(T) &) = 111 105 join ? cancelHandler : default_thread_cancel_handler; 112 106 113 107 // TODO: Remove explitate vtable set once trac#186 is fixed. 114 SomeThreadCancelledexcept;115 except.virtual_table = & std_thread_cancelled;108 ThreadCancelled(T) except; 109 except.virtual_table = &_default_vtable; 116 110 except.the_thread = &thrd; 117 111 except.the_exception = __cfaehm_cancellation_exception( cancellation ); 118 112 // Why is this cast required? 119 throwResume ( SomeThreadCancelled&)except;113 throwResume (ThreadCancelled(T) &)except; 120 114 121 115 except.the_exception->virtual_table->free( except.the_exception ); … … 164 158 165 159 //----------------------------------------------------------------------------- 166 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled)) 160 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) 161 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; }) 167 162 T & join( T & this ) { 168 163 thread_dtor_guard_t guard = { this, defaultResumptionHandler }; -
libcfa/src/concurrency/thread.hfa
rfec63b2 r50f6afb 31 31 $thread* get_thread(T& this); 32 32 }; 33 34 EHM_EXCEPTION(SomeThreadCancelled) (35 void * the_thread;36 exception_t * the_exception;37 );38 39 EHM_EXTERN_VTABLE(SomeThreadCancelled, std_thread_cancelled);40 33 41 34 EHM_FORALL_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) ( … … 86 79 }; 87 80 88 forall( T & | is_thread(T) | IS_EXCEPTION(SomeThreadCancelled) ) 89 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(SomeThreadCancelled &) ); 81 forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) 82 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } ) 83 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) ); 90 84 void ^?{}( thread_dtor_guard_t & this ); 91 85 … … 132 126 //---------- 133 127 // join 134 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled) ) 128 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) 129 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } ) 135 130 T & join( T & this ); 136 131
Note: See TracChangeset
for help on using the changeset viewer.