Changeset bede27b for src/libcfa/concurrency/preemption.c
- Timestamp:
- Feb 9, 2018, 4:39:52 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, resolv-new, with_gc
- Children:
- 298ed08
- Parents:
- 381fdee (diff), a722c7a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/preemption.c
r381fdee rbede27b 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 9 1 4:42:34201813 // Update Count : 2512 // Last Modified On : Fri Feb 9 16:38:13 2018 13 // Update Count : 14 14 14 // 15 15 … … 67 67 } 68 68 69 enum { 70 PREEMPT_NORMAL = 0, 71 PREEMPT_TERMINATE = 1, 72 }; 73 69 74 //============================================================================================= 70 75 // Kernel Preemption logic … … 192 197 193 198 if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) { 194 abort f( "internal error, pthread_sigmask" );199 abort( "internal error, pthread_sigmask" ); 195 200 } 196 201 } … … 203 208 204 209 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { 205 abort f( "internal error, pthread_sigmask" );210 abort( "internal error, pthread_sigmask" ); 206 211 } 207 212 } … … 209 214 // kill wrapper : signal a processor 210 215 static void preempt( processor * this ) { 211 pthread_kill( this->kernel_thread, SIGUSR1 ); 216 sigval_t value = { PREEMPT_NORMAL }; 217 pthread_sigqueue( this->kernel_thread, SIGUSR1, value ); 218 } 219 220 // kill wrapper : signal a processor 221 void terminate(processor * this) { 222 this->do_terminate = true; 223 sigval_t value = { PREEMPT_TERMINATE }; 224 pthread_sigqueue( this->kernel_thread, SIGUSR1, value ); 212 225 } 213 226 … … 234 247 // Called from kernel_startup 235 248 void kernel_start_preemption() { 236 __cfaabi_dbg_print_safe( "Kernel : Starting preemption\n");249 __cfaabi_dbg_print_safe( "Kernel : Starting preemption\n" ); 237 250 238 251 // Start with preemption disabled until ready … … 255 268 // Called from kernel_shutdown 256 269 void kernel_stop_preemption() { 257 __cfaabi_dbg_print_safe( "Kernel : Preemption stopping\n");270 __cfaabi_dbg_print_safe( "Kernel : Preemption stopping\n" ); 258 271 259 272 // Block all signals since we are already shutting down … … 271 284 // Preemption is now fully stopped 272 285 273 __cfaabi_dbg_print_safe( "Kernel : Preemption stopped\n");286 __cfaabi_dbg_print_safe( "Kernel : Preemption stopped\n" ); 274 287 } 275 288 … … 299 312 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.CFA_REG_IP); ) 300 313 314 // SKULLDUGGERY: if a thread creates a processor and the immediately deletes it, 315 // the interrupt that is supposed to force the kernel thread to preempt might arrive 316 // before the kernel thread has even started running. When that happens an iterrupt 317 // we a null 'this_processor' will be caught, just ignore it. 318 if(!this_processor) return; 319 320 choose(sfp->si_value.sival_int) { 321 case PREEMPT_NORMAL : ;// Normal case, nothing to do here 322 case PREEMPT_TERMINATE: verify(this_processor->do_terminate); 323 default: 324 abort( "internal error, signal value is %d", sfp->si_value.sival_int ); 325 } 326 301 327 // Check if it is safe to preempt here 302 328 if( !preemption_ready() ) { return; } 303 329 304 __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);330 __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread); 305 331 306 332 preemption_in_progress = true; // Sync flag : prevent recursive calls to the signal handler … … 322 348 323 349 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { 324 abort f( "internal error, pthread_sigmask" );350 abort( "internal error, pthread_sigmask" ); 325 351 } 326 352 … … 339 365 continue; 340 366 case EINVAL : 341 abort f("Timeout was invalid.");367 abort( "Timeout was invalid." ); 342 368 default: 343 abort f("Unhandled error %d", err);369 abort( "Unhandled error %d", err); 344 370 } 345 371 } … … 348 374 assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int); 349 375 350 // __cfaabi_dbg_print_safe( "Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );376 // __cfaabi_dbg_print_safe( "Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int ); 351 377 // Switch on the code (a.k.a. the sender) to 352 378 switch( info.si_code ) … … 356 382 case SI_TIMER: 357 383 case SI_KERNEL: 358 // __cfaabi_dbg_print_safe( "Kernel : Preemption thread tick\n");384 // __cfaabi_dbg_print_safe( "Kernel : Preemption thread tick\n" ); 359 385 lock( event_kernel->lock __cfaabi_dbg_ctx2 ); 360 386 tick_preemption(); … … 370 396 371 397 EXIT: 372 __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n");398 __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" ); 373 399 return NULL; 374 400 }
Note: See TracChangeset
for help on using the changeset viewer.