Changeset 629


Ignore:
Timestamp:
Jul 18, 2015, 3:00:42 PM (9 years ago)
Author:
alain
Message:

Modify the task activation/desactivation mechanism
to support the _kill_application() and _exec_application() system functions.
The RUN Boolean in task context has been replaced by the NORUN bit-vector.

Location:
soft/giet_vm/giet_kernel
Files:
7 edited

Legend:

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

    r528 r629  
    3939            " - CTX_RA    = %x\n"
    4040            " - CTX_SP    = %x\n"
    41             " - CTX_RUN  = %x\n"
     41            " - CTX_NORUN = %x\n"
    4242            "########## %s\n",
    4343            x , y , p , ltid ,
     
    4949            psched->context[ltid][CTX_RA_ID],
    5050            psched->context[ltid][CTX_SP_ID],
    51             psched->context[ltid][CTX_RUN_ID],
     51            psched->context[ltid][CTX_NORUN_ID],
    5252            string );
    5353}  // _ctx_display()
     
    7979        next_task_id = tid % tasks;
    8080        // test if the task is runable
    81         if ( psched->context[next_task_id][CTX_RUN_ID] )
     81        if ( psched->context[next_task_id][CTX_NORUN_ID] == 0 )
    8282        {
    8383            found = 1;
  • soft/giet_vm/giet_kernel/ctx_handler.h

    r556 r629  
    1414// is launched by the scheduler when there is no other runable task.
    1515/////////////////////////////////////////////////////////////////////////////////
    16 // A task context is an array of 64 words = 256 bytes.
     16// A task context is an array of 64 uint32 words => 256 bytes.
    1717// It contains copies of processor registers (when the task is preempted)
    18 // and some general informations associated to a task, such as the peripherals
    19 // allocated to the task (private peripheral channel)
     18// and some general informations associated to a task, such as the private
     19// peripheral channels allocated to the task, the vspace index, the various
     20// task index (local / global / application), and the runnable status.
    2021/////////////////////////////////////////////////////////////////////////////////
    2122// ctx[0] <- ***   |ctx[8] <- $8     |ctx[16]<- $16    |ctx[24]<- $24
     
    3031// ctx[32]<- EPC   |ctx[40]<- TTY    |ctx[48]<- TRDID  |ctx[56]<- ***
    3132// ctx[33]<- CR    |ctx[41]<- CMA_FB |ctx[49]<- GTID   |ctx[57]<- ***
    32 // ctx[34]<- SR    |ctx[42]<- CMA_RX |ctx[50]<- RUN    |ctx[58]<- ***
     33// ctx[34]<- SR    |ctx[42]<- CMA_RX |ctx[50]<- NORUN  |ctx[58]<- ***
    3334// ctx[35]<- BVAR  |ctx[43]<- CMA_TX |ctx[51]<- COPROC |ctx[59]<- ***
    3435// ctx[36]<- PTAB  |ctx[44]<- NIC_RX |ctx[52]<- ***    |ctx[60]<- ***
     
    4748/////////////////////////////////////////////////////////////////////////////////
    4849
    49 #define CTX_SP_ID        29  // Stack Pointer
    50 #define CTX_RA_ID        31  // Return Address
     50#define CTX_SP_ID        29    // Stack Pointer
     51#define CTX_RA_ID        31    // Return Address
    5152
    52 #define CTX_EPC_ID       32  // Exception Program Counter (CP0)
    53 #define CTX_CR_ID        33  // Cause Register (CP0)
    54 #define CTX_SR_ID        34  // Status Register (CP0)
    55 #define CTX_BVAR_ID      35      // Bad Virtual Address Register (CP0)
    56 #define CTX_PTAB_ID      36  // Page Table Virtual address
    57 #define CTX_LTID_ID      37  // Local  Task Index (in scheduler)
    58 #define CTX_VSID_ID      38  // Vspace Index     
    59 #define CTX_PTPR_ID      39  // Page Table Pointer Register (PADDR>>13)
     53#define CTX_EPC_ID       32    // Exception Program Counter (CP0)
     54#define CTX_CR_ID        33    // Cause Register (CP0)
     55#define CTX_SR_ID        34    // Status Register (CP0)
     56#define CTX_BVAR_ID      35        // Bad Virtual Address Register (CP0)
     57#define CTX_PTAB_ID      36    // Page Table Virtual address
     58#define CTX_LTID_ID      37    // Local  Task Index (in scheduler)
     59#define CTX_VSID_ID      38    // Vspace Index     
     60#define CTX_PTPR_ID      39    // Page Table Pointer Register (PADDR>>13)
    6061
    61 #define CTX_TTY_ID       40  // private TTY channel index 
    62 #define CTX_CMA_FB_ID    41  // private CMA channel index for FBF write
    63 #define CTX_CMA_RX_ID    42  // private CMA channel index for NIC_TX
    64 #define CTX_CMA_TX_ID    43  // private CMA channel index for NIC_RX
    65 #define CTX_NIC_RX_ID    44  // private NIC channel index RX transfer
    66 #define CTX_NIC_TX_ID    45  // private NIC channel index TX transfer
    67 #define CTX_TIM_ID       46  // ptivate TIM channel index
    68 #define CTX_HBA_ID       47  // private HBA channel index
     62#define CTX_TTY_ID       40    // private TTY channel index 
     63#define CTX_CMA_FB_ID    41    // private CMA channel index for FBF write
     64#define CTX_CMA_RX_ID    42    // private CMA channel index for NIC_TX
     65#define CTX_CMA_TX_ID    43    // private CMA channel index for NIC_RX
     66#define CTX_NIC_RX_ID    44    // private NIC channel index RX transfer
     67#define CTX_NIC_TX_ID    45    // private NIC channel index TX transfer
     68#define CTX_TIM_ID       46    // ptivate TIM channel index
     69#define CTX_HBA_ID       47    // private HBA channel index
    6970
    70 #define CTX_TRDID_ID     48  // Thread Task Index in vspace
    71 #define CTX_GTID_ID      49  // Global Task Index in all system
    72 #define CTX_RUN_ID       50  // Boolean: task runable
    73 #define CTX_COPROC_ID    51  // cluster_xy : coprocessor coordinates
     71#define CTX_TRDID_ID     48    // Thread Task Index in vspace
     72#define CTX_GTID_ID      49    // Global Task Index in all system
     73#define CTX_NORUN_ID     50    // bit-vector : task runable if all zero
     74#define CTX_COPROC_ID    51    // cluster_xy : coprocessor coordinates
    7475
    7576/////////////////////////////////////////////////////////////////////////////////
     77//    Definition of the NORUN bit-vector masks
     78/////////////////////////////////////////////////////////////////////////////////
     79
     80#define NORUN_MASK_TASK       0x00000001   // Task not active 
     81#define NORUN_MASK_IOC        0x00000002   // Task blocked on IOC transfer
     82#define NORUN_MASK_COPROC     0x00000004   // Task blocked on COPROC transfer
    7683
    7784/////////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/giet_kernel/exc_handler.c

    r547 r629  
    8585
    8686    // goes to sleeping state
    87     _set_context_slot(CTX_RUN_ID, 0);
     87    _set_context_slot( CTX_NORUN_ID , 1 );
    8888
    89     // deschedule (suicide)
    90     unsigned int save_sr;  // unused
     89    // deschedule
     90    unsigned int save_sr; 
    9191    _it_disable( &save_sr );
    9292    _ctx_switch();
  • soft/giet_vm/giet_kernel/irq_handler.h

    r547 r629  
    88// They contain the code of used to handlle HWI, WTI, PTI interrupts.
    99///////////////////////////////////////////////////////////////////////////
     10
     11#include <giet_config.h>
    1012
    1113#ifndef _IRQ_HANDLER_H
  • soft/giet_vm/giet_kernel/kernel_init.c

    r615 r629  
    113113unsigned int   _tty0_boot_mode = 0;
    114114
    115 // Kernel uses distributed locks to protect MMC   
    116 __attribute__((section(".kdata")))
    117 unsigned int   _mmc_boot_mode = 0;
    118 
    119115// Kernel uses sqt_lock to protect command allocator in HBA       
    120116__attribute__((section(".kdata")))
     
    131127// this variable is defined in tty0.c file
    132128extern sqt_lock_t _tty0_sqt_lock;
     129
     130// this variable is allocated in mmc_kernel.c
     131extern unsigned int _mmc_boot_mode;
    133132
    134133////////////////////////////////////////////////////////////////////////////////
     
    167166#endif
    168167        //////  distributed lock for MMC
     168        _mmc_boot_mode = 0;
    169169        _mmc_init_locks();
    170170
     
    293293        // compute ctx_epc
    294294        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);
     295        _set_task_slot( x , y , p , ltid , CTX_EPC_ID , *ptr );
    296296
    297297#if GIET_DEBUG_INIT
  • soft/giet_vm/giet_kernel/sys_handler.c

    r614 r629  
    8181extern unsigned int _tty_rx_buf[NB_TTY_CHANNELS];
    8282
     83// allocated in kernel_init.c file
     84extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
     85
    8386////////////////////////////////////////////////////////////////////////////
    8487//     Channel allocators for peripherals
     
    158161    &_sys_tim_start,                 /* 0x15 */
    159162    &_sys_tim_stop,                  /* 0x16 */
    160     &_sys_ukn,                       /* 0x17 */
    161     &_sys_ukn,                       /* 0x18 */   
     163    &_sys_kill_application,          /* 0x17 */
     164    &_sys_exec_application,          /* 0x18 */   
    162165    &_sys_context_switch,            /* 0x19 */
    163166    &_sys_vseg_get_vbase,            /* 0x1A */
     
    495498        _it_disable( &save_sr );
    496499
    497         // reset runnable
    498         _set_task_slot( x, y, p, ltid, CTX_RUN_ID, 0 ); 
     500        // set NORUN_MASK_COPROC bit
     501        static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
     502        unsigned int*       ptr     = &psched->context[ltid][CTX_NORUN_ID];
     503        _atomic_or( ptr , NORUN_MASK_COPROC );
    499504
    500505        // start coprocessor
     
    17851790    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
    17861791    unsigned int x          = cluster_xy >> Y_WIDTH;
    1787     unsigned int lpid       = gpid & ((1<<P_WIDTH)-1);
    1788 
    1789     unsigned int task_id    = _get_context_slot(CTX_LTID_ID);
     1792    unsigned int p          = gpid & ((1<<P_WIDTH)-1);
     1793
     1794    unsigned int ltid       = _get_context_slot(CTX_LTID_ID);
    17901795
    17911796    // print exit message
    17921797    _printf("\n[GIET] Exit task %d on processor[%d,%d,%d] at cycle %d"
    17931798            "\n       Cause : %s\n\n",
    1794             task_id, x, y, lpid, date, string );
    1795 
    1796     // goes to sleeping state
    1797     _set_context_slot(CTX_RUN_ID, 0);
     1799            ltid, x, y, p, date, string );
     1800
     1801    // set NORUN_MASK_TASK bit (non runnable state)
     1802    static_scheduler_t*  psched  = (static_scheduler_t*)_schedulers[x][y][p];
     1803    unsigned int*        ptr     = &psched->context[ltid][CTX_NORUN_ID];
     1804    _atomic_or( ptr , NORUN_MASK_TASK );
    17981805
    17991806    // deschedule
     
    18031810}
    18041811
     1812///////////////////////////////////////
     1813int _sys_kill_application( char* name )
     1814{
     1815    mapping_header_t * header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
     1816    mapping_vspace_t * vspace  = _get_vspace_base(header);
     1817    mapping_task_t   * task    = _get_task_base(header);
     1818
     1819    unsigned int vspace_id;
     1820    unsigned int task_id;
     1821    unsigned int y_size = header->y_size;
     1822
     1823    // scan vspaces
     1824    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++)
     1825    {
     1826        if ( _strcmp( vspace[vspace_id].name, name ) == 0 )
     1827        {
     1828            // scan tasks in vspace
     1829            for (task_id = vspace[vspace_id].task_offset;
     1830                 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
     1831                 task_id++)
     1832            {
     1833                unsigned int cid   = task[task_id].clusterid;
     1834                unsigned int x     = cid / y_size;
     1835                unsigned int y     = cid % y_size;
     1836                unsigned int p     = task[task_id].proclocid;
     1837                unsigned int ltid  = task[task_id].ltid;
     1838
     1839                // set NORUN_MASK_TASK bit
     1840                static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
     1841                unsigned int*       ptr     = &psched->context[ltid][CTX_NORUN_ID];
     1842                _atomic_or( ptr , NORUN_MASK_TASK );
     1843            }
     1844            return 0;
     1845        }
     1846    }
     1847    return -1;    // not found
     1848}
     1849   
     1850///////////////////////////////////////
     1851int _sys_exec_application( char* name )
     1852{
     1853    mapping_header_t * header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
     1854    mapping_vspace_t * vspace  = _get_vspace_base(header);
     1855    mapping_task_t   * task    = _get_task_base(header);
     1856    mapping_vseg_t   * vseg    = _get_vseg_base(header);
     1857
     1858    unsigned int vspace_id;
     1859    unsigned int task_id;
     1860    unsigned int vseg_id;
     1861
     1862    unsigned int y_size = header->y_size;
     1863
     1864    // scan vspaces
     1865    for (vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++)
     1866    {
     1867        if ( _strcmp( vspace[vspace_id].name, name ) == 0 )
     1868        {
     1869            // scan tasks in vspace
     1870            for (task_id = vspace[vspace_id].task_offset;
     1871                 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
     1872                 task_id++)
     1873            {
     1874                unsigned int cid   = task[task_id].clusterid;
     1875                unsigned int x     = cid / y_size;
     1876                unsigned int y     = cid % y_size;
     1877                unsigned int p     = task[task_id].proclocid;
     1878                unsigned int ltid  = task[task_id].ltid;
     1879
     1880                // compute stack pointer value (sp_value)
     1881                vseg_id = task[task_id].stack_vseg_id;
     1882                unsigned int sp_value = vseg[vseg_id].vbase + vseg[vseg_id].length;
     1883
     1884                // compute task entry point value (epc_value)
     1885                vseg_id = vspace[vspace_id].start_vseg_id;     
     1886                unsigned int* vaddr = (unsigned int*)( vseg[vseg_id].vbase +
     1887                                                       ((task[task_id].startid)<<2) );
     1888                unsigned int  epc_value = *vaddr;
     1889
     1890                // compute reurn address value (ra_value)
     1891                unsigned int ra_value = (unsigned int)(&_ctx_eret);
     1892
     1893                // get scheduler pointer
     1894                static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
     1895
     1896                // initialise task context: RA / SR / EPC / SP / NORUN slots
     1897                psched->context[ltid][CTX_RA_ID]    = ra_value;
     1898                psched->context[ltid][CTX_SR_ID]    = GIET_SR_INIT_VALUE;
     1899                psched->context[ltid][CTX_SP_ID]    = sp_value;
     1900                psched->context[ltid][CTX_EPC_ID]   = epc_value;
     1901                psched->context[ltid][CTX_NORUN_ID] = 0;
     1902            }
     1903            return 0;
     1904        }
     1905    }
     1906    return -1;    // not found
     1907}
     1908   
    18051909/////////////////////////
    18061910int _sys_context_switch()
  • soft/giet_vm/giet_kernel/sys_handler.h

    r614 r629  
    204204int _sys_task_exit( char* string );
    205205
     206int _sys_kill_application( char* name );
     207
     208int _sys_exec_application( char* name );
     209
    206210int _sys_context_switch();
    207211
Note: See TracChangeset for help on using the changeset viewer.