Ignore:
Timestamp:
Oct 1, 2015, 4:20:46 PM (9 years ago)
Author:
alain
Message:

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
File:
1 edited

Legend:

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

    r688 r709  
    2323#include <bdv_driver.h>
    2424#include <mmc_driver.h>
     25#include <tty_driver.h>
    2526#include <ctx_handler.h>
    2627#include <irq_handler.h>
     28#include <sys_handler.h>
    2729#include <mapping_info.h>
    2830#include <mips32_registers.h>
     
    6062#endif
    6163
    62 #if !defined(IDLE_TASK_INDEX)
    63 # error: You must define IDLE_TASK_INDEX in the ctx_handler.h file
     64#if !defined(IDLE_THREAD_INDEX)
     65# error: You must define IDLE_THREAD_INDEX in the ctx_handler.h file
    6466#endif
    6567
     
    109111volatile unsigned int _kernel_init_done = 0;
    110112
    111 // Kernel uses sqt_lock to protect TTY0       
     113// Kernel uses a sqt_lock to protect TTY0       
    112114__attribute__((section(".kdata")))
    113115unsigned int   _tty0_boot_mode = 0;
    114116
    115 // Kernel uses sqt_lock to protect command allocator in HBA       
     117// Kernel uses a sqt_lock to protect command allocator in HBA       
    116118__attribute__((section(".kdata")))
    117119unsigned int   _hba_boot_mode = 0;
     
    125127////////////////////////////////////////////////////////////////////////////////
    126128
    127 // this variable is defined in tty0.c file
     129// this variable is allocated in tty0.c file
    128130extern sqt_lock_t _tty0_sqt_lock;
    129131
    130 // this variable is allocated in mmc_kernel.c
     132// this variable is allocated in mmc_driver.c file
    131133extern unsigned int _mmc_boot_mode;
    132134
    133 ////////////////////////////////////////////////////////////////////////////////
    134 // This kernel_init() function completes the kernel initialisation in 6 steps:
     135// this variable is allocated in sys_handler.c file
     136extern unsigned int _tty_channel_alloc[NB_TTY_CHANNELS];
     137
     138////////////////////////////////////////////////////////////////////////////////
     139// This kernel_init() function completes the kernel initialisation in 5 steps:
    135140// Step 0 is done by processor[0,0,0]. Steps 1 to 4 are executed in parallel
    136141// by all processors.
     
    138143// - step 1 : Each processor initialises scheduler pointers array.
    139144// - step 2 : Each processor initialises PTAB pointers arrays.
    140 // - step 3 : Each processor initialise idle task and starts TICK timer.
     145// - step 3 : Each processor initialise idle thread and starts TICK timer.
    141146// - step 4 : Each processor set sp, sr, ptpr, epc registers values.
    142147////////////////////////////////////////////////////////////////////////////////
     
    165170_nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes kernel heap init\n", x, y, p );
    166171#endif
    167         //////  distributed lock for MMC
     172        //////  distributed locks for MMC
    168173        _mmc_boot_mode = 0;
    169174        _mmc_init_locks();
    170175
    171176#if GIET_DEBUG_INIT
    172 _nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes MMC distributed lock init\n", x , y , p );
     177_nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes MMC distributed locks init\n", x , y , p );
    173178#endif
    174179        //////  distributed lock for TTY0
    175180        _sqt_lock_init( &_tty0_sqt_lock );
     181        _tty_channel_alloc[0] = 1;
    176182
    177183#if GIET_DEBUG_INIT
     
    183189#if GIET_DEBUG_INIT
    184190_nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes barrier init\n", x , y , p );
     191#endif
     192
     193        //////  TTY fifos initialisation
     194        unsigned int tty_id;
     195        for ( tty_id = 0 ; tty_id < NB_TTY_CHANNELS ; tty_id++) _tty_init( tty_id );
     196
     197#if GIET_DEBUG_INIT
     198_nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes TTY fifos init\n", x , y , p );
    185199#endif
    186200
     
    245259
    246260    static_scheduler_t* psched     = (static_scheduler_t*)_get_sched();
    247     unsigned int        tasks      = psched->tasks;
     261    unsigned int        threads    = psched->threads;
    248262
    249263    _schedulers[x][y][p] = psched;
     
    252266_printf("\n[DEBUG KINIT] P[%d,%d,%d] initialises SCHED array\n"
    253267        " - scheduler vbase = %x\n"
    254         " - tasks           = %d\n",
    255         x, y, p, (unsigned int)psched, tasks );
     268        " - threads         = %d\n",
     269        x, y, p, (unsigned int)psched, threads );
    256270#endif
    257271
     
    261275
    262276    ////////////////////////////////////////////////////////////////////////////
    263     // step 2 : each processor that is allocated at least one task loops
    264     //          on its allocated tasks:
    265     //          - contributes to _ptabs_vaddr[][][] & _ptabs_ptprs[][][]
    266     //            initialisation, from values stored in the tasks contexts.
     277    // step 2 : each processor that is allocated at least one thread loops
     278    //          on its allocated threads:
     279    //          - contributes to _ptabs_vaddr & _ptabs_ptprs arrays
     280    //            initialisation, from values stored in the threads contexts.
    267281    //          - set CTX_RA slot  with the kernel _ctx_eret() virtual address.
    268     //          - set CTX_ENTRY slot that must contain the task entry point,
    269     //            and contain only at this point the virtual address of the
    270     //            memory word containing this entry point.
     282    //          - set CTX_ENTRY & CTX_EPC slots that must contain the thread
     283    //            entry point. The CTX_ENTRY slot contain only at this point
     284    //            a pointer on the memory word containing this entry point.
    271285    ////////////////////////////////////////////////////////////////////////////
    272286
    273287    unsigned int ltid;
    274288
    275     for (ltid = 0; ltid < tasks; ltid++)
     289    for (ltid = 0; ltid < threads; ltid++)
    276290    {
    277         unsigned int vsid = _get_task_slot( x, y, p, ltid , CTX_VSID_ID );
    278         unsigned int ptab = _get_task_slot( x, y, p, ltid , CTX_PTAB_ID );
    279         unsigned int ptpr = _get_task_slot( x, y, p, ltid , CTX_PTPR_ID );
     291        unsigned int vsid = _get_thread_slot( x, y, p, ltid , CTX_VSID_ID );
     292        unsigned int ptab = _get_thread_slot( x, y, p, ltid , CTX_PTAB_ID );
     293        unsigned int ptpr = _get_thread_slot( x, y, p, ltid , CTX_PTPR_ID );
    280294
    281295        // initialize PTABS arrays
     
    289303        // set CTX_RA slot
    290304        unsigned int ctx_ra = (unsigned int)(&_ctx_eret);
    291         _set_task_slot( x, y, p, ltid, CTX_RA_ID, ctx_ra );
    292 
    293         // set CTX_ENTRY slot
    294         unsigned int* ptr = (unsigned int*)_get_task_slot(x , y , p , ltid , CTX_ENTRY_ID);
     305        _set_thread_slot( x, y, p, ltid, CTX_RA_ID, ctx_ra );
     306
     307        // set CTX_ENTRY and CTX_EPC slots
     308        unsigned int* ptr = (unsigned int*)_get_thread_slot(x , y , p , ltid , CTX_ENTRY_ID);
    295309        unsigned int ctx_entry = *ptr;
    296         _set_task_slot( x , y , p , ltid , CTX_ENTRY_ID , ctx_entry );
     310        _set_thread_slot( x , y , p , ltid , CTX_ENTRY_ID , ctx_entry );
     311        _set_thread_slot( x , y , p , ltid , CTX_EPC_ID , ctx_entry );
    297312
    298313#if GIET_DEBUG_INIT
    299314_printf("\n[DEBUG KINIT] P[%d,%d,%d] initialises PTABS arrays"
    300         " and context for task %d \n"
     315        " and context for thread %d \n"
    301316        " - ptabs_vaddr[%d][%d][%d] = %x\n"
    302317        " - ptabs_paddr[%d][%d][%d] = %l\n"
     
    309324#endif
    310325
    311     }  // end for tasks
     326    }  // end for threads
    312327
    313328    /////////////////////////////////////////
     
    316331
    317332    ////////////////////////////////////////////////////////////////////////////
    318     // step 3 : - Each processor complete idle task context initialisation.
     333    // step 3 : - Each processor complete idle thread context initialisation.
    319334    //            Only CTX_SP, CTX_RA, CTX_EPC, CTX_ENTRY slots, because other
    320335    //            slots have been initialised in boot code)
    321336    //            The 4 Kbytes idle stack is implemented in the scheduler itself.
    322     //          - Each processor starts TICK timer, if at least one task.
     337    //          - Each processor starts TICK timer, if at least one thread.
    323338    //          - P[0,0,0] initialises FAT (not done before, because it must
    324339    //            be done after the _ptabs_vaddr[v][x][y] array initialisation,
     
    328343    unsigned int sp    = ((unsigned int)psched) + 0x2000;
    329344    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_EPC_ID , entry );
    335     _set_task_slot( x , y , p , IDLE_TASK_INDEX , CTX_ENTRY_ID , entry );
    336 
    337     if (tasks > 0) _xcu_timer_start( cluster_xy, p, GIET_TICK_VALUE );
    338 
    339 #if GIET_DEBUG_INIT
    340 _printf("\n[DEBUG KINIT] P[%d,%d,%d] initializes idle_task and starts TICK\n", 
     345    unsigned int entry = (unsigned int)(&_idle_thread);
     346
     347    _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_SP_ID  , sp    );
     348    _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_RA_ID  , ra    );
     349    _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_EPC_ID , entry );
     350    _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_ENTRY_ID , entry );
     351
     352    if (threads > 0) _xcu_timer_start( cluster_xy, p, GIET_TICK_VALUE );
     353
     354#if GIET_DEBUG_INIT
     355_printf("\n[DEBUG KINIT] P[%d,%d,%d] initializes idle_thread and starts TICK\n", 
    341356        x, y, p );
    342357#endif
     
    358373
    359374    ////////////////////////////////////////////////////////////////////////////
    360     // step 4 : Each processor computes the task index (ltid), and the values
     375    // step 4 : Each processor computes the thread index (ltid), and the values
    361376    //          to initialize the SP, SR, PTPR, EPC registers.
    362     //          It jumps to a runable task if possible, and jumps to IDLE-TASK
    363     //          if no task allocated or no runable task.
    364     ////////////////////////////////////////////////////////////////////////////
    365 
    366     if (tasks == 0) _printf("\n[GIET WARNING] No task allocated to P[%d,%d,%d]\n",
     377    //          It jumps to a runable thread if possible,
     378    //          or jumps to IDLE-THREAD if no runable thread.
     379    ////////////////////////////////////////////////////////////////////////////
     380
     381    if (threads == 0) _printf("\n[GIET WARNING] No thread allocated to P[%d,%d,%d]\n",
    367382                            x, y, p );
    368383
    369384    // default value for ltid
    370     ltid = IDLE_TASK_INDEX;
    371 
    372     // scan allocated tasks to find a runable task
    373     unsigned int  task_id;
    374     for ( task_id = 0 ; task_id < tasks ; task_id++ )
     385    ltid = IDLE_THREAD_INDEX;
     386
     387    // scan allocated threads to find a runable thread
     388    unsigned int  thread_id;
     389    for ( thread_id = 0 ; thread_id < threads ; thread_id++ )
    375390    {
    376         if ( _get_task_slot( x, y, p, task_id, CTX_NORUN_ID ) == 0 )
     391        if ( _get_thread_slot( x, y, p, thread_id, CTX_NORUN_ID ) == 0 )
    377392        {
    378             ltid = task_id;
     393            ltid = thread_id;
    379394            break;
    380395        }
     
    384399    psched->current = ltid;
    385400
    386     // get values from selected task context
    387     unsigned int sp_value   = _get_task_slot( x, y, p, ltid, CTX_SP_ID);
    388     unsigned int sr_value   = _get_task_slot( x, y, p, ltid, CTX_SR_ID);
    389     unsigned int ptpr_value = _get_task_slot( x, y, p, ltid, CTX_PTPR_ID);
    390     unsigned int epc_value  = _get_task_slot( x, y, p, ltid, CTX_ENTRY_ID);
     401    // get values from selected thread context
     402    unsigned int sp_value   = _get_thread_slot( x, y, p, ltid, CTX_SP_ID);
     403    unsigned int sr_value   = _get_thread_slot( x, y, p, ltid, CTX_SR_ID);
     404    unsigned int ptpr_value = _get_thread_slot( x, y, p, ltid, CTX_PTPR_ID);
     405    unsigned int epc_value  = _get_thread_slot( x, y, p, ltid, CTX_ENTRY_ID);
    391406
    392407#if GIET_DEBUG_INIT
Note: See TracChangeset for help on using the changeset viewer.