Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/startup.cfa

    r639e4fc r116a2ea  
    1616#define __cforall_thread__
    1717#define _GNU_SOURCE
    18 
    19 // #define __CFA_DEBUG_PRINT_RUNTIME_CORE__
    2018
    2119// C Includes
     
    115113KERNEL_STORAGE(thread$,              mainThread);
    116114KERNEL_STORAGE(__stack_t,            mainThreadCtx);
     115// KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock);
     116KERNEL_STORAGE(eventfd_t,            mainIdleEventFd);
     117KERNEL_STORAGE(io_future_t,          mainIdleFuture);
    117118#if !defined(__CFA_NO_STATISTICS__)
    118119KERNEL_STORAGE(__stats_t, mainProcStats);
     
    221222                ( this.runner ){};
    222223                init( this, "Main Processor", *mainCluster, 0p );
    223                 kernel_thread = __cfaabi_pthread_self();
     224                kernel_thread = pthread_self();
    224225
    225226                runner{ &this };
     
    231232        mainProcessor = (processor *)&storage_mainProcessor;
    232233        (*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) );
    233238
    234239        __cfa_io_start( mainProcessor );
     
    278283}
    279284
    280 extern "C"{
    281         void pthread_delete_kernel_threads_();
    282 }
    283 
    284 
    285285static void __kernel_shutdown(void) {
    286286        if(!cfa_main_returned) return;
    287 
    288         //delete kernel threads for pthread_concurrency
    289         pthread_delete_kernel_threads_();
    290 
    291287        /* paranoid */ verify( __preemption_enabled() );
    292288        disable_interrupts();
     
    331327
    332328                /* paranoid */ verify( this.do_terminate == true );
    333                 __cfadbg_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);
    334330        }
    335331
     
    377373        register_tls( proc );
    378374
     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
    379382        // SKULLDUGGERY: We want to create a context for the processor coroutine
    380383        // which is needed for the 2-step context switch. However, there is no reason
     
    385388        (proc->runner){ proc, &info };
    386389
    387         __cfadbg_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);
    388391
    389392        //Set global state
     
    511514        self_mon.recursion = 1;
    512515        self_mon_p = &self_mon;
    513         rdy_link.next = 0p;
    514         rdy_link.ts   = MAX;
     516        link.next = 0p;
     517        link.ts   = MAX;
    515518        preferred = ready_queue_new_preferred();
    516519        last_proc = 0p;
    517520        random_state = __global_random_mask ? __global_random_prime : __global_random_prime ^ rdtscl();
    518521        #if defined( __CFA_WITH_VERIFY__ )
    519                 executing = 0p;
    520522                canary = 0x0D15EA5E0D15EA5Ep;
    521523        #endif
    522524
     525        node.next = 0p;
     526        node.prev = 0p;
    523527        doregister(curr_cluster, this);
    524528
     
    643647        #endif
    644648
    645         threads{};
     649        threads{ __get };
    646650
    647651        io.arbiter = create();
    648652        io.params = io_params;
    649 
    650         managed.procs = 0p;
    651         managed.cnt = 0;
    652653
    653654        doregister(this);
     
    666667
    667668void ^?{}(cluster & this) libcfa_public {
    668         set_concurrency( this, 0 );
    669 
    670669        destroy(this.io.arbiter);
    671670
     
    723722        lock      (cltr->thread_list_lock __cfaabi_dbg_ctx2);
    724723        cltr->nthreads += 1;
    725         insert_first(cltr->threads, thrd);
     724        push_front(cltr->threads, thrd);
    726725        unlock    (cltr->thread_list_lock);
    727726}
     
    729728void unregister( cluster * cltr, thread$ & thrd ) {
    730729        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;
    737732        unlock(cltr->thread_list_lock);
    738733}
     
    782777        pthread_attr_t attr;
    783778
    784         check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
     779        check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    785780
    786781        size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE );
     
    809804        #endif
    810805
    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" );
    813808        return stack;
    814809}
    815810
    816811void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) {
    817         int err = __cfaabi_pthread_join( pthread, retval );
     812        int err = pthread_join( pthread, retval );
    818813        if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err));
    819814
     
    821816                pthread_attr_t attr;
    822817
    823                 check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
     818                check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    824819
    825820                size_t stacksize;
    826821                // 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" );
    828823                assert( stacksize >= PTHREAD_STACK_MIN );
    829824                stacksize += __page_size;
     
    843838}
    844839
    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 procs
    851         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 procs
    861         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 count
    867         return old;
    868 }
    869 
    870840#if defined(__CFA_WITH_VERIFY__)
    871841static bool verify_fwd_bck_rng(void) {
Note: See TracChangeset for help on using the changeset viewer.