Ignore:
Timestamp:
Aug 7, 2015, 5:42:06 PM (9 years ago)
Author:
guerin
Message:

kernel: defer task kill to _ctx_switch()

Introduce SIG slot in task context.
Add release functions for tty, tim and nic in sys_handler.
Process signals in _ctx_switch().

Location:
soft/giet_vm/giet_kernel
Files:
4 edited

Legend:

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

    r648 r695  
    77
    88#include <ctx_handler.h>
     9#include <sys_handler.h>
    910#include <giet_config.h>
    1011#include <hard_config.h>
     
    2223// allocated in boot.c or kernel_init.c files
    2324extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
     25
     26//////////////////
     27static void _ctx_kill_task( unsigned int ltid )
     28{
     29    // get scheduler address
     30    static_scheduler_t* psched = (static_scheduler_t*)_get_sched();
     31
     32    // release private TTY terminal if required
     33    if ( psched->context[ltid][CTX_TTY_ID] < NB_TTY_CHANNELS )
     34    {
     35        psched->context[ltid][CTX_TTY_ID] = 0xFFFFFFFF;
     36        _sys_tty_release();
     37    }
     38
     39    // release private TIM channel if required
     40    if ( psched->context[ltid][CTX_TIM_ID] < NB_TIM_CHANNELS )
     41    {
     42        psched->context[ltid][CTX_TIM_ID] = 0xFFFFFFFF;
     43        _sys_tim_release();
     44    }
     45
     46    // release private NIC_RX channel if required
     47    if ( psched->context[ltid][CTX_NIC_RX_ID] < NB_NIC_CHANNELS )
     48    {
     49        psched->context[ltid][CTX_NIC_RX_ID] = 0xFFFFFFFF;
     50        _sys_nic_release( 1 );
     51    }
     52
     53    // release private NIC_TX channel if required
     54    if ( psched->context[ltid][CTX_NIC_TX_ID] < NB_NIC_CHANNELS )
     55    {
     56        psched->context[ltid][CTX_NIC_TX_ID] = 0xFFFFFFFF;
     57        _sys_nic_release( 0 );
     58    }
     59
     60    // set NORUN_MASK_TASK bit
     61    _atomic_or( &psched->context[ltid][CTX_NORUN_ID], NORUN_MASK_TASK );
     62}
     63
    2464
    2565//////////////////////////////////
     
    4080            " - CTX_SP    = %x\n"
    4181            " - CTX_NORUN = %x\n"
     82            " - CTX_SIG   = %x\n"
    4283            "########## %s\n",
    4384            x , y , p , ltid ,
     
    5091            psched->context[ltid][CTX_SP_ID],
    5192            psched->context[ltid][CTX_NORUN_ID],
     93            psched->context[ltid][CTX_SIG_ID],
    5294            string );
    5395}  // _ctx_display()
     
    78120    {
    79121        next_task_id = tid % tasks;
     122
     123        // this task needs to be killed
     124        if ( psched->context[next_task_id][CTX_SIG_ID] & SIG_MASK_KILL )
     125        {
     126            _ctx_kill_task( next_task_id );
     127
     128            // acknowledge signal
     129            _atomic_and( &psched->context[next_task_id][CTX_SIG_ID], ~SIG_MASK_KILL );
     130
     131            // skip
     132            continue;
     133        }
     134
    80135        // test if the task is runable
    81136        if ( psched->context[next_task_id][CTX_NORUN_ID] == 0 )
    82137        {
    83138            found = 1;
     139            // TODO: don't break to process all pending signals.
    84140            break;
    85141        }
  • soft/giet_vm/giet_kernel/ctx_handler.h

    r648 r695  
    3434// ctx[35]<- BVAR  |ctx[43]<- CMA_TX |ctx[51]<- COPROC |ctx[59]<- ***
    3535// ctx[36]<- PTAB  |ctx[44]<- NIC_RX |ctx[52]<- ENTRY  |ctx[60]<- ***
    36 // ctx[37]<- LTID  |ctx[45]<- NIC_TX |ctx[53]<- ***    |ctx[61]<- ***
     36// ctx[37]<- LTID  |ctx[45]<- NIC_TX |ctx[53]<- SIG    |ctx[61]<- ***
    3737// ctx[38]<- VSID  |ctx[46]<- TIM    |ctx[54]<- ***    |ctx[62]<- ***
    3838// ctx[39]<- PTPR  |ctx[47]<- HBA    |ctx[55]<- ***    |ctx[63]<- ***
     
    7474#define CTX_COPROC_ID    51    // cluster_xy : coprocessor coordinates
    7575#define CTX_ENTRY_ID     52    // Virtual address of task entry point
     76#define CTX_SIG_ID       53    // bit-vector : pending signals for task
    7677
    7778/////////////////////////////////////////////////////////////////////////////////
     
    8283#define NORUN_MASK_IOC        0x00000002   // Task blocked on IOC transfer
    8384#define NORUN_MASK_COPROC     0x00000004   // Task blocked on COPROC transfer
     85
     86/////////////////////////////////////////////////////////////////////////////////
     87//    Definition of the SIG bit-vector masks
     88/////////////////////////////////////////////////////////////////////////////////
     89
     90#define SIG_MASK_KILL         0x00000001   // Task will be killed at next tick
    8491
    8592/////////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/giet_kernel/sys_handler.c

    r690 r695  
    232232        if ( _strcmp( vspace[vspace_id].name, name ) == 0 )
    233233        {
    234             // check if pplication can be killed
     234            // check if application can be killed
    235235            if ( vspace[vspace_id].active ) return -2;
    236236
     
    249249                static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
    250250
    251                 // release private TTY terminal if required
    252                 if ( psched->context[ltid][CTX_TTY_ID] < NB_TTY_CHANNELS )
    253                 {
    254                     psched->context[ltid][CTX_TTY_ID] = 0xFFFFFFFF;
    255                     _atomic_increment( &_tty_channel_allocator , 0xFFFFFFFF );
    256                 }
    257 
    258                 // release private TIM channel if required
    259                 if ( psched->context[ltid][CTX_TIM_ID] < NB_TIM_CHANNELS )
    260                 {
    261                     psched->context[ltid][CTX_TIM_ID] = 0xFFFFFFFF;
    262                     _atomic_increment( &_tim_channel_allocator , 0xFFFFFFFF );
    263                 }
    264 
    265                 // release private NIC_RX channel if required
    266                 if ( psched->context[ltid][CTX_NIC_RX_ID] < NB_NIC_CHANNELS )
    267                 {
    268                     psched->context[ltid][CTX_NIC_RX_ID] = 0xFFFFFFFF;
    269                     _atomic_increment( &_nic_rx_channel_allocator , 0xFFFFFFFF );
    270                 }
    271 
    272                 // release private NIC_TX channel if required
    273                 if ( psched->context[ltid][CTX_NIC_TX_ID] < NB_NIC_CHANNELS )
    274                 {
    275                     psched->context[ltid][CTX_NIC_TX_ID] = 0xFFFFFFFF;
    276                     _atomic_increment( &_nic_tx_channel_allocator , 0xFFFFFFFF );
    277                 }
    278 
    279                 // set NORUN_MASK_TASK bit
    280                 unsigned int*       ptr     = &psched->context[ltid][CTX_NORUN_ID];
    281                 _atomic_or( ptr , NORUN_MASK_TASK );
     251                // set KILL signal bit
     252                _atomic_or( &psched->context[ltid][CTX_SIG_ID] , SIG_MASK_KILL );
    282253            }
    283254
    284255#if GIET_DEBUG_EXEC
    285256if ( _get_proctime() > GIET_DEBUG_EXEC )
    286 _printf("\n[DEBUG EXEC] exit _sys_kill_application() : %s desactivated\n", name );
     257_printf("\n[DEBUG EXEC] exit _sys_kill_application() : %s will be killed\n", name );
    287258#endif
    288259
     
    848819}
    849820
     821/////////////////////////////////////////
     822// NOTE: not a syscall
     823int _sys_tty_release()
     824{
     825    // release one TTY terminal
     826    _atomic_increment( &_tty_channel_allocator , 0xFFFFFFFF );
     827
     828    return 0;
     829}
     830
    850831/////////////////////////////////////////////////
    851832int _sys_tty_write( const char*  buffer,   
     
    942923        return 0;
    943924    }
     925}
     926
     927////////////////////
     928// NOTE: not a syscall
     929int _sys_tim_release()
     930{
     931    // release one timer
     932    _atomic_increment( &_tim_channel_allocator, 0xFFFFFFFF );
     933
     934    return 0;
    944935}
    945936
     
    12251216    return nic_channel;
    12261217} // end _sys_nic_alloc()
     1218
     1219
     1220////////////////////////////////////////
     1221// NOTE: not a syscall
     1222int _sys_nic_release( unsigned int is_rx )
     1223{
     1224    if ( is_rx )
     1225        _atomic_increment( &_nic_rx_channel_allocator , 0xFFFFFFFF );
     1226    else
     1227        _atomic_increment( &_nic_tx_channel_allocator , 0xFFFFFFFF );
     1228
     1229    return 0;
     1230}
    12271231
    12281232
  • soft/giet_vm/giet_kernel/sys_handler.h

    r688 r695  
    118118int _sys_tty_alloc( unsigned int shared );
    119119
     120int _sys_tty_release();
     121
    120122int _sys_tty_write( const char*  buffer,
    121123                    unsigned int length,
     
    131133
    132134int _sys_tim_alloc();
     135
     136int _sys_tim_release();
    133137
    134138int _sys_tim_start( unsigned int period );
     
    144148                    unsigned int ymax );
    145149
     150int _sys_nic_release( unsigned int is_rx );
    146151
    147152int _sys_nic_start( unsigned int is_rx,
Note: See TracChangeset for help on using the changeset viewer.