Changes in / [578e6037:24fc196]
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/benchmark/create_pthrd.c
r578e6037 r24fc196 17 17 18 18 for (size_t i = 0; i < n; i++) { 19 pthread_ attr_t attr;20 if (pthread_ attr_init(&attr) < 0) {19 pthread_t thread; 20 if (pthread_create(&thread, NULL, foo, NULL) < 0) { 21 21 return 1; 22 22 } 23 if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) < 0) { 24 return 1; 25 } 26 pthread_t thread; 27 if (pthread_create(&thread, &attr, foo, NULL) < 0) { 23 24 if (pthread_join( thread, NULL) < 0) { 28 25 return 1; 29 26 } -
src/libcfa/concurrency/kernel.c
r578e6037 r24fc196 60 60 volatile thread_local coroutine_desc * this_coroutine; 61 61 volatile thread_local thread_desc * this_thread; 62 volatile thread_local bool preemption_in_progress = 0; 62 63 volatile thread_local unsigned short disable_preempt_count = 1; 63 64 -
src/libcfa/concurrency/kernel_private.h
r578e6037 r24fc196 79 79 extern volatile thread_local coroutine_desc * this_coroutine; 80 80 extern volatile thread_local thread_desc * this_thread; 81 extern volatile thread_local bool preemption_in_progress; 81 82 extern volatile thread_local unsigned short disable_preempt_count; 82 83 -
src/libcfa/concurrency/preemption.c
r578e6037 r24fc196 180 180 181 181 static inline bool preemption_ready() { 182 return disable_preempt_count == 0 ;182 return disable_preempt_count == 0 && !preemption_in_progress; 183 183 } 184 184 … … 218 218 219 219 void kernel_stop_preemption() { 220 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopping\n"); 221 220 222 sigset_t mask; 221 223 sigfillset( &mask ); 222 224 sigprocmask( SIG_BLOCK, &mask, NULL ); 223 225 224 pthread_kill( alarm_thread, SIGINT ); 226 sigval val = { 1 }; 227 pthread_sigqueue( alarm_thread, SIGALRM, val ); 225 228 pthread_join( alarm_thread, NULL ); 226 229 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopped\n"); … … 247 250 LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); ) 248 251 if( preemption_ready() ) { 252 preemption_in_progress = true; 249 253 signal_unblock( SIGUSR1 ); 254 this_processor->pending_preemption = false; 255 preemption_in_progress = false; 250 256 BlockInternal( (thread_desc*)this_thread ); 251 257 } … … 254 260 } 255 261 } 256 257 // void sigHandler_alarm( __CFA_SIGPARMS__ ) {258 // LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )259 // verify( this_processor == systemProcessor );260 261 // if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) {262 // tick_preemption();263 // systemProcessor->pending_alarm = false;264 // unlock( &systemProcessor->alarm_lock );265 // }266 // else {267 // defer_alarm();268 // }269 270 // signal_unblock( SIGALRM );271 272 // if( preemption_ready() && this_processor->pending_preemption ) {273 274 // this_processor->pending_preemption = false;275 // BlockInternal( (thread_desc*)this_thread );276 // }277 // }278 262 279 263 void * alarm_loop( __attribute__((unused)) void * args ) { … … 281 265 sigemptyset( &mask ); 282 266 sigaddset( &mask, SIGALRM ); 283 sigaddset( &mask, SIGUSR2 );284 sigaddset( &mask, SIGINT );285 267 286 268 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { … … 289 271 290 272 while( true ) { 291 int sig; 292 if( sigwait( &mask, &sig ) != 0 ) { 273 siginfo_t info; 274 int sig = sigwaitinfo( &mask, &info ); 275 if( sig < 0 ) { 293 276 abortf( "internal error, sigwait" ); 294 277 } 295 296 switch( sig) { 297 case SIGALRM: 278 else if( sig == SIGALRM ) 279 { 280 LIB_DEBUG_PRINT_SAFE("Kernel : Caught signal %d (%d)\n", sig, info.si_value.sival_int ); 281 if( info.si_value.sival_int == 0 ) 282 { 298 283 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread tick\n"); 299 284 lock( &systemProcessor->alarm_lock DEBUG_CTX2 ); 300 285 tick_preemption(); 301 286 unlock( &systemProcessor->alarm_lock ); 287 } 288 else if( info.si_value.sival_int == 1 ) 289 { 302 290 break; 303 case SIGUSR2: 304 //TODO other actions 305 break; 306 case SIGINT: 307 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread stopping\n"); 308 return NULL; 309 default: 310 abortf( "internal error, sigwait returned sig %d", sig ); 311 break; 312 } 313 } 291 } 292 } 293 else 294 { 295 LIB_DEBUG_PRINT_SAFE("Kernel : Unexpected signal %d (%d)\n", sig, info.si_value.sival_int); 296 } 297 } 298 299 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread stopping\n"); 300 return NULL; 314 301 } 315 302 -
src/tests/preempt_longrun/Makefile.am
r578e6037 r24fc196 16 16 17 17 repeats=10 18 max_time= 3018 max_time=600 19 19 preempt=1_000ul 20 20 -
src/tests/preempt_longrun/Makefile.in
r578e6037 r24fc196 449 449 top_srcdir = @top_srcdir@ 450 450 repeats = 10 451 max_time = 30451 max_time = 600 452 452 preempt = 1_000ul 453 453 REPEAT = ${abs_top_srcdir}/tools/repeat -s -
src/tests/preempt_longrun/create.c
r578e6037 r24fc196 15 15 16 16 int main(int argc, char* argv[]) { 17 processor p; 17 18 for(int i = 0; i < 10_000ul; i++) { 18 19 worker_t w[7];
Note: See TracChangeset
for help on using the changeset viewer.