Ignore:
File:
1 edited

Legend:

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

    rde6319f r01963df  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr  9 16:11:46 2018
    13 // Update Count     : 24
     12// Last Modified On : Fri Mar 30 18:26:11 2018
     13// Update Count     : 23
    1414//
    1515
     
    2525
    2626//CFA Includes
    27 #include "time"
    2827#include "kernel_private.h"
    2928#include "preemption.h"
     
    4241KERNEL_STORAGE(cluster,           mainCluster);
    4342KERNEL_STORAGE(processor,         mainProcessor);
     43KERNEL_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 // Struct to steal stack
     66// Main thread construction
    6767struct current_stack_info_t {
    6868        machine_context_t ctx;
     
    8989}
    9090
    91 //-----------------------------------------------------------------------------
    92 // Main thread construction
    9391void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {
    9492        size      = info->size;
     
    112110        self_cor{ info };
    113111        curr_cor = &self_cor;
    114         curr_cluster = mainCluster;
    115112        self_mon.owner = &this;
    116113        self_mon.recursion = 1;
     
    128125//-----------------------------------------------------------------------------
    129126// Processor coroutine
    130 void ?{}(processorCtx_t & this) {
    131 
     127void ?{}(processorCtx_t & this) {}
     128
     129// Construct the processor context of the main processor
     130void ?{}(processorCtx_t & this, processor * proc) {
     131        (this.__cor){ "Processor" };
     132        this.__cor.starter = NULL;
     133        this.proc = proc;
    132134}
    133135
     
    138140}
    139141
    140 void ?{}(processor & this, const char * name, cluster & cltr) with( this ) {
    141         this.name = name;
    142         this.cltr = &cltr;
     142void ?{}(processor & this) {
     143        this{ mainCluster };
     144}
     145
     146void ?{}(processor & this, cluster * cltr) with( this ) {
     147        this.cltr = cltr;
    143148        terminated{ 0 };
    144149        do_terminate = false;
     
    148153
    149154        start( &this );
     155}
     156
     157void ?{}(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 };
    150168}
    151169
     
    162180}
    163181
    164 void ?{}(cluster & this, const char * name, Duration preemption_rate) with( this ) {
    165         this.name = name;
    166         this.preemption_rate = preemption_rate;
     182void ?{}(cluster & this) with( this ) {
    167183        ready_queue{};
    168184        ready_queue_lock{};
     185
     186        preemption_rate = default_preemption();
    169187}
    170188
     
    293311        TL_SET( this_coroutine, NULL );
    294312        TL_SET( this_thread, NULL );
    295         TL_GET( preemption_state ).[enabled, disable_count] = [false, 1];
     313        TL_GET( preemption_state ).enabled = false;
     314        TL_GET( preemption_state ).disable_count = 1;
    296315        // SKULLDUGGERY: We want to create a context for the processor coroutine
    297316        // which is needed for the 2-step context switch. However, there is no reason
     
    382401        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    383402
    384         with( *thrd->curr_cluster ) {
     403        with( *TL_GET( this_processor )->cltr ) {
    385404                lock  ( ready_queue_lock __cfaabi_dbg_ctx2 );
    386405                append( ready_queue, thrd );
     
    410429void BlockInternal( __spinlock_t * lock ) {
    411430        disable_interrupts();
    412         with( *TL_GET( this_processor ) ) {
    413                 finish.action_code = Release;
    414                 finish.lock        = lock;
    415         }
     431        TL_GET( this_processor )->finish.action_code = Release;
     432        TL_GET( this_processor )->finish.lock        = lock;
    416433
    417434        verify( ! TL_GET( preemption_state ).enabled );
     
    424441void BlockInternal( thread_desc * thrd ) {
    425442        disable_interrupts();
    426         with( *TL_GET( this_processor ) ) {
    427                 finish.action_code = Schedule;
    428                 finish.thrd        = thrd;
    429         }
     443        TL_GET( this_processor )->finish.action_code = Schedule;
     444        TL_GET( this_processor )->finish.thrd        = thrd;
    430445
    431446        verify( ! TL_GET( preemption_state ).enabled );
     
    439454        assert(thrd);
    440455        disable_interrupts();
    441         with( *TL_GET( this_processor ) ) {
    442                 finish.action_code = Release_Schedule;
    443                 finish.lock        = lock;
    444                 finish.thrd        = thrd;
    445         }
     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;
    446459
    447460        verify( ! TL_GET( preemption_state ).enabled );
     
    454467void BlockInternal(__spinlock_t * locks [], unsigned short count) {
    455468        disable_interrupts();
    456         with( *TL_GET( this_processor ) ) {
    457                 finish.action_code = Release_Multi;
    458                 finish.locks       = locks;
    459                 finish.lock_count  = count;
    460         }
     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;
    461472
    462473        verify( ! TL_GET( preemption_state ).enabled );
     
    469480void BlockInternal(__spinlock_t * locks [], unsigned short lock_count, thread_desc * thrds [], unsigned short thrd_count) {
    470481        disable_interrupts();
    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         }
     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;
    478487
    479488        verify( ! TL_GET( preemption_state ).enabled );
     
    486495void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    487496        verify( ! TL_GET( preemption_state ).enabled );
    488         with( *TL_GET( this_processor ) ) {
    489                 finish.action_code = thrd ? Release_Schedule : Release;
    490                 finish.lock        = lock;
    491                 finish.thrd        = thrd;
    492         }
     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;
    493500
    494501        returnToKernel();
     
    504511        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    505512
    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");
    511 
    512513        // Start by initializing the main thread
    513514        // SKULLDUGGERY: the mainThread steals the process main thread
     
    519520        __cfaabi_dbg_print_safe("Kernel : Main thread ready\n");
    520521
    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         }
     522        // Initialize the main cluster
     523        mainCluster = (cluster *)&storage_mainCluster;
     524        (*mainCluster){};
     525
     526        __cfaabi_dbg_print_safe("Kernel : main cluster ready\n");
    542527
    543528        // Initialize the main processor and the main processor ctx
    544529        // (the coroutine that contains the processing control flow)
    545530        mainProcessor = (processor *)&storage_mainProcessor;
    546         (*mainProcessor){};
     531        (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx };
    547532
    548533        //initialize the global state variables
     
    739724                thrd->dbg_next = NULL;
    740725        }
    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         }
    746726)
    747727// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.