Changeset 47ecf2b
- Timestamp:
- Jul 4, 2017, 3:39:28 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, 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
- Location:
- src/libcfa/concurrency
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
r8ee50281 r47ecf2b 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/coroutine.c
r8ee50281 r47ecf2b 44 44 // Coroutine ctors and dtors 45 45 void ?{}(coStack_t* this) { 46 this->size = 10240; // size of stack46 this->size = 65000; // size of stack 47 47 this->storage = NULL; // pointer to stack 48 48 this->limit = NULL; // stack grows towards stack limit … … 50 50 this->context = NULL; // address of cfa_context_t 51 51 this->top = NULL; // address of top of storage 52 this->userStack = false; 52 this->userStack = false; 53 53 } 54 54 … … 114 114 assert( src->stack.context ); 115 115 CtxSwitch( src->stack.context, dst->stack.context ); 116 // when CtxSwitch returns we are back in the src coroutine 116 // when CtxSwitch returns we are back in the src coroutine 117 117 118 118 // set state of new coroutine to active … … 132 132 this->size = libCeiling( storageSize, 16 ); 133 133 // use malloc/memalign because "new" raises an exception for out-of-memory 134 134 135 135 // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment 136 136 LIB_DEBUG_DO( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) ); -
src/libcfa/concurrency/kernel.c
r8ee50281 r47ecf2b 337 337 sigaddset( &new_mask, SIGALRM ); 338 338 339 if ( sigprocmask( SIG_BLOCK, &new_mask, &old_mask ) == -1 ) {340 abortf( "internal error, sigprocmask" );339 if ( pthread_sigmask( SIG_BLOCK, &new_mask, &old_mask ) == -1 ) { 340 abortf( "internal error, pthread_sigmask" ); 341 341 } 342 342 … … 348 348 // Toggle back previous signal mask of system processor. 349 349 if ( is_system_proc ) { 350 if ( sigprocmask( SIG_SETMASK, &old_mask, NULL ) == -1 ) {351 abortf( "internal error, sigprocmask" );350 if ( pthread_sigmask( SIG_SETMASK, &old_mask, NULL ) == -1 ) { 351 abortf( "internal error, pthread_sigmask" ); 352 352 } // if 353 353 } // if -
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.