- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel/startup.cfa (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel/startup.cfa
r639e4fc r116a2ea 16 16 #define __cforall_thread__ 17 17 #define _GNU_SOURCE 18 19 // #define __CFA_DEBUG_PRINT_RUNTIME_CORE__20 18 21 19 // C Includes … … 115 113 KERNEL_STORAGE(thread$, mainThread); 116 114 KERNEL_STORAGE(__stack_t, mainThreadCtx); 115 // KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock); 116 KERNEL_STORAGE(eventfd_t, mainIdleEventFd); 117 KERNEL_STORAGE(io_future_t, mainIdleFuture); 117 118 #if !defined(__CFA_NO_STATISTICS__) 118 119 KERNEL_STORAGE(__stats_t, mainProcStats); … … 221 222 ( this.runner ){}; 222 223 init( this, "Main Processor", *mainCluster, 0p ); 223 kernel_thread = __cfaabi_pthread_self();224 kernel_thread = pthread_self(); 224 225 225 226 runner{ &this }; … … 231 232 mainProcessor = (processor *)&storage_mainProcessor; 232 233 (*mainProcessor){}; 234 235 mainProcessor->idle_wctx.rdbuf = &storage_mainIdleEventFd; 236 mainProcessor->idle_wctx.ftr = (io_future_t*)&storage_mainIdleFuture; 237 /* paranoid */ verify( sizeof(storage_mainIdleEventFd) == sizeof(eventfd_t) ); 233 238 234 239 __cfa_io_start( mainProcessor ); … … 278 283 } 279 284 280 extern "C"{281 void pthread_delete_kernel_threads_();282 }283 284 285 285 static void __kernel_shutdown(void) { 286 286 if(!cfa_main_returned) return; 287 288 //delete kernel threads for pthread_concurrency289 pthread_delete_kernel_threads_();290 291 287 /* paranoid */ verify( __preemption_enabled() ); 292 288 disable_interrupts(); … … 331 327 332 328 /* paranoid */ verify( this.do_terminate == true ); 333 __cfa dbg_print_safe(runtime_core,"Kernel : destroyed main processor context %p\n", &runner);329 __cfaabi_dbg_print_safe("Kernel : destroyed main processor context %p\n", &runner); 334 330 } 335 331 … … 377 373 register_tls( proc ); 378 374 375 // used for idle sleep when io_uring is present 376 io_future_t future; 377 eventfd_t idle_buf; 378 proc->idle_wctx.ftr = &future; 379 proc->idle_wctx.rdbuf = &idle_buf; 380 381 379 382 // SKULLDUGGERY: We want to create a context for the processor coroutine 380 383 // which is needed for the 2-step context switch. However, there is no reason … … 385 388 (proc->runner){ proc, &info }; 386 389 387 __cfa dbg_print_safe(runtime_core,"Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage);390 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage); 388 391 389 392 //Set global state … … 511 514 self_mon.recursion = 1; 512 515 self_mon_p = &self_mon; 513 rdy_link.next = 0p;514 rdy_link.ts = MAX;516 link.next = 0p; 517 link.ts = MAX; 515 518 preferred = ready_queue_new_preferred(); 516 519 last_proc = 0p; 517 520 random_state = __global_random_mask ? __global_random_prime : __global_random_prime ^ rdtscl(); 518 521 #if defined( __CFA_WITH_VERIFY__ ) 519 executing = 0p;520 522 canary = 0x0D15EA5E0D15EA5Ep; 521 523 #endif 522 524 525 node.next = 0p; 526 node.prev = 0p; 523 527 doregister(curr_cluster, this); 524 528 … … 643 647 #endif 644 648 645 threads{ };649 threads{ __get }; 646 650 647 651 io.arbiter = create(); 648 652 io.params = io_params; 649 650 managed.procs = 0p;651 managed.cnt = 0;652 653 653 654 doregister(this); … … 666 667 667 668 void ^?{}(cluster & this) libcfa_public { 668 set_concurrency( this, 0 );669 670 669 destroy(this.io.arbiter); 671 670 … … 723 722 lock (cltr->thread_list_lock __cfaabi_dbg_ctx2); 724 723 cltr->nthreads += 1; 725 insert_first(cltr->threads, thrd);724 push_front(cltr->threads, thrd); 726 725 unlock (cltr->thread_list_lock); 727 726 } … … 729 728 void unregister( cluster * cltr, thread$ & thrd ) { 730 729 lock (cltr->thread_list_lock __cfaabi_dbg_ctx2); 731 { 732 tytagref( dlink(thread$), dlink(thread$) ) ?`inner( thread$ & this ) = void; 733 with( DLINK_VIA( thread$, struct __thread_user_link ) ) 734 remove( thrd ); 735 cltr->nthreads -= 1; 736 } 730 remove(cltr->threads, thrd ); 731 cltr->nthreads -= 1; 737 732 unlock(cltr->thread_list_lock); 738 733 } … … 782 777 pthread_attr_t attr; 783 778 784 check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute779 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 785 780 786 781 size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE ); … … 809 804 #endif 810 805 811 check( __cfaabi_pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );812 check( __cfaabi_pthread_create( pthread, &attr, start, arg ), "pthread_create" );806 check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 807 check( pthread_create( pthread, &attr, start, arg ), "pthread_create" ); 813 808 return stack; 814 809 } 815 810 816 811 void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) { 817 int err = __cfaabi_pthread_join( pthread, retval );812 int err = pthread_join( pthread, retval ); 818 813 if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err)); 819 814 … … 821 816 pthread_attr_t attr; 822 817 823 check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute818 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 824 819 825 820 size_t stacksize; 826 821 // default stack size, normally defined by shell limit 827 check( __cfaabi_pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );822 check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" ); 828 823 assert( stacksize >= PTHREAD_STACK_MIN ); 829 824 stacksize += __page_size; … … 843 838 } 844 839 845 unsigned set_concurrency( cluster & this, unsigned new ) libcfa_public {846 unsigned old = this.managed.cnt;847 848 __cfadbg_print_safe(runtime_core, "Kernel : resizing cluster from %u to %u\n", old, (unsigned)new);849 850 // Delete all the old unneeded procs851 if(old > new) for(i; (unsigned)new ~ old) {852 __cfadbg_print_safe(runtime_core, "Kernel : destroying %u\n", i);853 delete( this.managed.procs[i] );854 }855 856 // Allocate new array (uses realloc and memcpies the data)857 this.managed.procs = alloc( new, this.managed.procs`realloc );858 this.managed.cnt = new;859 860 // Create the desired new procs861 if(old < new) for(i; old ~ new) {862 __cfadbg_print_safe(runtime_core, "Kernel : constructing %u\n", i);863 (*(this.managed.procs[i] = alloc())){ this };864 }865 866 // return the old count867 return old;868 }869 870 840 #if defined(__CFA_WITH_VERIFY__) 871 841 static bool verify_fwd_bck_rng(void) {
Note:
See TracChangeset
for help on using the changeset viewer.