Ignore:
Timestamp:
Feb 16, 2018, 4:22:25 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, resolv-new, with_gc
Children:
5964127
Parents:
c71b256 (diff), 62cd621 (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 plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rc71b256 r7c782af  
    5656thread_local processor *      volatile this_processor;
    5757
    58 volatile thread_local bool preemption_in_progress = 0;
    59 volatile thread_local bool preemption_enabled = false;
    60 volatile thread_local unsigned short disable_preempt_count = 1;
     58// volatile thread_local bool preemption_in_progress = 0;
     59// volatile thread_local bool preemption_enabled = false;
     60// volatile thread_local unsigned short disable_preempt_count = 1;
     61
     62volatile thread_local __cfa_kernel_preemption_data_t preemption = { false, false, 1 };
    6163
    6264//-----------------------------------------------------------------------------
     
    207209                        if(readyThread)
    208210                        {
    209                                 verify( !preemption_enabled );
     211                                verify( !preemption.enabled );
    210212
    211213                                runThread(this, readyThread);
    212214
    213                                 verify( !preemption_enabled );
     215                                verify( !preemption.enabled );
    214216
    215217                                //Some actions need to be taken from the kernel
     
    260262void finishRunning(processor * this) with( this->finish ) {
    261263        if( action_code == Release ) {
    262                 verify( !preemption_enabled );
     264                verify( !preemption.enabled );
    263265                unlock( *lock );
    264266        }
     
    267269        }
    268270        else if( action_code == Release_Schedule ) {
    269                 verify( !preemption_enabled );
     271                verify( !preemption.enabled );
    270272                unlock( *lock );
    271273                ScheduleThread( thrd );
    272274        }
    273275        else if( action_code == Release_Multi ) {
    274                 verify( !preemption_enabled );
     276                verify( !preemption.enabled );
    275277                for(int i = 0; i < lock_count; i++) {
    276278                        unlock( *locks[i] );
     
    304306        this_coroutine = NULL;
    305307        this_thread = NULL;
    306         preemption_enabled = false;
    307         disable_preempt_count = 1;
     308        preemption.enabled = false;
     309        preemption.disable_count = 1;
    308310        // SKULLDUGGERY: We want to create a context for the processor coroutine
    309311        // which is needed for the 2-step context switch. However, there is no reason
     
    345347}
    346348
     349void kernel_first_resume(processor * this) {
     350        coroutine_desc * src = this_coroutine;
     351        coroutine_desc * dst = get_coroutine(*this->runner);
     352
     353        verify( !preemption.enabled );
     354
     355        create_stack(&dst->stack, dst->stack.size);
     356        CtxStart(this->runner, CtxInvokeCoroutine);
     357
     358        verify( !preemption.enabled );
     359
     360        dst->last = src;
     361        dst->starter = dst->starter ? dst->starter : src;
     362
     363        // set state of current coroutine to inactive
     364        src->state = src->state == Halted ? Halted : Inactive;
     365
     366        // set new coroutine that task is executing
     367        this_coroutine = dst;
     368
     369        // SKULLDUGGERY normally interrupts are enable before leaving a coroutine ctxswitch.
     370        // Therefore, when first creating a coroutine, interrupts are enable before calling the main.
     371        // This is consistent with thread creation. However, when creating the main processor coroutine,
     372        // we wan't interrupts to be disabled. Therefore, we double-disable interrupts here so they will
     373        // stay disabled.
     374        disable_interrupts();
     375
     376        // context switch to specified coroutine
     377        assert( src->stack.context );
     378        CtxSwitch( src->stack.context, dst->stack.context );
     379        // when CtxSwitch returns we are back in the src coroutine
     380
     381        // set state of new coroutine to active
     382        src->state = Active;
     383
     384        verify( !preemption.enabled );
     385}
     386
    347387//-----------------------------------------------------------------------------
    348388// Scheduler routines
     
    352392        verify( thrd->self_cor.state != Halted );
    353393
    354         verify( !preemption_enabled );
     394        verify( !preemption.enabled );
    355395
    356396        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
     
    362402        }
    363403
    364         verify( !preemption_enabled );
     404        verify( !preemption.enabled );
    365405}
    366406
    367407thread_desc * nextThread(cluster * this) with( *this ) {
    368         verify( !preemption_enabled );
     408        verify( !preemption.enabled );
    369409        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
    370410        thread_desc * head = pop_head( ready_queue );
    371411        unlock( ready_queue_lock );
    372         verify( !preemption_enabled );
     412        verify( !preemption.enabled );
    373413        return head;
    374414}
     
    376416void BlockInternal() {
    377417        disable_interrupts();
    378         verify( !preemption_enabled );
     418        verify( !preemption.enabled );
    379419        returnToKernel();
    380         verify( !preemption_enabled );
     420        verify( !preemption.enabled );
    381421        enable_interrupts( __cfaabi_dbg_ctx );
    382422}
     
    387427        this_processor->finish.lock        = lock;
    388428
    389         verify( !preemption_enabled );
     429        verify( !preemption.enabled );
    390430        returnToKernel();
    391         verify( !preemption_enabled );
     431        verify( !preemption.enabled );
    392432
    393433        enable_interrupts( __cfaabi_dbg_ctx );
     
    399439        this_processor->finish.thrd        = thrd;
    400440
    401         verify( !preemption_enabled );
     441        verify( !preemption.enabled );
    402442        returnToKernel();
    403         verify( !preemption_enabled );
     443        verify( !preemption.enabled );
    404444
    405445        enable_interrupts( __cfaabi_dbg_ctx );
     
    413453        this_processor->finish.thrd        = thrd;
    414454
    415         verify( !preemption_enabled );
     455        verify( !preemption.enabled );
    416456        returnToKernel();
    417         verify( !preemption_enabled );
     457        verify( !preemption.enabled );
    418458
    419459        enable_interrupts( __cfaabi_dbg_ctx );
     
    426466        this_processor->finish.lock_count  = count;
    427467
    428         verify( !preemption_enabled );
     468        verify( !preemption.enabled );
    429469        returnToKernel();
    430         verify( !preemption_enabled );
     470        verify( !preemption.enabled );
    431471
    432472        enable_interrupts( __cfaabi_dbg_ctx );
     
    441481        this_processor->finish.thrd_count  = thrd_count;
    442482
    443         verify( !preemption_enabled );
     483        verify( !preemption.enabled );
    444484        returnToKernel();
    445         verify( !preemption_enabled );
     485        verify( !preemption.enabled );
    446486
    447487        enable_interrupts( __cfaabi_dbg_ctx );
     
    449489
    450490void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    451         verify( !preemption_enabled );
     491        verify( !preemption.enabled );
    452492        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    453493        this_processor->finish.lock        = lock;
     
    463503// Kernel boot procedures
    464504void kernel_startup(void) {
     505        verify( !preemption.enabled );
    465506        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    466507
     
    500541        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    501542        // mainThread is on the ready queue when this call is made.
    502         resume( *mainProcessor->runner );
     543        kernel_first_resume( this_processor );
    503544
    504545
     
    507548        __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n");
    508549
     550        verify( !preemption.enabled );
    509551        enable_interrupts( __cfaabi_dbg_ctx );
     552        verify( preemption.enabled );
    510553}
    511554
     
    513556        __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n");
    514557
     558        verify( preemption.enabled );
    515559        disable_interrupts();
     560        verify( !preemption.enabled );
    516561
    517562        // SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
Note: See TracChangeset for help on using the changeset viewer.