Changes in / [85521c7:33c0ce8]
- Files:
-
- 9 edited
-
configure (modified) (2 diffs)
-
configure.ac (modified) (1 diff)
-
doc/theses/thierry_delisle/Makefile (modified) (2 diffs)
-
src/benchmark/Makefile.am (modified) (3 diffs)
-
src/benchmark/Makefile.in (modified) (3 diffs)
-
src/libcfa/concurrency/kernel.c (modified) (14 diffs)
-
src/libcfa/concurrency/kernel_private.h (modified) (1 diff)
-
src/libcfa/concurrency/monitor.c (modified) (4 diffs)
-
src/libcfa/concurrency/preemption.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
configure
r85521c7 r33c0ce8 678 678 CFA_INCDIR 679 679 CFA_PREFIX 680 DOendif681 DOifskipcompile682 680 BUILD_CONCURRENCY_FALSE 683 681 BUILD_CONCURRENCY_TRUE … … 3344 3342 3345 3343 3346 DOifskipcompile='ifeq ($(skipcompile),yes)3347 else'3348 3349 3350 3351 DOendif='endif'3352 3353 3354 3355 3344 if test "x$prefix" = "xNONE"; then 3356 3345 cfa_prefix=${ac_default_prefix} -
configure.ac
r85521c7 r33c0ce8 130 130 AM_CONDITIONAL([BUILD_NO_LIB], [test "x$build_release$build_debug" = "xnono"]) 131 131 AM_CONDITIONAL([BUILD_CONCURRENCY], [test "x$build_threading" = "xyes"]) 132 133 DOifskipcompile='ifeq ($(skipcompile),yes)134 else'135 AC_SUBST([DOifskipcompile])136 AM_SUBST_NOTMAKE([DOifskipcompile])137 138 DOendif='endif'139 AC_SUBST([DOendif])140 AM_SUBST_NOTMAKE([DOendif])141 132 142 133 if test "x$prefix" = "xNONE"; then -
doc/theses/thierry_delisle/Makefile
r85521c7 r33c0ce8 98 98 fig2dev -L pstex_t -p ${Build}/$@ $< > ${Build}/$@_t 99 99 100 #----------------------------------------------------------------------------------- 101 # Tools to generate png files 102 # to create a png we create a pdf and convert it to png 103 %.png : build/%.pstex figures/%.tex 104 echo ${basename $@} 105 ${LaTeX} figures/${basename $@}.tex 106 dvips build/${basename $@}.dvi -o build/${basename $@}.ps 107 ps2pdf build/${basename $@}.ps 108 convert -negate ${basename $@}.pdf $@ 109 110 # creating a pdf of a figure requires generating some latex that just includes the figure 111 figures/%.tex: build/%.pstex 100 %.tex: %.pstex 112 101 echo -n "\documentclass[preview]{standalone}\n" \ 113 102 "\usepackage[T1]{fontenc}\n" \ … … 121 110 "\end{document}" > $@ 122 111 112 %.png : %.pstex %.tex 113 echo ${basename $@} 114 ${LaTeX} figures/${basename $@}.tex 115 dvips build/${basename $@}.dvi -o build/${basename $@}.ps 116 ps2pdf build/${basename $@}.ps 117 convert -negate ${basename $@}.pdf $@ 118 123 119 # Local Variables: # 124 120 # compile-command: "make" # -
src/benchmark/Makefile.am
r85521c7 r33c0ce8 23 23 STATS = ${TOOLSDIR}stat.py 24 24 repeats = 30 25 skipcompile = no26 25 TIME_FORMAT = "%E" 27 26 PRINT_FORMAT = %20s: #Comments needed for spacing … … 44 43 %.runquiet : 45 44 @+make $(basename $@) 46 @ taskset -c 1./a.out45 @./a.out 47 46 @rm -f a.out 48 47 … … 60 59 @echo -e '\t"githash": "'${githash}'",' 61 60 @echo -e '\t"arch": "' ${arch} '",' 62 @DOifskipcompile@63 61 @echo -e '\t"compile": {' 64 62 @+make compile TIME_FORMAT='%e,' PRINT_FORMAT='\t\t\"%s\" :' 65 63 @echo -e '\t\t"dummy" : {}' 66 64 @echo -e '\t},' 67 @DOendif@68 65 @echo -e '\t"ctxswitch": {' 69 66 @echo -en '\t\t"coroutine":' -
src/benchmark/Makefile.in
r85521c7 r33c0ce8 253 253 STATS = ${TOOLSDIR}stat.py 254 254 repeats = 30 255 skipcompile = no256 255 TIME_FORMAT = "%E" 257 256 PRINT_FORMAT = %20s: #Comments needed for spacing … … 460 459 %.runquiet : 461 460 @+make $(basename $@) 462 @ taskset -c 1./a.out461 @./a.out 463 462 @rm -f a.out 464 463 … … 474 473 @echo -e '\t"githash": "'${githash}'",' 475 474 @echo -e '\t"arch": "' ${arch} '",' 476 @DOifskipcompile@477 475 @echo -e '\t"compile": {' 478 476 @+make compile TIME_FORMAT='%e,' PRINT_FORMAT='\t\t\"%s\" :' 479 477 @echo -e '\t\t"dummy" : {}' 480 478 @echo -e '\t},' 481 @DOendif@482 479 @echo -e '\t"ctxswitch": {' 483 480 @echo -en '\t\t"coroutine":' -
src/libcfa/concurrency/kernel.c
r85521c7 r33c0ce8 59 59 60 60 volatile thread_local bool preemption_in_progress = 0; 61 volatile thread_local bool preemption_enabled = false;62 61 volatile thread_local unsigned short disable_preempt_count = 1; 63 62 … … 197 196 if(readyThread) 198 197 { 199 verify( !preemption_enabled);198 verify( disable_preempt_count > 0 ); 200 199 201 200 runThread(this, readyThread); 202 201 203 verify( !preemption_enabled);202 verify( disable_preempt_count > 0 ); 204 203 205 204 //Some actions need to be taken from the kernel … … 243 242 void finishRunning(processor * this) with( this->finish ) { 244 243 if( action_code == Release ) { 245 verify( !preemption_enabled);244 verify( disable_preempt_count > 1 ); 246 245 unlock( *lock ); 247 246 } … … 250 249 } 251 250 else if( action_code == Release_Schedule ) { 252 verify( !preemption_enabled);251 verify( disable_preempt_count > 1 ); 253 252 unlock( *lock ); 254 253 ScheduleThread( thrd ); 255 254 } 256 255 else if( action_code == Release_Multi ) { 257 verify( !preemption_enabled);256 verify( disable_preempt_count > lock_count ); 258 257 for(int i = 0; i < lock_count; i++) { 259 258 unlock( *locks[i] ); … … 287 286 this_coroutine = NULL; 288 287 this_thread = NULL; 289 preemption_enabled = false;290 288 disable_preempt_count = 1; 291 289 // SKULLDUGGERY: We want to create a context for the processor coroutine … … 335 333 verify( thrd->self_cor.state != Halted ); 336 334 337 verify( !preemption_enabled);335 verify( disable_preempt_count > 0 ); 338 336 339 337 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); … … 345 343 } 346 344 347 verify( !preemption_enabled);345 verify( disable_preempt_count > 0 ); 348 346 } 349 347 350 348 thread_desc * nextThread(cluster * this) with( *this ) { 351 verify( !preemption_enabled);349 verify( disable_preempt_count > 0 ); 352 350 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 353 351 thread_desc * head = pop_head( ready_queue ); 354 352 unlock( ready_queue_lock ); 355 verify( !preemption_enabled);353 verify( disable_preempt_count > 0 ); 356 354 return head; 357 355 } … … 359 357 void BlockInternal() { 360 358 disable_interrupts(); 361 verify( !preemption_enabled);362 suspend(); 363 verify( !preemption_enabled);359 verify( disable_preempt_count > 0 ); 360 suspend(); 361 verify( disable_preempt_count > 0 ); 364 362 enable_interrupts( __cfaabi_dbg_ctx ); 365 363 } … … 370 368 this_processor->finish.lock = lock; 371 369 372 verify( !preemption_enabled);373 suspend(); 374 verify( !preemption_enabled);370 verify( disable_preempt_count > 1 ); 371 suspend(); 372 verify( disable_preempt_count > 0 ); 375 373 376 374 enable_interrupts( __cfaabi_dbg_ctx ); … … 382 380 this_processor->finish.thrd = thrd; 383 381 384 verify( !preemption_enabled);385 suspend(); 386 verify( !preemption_enabled);382 verify( disable_preempt_count > 0 ); 383 suspend(); 384 verify( disable_preempt_count > 0 ); 387 385 388 386 enable_interrupts( __cfaabi_dbg_ctx ); … … 396 394 this_processor->finish.thrd = thrd; 397 395 398 verify( !preemption_enabled);399 suspend(); 400 verify( !preemption_enabled);396 verify( disable_preempt_count > 1 ); 397 suspend(); 398 verify( disable_preempt_count > 0 ); 401 399 402 400 enable_interrupts( __cfaabi_dbg_ctx ); … … 409 407 this_processor->finish.lock_count = count; 410 408 411 verify( !preemption_enabled);412 suspend(); 413 verify( !preemption_enabled);409 verify( disable_preempt_count > 0 ); 410 suspend(); 411 verify( disable_preempt_count > 0 ); 414 412 415 413 enable_interrupts( __cfaabi_dbg_ctx ); … … 424 422 this_processor->finish.thrd_count = thrd_count; 425 423 426 verify( !preemption_enabled);427 suspend(); 428 verify( !preemption_enabled);424 verify( disable_preempt_count > 0 ); 425 suspend(); 426 verify( disable_preempt_count > 0 ); 429 427 430 428 enable_interrupts( __cfaabi_dbg_ctx ); … … 432 430 433 431 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 434 verify( !preemption_enabled);432 verify( disable_preempt_count > 0 ); 435 433 this_processor->finish.action_code = thrd ? Release_Schedule : Release; 436 434 this_processor->finish.lock = lock; -
src/libcfa/concurrency/kernel_private.h
r85521c7 r33c0ce8 74 74 75 75 extern volatile thread_local bool preemption_in_progress; 76 extern volatile thread_local bool preemption_enabled;77 76 extern volatile thread_local unsigned short disable_preempt_count; 78 77 -
src/libcfa/concurrency/monitor.c
r85521c7 r33c0ce8 87 87 thread_desc * thrd = this_thread; 88 88 89 verify( disable_preempt_count > 0 ); 90 89 91 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 90 92 … … 115 117 // Some one else has the monitor, wait in line for it 116 118 append( this->entry_queue, thrd ); 119 120 verify( disable_preempt_count > 0 ); 117 121 118 122 BlockInternal( &this->lock ); … … 392 396 append( this.blocked, &waiter ); 393 397 398 verify( disable_preempt_count == 0 ); 399 394 400 // Lock all monitors (aggregates the locks as well) 395 401 lock_all( monitors, locks, count ); 402 403 // verifyf( disable_preempt_count == count, "Got %d, expected %d\n", disable_preempt_count, count ); 404 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); } 396 405 397 406 // Find the next thread(s) to run … … 468 477 monitor_ctx( this.monitors, this.monitor_count ); 469 478 479 verify( disable_preempt_count == 0 ); 480 470 481 // Lock all monitors (aggregates the locks them as well) 471 482 lock_all( monitors, locks, count ); 483 484 // verify( disable_preempt_count == count ); 485 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); } 472 486 473 487 -
src/libcfa/concurrency/preemption.c
r85521c7 r33c0ce8 49 49 // Machine specific register name 50 50 #if defined(__x86_64__) 51 #define CFA_REG_IP gregs[REG_RIP]51 #define CFA_REG_IP REG_RIP 52 52 #elif defined(__i386__) 53 #define CFA_REG_IP gregs[REG_EIP]53 #define CFA_REG_IP REG_EIP 54 54 #elif defined(__ARM_ARCH__) 55 #define CFA_REG_IP arm_pc55 #define CFA_REG_IP REG_R15 56 56 #endif 57 57 … … 142 142 // Disable interrupts by incrementing the counter 143 143 void disable_interrupts() { 144 preemption_enabled = false; 145 __attribute__((unused)) unsigned short new_val = disable_preempt_count + 1; 146 disable_preempt_count = new_val; 144 __attribute__((unused)) unsigned short new_val = __atomic_add_fetch_2( &disable_preempt_count, 1, __ATOMIC_SEQ_CST ); 147 145 verify( new_val < 65_000u ); // If this triggers someone is disabling interrupts without enabling them 148 146 } … … 154 152 thread_desc * thrd = this_thread; // Cache the thread now since interrupts can start happening after the atomic add 155 153 156 unsigned short prev = disable_preempt_count; 157 disable_preempt_count -= 1; 154 unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST ); 158 155 verify( prev != 0u ); // If this triggers someone is enabled already enabled interruptsverify( prev != 0u ); 159 156 160 157 // Check if we need to prempt the thread because an interrupt was missed 161 if( prev == 1 ) { 162 preemption_enabled = true; 163 if( proc->pending_preemption ) { 164 proc->pending_preemption = false; 165 BlockInternal( thrd ); 166 } 158 if( prev == 1 && proc->pending_preemption ) { 159 proc->pending_preemption = false; 160 BlockInternal( thrd ); 167 161 } 168 162 … … 174 168 // Don't execute any pending CtxSwitch even if counter reaches 0 175 169 void enable_interrupts_noPoll() { 176 unsigned short prev = disable_preempt_count; 177 disable_preempt_count -= 1; 170 __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST ); 178 171 verifyf( prev != 0u, "Incremented from %u\n", prev ); // If this triggers someone is enabled already enabled interrupts 179 if( prev == 1 ) {180 preemption_enabled = true;181 }182 172 } 183 173 } … … 220 210 // If false : preemption is unsafe and marked as pending 221 211 static inline bool preemption_ready() { 222 bool ready = preemption_enabled&& !preemption_in_progress; // Check if preemption is safe212 bool ready = disable_preempt_count == 0 && !preemption_in_progress; // Check if preemption is safe 223 213 this_processor->pending_preemption = !ready; // Adjust the pending flag accordingly 224 214 return ready; … … 235 225 236 226 // Start with preemption disabled until ready 237 preemption_enabled = false;238 227 disable_preempt_count = 1; 239 228 … … 295 284 // Receives SIGUSR1 signal and causes the current thread to yield 296 285 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) { 297 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.CFA_REG_IP); ) 298 299 // Check if it is safe to preempt here 286 #if defined( __ARM_ARCH ) 287 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.arm_pc); ) 288 #else 289 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); ) 290 #endif 291 292 // Check if it is safe to preempt here 300 293 if( !preemption_ready() ) { return; } 301 294
Note:
See TracChangeset
for help on using the changeset viewer.