Changeset b227f68 for src/libcfa
- Timestamp:
- Jun 29, 2017, 11:59:09 AM (7 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, resolv-new, with_gc
- Children:
- b751c8e
- Parents:
- 7bbba76
- Location:
- src/libcfa/concurrency
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
r7bbba76 rb227f68 38 38 clock_gettime( CLOCK_REALTIME, &curr ); 39 39 __cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec; 40 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time );40 // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time ); 41 41 return curr_time; 42 42 } 43 43 44 44 void __kernel_set_timer( __cfa_time_t alarm ) { 45 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );45 // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm ); 46 46 itimerval val; 47 47 val.it_value.tv_sec = alarm / TIMEGRAN; // seconds -
src/libcfa/concurrency/invoke.h
r7bbba76 rb227f68 32 32 volatile int lock; 33 33 #ifdef __CFA_DEBUG__ 34 const char * prev; 34 const char * prev_name; 35 void* prev_thrd; 35 36 #endif 36 37 }; … … 101 102 #ifndef _INVOKE_PRIVATE_H_ 102 103 #define _INVOKE_PRIVATE_H_ 103 104 104 105 struct machine_context_t { 105 106 void *SP; -
src/libcfa/concurrency/kernel
r7bbba76 rb227f68 28 28 //----------------------------------------------------------------------------- 29 29 // Locks 30 bool try_lock( spinlock * DEBUG_CTX_PARAM2 ); 31 void lock ( spinlock * DEBUG_CTX_PARAM2 ); 32 void unlock ( spinlock * ); 30 bool try_lock ( spinlock * DEBUG_CTX_PARAM2 ); 31 void lock ( spinlock * DEBUG_CTX_PARAM2 ); 32 void lock_yield( spinlock * DEBUG_CTX_PARAM2 ); 33 void unlock ( spinlock * ); 33 34 34 35 struct signal_once { -
src/libcfa/concurrency/kernel.c
r7bbba76 rb227f68 605 605 606 606 bool try_lock( spinlock * this DEBUG_CTX_PARAM2 ) { 607 bool ret = this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0; 608 LIB_DEBUG_DO( this->prev = caller; ) 609 return ret; 607 return this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0; 610 608 } 611 609 612 610 void lock( spinlock * this DEBUG_CTX_PARAM2 ) { 613 611 for ( unsigned int i = 1;; i += 1 ) { 614 if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) break; 615 } 616 LIB_DEBUG_DO( this->prev = caller; ) 617 } 612 if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) { break; } 613 } 614 LIB_DEBUG_DO( 615 this->prev_name = caller; 616 this->prev_thrd = this_thread; 617 ) 618 } 619 620 void lock_yield( spinlock * this DEBUG_CTX_PARAM2 ) { 621 for ( unsigned int i = 1;; i += 1 ) { 622 if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) { break; } 623 yield(); 624 } 625 LIB_DEBUG_DO( 626 this->prev_name = caller; 627 this->prev_thrd = this_thread; 628 ) 629 } 630 618 631 619 632 void unlock( spinlock * this ) { -
src/libcfa/concurrency/monitor.c
r7bbba76 rb227f68 45 45 extern "C" { 46 46 void __enter_monitor_desc( monitor_desc * this ) { 47 lock ( &this->lock DEBUG_CTX2 );47 lock_yield( &this->lock DEBUG_CTX2 ); 48 48 thread_desc * thrd = this_thread; 49 49 … … 76 76 // TODO 77 77 void __leave_monitor_desc( monitor_desc * this ) { 78 lock ( &this->lock DEBUG_CTX2 );78 lock_yield( &this->lock DEBUG_CTX2 ); 79 79 80 80 // LIB_DEBUG_PRINT_SAFE("%p Leaving %p (o: %p, r: %i). ", this_thread, this, this->owner, this->recursion); … … 104 104 void __leave_thread_monitor( thread_desc * thrd ) { 105 105 monitor_desc * this = &thrd->mon; 106 lock ( &this->lock DEBUG_CTX2 );106 lock_yield( &this->lock DEBUG_CTX2 ); 107 107 108 108 disable_interrupts(); … … 188 188 // Internal scheduling 189 189 void wait( condition * this, uintptr_t user_info = 0 ) { 190 LIB_DEBUG_PRINT_SAFE("Waiting\n");190 // LIB_DEBUG_PRINT_SAFE("Waiting\n"); 191 191 192 192 brand_condition( this ); … … 201 201 spinlock * locks [ count ]; //We need to pass-in an array of locks to BlockInternal 202 202 203 LIB_DEBUG_PRINT_SAFE("count %i\n", count);203 // LIB_DEBUG_PRINT_SAFE("count %i\n", count); 204 204 205 205 __condition_node_t waiter = { (thread_desc*)this_thread, count, user_info }; … … 208 208 for(int i = 0; i < count; i++) { 209 209 (&criteria[i]){ this->monitors[i], &waiter }; 210 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );210 // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] ); 211 211 } 212 212 … … 230 230 } 231 231 232 LIB_DEBUG_PRINT_SAFE("Will unblock: ");232 // LIB_DEBUG_PRINT_SAFE("Will unblock: "); 233 233 for(int i = 0; i < thread_count; i++) { 234 LIB_DEBUG_PRINT_SAFE("%p ", threads[i]);235 } 236 LIB_DEBUG_PRINT_SAFE("\n");234 // LIB_DEBUG_PRINT_SAFE("%p ", threads[i]); 235 } 236 // LIB_DEBUG_PRINT_SAFE("\n"); 237 237 238 238 // Everything is ready to go to sleep … … 251 251 bool signal( condition * this ) { 252 252 if( is_empty( this ) ) { 253 LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");253 // LIB_DEBUG_PRINT_SAFE("Nothing to signal\n"); 254 254 return false; 255 255 } … … 277 277 //Lock all the monitors 278 278 lock_all( this->monitors, NULL, count ); 279 LIB_DEBUG_PRINT_SAFE("Signalling");279 // LIB_DEBUG_PRINT_SAFE("Signalling"); 280 280 281 281 //Pop the head of the waiting queue … … 285 285 for(int i = 0; i < count; i++) { 286 286 __condition_criterion_t * crit = &node->criteria[i]; 287 LIB_DEBUG_PRINT_SAFE(" %p", crit->target);287 // LIB_DEBUG_PRINT_SAFE(" %p", crit->target); 288 288 assert( !crit->ready ); 289 289 push( &crit->target->signal_stack, crit ); 290 290 } 291 291 292 LIB_DEBUG_PRINT_SAFE("\n");292 // LIB_DEBUG_PRINT_SAFE("\n"); 293 293 294 294 //Release … … 320 320 for(int i = 0; i < count; i++) { 321 321 (&criteria[i]){ this->monitors[i], &waiter }; 322 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );322 // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] ); 323 323 push( &criteria[i].target->signal_stack, &criteria[i] ); 324 324 } … … 422 422 static inline void lock_all( spinlock ** locks, unsigned short count ) { 423 423 for( int i = 0; i < count; i++ ) { 424 lock ( locks[i] DEBUG_CTX2 );424 lock_yield( locks[i] DEBUG_CTX2 ); 425 425 } 426 426 } … … 429 429 for( int i = 0; i < count; i++ ) { 430 430 spinlock * l = &source[i]->lock; 431 lock ( l DEBUG_CTX2 );431 lock_yield( l DEBUG_CTX2 ); 432 432 if(locks) locks[i] = l; 433 433 } … … 472 472 for( int i = 0; i < count; i++ ) { 473 473 474 LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );474 // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target ); 475 475 if( &criteria[i] == target ) { 476 476 criteria[i].ready = true; 477 LIB_DEBUG_PRINT_SAFE( "True\n" );477 // LIB_DEBUG_PRINT_SAFE( "True\n" ); 478 478 } 479 479 … … 481 481 } 482 482 483 LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run );483 // LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run ); 484 484 return ready2run ? node->waiting_thread : NULL; 485 485 } … … 488 488 thread_desc * thrd = this_thread; 489 489 if( !this->monitors ) { 490 LIB_DEBUG_PRINT_SAFE("Branding\n");490 // LIB_DEBUG_PRINT_SAFE("Branding\n"); 491 491 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition", thrd->current_monitors ); 492 492 this->monitor_count = thrd->current_monitor_count; -
src/libcfa/concurrency/preemption.c
r7bbba76 rb227f68 158 158 //============================================================================================= 159 159 160 LIB_DEBUG_DO( static thread_local void * last_interrupt = 0; ) 161 160 162 extern "C" { 161 163 void disable_interrupts() { … … 187 189 188 190 static inline void signal_unblock( int sig ) { 189 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : %p unblocking sig %i\n", this_processor, sig ); 191 // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : %p unblocking sig %i\n", this_processor, sig ); 192 193 // LIB_DEBUG_DO( 194 // sigset_t waiting; 195 // sigemptyset(&waiting); 196 // sigpending(&waiting); 197 // verify( !sigismember(&waiting, sig) ); 198 // ) 190 199 191 200 sigset_t mask; … … 217 226 218 227 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) { 219 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Ctx Switch IRH %p running %p @ %p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) ); 228 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "CtxSw IRH %10p running %10p @ %10p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) ); 229 LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[REG_RIP]); ) 220 230 221 231 if( preemption_ready() ) { 222 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Blocking thread %p on %p\n", this_thread, this_processor );232 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Blocking thread %p on %p\n", this_thread, this_processor ); 223 233 signal_unblock( SIGUSR1 ); 224 234 BlockInternal( (thread_desc*)this_thread ); 225 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Back\n\n");235 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Back\n\n"); 226 236 } 227 237 else { 228 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Defering\n" );238 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Defering\n" ); 229 239 defer_ctxSwitch(); 230 240 signal_unblock( SIGUSR1 ); … … 233 243 234 244 void sigHandler_alarm( __CFA_SIGPARMS__ ) { 235 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "\nAlarm IRH %p running %p @ %p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) ); 236 237 // if( ((intptr_t)cxt->uc_mcontext.gregs[REG_RIP]) > 0xFFFFFF ) __debug_break(); 245 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "\nAlarm IRH %10p running %10p @ %10p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) ); 246 LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[REG_RIP]); ) 238 247 239 248 if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) { … … 248 257 249 258 if( preemption_ready() && this_processor->pending_preemption ) { 250 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm IRH : Blocking thread %p on %p\n", this_thread, this_processor );259 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm IRH : Blocking thread %p on %p\n", this_thread, this_processor ); 251 260 this_processor->pending_preemption = false; 252 261 BlockInternal( (thread_desc*)this_thread ); 253 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm Switch IRH : Back\n\n");262 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm Switch IRH : Back\n\n"); 254 263 } 255 264 }
Note: See TracChangeset
for help on using the changeset viewer.