Ignore:
Timestamp:
Apr 28, 2018, 10:35:51 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
b6dc097
Parents:
9997fee (diff), a0c7d5cc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    r9997fee r534d84e  
    4242KERNEL_STORAGE(cluster,           mainCluster);
    4343KERNEL_STORAGE(processor,         mainProcessor);
    44 KERNEL_STORAGE(processorCtx_t,    mainProcessorCtx);
    4544KERNEL_STORAGE(thread_desc,       mainThread);
    4645KERNEL_STORAGE(machine_context_t, mainThreadCtx);
    4746
    48 cluster *    mainCluster;
    49 processor mainProcessor;
     47cluster     * mainCluster;
     48processor   * mainProcessor;
    5049thread_desc * mainThread;
    5150
     
    6564
    6665//-----------------------------------------------------------------------------
    67 // Main thread construction
     66// Struct to steal stack
    6867struct current_stack_info_t {
    6968        machine_context_t ctx;
     
    9089}
    9190
     91//-----------------------------------------------------------------------------
     92// Main thread construction
    9293void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {
    9394        size      = info->size;
     
    111112        self_cor{ info };
    112113        curr_cor = &self_cor;
     114        curr_cluster = mainCluster;
    113115        self_mon.owner = &this;
    114116        self_mon.recursion = 1;
     
    126128//-----------------------------------------------------------------------------
    127129// Processor coroutine
    128 void ?{}(processorCtx_t & this) {}
    129 
    130 // Construct the processor context of the main processor
    131 void ?{}(processorCtx_t & this, processor * proc) {
    132         (this.__cor){ "Processor" };
    133         this.__cor.starter = NULL;
    134         this.proc = proc;
     130void ?{}(processorCtx_t & this) {
     131
    135132}
    136133
     
    141138}
    142139
    143 void ?{}(processor & this) {
    144         this{ mainCluster };
    145 }
    146 
    147 void ?{}(processor & this, cluster * cltr) with( this ) {
    148         this.cltr = cltr;
     140void ?{}(processor & this, const char * name, cluster & cltr) with( this ) {
     141        this.name = name;
     142        this.cltr = &cltr;
    149143        terminated{ 0 };
    150144        do_terminate = false;
     
    154148
    155149        start( &this );
    156 }
    157 
    158 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) with( this ) {
    159         this.cltr = cltr;
    160         terminated{ 0 };
    161         do_terminate = false;
    162         preemption_alarm = NULL;
    163         pending_preemption = false;
    164         kernel_thread = pthread_self();
    165         runner.proc = &this;
    166 
    167         __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner);
    168         runner{ &this };
    169150}
    170151
     
    181162}
    182163
    183 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;
    184167        ready_queue{};
    185168        ready_queue_lock{};
    186 
    187         preemption_rate = default_preemption();
    188169}
    189170
     
    312293        TL_SET( this_coroutine, NULL );
    313294        TL_SET( this_thread, NULL );
    314         TL_GET( preemption_state ).enabled = false;
    315         TL_GET( preemption_state ).disable_count = 1;
     295        TL_GET( preemption_state ).[enabled, disable_count] = [false, 1];
    316296        // SKULLDUGGERY: We want to create a context for the processor coroutine
    317297        // which is needed for the 2-step context switch. However, there is no reason
     
    402382        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    403383
    404         with( *TL_GET( this_processor )->cltr ) {
     384        with( *thrd->curr_cluster ) {
    405385                lock  ( ready_queue_lock __cfaabi_dbg_ctx2 );
    406386                append( ready_queue, thrd );
     
    430410void BlockInternal( __spinlock_t * lock ) {
    431411        disable_interrupts();
    432         TL_GET( this_processor )->finish.action_code = Release;
    433         TL_GET( this_processor )->finish.lock        = lock;
     412        with( *TL_GET( this_processor ) ) {
     413                finish.action_code = Release;
     414                finish.lock        = lock;
     415        }
    434416
    435417        verify( ! TL_GET( preemption_state ).enabled );
     
    442424void BlockInternal( thread_desc * thrd ) {
    443425        disable_interrupts();
    444         TL_GET( this_processor )->finish.action_code = Schedule;
    445         TL_GET( this_processor )->finish.thrd        = thrd;
     426        with( *TL_GET( this_processor ) ) {
     427                finish.action_code = Schedule;
     428                finish.thrd        = thrd;
     429        }
    446430
    447431        verify( ! TL_GET( preemption_state ).enabled );
     
    455439        assert(thrd);
    456440        disable_interrupts();
    457         TL_GET( this_processor )->finish.action_code = Release_Schedule;
    458         TL_GET( this_processor )->finish.lock        = lock;
    459         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        }
    460446
    461447        verify( ! TL_GET( preemption_state ).enabled );
     
    468454void BlockInternal(__spinlock_t * locks [], unsigned short count) {
    469455        disable_interrupts();
    470         TL_GET( this_processor )->finish.action_code = Release_Multi;
    471         TL_GET( this_processor )->finish.locks       = locks;
    472         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        }
    473461
    474462        verify( ! TL_GET( preemption_state ).enabled );
     
    481469void BlockInternal(__spinlock_t * locks [], unsigned short lock_count, thread_desc * thrds [], unsigned short thrd_count) {
    482470        disable_interrupts();
    483         TL_GET( this_processor )->finish.action_code = Release_Multi_Schedule;
    484         TL_GET( this_processor )->finish.locks       = locks;
    485         TL_GET( this_processor )->finish.lock_count  = lock_count;
    486         TL_GET( this_processor )->finish.thrds       = thrds;
    487         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        }
    488478
    489479        verify( ! TL_GET( preemption_state ).enabled );
     
    496486void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    497487        verify( ! TL_GET( preemption_state ).enabled );
    498         TL_GET( this_processor )->finish.action_code = thrd ? Release_Schedule : Release;
    499         TL_GET( this_processor )->finish.lock        = lock;
    500         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        }
    501493
    502494        returnToKernel();
     
    511503        verify( ! TL_GET( preemption_state ).enabled );
    512504        __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");
    513511
    514512        // Start by initializing the main thread
     
    521519        __cfaabi_dbg_print_safe("Kernel : Main thread ready\n");
    522520
    523         // Initialize the main cluster
    524         mainCluster = (cluster *)&storage_mainCluster;
    525         (*mainCluster){};
    526 
    527         __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        }
    528542
    529543        // Initialize the main processor and the main processor ctx
    530544        // (the coroutine that contains the processing control flow)
    531545        mainProcessor = (processor *)&storage_mainProcessor;
    532         (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx };
     546        (*mainProcessor){};
    533547
    534548        //initialize the global state variables
     
    725739                thrd->dbg_next = NULL;
    726740        }
     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        }
    727746)
    728747// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.