Changeset 85b1deb for src/libcfa/concurrency
- Timestamp:
- Jun 7, 2018, 6:10:10 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 7bdcac1, beefc34c
- Parents:
- 08b5a7e
- Location:
- src/libcfa/concurrency
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel
r08b5a7e r85b1deb 113 113 pthread_t kernel_thread; 114 114 115 // RunThread data 116 // Action to do after a thread is ran 117 struct FinishAction finish; 118 119 // Preemption data 120 // Node which is added in the discrete event simulaiton 121 struct alarm_node_t * preemption_alarm; 122 123 // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible 124 bool pending_preemption; 125 126 // Idle lock 127 __bin_sem_t idleLock; 128 115 129 // Termination 116 130 // Set to true to notify the processor should terminate … … 119 133 // Termination synchronisation 120 134 semaphore terminated; 121 122 // RunThread data123 // Action to do after a thread is ran124 struct FinishAction finish;125 126 // Preemption data127 // Node which is added in the discrete event simulaiton128 struct alarm_node_t * preemption_alarm;129 130 // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible131 bool pending_preemption;132 133 // Idle lock134 sem_t idleLock;135 // __bin_sem_t idleLock;136 135 137 136 // Link lists fields -
src/libcfa/concurrency/kernel.c
r08b5a7e r85b1deb 147 147 runner.proc = &this; 148 148 149 sem_init(&idleLock, 0, 0);149 idleLock{}; 150 150 151 151 start( &this ); … … 155 155 if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) { 156 156 __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this); 157 terminate(&this); 158 verify( __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 159 verify( kernelTLS.this_processor != &this); 157 158 __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED); 159 wake( &this ); 160 160 161 P( terminated ); 161 162 verify( kernelTLS.this_processor != &this); 162 pthread_join( kernel_thread, NULL ); 163 } 164 165 sem_destroy(&idleLock); 163 } 164 165 pthread_join( kernel_thread, NULL ); 166 166 } 167 167 … … 295 295 } 296 296 297 // Handles spinning logic298 // TODO : find some strategy to put cores to sleep after some time299 void spin(processor * this, unsigned int * spin_count) {300 // (*spin_count)++;301 halt(this);302 }303 304 297 // KERNEL_ONLY 305 298 // Context invoker for processors … … 408 401 unlock( ready_queue_lock ); 409 402 410 if( was_empty) {403 if(was_empty) { 411 404 lock (proc_list_lock __cfaabi_dbg_ctx2); 412 405 if(idles) { 413 wake (idles.head);406 wake_fast(idles.head); 414 407 } 415 408 unlock (proc_list_lock); 416 409 } 410 else if( struct processor * idle = idles.head ) { 411 wake_fast(idle); 412 } 413 417 414 } 418 415 … … 660 657 661 658 void halt(processor * this) with( *this ) { 662 verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );659 // verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 663 660 664 661 with( *cltr ) { … … 671 668 __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this); 672 669 673 // #ifdef __CFA_WITH_VERIFY__ 674 // int sval = 0; 675 // sem_getvalue(&this->idleLock, &sval); 676 // verifyf(sval < 200, "Binary semaphore reached value %d : \n", sval); 677 // #endif 678 679 verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 680 int __attribute__((unused)) ret = sem_wait(&idleLock); 681 // verifyf(ret >= 0 || errno == EINTR, "Sem_wait returned %d (errno %d : %s\n", ret, errno, strerror(errno)); 682 683 // wait( idleLock ); 670 wait( idleLock ); 684 671 685 672 __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this); … … 691 678 unlock (proc_list_lock); 692 679 } 693 }694 695 void wake(processor * this) {696 __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);697 int __attribute__((unused)) ret = sem_post(&this->idleLock);698 // verifyf(ret >= 0 || errno == EINTR, "Sem_post returned %d (errno %d : %s\n", ret, errno, strerror(errno));699 700 // #ifdef __CFA_WITH_VERIFY__701 // int sval = 0;702 // sem_getvalue(&this->idleLock, &sval);703 // verifyf(sval < 200, "Binary semaphore reached value %d\n", sval);704 // #endif705 706 // post( this->idleLock );707 680 } 708 681 -
src/libcfa/concurrency/kernel_private.h
r08b5a7e r85b1deb 58 58 void finishRunning(processor * this); 59 59 void halt(processor * this); 60 void wake(processor * this); 61 void terminate(processor * this); 62 void spin(processor * this, unsigned int * spin_count); 60 61 static inline void wake_fast(processor * this) { 62 __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this); 63 post( this->idleLock ); 64 } 65 66 static inline void wake(processor * this) { 67 disable_interrupts(); 68 wake_fast(this); 69 enable_interrupts( __cfaabi_dbg_ctx ); 70 } 63 71 64 72 struct event_kernel_t { … … 68 76 69 77 extern event_kernel_t * event_kernel; 70 71 //extern thread_local coroutine_desc * volatile this_coroutine;72 //extern thread_local thread_desc * volatile this_thread;73 //extern thread_local processor * volatile this_processor;74 75 // extern volatile thread_local bool preemption_in_progress;76 // extern volatile thread_local bool preemption_enabled;77 // extern volatile thread_local unsigned short disable_preempt_count;78 78 79 79 struct __cfa_kernel_preemption_state_t { -
src/libcfa/concurrency/preemption.c
r08b5a7e r85b1deb 260 260 static void preempt( processor * this ) { 261 261 sigval_t value = { PREEMPT_NORMAL }; 262 pthread_sigqueue( this->kernel_thread, SIGUSR1, value );263 }264 265 // kill wrapper : signal a processor266 void terminate(processor * this) {267 disable_interrupts();268 __atomic_store_n(&this->do_terminate, true, __ATOMIC_SEQ_CST);269 wake( this );270 sigval_t value = { PREEMPT_TERMINATE };271 enable_interrupts( __cfaabi_dbg_ctx );272 262 pthread_sigqueue( this->kernel_thread, SIGUSR1, value ); 273 263 }
Note: See TracChangeset
for help on using the changeset viewer.