Ignore:
File:
1 edited

Legend:

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

    r4069faad r2d8f7b0  
    1515
    1616#define __cforall_thread__
    17 // #define __CFA_DEBUG_PRINT_RUNTIME_CORE__
    1817
    1918//C Includes
     
    4140#include "invoke.h"
    4241
    43 
    4442//-----------------------------------------------------------------------------
    4543// Some assembly required
     
    232230        idle{};
    233231
    234         __cfadbg_print_safe(runtime_core, "Kernel : Starting core %p\n", &this);
     232        __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", &this);
    235233
    236234        this.stack = __create_pthread( &this.kernel_thread, __invoke_processor, (void *)&this );
    237235
    238         __cfadbg_print_safe(runtime_core, "Kernel : core %p created\n", &this);
     236        __cfaabi_dbg_print_safe("Kernel : core %p started\n", &this);
    239237}
    240238
    241239void ^?{}(processor & this) with( this ){
    242240        if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
    243                 __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this);
     241                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    244242
    245243                __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED);
     
    260258        ready_queue_lock{};
    261259
    262         #if !defined(__CFA_NO_STATISTICS__)
    263                 print_stats = false;
    264         #endif
    265 
    266260        procs{ __get };
    267261        idles{ __get };
    268262        threads{ __get };
    269263
    270         __kernel_io_startup( this, &this == mainCluster );
     264        __kernel_io_startup( this );
    271265
    272266        doregister(this);
     
    274268
    275269void ^?{}(cluster & this) {
    276         __kernel_io_shutdown( this, &this == mainCluster );
     270        __kernel_io_shutdown( this );
    277271
    278272        unregister(this);
     
    291285        verify(this);
    292286
    293         __cfadbg_print_safe(runtime_core, "Kernel : core %p starting\n", this);
     287        __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this);
    294288
    295289        doregister(this->cltr, this);
     
    299293                preemption_scope scope = { this };
    300294
    301                 __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this);
     295                __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
    302296
    303297                $thread * readyThread = 0p;
     
    325319                }
    326320
    327                 __cfadbg_print_safe(runtime_core, "Kernel : core %p stopping\n", this);
     321                __cfaabi_dbg_print_safe("Kernel : core %p stopping\n", this);
    328322        }
    329323
     
    332326        V( this->terminated );
    333327
    334         __cfadbg_print_safe(runtime_core, "Kernel : core %p terminated\n", this);
     328        __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this);
    335329
    336330        // HACK : the coroutine context switch expects this_thread to be set
     
    477471
    478472        //We now have a proper context from which to schedule threads
    479         __cfadbg_print_safe(runtime_core, "Kernel : core %p created (%p, %p)\n", proc, &proc->runner, &ctx);
     473        __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, &proc->runner, &ctx);
    480474
    481475        // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't
     
    488482
    489483        // Main routine of the core returned, the core is now fully terminated
    490         __cfadbg_print_safe(runtime_core, "Kernel : core %p main ended (%p)\n", proc, &proc->runner);
     484        __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, &proc->runner);
    491485
    492486        return 0p;
     
    719713static void __kernel_startup(void) {
    720714        verify( ! kernelTLS.preemption_state.enabled );
    721         __cfadbg_print_safe(runtime_core, "Kernel : Starting\n");
     715        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    722716
    723717        __page_size = sysconf( _SC_PAGESIZE );
     
    730724        (*mainCluster){"Main Cluster"};
    731725
    732         __cfadbg_print_safe(runtime_core, "Kernel : Main cluster ready\n");
     726        __cfaabi_dbg_print_safe("Kernel : Main cluster ready\n");
    733727
    734728        // Start by initializing the main thread
     
    740734        (*mainThread){ &info };
    741735
    742         __cfadbg_print_safe(runtime_core, "Kernel : Main thread ready\n");
     736        __cfaabi_dbg_print_safe("Kernel : Main thread ready\n");
    743737
    744738
     
    761755
    762756                runner{ &this };
    763                 __cfadbg_print_safe(runtime_core, "Kernel : constructed main processor context %p\n", &runner);
     757                __cfaabi_dbg_print_safe("Kernel : constructed main processor context %p\n", &runner);
    764758        }
    765759
     
    786780
    787781
     782
    788783        // THE SYSTEM IS NOW COMPLETELY RUNNING
    789 
    790 
    791         // Now that the system is up, finish creating systems that need threading
    792         __kernel_io_finish_start( *mainCluster );
    793 
    794 
    795         __cfadbg_print_safe(runtime_core, "Kernel : Started\n--------------------------------------------------\n\n");
     784        __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n");
    796785
    797786        verify( ! kernelTLS.preemption_state.enabled );
     
    801790
    802791static void __kernel_shutdown(void) {
    803         //Before we start shutting things down, wait for systems that need threading to shutdown
    804         __kernel_io_prepare_stop( *mainCluster );
     792        __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n");
    805793
    806794        /* paranoid */ verify( TL_GET( preemption_state.enabled ) );
    807795        disable_interrupts();
    808796        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    809 
    810         __cfadbg_print_safe(runtime_core, "\n--------------------------------------------------\nKernel : Shutting down\n");
    811797
    812798        // SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
     
    836822        ^(__cfa_dbg_global_clusters.lock){};
    837823
    838         __cfadbg_print_safe(runtime_core, "Kernel : Shutdown complete\n");
     824        __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
    839825}
    840826
     
    861847
    862848        // We are ready to sleep
    863         __cfadbg_print_safe(runtime_core, "Kernel : Processor %p ready to sleep\n", this);
     849        __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);
    864850        wait( idle );
    865851
    866852        // We have woken up
    867         __cfadbg_print_safe(runtime_core, "Kernel : Processor %p woke up and ready to run\n", this);
     853        __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);
    868854
    869855        // Get ourself off the idle list
     
    881867static bool __wake_one(cluster * this, __attribute__((unused)) bool force) {
    882868        // if we don't want to force check if we know it's false
    883         // if( !this->idles.head && !force ) return false;
     869        if( !this->idles.head && !force ) return false;
    884870
    885871        // First, lock the cluster idle
     
    894880
    895881        // Wake them up
    896         __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this->idles.head);
    897882        post( this->idles.head->idle );
    898883
     
    904889// Unconditionnaly wake a thread
    905890static bool __wake_proc(processor * this) {
    906         __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this);
    907891        return post( this->idle );
    908892}
     
    10161000        // make new owner
    10171001        unpark( thrd __cfaabi_dbg_ctx2 );
    1018 
    1019         return thrd != 0p;
    1020 }
    1021 
    1022 bool V(semaphore & this, unsigned diff) with( this ) {
    1023         $thread * thrd = 0p;
    1024         lock( lock __cfaabi_dbg_ctx2 );
    1025         int release = max(-count, (int)diff);
    1026         count += diff;
    1027         for(release) {
    1028                 unpark( pop_head( waiting ) __cfaabi_dbg_ctx2 );
    1029         }
    1030 
    1031         unlock( lock );
    10321002
    10331003        return thrd != 0p;
Note: See TracChangeset for help on using the changeset viewer.