Changeset f7fac4b for libcfa/src/concurrency
- Timestamp:
- Aug 25, 2020, 9:17:22 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- af4487d
- Parents:
- 95472ee (diff), ceb7db8 (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. - Location:
- libcfa/src/concurrency
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
r95472ee rf7fac4b 215 215 return cor; 216 216 } 217 218 struct $coroutine * __cfactx_cor_active(void) {219 return active_coroutine();220 }221 217 } 222 218 -
libcfa/src/concurrency/invoke.c
r95472ee rf7fac4b 29 29 // Called from the kernel when starting a coroutine or task so must switch back to user mode. 30 30 31 extern struct $coroutine * __cfactx_cor_active(void);32 31 extern struct $coroutine * __cfactx_cor_finish(void); 33 32 extern void __cfactx_cor_leave ( struct $coroutine * ); … … 36 35 extern void disable_interrupts() OPTIONAL_THREAD; 37 36 extern void enable_interrupts( __cfaabi_dbg_ctx_param ); 38 39 struct exception_context_t * this_exception_context() {40 return &__get_stack( __cfactx_cor_active() )->exception_context;41 }42 37 43 38 void __cfactx_invoke_coroutine( -
libcfa/src/concurrency/invoke.h
r95472ee rf7fac4b 98 98 } 99 99 100 struct exception_context_t * this_exception_context();101 102 100 // struct which calls the monitor is accepting 103 101 struct __waitfor_mask_t { -
libcfa/src/concurrency/io/setup.cfa
r95472ee rf7fac4b 384 384 /* paranoid */ verify( is_pow2( params_in.num_ready ) || (params_in.num_ready < 8) ); 385 385 sq.ready_cnt = max( params_in.num_ready, 8 ); 386 sq.ready = alloc _align( 64, sq.ready_cnt);386 sq.ready = alloc( sq.ready_cnt, 64`align ); 387 387 for(i; sq.ready_cnt) { 388 388 sq.ready[i] = -1ul32; -
libcfa/src/concurrency/kernel/startup.cfa
r95472ee rf7fac4b 579 579 580 580 // Lock the RWlock so no-one pushes/pops while we are changing the queue 581 disable_interrupts(); 581 582 uint_fast32_t last_size = ready_mutate_lock(); 582 583 … … 586 587 // Unlock the RWlock 587 588 ready_mutate_unlock( last_size ); 589 enable_interrupts_noPoll(); // Don't poll, could be in main cluster 590 588 591 589 592 this.io.cnt = num_io; … … 601 604 602 605 // Lock the RWlock so no-one pushes/pops while we are changing the queue 606 disable_interrupts(); 603 607 uint_fast32_t last_size = ready_mutate_lock(); 604 608 … … 608 612 // Unlock the RWlock 609 613 ready_mutate_unlock( last_size ); 614 enable_interrupts_noPoll(); // Don't poll, could be in main cluster 610 615 611 616 #if !defined(__CFA_NO_STATISTICS__) -
libcfa/src/concurrency/ready_queue.cfa
r95472ee rf7fac4b 215 215 } 216 216 217 static inline [unsigned, bool] idx_from_r(unsigned r, unsigned preferred) { 218 unsigned i; 219 bool local; 220 #if defined(BIAS) 221 unsigned rlow = r % BIAS; 222 unsigned rhigh = r / BIAS; 223 if((0 != rlow) && preferred >= 0) { 224 // (BIAS - 1) out of BIAS chances 225 // Use perferred queues 226 i = preferred + (rhigh % 4); 227 local = true; 228 } 229 else { 230 // 1 out of BIAS chances 231 // Use all queues 232 i = rhigh; 233 local = false; 234 } 235 #else 236 i = r; 237 local = false; 238 #endif 239 return [i, local]; 240 } 241 217 242 //----------------------------------------------------------------------- 218 243 __attribute__((hot)) bool push(struct cluster * cltr, struct $thread * thrd) with (cltr->ready_queue) { … … 222 247 thrd->link.ts = rdtscl(); 223 248 224 #if defined(BIAS) && !defined(__CFA_NO_STATISTICS__) 225 bool local = false; 226 int preferred = 249 __attribute__((unused)) bool local; 250 __attribute__((unused)) int preferred; 251 #if defined(BIAS) 252 preferred = 227 253 //* 228 254 kernelTLS.this_processor ? kernelTLS.this_processor->id * 4 : -1; … … 230 256 thrd->link.preferred * 4; 231 257 //*/ 232 233 234 258 #endif 235 259 … … 238 262 do { 239 263 // Pick the index of a lane 240 #if defined(BIAS) 241 unsigned r = __tls_rand(); 242 unsigned rlow = r % BIAS; 243 unsigned rhigh = r / BIAS; 244 if((0 != rlow) && preferred >= 0) { 245 // (BIAS - 1) out of BIAS chances 246 // Use perferred queues 247 i = preferred + (rhigh % 4); 248 249 #if !defined(__CFA_NO_STATISTICS__) 250 local = true; 251 __tls_stats()->ready.pick.push.local++; 252 #endif 253 } 254 else { 255 // 1 out of BIAS chances 256 // Use all queues 257 i = rhigh; 258 local = false; 259 } 260 #else 261 i = __tls_rand(); 264 // unsigned r = __tls_rand(); 265 unsigned r = __tls_rand_fwd(); 266 [i, local] = idx_from_r(r, preferred); 267 268 #if !defined(__CFA_NO_STATISTICS__) 269 if(local) { 270 __tls_stats()->ready.pick.push.local++; 271 } 262 272 #endif 263 273 … … 274 284 275 285 // Actually push it 276 bool lane_first = push(lanes.data[i], thrd); 286 #ifdef USE_SNZI 287 bool lane_first = 288 #endif 289 290 push(lanes.data[i], thrd); 277 291 278 292 #ifdef USE_SNZI … … 287 301 #endif 288 302 303 __tls_rand_advance_bck(); 304 289 305 // Unlock and return 290 306 __atomic_unlock( &lanes.data[i].lock ); … … 311 327 /* paranoid */ verify( lanes.count > 0 ); 312 328 unsigned count = __atomic_load_n( &lanes.count, __ATOMIC_RELAXED ); 329 int preferred; 313 330 #if defined(BIAS) 314 331 // Don't bother trying locally too much 315 332 int local_tries = 8; 316 #endif 333 preferred = kernelTLS.this_processor->id * 4; 334 #endif 335 317 336 318 337 // As long as the list is not empty, try finding a lane that isn't empty and pop from it … … 323 342 #endif 324 343 // Pick two lists at random 325 unsigned i,j; 326 #if defined(BIAS) 327 #if !defined(__CFA_NO_STATISTICS__) 328 bool local = false; 329 #endif 330 uint64_t r = __tls_rand(); 331 unsigned rlow = r % BIAS; 332 uint64_t rhigh = r / BIAS; 333 if(local_tries && 0 != rlow) { 334 // (BIAS - 1) out of BIAS chances 335 // Use perferred queues 336 unsigned pid = kernelTLS.this_processor->id * 4; 337 i = pid + (rhigh % 4); 338 j = pid + ((rhigh >> 32ull) % 4); 339 340 // count the tries 341 local_tries--; 342 343 #if !defined(__CFA_NO_STATISTICS__) 344 local = true; 345 __tls_stats()->ready.pick.pop.local++; 346 #endif 347 } 348 else { 349 // 1 out of BIAS chances 350 // Use all queues 351 i = rhigh; 352 j = rhigh >> 32ull; 353 } 354 #else 355 i = __tls_rand(); 356 j = __tls_rand(); 344 // unsigned ri = __tls_rand(); 345 // unsigned rj = __tls_rand(); 346 unsigned ri = __tls_rand_bck(); 347 unsigned rj = __tls_rand_bck(); 348 349 unsigned i, j; 350 __attribute__((unused)) bool locali, localj; 351 [i, locali] = idx_from_r(ri, preferred); 352 [j, localj] = idx_from_r(rj, preferred); 353 354 #if !defined(__CFA_NO_STATISTICS__) 355 if(locali) { 356 __tls_stats()->ready.pick.pop.local++; 357 } 358 if(localj) { 359 __tls_stats()->ready.pick.pop.local++; 360 } 357 361 #endif 358 362 … … 364 368 if(thrd) { 365 369 #if defined(BIAS) && !defined(__CFA_NO_STATISTICS__) 366 if( local ) __tls_stats()->ready.pick.pop.lsuccess++;370 if( locali || localj ) __tls_stats()->ready.pick.pop.lsuccess++; 367 371 #endif 368 372 return thrd; … … 543 547 544 548 // Allocate new array (uses realloc and memcpies the data) 545 lanes.data = alloc( lanes.data, ncount);549 lanes.data = alloc( ncount, lanes.data`realloc ); 546 550 547 551 // Fix the moved data … … 634 638 635 639 // Allocate new array (uses realloc and memcpies the data) 636 lanes.data = alloc( lanes.data, lanes.count);640 lanes.data = alloc( lanes.count, lanes.data`realloc ); 637 641 638 642 // Fix the moved data
Note: See TracChangeset
for help on using the changeset viewer.