Changeset 47ecf2b for src/libcfa/concurrency/preemption.c
- Timestamp:
- Jul 4, 2017, 3:39:28 PM (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:
- cd17862
- Parents:
- 8ee50281
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/preemption.c
r8ee50281 r47ecf2b 179 179 if( prev == 1 && proc->pending_preemption ) { 180 180 proc->pending_preemption = false; 181 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Executing deferred CtxSwitch on %p\n", this_processor );182 181 BlockInternal( thrd ); 183 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Executing deferred back\n" );184 182 } 185 183 … … 189 187 190 188 static inline void signal_unblock( int 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 // ) 189 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Unblock %d on %p\n", sig, this_processor ); 199 190 200 191 sigset_t mask; … … 202 193 sigaddset( &mask, sig ); 203 194 204 if ( sigprocmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {205 abortf( "internal error, sigprocmask" );195 if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) { 196 abortf( "internal error, pthread_sigmask" ); 206 197 } // if 207 198 } 199 200 // static inline void signal_block( int sig ) { 201 // sigset_t mask; 202 // sigemptyset( &mask ); 203 // sigaddset( &mask, sig ); 204 205 // if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { 206 // abortf( "internal error, pthread_sigmask" ); 207 // } // if 208 // } 208 209 209 210 static inline bool preemption_ready() { … … 225 226 } 226 227 228 #ifdef __x86_64__ 229 #define CFA_REG_IP REG_RIP 230 #else 231 #define CFA_REG_IP REG_EIP 232 #endif 233 227 234 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) { 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]); )235 LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); ) 236 verify( this_processor != systemProcessor ); 230 237 231 238 if( preemption_ready() ) { 232 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Blocking thread %p on %p\n", this_thread, this_processor );233 239 signal_unblock( SIGUSR1 ); 234 240 BlockInternal( (thread_desc*)this_thread ); 235 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Back\n\n");236 241 } 237 242 else { 238 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Defering\n" );239 243 defer_ctxSwitch(); 240 signal_unblock( SIGUSR1 );241 244 } 242 245 } 243 246 244 247 void sigHandler_alarm( __CFA_SIGPARMS__ ) { 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]); )248 LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); ) 249 verify( this_processor == systemProcessor ); 247 250 248 251 if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) { 249 252 tick_preemption(); 253 systemProcessor->pending_alarm = false; 250 254 unlock( &systemProcessor->alarm_lock ); 251 255 } … … 257 261 258 262 if( preemption_ready() && this_processor->pending_preemption ) { 259 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm IRH : Blocking thread %p on %p\n", this_thread, this_processor ); 263 260 264 this_processor->pending_preemption = false; 261 265 BlockInternal( (thread_desc*)this_thread ); 262 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm Switch IRH : Back\n\n");263 266 } 264 267 } 265 268 266 269 static void preempt( processor * this ) { 267 // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : signalling %p\n", this );268 269 270 if( this != systemProcessor ) { 270 271 pthread_kill( this->kernel_thread, SIGUSR1 ); … … 284 285 act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler; 285 286 act.sa_flags = flags; 286 287 // disabled during signal handler288 sigemptyset( &act.sa_mask );289 sigaddset( &act.sa_mask, sig );290 287 291 288 if ( sigaction( sig, &act, NULL ) == -1 ) {
Note: See TracChangeset
for help on using the changeset viewer.