Ignore:
File:
1 edited

Legend:

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

    r01963df rde6319f  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 30 18:26:11 2018
    13 // Update Count     : 23
     12// Last Modified On : Mon Apr  9 16:11:46 2018
     13// Update Count     : 24
    1414//
    1515
     
    2525
    2626//CFA Includes
     27#include "time"
    2728#include "kernel_private.h"
    2829#include "preemption.h"
     
    4142KERNEL_STORAGE(cluster,           mainCluster);
    4243KERNEL_STORAGE(processor,         mainProcessor);
    43 KERNEL_STORAGE(processorCtx_t,    mainProcessorCtx);
    4444KERNEL_STORAGE(thread_desc,       mainThread);
    4545KERNEL_STORAGE(machine_context_t, mainThreadCtx);
    4646
    47 cluster *    mainCluster;
    48 processor mainProcessor;
     47cluster     * mainCluster;
     48processor   * mainProcessor;
    4949thread_desc * mainThread;
    5050
     
    6464
    6565//-----------------------------------------------------------------------------
    66 // Main thread construction
     66// Struct to steal stack
    6767struct current_stack_info_t {
    6868        machine_context_t ctx;
     
    8989}
    9090
     91//-----------------------------------------------------------------------------
     92// Main thread construction
    9193void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {
    9294        size      = info->size;
     
    110112        self_cor{ info };
    111113        curr_cor = &self_cor;
     114        curr_cluster = mainCluster;
    112115        self_mon.owner = &this;
    113116        self_mon.recursion = 1;
     
    125128//-----------------------------------------------------------------------------
    126129// Processor coroutine
    127 void ?{}(processorCtx_t & this) {}
    128 
    129 // Construct the processor context of the main processor
    130 void ?{}(processorCtx_t & this, processor * proc) {
    131         (this.__cor){ "Processor" };
    132         this.__cor.starter = NULL;
    133         this.proc = proc;
     130void ?{}(processorCtx_t & this) {
     131
    134132}
    135133
     
    140138}
    141139
    142 void ?{}(processor & this) {
    143         this{ mainCluster };
    144 }
    145 
    146 void ?{}(processor & this, cluster * cltr) with( this ) {
    147         this.cltr = cltr;
     140void ?{}(processor & this, const char * name, cluster & cltr) with( this ) {
     141        this.name = name;
     142        this.cltr = &cltr;
    148143        terminated{ 0 };
    149144        do_terminate = false;
     
    153148
    154149        start( &this );
    155 }
    156 
    157 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) with( this ) {
    158         this.cltr = cltr;
    159         terminated{ 0 };
    160         do_terminate = false;
    161         preemption_alarm = NULL;
    162         pending_preemption = false;
    163         kernel_thread = pthread_self();
    164         runner.proc = &this;
    165 
    166         __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner);
    167         runner{ &this };
    168150}
    169151
     
    180162}
    181163
    182 void ?{}(cluster & this) with( this ) {
     164void ?{}(cluster & this, const char * name, Duration preemption_rate) with( this ) {
     165        this.name = name;
     166        this.preemption_rate = preemption_rate;
    183167        ready_queue{};
    184168        ready_queue_lock{};
    185 
    186         preemption_rate = default_preemption();
    187169}
    188170
     
    311293        TL_SET( this_coroutine, NULL );
    312294        TL_SET( this_thread, NULL );
    313         TL_GET( preemption_state ).enabled = false;
    314         TL_GET( preemption_state ).disable_count = 1;
     295        TL_GET( preemption_state ).[enabled, disable_count] = [false, 1];
    315296        // SKULLDUGGERY: We want to create a context for the processor coroutine
    316297        // which is needed for the 2-step context switch. However, there is no reason
     
    401382        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    402383
    403         with( *TL_GET( this_processor )->cltr ) {
     384        with( *thrd->curr_cluster ) {
    404385                lock  ( ready_queue_lock __cfaabi_dbg_ctx2 );
    405386                append( ready_queue, thrd );
     
    429410void BlockInternal( __spinlock_t * lock ) {
    430411        disable_interrupts();
    431         TL_GET( this_processor )->finish.action_code = Release;
    432         TL_GET( this_processor )->finish.lock        = lock;
     412        with( *TL_GET( this_processor ) ) {
     413                finish.action_code = Release;
     414                finish.lock        = lock;
     415        }
    433416
    434417        verify( ! TL_GET( preemption_state ).enabled );
     
    441424void BlockInternal( thread_desc * thrd ) {
    442425        disable_interrupts();
    443         TL_GET( this_processor )->finish.action_code = Schedule;
    444         TL_GET( this_processor )->finish.thrd        = thrd;
     426        with( *TL_GET( this_processor ) ) {
     427                finish.action_code = Schedule;
     428                finish.thrd        = thrd;
     429        }
    445430
    446431        verify( ! TL_GET( preemption_state ).enabled );
     
    454439        assert(thrd);
    455440        disable_interrupts();
    456         TL_GET( this_processor )->finish.action_code = Release_Schedule;
    457         TL_GET( this_processor )->finish.lock        = lock;
    458         TL_GET( this_processor )->finish.thrd        = thrd;
     441        with( *TL_GET( this_processor ) ) {
     442                finish.action_code = Release_Schedule;
     443                finish.lock        = lock;
     444                finish.thrd        = thrd;
     445        }
    459446
    460447        verify( ! TL_GET( preemption_state ).enabled );
     
    467454void BlockInternal(__spinlock_t * locks [], unsigned short count) {
    468455        disable_interrupts();
    469         TL_GET( this_processor )->finish.action_code = Release_Multi;
    470         TL_GET( this_processor )->finish.locks       = locks;
    471         TL_GET( this_processor )->finish.lock_count  = count;
     456        with( *TL_GET( this_processor ) ) {
     457                finish.action_code = Release_Multi;
     458                finish.locks       = locks;
     459                finish.lock_count  = count;
     460        }
    472461
    473462        verify( ! TL_GET( preemption_state ).enabled );
     
    480469void BlockInternal(__spinlock_t * locks [], unsigned short lock_count, thread_desc * thrds [], unsigned short thrd_count) {
    481470        disable_interrupts();
    482         TL_GET( this_processor )->finish.action_code = Release_Multi_Schedule;
    483         TL_GET( this_processor )->finish.locks       = locks;
    484         TL_GET( this_processor )->finish.lock_count  = lock_count;
    485         TL_GET( this_processor )->finish.thrds       = thrds;
    486         TL_GET( this_processor )->finish.thrd_count  = thrd_count;
     471        with( *TL_GET( this_processor ) ) {
     472                finish.action_code = Release_Multi_Schedule;
     473                finish.locks       = locks;
     474                finish.lock_count  = lock_count;
     475                finish.thrds       = thrds;
     476                finish.thrd_count  = thrd_count;
     477        }
    487478
    488479        verify( ! TL_GET( preemption_state ).enabled );
     
    495486void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    496487        verify( ! TL_GET( preemption_state ).enabled );
    497         TL_GET( this_processor )->finish.action_code = thrd ? Release_Schedule : Release;
    498         TL_GET( this_processor )->finish.lock        = lock;
    499         TL_GET( this_processor )->finish.thrd        = thrd;
     488        with( *TL_GET( this_processor ) ) {
     489                finish.action_code = thrd ? Release_Schedule : Release;
     490                finish.lock        = lock;
     491                finish.thrd        = thrd;
     492        }
    500493
    501494        returnToKernel();
     
    510503        verify( ! TL_GET( preemption_state ).enabled );
    511504        __cfaabi_dbg_print_safe("Kernel : Starting\n");
     505
     506        // Initialize the main cluster
     507        mainCluster = (cluster *)&storage_mainCluster;
     508        (*mainCluster){"Main Cluster"};
     509
     510        __cfaabi_dbg_print_safe("Kernel : Main cluster ready\n");
    512511
    513512        // Start by initializing the main thread
     
    520519        __cfaabi_dbg_print_safe("Kernel : Main thread ready\n");
    521520
    522         // Initialize the main cluster
    523         mainCluster = (cluster *)&storage_mainCluster;
    524         (*mainCluster){};
    525 
    526         __cfaabi_dbg_print_safe("Kernel : main cluster ready\n");
     521
     522
     523        // Construct the processor context of the main processor
     524        void ?{}(processorCtx_t & this, processor * proc) {
     525                (this.__cor){ "Processor" };
     526                this.__cor.starter = NULL;
     527                this.proc = proc;
     528        }
     529
     530        void ?{}(processor & this) with( this ) {
     531                name = "Main Processor";
     532                cltr = mainCluster;
     533                terminated{ 0 };
     534                do_terminate = false;
     535                preemption_alarm = NULL;
     536                pending_preemption = false;
     537                kernel_thread = pthread_self();
     538
     539                runner{ &this };
     540                __cfaabi_dbg_print_safe("Kernel : constructed main processor context %p\n", &runner);
     541        }
    527542
    528543        // Initialize the main processor and the main processor ctx
    529544        // (the coroutine that contains the processing control flow)
    530545        mainProcessor = (processor *)&storage_mainProcessor;
    531         (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx };
     546        (*mainProcessor){};
    532547
    533548        //initialize the global state variables
     
    724739                thrd->dbg_next = NULL;
    725740        }
     741
     742        void __cfaabi_dbg_record(__spinlock_t & this, const char * prev_name) {
     743                this.prev_name = prev_name;
     744                this.prev_thrd = TL_GET( this_thread );
     745        }
    726746)
    727747// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.