Changeset fa21ac9


Ignore:
Timestamp:
Jun 5, 2017, 11:42:05 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
b3c36f4
Parents:
2f9a722
Message:

Added alarm list to the system processor in the kernel

Location:
src/libcfa/concurrency
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel

    r2f9a722 rfa21ac9  
    9494
    9595// Local Variables: //
    96 // mode: c //
    97 // tab-width: 4 //
     96// mode: CFA //
     97// tab-width: 6 //
    9898// End: //
  • src/libcfa/concurrency/kernel.c

    r2f9a722 rfa21ac9  
    4747KERNEL_STORAGE(processorCtx_t, systemProcessorCtx);
    4848KERNEL_STORAGE(cluster, systemCluster);
    49 KERNEL_STORAGE(processor, systemProcessor);
     49KERNEL_STORAGE(system_proc_t, systemProcessor);
    5050KERNEL_STORAGE(thread_desc, mainThread);
    5151KERNEL_STORAGE(machine_context_t, mainThread_context);
    5252
    5353cluster * systemCluster;
    54 processor * systemProcessor;
     54system_proc_t * systemProcessor;
    5555thread_desc * mainThread;
    5656
     
    8181
    8282void ?{}( current_stack_info_t * this ) {
     83        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 1\n");
    8384        CtxGet( &this->ctx );
    8485        this->base = this->ctx.FP;
     
    9596
    9697void ?{}( coStack_t * this, current_stack_info_t * info) {
     98        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 2\n");
    9799        this->size = info->size;
    98100        this->storage = info->storage;
     
    105107
    106108void ?{}( coroutine_desc * this, current_stack_info_t * info) {
     109        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 3\n");
    107110        (&this->stack){ info };
    108111        this->name = "Main Thread";
     
    112115
    113116void ?{}( thread_desc * this, current_stack_info_t * info) {
     117        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 4\n");
    114118        (&this->cor){ info };
    115119}
     
    118122// Processor coroutine
    119123void ?{}(processorCtx_t * this, processor * proc) {
    120         (&this->__cor){};
     124        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 5\n");
     125        (&this->__cor){ "Processor" };
    121126        this->proc = proc;
    122127        proc->runner = this;
     
    124129
    125130void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) {
     131        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 6\n");
    126132        (&this->__cor){ info };
    127133        this->proc = proc;
     
    130136
    131137void ?{}(processor * this) {
     138        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 7\n");
    132139        this{ systemCluster };
    133140}
    134141
    135142void ?{}(processor * this, cluster * cltr) {
     143        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 8\n");
    136144        this->cltr = cltr;
    137145        this->current_coroutine = NULL;
     
    153161        LIB_DEBUG_PRINT_SAFE("Kernel : constructing processor context %p\n", runner);
    154162        runner{ this };
     163}
     164
     165void ?{}(system_proc_t * this, cluster * cltr, processorCtx_t * runner) {
     166        LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 9\n");
     167        (&this->alarms){};
     168        (&this->alarm_lock){};
     169
     170        (&this->proc){ cltr, runner };
    155171}
    156172
     
    316332        assertf( thrd->next == NULL, "Expected null got %p", thrd->next );
    317333       
    318         lock( &systemProcessor->cltr->lock );
    319         append( &systemProcessor->cltr->ready_queue, thrd );
    320         unlock( &systemProcessor->cltr->lock );
     334        lock( &systemProcessor->proc.cltr->lock );
     335        append( &systemProcessor->proc.cltr->ready_queue, thrd );
     336        unlock( &systemProcessor->proc.cltr->lock );
    321337}
    322338
     
    367383}
    368384
     385//=============================================================================================
     386// Kernel Preemption logic
     387//=============================================================================================
     388
     389#define __CFA_DEFAULT_PREEMPTION__ 10
     390
     391unsigned int default_preemption() {
     392        return __CFA_DEFAULT_PREEMPTION__;
     393}
     394
     395void kernel_start_preemption() {
     396
     397}
     398
     399//=============================================================================================
     400// Kernel Setup logic
     401//=============================================================================================
    369402//-----------------------------------------------------------------------------
    370403// Kernel boot procedures
     
    379412        mainThread{ &info };
    380413
     414        LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
     415
     416        // Enable preemption
     417        kernel_start_preemption();
     418
    381419        // Initialize the system cluster
    382420        systemCluster = (cluster *)&systemCluster_storage;
    383421        systemCluster{};
    384422
     423        LIB_DEBUG_PRINT_SAFE("Kernel : System cluster ready\n");
     424
    385425        // Initialize the system processor and the system processor ctx
    386426        // (the coroutine that contains the processing control flow)
    387         systemProcessor = (processor *)&systemProcessor_storage;
     427        systemProcessor = (system_proc_t *)&systemProcessor_storage;
    388428        systemProcessor{ systemCluster, (processorCtx_t *)&systemProcessorCtx_storage };
    389429
    390430        // Add the main thread to the ready queue
    391         // once resume is called on systemProcessor->ctx the mainThread needs to be scheduled like any normal thread
     431        // once resume is called on systemProcessor->runner the mainThread needs to be scheduled like any normal thread
    392432        ScheduleThread(mainThread);
    393433
    394434        //initialize the global state variables
    395         this_processor = systemProcessor;
     435        this_processor = &systemProcessor->proc;
    396436        this_processor->current_thread = mainThread;
    397437        this_processor->current_coroutine = &mainThread->cor;
     
    400440        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    401441        // mainThread is on the ready queue when this call is made.
    402         resume(systemProcessor->runner);
     442        resume( systemProcessor->proc.runner );
    403443
    404444
     
    414454        // When its coroutine terminates, it return control to the mainThread
    415455        // which is currently here
    416         systemProcessor->is_terminated = true;
     456        systemProcessor->proc.is_terminated = true;
    417457        suspend();
    418458
     
    421461        // Destroy the system processor and its context in reverse order of construction
    422462        // These were manually constructed so we need manually destroy them
    423         ^(systemProcessor->runner){};
     463        ^(systemProcessor->proc.runner){};
    424464        ^(systemProcessor){};
    425465
     
    484524}
    485525
     526//=============================================================================================
     527// Kernel Utilities
     528//=============================================================================================
    486529//-----------------------------------------------------------------------------
    487530// Locks
  • src/libcfa/concurrency/kernel_private.h

    r2f9a722 rfa21ac9  
    2121#include "thread"
    2222
     23#include "alarm.h"
     24
    2325//-----------------------------------------------------------------------------
    2426// Scheduler
     
    3537//-----------------------------------------------------------------------------
    3638// Processor
    37 struct processorCtx_t {
     39coroutine processorCtx_t {
    3840        processor * proc;
    39         coroutine_desc __cor;
    4041};
    41 
    42 DECL_COROUTINE(processorCtx_t);
    4342
    4443void main(processorCtx_t *);
     
    4746void finishRunning(processor * this);
    4847void spin(processor * this, unsigned int * spin_count);
     48
     49struct system_proc_t {
     50        processor proc;
     51
     52        alarm_list_t alarms;
     53        spinlock alarm_lock;
     54};
     55
     56extern cluster * systemCluster;
     57extern system_proc_t * systemProcessor;
    4958
    5059//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.