Ignore:
Timestamp:
Jul 22, 2015, 1:11:08 PM (9 years ago)
Author:
alain
Message:

Introducing support for the new mechanism to start tasks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_kernel/kernel_init.c

    r629 r648  
    266266    //            initialisation, from values stored in the tasks contexts.
    267267    //          - set CTX_RA slot  with the kernel _ctx_eret() virtual address.
    268     //          - set CTX_EPC slot that must contain the task entry point,
     268    //          - set CTX_ENTRY slot that must contain the task entry point,
    269269    //            and contain only at this point the virtual address of the
    270     //            memory slot containing this entry point.
     270    //            memory word containing this entry point.
    271271    ////////////////////////////////////////////////////////////////////////////
    272272
     
    283283        _ptabs_ptprs[vsid][x][y] = ptpr;
    284284
    285         // set the ptpr to use the local page table
     285        // set the PTPR to use the local page table
    286286        asm volatile( "mtc2    %0,   $0"
    287287                      : : "r" (ptpr) );
    288288
    289         // compute ctx_ra
     289        // set CTX_RA slot
    290290        unsigned int ctx_ra = (unsigned int)(&_ctx_eret);
    291291        _set_task_slot( x, y, p, ltid, CTX_RA_ID, ctx_ra );
    292292
    293         // compute ctx_epc
    294         unsigned int* ptr = (unsigned int*)_get_task_slot(x,y,p,ltid,CTX_EPC_ID);
    295         _set_task_slot( x , y , p , ltid , CTX_EPC_ID , *ptr );
     293        // set CTX_ENTRY slot
     294        unsigned int* ptr = (unsigned int*)_get_task_slot(x , y , p , ltid , CTX_ENTRY_ID);
     295        unsigned int ctx_entry = *ptr;
     296        _set_task_slot( x , y , p , ltid , CTX_ENTRY_ID , ctx_entry );
    296297
    297298#if GIET_DEBUG_INIT
     
    300301        " - ptabs_vaddr[%d][%d][%d] = %x\n"
    301302        " - ptabs_paddr[%d][%d][%d] = %l\n"
    302         " - ctx_epc              = %x\n"
     303        " - ctx_entry            = %x\n"
    303304        " - ctx_ra               = %x\n",
    304305        x , y , p , ltid , 
    305306        vsid , x , y , ptab ,
    306307        vsid , x , y , ((unsigned long long)ptpr)<<13 ,
    307         _get_task_slot( x, y, p, ltid, CTX_EPC_ID ),
    308         _get_task_slot( x, y, p, ltid, CTX_RA_ID ) );
     308        ctx_entry, ctx_ra );
    309309#endif
    310310
     
    316316
    317317    ////////////////////////////////////////////////////////////////////////////
    318     // step 3 : - Each processor complete idle task context initialisation,
    319     //            (only the CTX_SP, CTX_RA, CTX_EPC slot, because the CTX_PTPR
    320     //            and CTX_PTAB slots have been initialised in boot code)
     318    // step 3 : - Each processor complete idle task context initialisation.
     319    //            Only CTX_SP, CTX_RA, CTX_EPC slots, because other slots
     320    //            have been initialised in boot code)
    321321    //            The 4 Kbytes idle stack is implemented in the scheduler itself.
    322     //          - Each processor starts TICK timer, as soon as at least one task
    323     //            is allocated.
     322    //          - Each processor starts TICK timer, if at least one task.
    324323    //          - P[0,0,0] initialises FAT (not done before, because it must
    325324    //            be done after the _ptabs_vaddr[v][x][y] array initialisation,
     
    327326    ////////////////////////////////////////////////////////////////////////////
    328327
    329     unsigned int sp  = ((unsigned int)psched) + 0x2000;
    330     unsigned int ra  = (unsigned int)(&_ctx_eret);
    331     unsigned int epc = (unsigned int)(&_idle_task);
    332 
    333     _set_task_slot( x , y , p , IDLE_TASK_INDEX , CTX_SP_ID  , sp  );
    334     _set_task_slot( x , y , p , IDLE_TASK_INDEX , CTX_RA_ID  , ra  );
    335     _set_task_slot( x , y , p , IDLE_TASK_INDEX , CTX_EPC_ID , epc );
     328    unsigned int sp    = ((unsigned int)psched) + 0x2000;
     329    unsigned int ra    = (unsigned int)(&_ctx_eret);
     330    unsigned int entry = (unsigned int)(&_idle_task);
     331
     332    _set_task_slot( x , y , p , IDLE_TASK_INDEX , CTX_SP_ID  , sp    );
     333    _set_task_slot( x , y , p , IDLE_TASK_INDEX , CTX_RA_ID  , ra    );
     334    _set_task_slot( x , y , p , IDLE_TASK_INDEX , CTX_ENTRY_ID , entry );
    336335
    337336    if (tasks > 0) _xcu_timer_start( cluster_xy, p, GIET_TICK_VALUE );
     
    358357
    359358    ////////////////////////////////////////////////////////////////////////////
    360     // step 4 : Each processor compute values for registers SP, SR, PTPR, EPC,
    361     //          corresponding to the first allocated task (can be idle task)
    362     //          and jumps to user code.
     359    // step 4 : Each processor computes the task index (ltid), and the values
     360    //          to initialize the SP, SR, PTPR, EPC registers.
     361    //          It jumps to a runable task if possible, and jumps to IDLE-TASK
     362    //          if no task allocated or no runable task.
    363363    ////////////////////////////////////////////////////////////////////////////
    364364
     
    366366                            x, y, p );
    367367
    368     if (tasks == 0) ltid = IDLE_TASK_INDEX;
    369     else            ltid = 0;
    370 
     368    // default value for ltid
     369    ltid = IDLE_TASK_INDEX;
     370
     371    // scan allocated tasks to find a runable task
     372    unsigned int  task_id;
     373    for ( task_id = 0 ; task_id < tasks ; task_id++ )
     374    {
     375        if ( _get_task_slot( x, y, p, task_id, CTX_NORUN_ID ) == 0 )
     376        {
     377            ltid = task_id;
     378            break;
     379        }
     380    }
     381
     382    // update scheduler
     383    psched->current = ltid;
     384
     385    // get values from selected task context
    371386    unsigned int sp_value   = _get_task_slot( x, y, p, ltid, CTX_SP_ID);
    372387    unsigned int sr_value   = _get_task_slot( x, y, p, ltid, CTX_SR_ID);
    373388    unsigned int ptpr_value = _get_task_slot( x, y, p, ltid, CTX_PTPR_ID);
    374     unsigned int epc_value  = _get_task_slot( x, y, p, ltid, CTX_EPC_ID);
    375 
    376 #if GIET_DEBUG_INIT
    377 _printf("\n[DEBUG KINIT] P[%d,%d,%d] jumps to user code at cycle %d\n"
     389    unsigned int epc_value  = _get_task_slot( x, y, p, ltid, CTX_ENTRY_ID);
     390
     391#if GIET_DEBUG_INIT
     392_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes kernel_init at cycle %d\n"
    378393        " ltid = %d / sp = %x / sr = %x / ptpr = %x / epc = %x\n",
    379394        x , y , p , _get_proctime() ,
Note: See TracChangeset for help on using the changeset viewer.