Changeset 2c88368 for src/libcfa/concurrency/preemption.c
- Timestamp:
- May 22, 2018, 4:46:29 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:
- 59c034c6, d807ca28
- Parents:
- a8706fc (diff), a1a17a74 (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
ra8706fc r2c88368 15 15 16 16 #include "preemption.h" 17 #include <assert.h> 17 18 18 19 extern "C" { … … 91 92 //Loop throught every thing expired 92 93 while( node = get_expired( alarms, currtime ) ) { 94 // __cfaabi_dbg_print_buffer_decl( " KERNEL: preemption tick.\n" ); 93 95 94 96 // Check if this is a kernel … … 103 105 Duration period = node->period; 104 106 if( period > 0 ) { 107 // __cfaabi_dbg_print_buffer_local( " KERNEL: alarm period is %lu.\n", period.tv ); 105 108 node->alarm = currtime + period; // Alarm is periodic, add currtime to it (used cached current time) 106 109 insert( alarms, node ); // Reinsert the node for the next time it triggers … … 112 115 113 116 // If there are still alarms pending, reset the timer 114 if( alarms->head ) { __kernel_set_timer( alarms->head->alarm - currtime ); } 117 if( alarms->head ) { 118 __cfaabi_dbg_print_buffer_decl( " KERNEL: @%lu(%lu) resetting alarm to %lu.\n", currtime.tv, __kernel_get_time().tv, (alarms->head->alarm - currtime).tv); 119 Duration delta = alarms->head->alarm - currtime; 120 Duration caped = max(delta, 50`us); 121 // itimerval tim = { caped }; 122 // __cfaabi_dbg_print_buffer_local( " Values are %lu, %lu, %lu %lu.\n", delta.tv, caped.tv, tim.it_value.tv_sec, tim.it_value.tv_usec); 123 124 __kernel_set_timer( caped ); 125 } 115 126 } 116 127 … … 335 346 if( !preemption_ready() ) { return; } 336 347 337 __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p ).\n", kernelTLS.this_processor, kernelTLS.this_thread);348 __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p @ %p).\n", kernelTLS.this_processor, kernelTLS.this_thread, (void *)(cxt->uc_mcontext.CFA_REG_IP) ); 338 349 339 350 // Sync flag : prevent recursive calls to the signal handler 340 351 kernelTLS.preemption_state.in_progress = true; 341 352 342 // We are about to CtxSwitch out of the signal handler, let other handlers in 343 signal_unblock( SIGUSR1 ); 353 // Clear sighandler mask before context switching. 354 static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" ); 355 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL ) == -1 ) { 356 abort( "internal error, sigprocmask" ); 357 } 344 358 345 359 // TODO: this should go in finish action … … 377 391 case EAGAIN : 378 392 case EINTR : 393 {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );} 379 394 continue; 380 395 case EINVAL : … … 424 439 sigset_t oldset; 425 440 int ret; 426 ret = sigprocmask(0, NULL, &oldset);441 ret = pthread_sigmask(0, NULL, &oldset); 427 442 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 428 443 429 444 ret = sigismember(&oldset, SIGUSR1); 430 445 if(ret < 0) { abort("ERROR sigismember returned %d", ret); } 431 432 446 if(ret == 1) { abort("ERROR SIGUSR1 is disabled"); } 447 448 ret = sigismember(&oldset, SIGALRM); 449 if(ret < 0) { abort("ERROR sigismember returned %d", ret); } 450 if(ret == 0) { abort("ERROR SIGALRM is enabled"); } 451 452 ret = sigismember(&oldset, SIGTERM); 453 if(ret < 0) { abort("ERROR sigismember returned %d", ret); } 454 if(ret == 1) { abort("ERROR SIGTERM is disabled"); } 433 455 } 434 456
Note: See TracChangeset
for help on using the changeset viewer.