Changeset 92538ab for libcfa/src/concurrency/kernel
- Timestamp:
- Apr 10, 2022, 2:53:18 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- d8e2a09
- Parents:
- 4559b34 (diff), 6256891 (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/kernel
- Files:
-
- 2 added
- 2 edited
- 1 moved
-
cluster.cfa (added)
-
cluster.hfa (added)
-
fwd.hfa (modified) (2 diffs)
-
private.hfa (moved) (moved from libcfa/src/concurrency/kernel_private.hfa ) (6 diffs)
-
startup.cfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel/fwd.hfa
r4559b34 r92538ab 248 248 // check if the future is available 249 249 bool available( future_t & this ) { 250 while( this.ptr == 2p ) Pause(); 250 251 return this.ptr == 1p; 251 252 } … … 347 348 struct oneshot * want = expected == 0p ? 1p : 2p; 348 349 if(__atomic_compare_exchange_n(&this.ptr, &expected, want, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 349 if( expected == 0p ) { /* paranoid */ verify( this.ptr == 1p);return 0p; }350 if( expected == 0p ) { return 0p; } 350 351 thread$ * ret = post( *expected, do_unpark ); 351 352 __atomic_store_n( &this.ptr, 1p, __ATOMIC_SEQ_CST); -
libcfa/src/concurrency/kernel/private.hfa
r4559b34 r92538ab 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // kernel _private.hfa --7 // kernel/private.hfa -- 8 8 // 9 9 // Author : Thierry Delisle … … 17 17 18 18 #if !defined(__cforall_thread__) 19 #error kernel _private.hfa should only be included in libcfathread source19 #error kernel/private.hfa should only be included in libcfathread source 20 20 #endif 21 21 … … 33 33 #else 34 34 #ifndef _GNU_SOURCE 35 #error kernel _private requires gnu_source35 #error kernel/private requires gnu_source 36 36 #endif 37 37 #include <sched.h> … … 40 40 41 41 // Defines whether or not we *want* to use io_uring_enter as the idle_sleep blocking call 42 #define CFA_WANT_IO_URING_IDLE42 // #define CFA_WANT_IO_URING_IDLE 43 43 44 44 // Defines whether or not we *can* use io_uring_enter as the idle_sleep blocking call … … 59 59 60 60 extern bool __preemption_enabled(); 61 62 enum { 63 PREEMPT_NORMAL = 0, 64 PREEMPT_TERMINATE = 1, 65 PREEMPT_IO = 2, 66 }; 61 67 62 68 static inline void __disable_interrupts_checked() { … … 359 365 void ready_queue_shrink(struct cluster * cltr); 360 366 367 //----------------------------------------------------------------------- 368 // Decrease the width of the ready queue (number of lanes) by 4 369 void ready_queue_close(struct cluster * cltr); 361 370 362 371 // Local Variables: // -
libcfa/src/concurrency/kernel/startup.cfa
r4559b34 r92538ab 18 18 19 19 // C Includes 20 #include <errno.h> // errno20 #include <errno.h> // errno 21 21 #include <signal.h> 22 #include <string.h> // strerror23 #include <unistd.h> // sysconf22 #include <string.h> // strerror 23 #include <unistd.h> // sysconf 24 24 25 25 extern "C" { 26 #include <limits.h>// PTHREAD_STACK_MIN27 #include <unistd.h> // syscall28 #include <sys/eventfd.h> // eventfd29 #include <sys/mman.h>// mprotect30 #include <sys/resource.h>// getrlimit26 #include <limits.h> // PTHREAD_STACK_MIN 27 #include <unistd.h> // syscall 28 #include <sys/eventfd.h> // eventfd 29 #include <sys/mman.h> // mprotect 30 #include <sys/resource.h> // getrlimit 31 31 } 32 32 33 33 // CFA Includes 34 #include "kernel_private.hfa" 35 #include "startup.hfa" // STARTUP_PRIORITY_XXX 34 #include "kernel/private.hfa" 35 #include "iofwd.hfa" 36 #include "startup.hfa" // STARTUP_PRIORITY_XXX 36 37 #include "limits.hfa" 37 38 #include "math.hfa" … … 97 98 extern void __kernel_alarm_startup(void); 98 99 extern void __kernel_alarm_shutdown(void); 100 extern void __cfa_io_start( processor * ); 101 extern void __cfa_io_stop ( processor * ); 99 102 100 103 //----------------------------------------------------------------------------- … … 102 105 extern void __wake_proc(processor *); 103 106 extern int cfa_main_returned; // from interpose.cfa 104 extern uint32_t __global_random_seed;107 uint32_t __global_random_prime = 4_294_967_291u, __global_random_mask = false; 105 108 106 109 //----------------------------------------------------------------------------- … … 111 114 KERNEL_STORAGE(__stack_t, mainThreadCtx); 112 115 KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock); 116 KERNEL_STORAGE(eventfd_t, mainIdleEventFd); 117 KERNEL_STORAGE(io_future_t, mainIdleFuture); 113 118 #if !defined(__CFA_NO_STATISTICS__) 114 119 KERNEL_STORAGE(__stats_t, mainProcStats); … … 224 229 (*mainProcessor){}; 225 230 231 mainProcessor->idle_wctx.rdbuf = &storage_mainIdleEventFd; 232 mainProcessor->idle_wctx.ftr = (io_future_t*)&storage_mainIdleFuture; 233 /* paranoid */ verify( sizeof(storage_mainIdleEventFd) == sizeof(eventfd_t) ); 234 235 __cfa_io_start( mainProcessor ); 226 236 register_tls( mainProcessor ); 227 237 … … 305 315 306 316 unregister_tls( mainProcessor ); 317 __cfa_io_stop( mainProcessor ); 307 318 308 319 // Destroy the main processor and its context in reverse order of construction … … 353 364 proc->local_data = &__cfaabi_tls; 354 365 366 __cfa_io_start( proc ); 355 367 register_tls( proc ); 368 369 // used for idle sleep when io_uring is present 370 io_future_t future; 371 eventfd_t idle_buf; 372 proc->idle_wctx.ftr = &future; 373 proc->idle_wctx.rdbuf = &idle_buf; 374 356 375 357 376 // SKULLDUGGERY: We want to create a context for the processor coroutine … … 395 414 396 415 unregister_tls( proc ); 416 __cfa_io_stop( proc ); 397 417 398 418 return 0p; … … 490 510 preferred = ready_queue_new_preferred(); 491 511 last_proc = 0p; 492 random_state = __global_random_ seed;512 random_state = __global_random_mask ? __global_random_prime : __global_random_prime ^ rdtscl(); 493 513 #if defined( __CFA_WITH_VERIFY__ ) 494 514 canary = 0x0D15EA5E0D15EA5Ep; … … 515 535 this.rdq.its = 0; 516 536 this.rdq.itr = 0; 517 this.rdq.id = MAX;537 this.rdq.id = 0; 518 538 this.rdq.target = MAX; 519 539 this.rdq.last = MAX; … … 532 552 this.local_data = 0p; 533 553 534 this.idle_fd = eventfd(0, 0);535 if (idle_ fd < 0) {554 idle_wctx.evfd = eventfd(0, 0); 555 if (idle_wctx.evfd < 0) { 536 556 abort("KERNEL ERROR: PROCESSOR EVENTFD - %s\n", strerror(errno)); 537 557 } 538 558 539 this.idle_wctx.fd = 0; 559 idle_wctx.sem = 0; 560 idle_wctx.wake__time = 0; 540 561 541 562 // I'm assuming these two are reserved for standard input and output 542 563 // so I'm using them as sentinels with idle_wctx. 543 /* paranoid */ verify( this.idle_fd != 0 );544 /* paranoid */ verify( this.idle_fd != 1 );564 /* paranoid */ verify( idle_wctx.evfd != 0 ); 565 /* paranoid */ verify( idle_wctx.evfd != 1 ); 545 566 546 567 #if !defined(__CFA_NO_STATISTICS__) … … 554 575 // Not a ctor, it just preps the destruction but should not destroy members 555 576 static void deinit(processor & this) { 556 close(this.idle_ fd);577 close(this.idle_wctx.evfd); 557 578 } 558 579 … … 605 626 this.name = name; 606 627 this.preemption_rate = preemption_rate; 607 ready_queue{}; 628 this.sched.readyQ.data = 0p; 629 this.sched.readyQ.tscs = 0p; 630 this.sched.readyQ.count = 0; 631 this.sched.io.tscs = 0p; 632 this.sched.io.data = 0p; 633 this.sched.caches = 0p; 608 634 609 635 #if !defined(__CFA_NO_STATISTICS__) … … 644 670 // Unlock the RWlock 645 671 ready_mutate_unlock( last_size ); 672 673 ready_queue_close( &this ); 674 /* paranoid */ verify( this.sched.readyQ.data == 0p ); 675 /* paranoid */ verify( this.sched.readyQ.tscs == 0p ); 676 /* paranoid */ verify( this.sched.readyQ.count == 0 ); 677 /* paranoid */ verify( this.sched.io.tscs == 0p ); 678 /* paranoid */ verify( this.sched.caches == 0p ); 679 646 680 enable_interrupts( false ); // Don't poll, could be in main cluster 681 647 682 648 683 #if !defined(__CFA_NO_STATISTICS__) … … 736 771 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 737 772 738 size_t stacksize = DEFAULT_STACK_SIZE;773 size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE ); 739 774 740 775 void * stack;
Note:
See TracChangeset
for help on using the changeset viewer.