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/irq_handler.c

    r702 r709  
    2626#include <tty0.h>
    2727
     28////////////////////////////////////////////////////////////////////////////
     29//        Extern variables
     30////////////////////////////////////////////////////////////////////////////
     31
     32// allocated in sys_handler.c file
     33extern unsigned int _tty_channel_wti[NB_TTY_CHANNELS];
     34extern unsigned int _tim_channel_wti[NB_TIM_CHANNELS];
     35extern unsigned int _cma_channel_wti[NB_CMA_CHANNELS];
     36extern unsigned int _nic_rx_channel_wti[NB_NIC_CHANNELS];
     37extern unsigned int _nic_tx_channel_wti[NB_NIC_CHANNELS];
     38
    2839/////////////////////////////////////////////////////////////////////////
    2940//       Global variables
     
    4152__attribute__((section(".kdata")))
    4253unsigned char _wti_alloc_ter[X_SIZE][Y_SIZE][NB_PROCS_MAX];
     54
     55#define MAX_RETRY   10000
    4356
    4457/////////////////////////////////////////////////////////////////////////
     
    134147}  // end _ext_irq_init()
    135148
    136 ////////////////////////////////////////////
     149/////////////////////////////////////////////
    137150void _ext_irq_alloc( unsigned int   isr_type,
    138151                     unsigned int   isr_channel,
     
    143156    unsigned int wti_addr;      // WTI mailbox physical address (32 lsb bits)
    144157
    145     // check arguments
     158    unsigned int count = MAX_RETRY;
     159
     160    // check input arguments
    146161    if ( isr_type >= GIET_ISR_TYPE_MAX )
    147162    {
     
    163178
    164179    // allocate a WTI mailbox to proc[x,y,p] (blocking until success)
     180   
    165181    while ( 1 )
    166182    {
     183        if ( count == 0 )
     184        {
     185            unsigned int trdid = _get_context_slot( CTX_TRDID_ID );
     186            unsigned int vsid  = _get_context_slot( CTX_VSID_ID );
     187            _printf("\n[GIET WARNING] thread %x in vspace %d "
     188                    "running on P[%d,%d,%d] still waiting in _ext_irq_alloc()\n",
     189                    trdid, vsid, x, y, p );
     190            count = MAX_RETRY;
     191        }
     192
    167193        if ( _wti_alloc_one[x][y][p] == 0 )
    168194        {
     
    183209            break;
    184210        }
     211        count--;
    185212    }   
     213
    186214    *wti_index = wti_id;
    187215
     
    196224
    197225#if GIET_DEBUG_IRQS
     226if ( _get_proctime() > GIET_DEBUG_IRQS )
    198227_printf("\n[DEBUG IRQS] _ext_irq_alloc() for P[%d,%d,%d] at cycle %d\n"
    199228        "  wti_id = %d / isr_type = %s / channel = %d / pic_input = %d\n",
     
    204233}  // end ext_irq_alloc()
    205234
    206 ////////////////////////////////////////////
     235////////////////////////////////////////////////
    207236void _ext_irq_release( unsigned int isr_type,
    208                        unsigned int isr_channel )
    209 {
    210     unsigned int wti_id;        // allocated WTI mailbox index in XCU
    211     unsigned int irq_id;        // external IRQ index in PIC (input)
    212 
    213     // get processor coordinates [x,y,p]
    214     unsigned int gpid           = _get_procid();
    215     unsigned int cluster_xy     = gpid >> P_WIDTH;
    216     unsigned int x              = cluster_xy >> Y_WIDTH;
    217     unsigned int y              = cluster_xy & ((1<<Y_WIDTH)-1);
    218     unsigned int p              = gpid & ((1<<P_WIDTH)-1);
    219 
    220     // check arguments
     237                       unsigned int channel )
     238{
     239    // check input arguments
    221240    if ( isr_type >= GIET_ISR_TYPE_MAX )
    222241    {
    223         _printf("\n[GIET ERROR] in _ext_irq_release() illegal ISR type\n");
    224         _exit();
    225     }
    226     if ( isr_channel >= GIET_ISR_CHANNEL_MAX )
    227     {
    228         _printf("\n[GIET ERROR] in _ext_irq_release() : illegal ISR channel\n");
    229         _exit();
    230     }
    231 
    232     // find WTI index
    233     static_scheduler_t*  psched = (static_scheduler_t*)_get_sched();
    234     for ( wti_id = 0 ; wti_id < 32 ; wti_id++ )
    235     {
    236         if ( psched->wti_vector[wti_id] == (isr_channel<<16 | isr_type) )
    237             break;
    238     }
    239     if ( wti_id == 32 )
    240     {
    241         _printf("\n[GIET ERROR] in _ext_irq_release() : isr not found\n");
    242         return;
    243     }
    244 
     242        _printf("\n[GIET ERROR] in _ext_irq_release() : "
     243                "illegal ISR type %d\n", isr_type );
     244        _exit();
     245    }
     246    if ( channel >= GIET_ISR_CHANNEL_MAX )
     247    {
     248        _printf("\n[GIET ERROR] in _ext_irq_release() : "
     249                "illegal ISR channel %d\n", channel );
     250        _exit();
     251    }
     252
     253    // analyse ISR type to get WTI index (wti), and coordinates
     254    // of processor (x,y,p) that has been allocated the external IRQ
     255    unsigned int wti    = 0;
     256    unsigned int x      = 0;
     257    unsigned int y      = 0;
     258    unsigned int p      = 0;
     259
     260    if      ( (isr_type == ISR_TTY_RX) || (isr_type == ISR_TTY_TX) )
     261    {
     262        x       = (_tty_channel_wti[channel]>>24) & 0xFF;
     263        y       = (_tty_channel_wti[channel]>>16) & 0xFF;
     264        p       = (_tty_channel_wti[channel]>> 8) & 0xFF;
     265        wti     = (_tty_channel_wti[channel]    ) & 0xFF;
     266    }
     267#if NB_TIM_CHANNELS
     268    else if ( isr_type == ISR_TIMER )
     269    {
     270        x       = (_tim_channel_wti[channel]>>24) & 0xFF;
     271        y       = (_tim_channel_wti[channel]>>16) & 0xFF;
     272        p       = (_tim_channel_wti[channel]>> 8) & 0xFF;
     273        wti     = (_tim_channel_wti[channel]    ) & 0xFF;
     274    }
     275#endif
     276#if NB_CMA_CHANNELS
     277    else if ( isr_type == ISR_CMA )
     278    {
     279        x       = (_cma_channel_wti[channel]>>24) & 0xFF;
     280        y       = (_cma_channel_wti[channel]>>16) & 0xFF;
     281        p       = (_cma_channel_wti[channel]>> 8) & 0xFF;
     282        wti     = (_cma_channel_wti[channel]    ) & 0xFF;
     283    }
     284#endif
     285#if NB_NIC_CHANNELS
     286    else if ( isr_type == ISR_NIC_RX )
     287    {
     288        x       = (_nic_rx_channel_wti[channel]>>24) & 0xFF;
     289        y       = (_nic_rx_channel_wti[channel]>>16) & 0xFF;
     290        p       = (_nic_rx_channel_wti[channel]>> 8) & 0xFF;
     291        wti     = (_nic_rx_channel_wti[channel]    ) & 0xFF;
     292    }
     293    else if ( isr_type == ISR_NIC_TX )
     294    {
     295        x       = (_nic_tx_channel_wti[channel]>>24) & 0xFF;
     296        y       = (_nic_tx_channel_wti[channel]>>16) & 0xFF;
     297        p       = (_nic_tx_channel_wti[channel]>> 8) & 0xFF;
     298        wti     = (_nic_tx_channel_wti[channel]    ) & 0xFF;
     299    }
     300#endif
     301    else 
     302    {
     303        _printf("\n[GIET ERROR] in _ext_irq_release() : "
     304                "ISR type %s not supported / thread = %x\n",
     305                _isr_type_str[isr_type] , _get_thread_trdid() );
     306        _exit();
     307    }
     308   
    245309    // desactivates dynamically allocated PIC entry
    246     irq_id = _ext_irq_index[isr_type][isr_channel];
     310    unsigned int irq_id = _ext_irq_index[isr_type][channel];
    247311    _pic_set_register( irq_id , IOPIC_MASK , 0 );
    248312
    249313    // releases dynamically allocated WTI mailbox
    250     if      ( wti_id == p +   NB_PROCS_MAX ) _wti_alloc_one[x][y][p] = 0;
    251     else if ( wti_id == p + 2*NB_PROCS_MAX ) _wti_alloc_two[x][y][p] = 0;
    252     else if ( wti_id == p + 3*NB_PROCS_MAX ) _wti_alloc_ter[x][y][p] = 0;
     314    if      ( wti == p +   NB_PROCS_MAX ) _wti_alloc_one[x][y][p] = 0;
     315    else if ( wti == p + 2*NB_PROCS_MAX ) _wti_alloc_two[x][y][p] = 0;
     316    else if ( wti == p + 3*NB_PROCS_MAX ) _wti_alloc_ter[x][y][p] = 0;
    253317    else
    254318    {
    255         _printf("\n[GIET ERROR] in _ext_irq_release() : illegal WTI index\n");
     319        _printf("\n[GIET ERROR] in _ext_irq_release() : "
     320                "WTI = %d / X = %d / Y = %d / P = %d\n", wti , x, y , p );
    256321        _exit();
    257322    }
     
    294359
    295360#if GIET_DEBUG_IRQS    // we don't take the TTY lock to avoid deadlocks
     361if ( _get_proctime() > GIET_DEBUG_IRQS )
    296362_nolock_printf("\n[DEBUG IRQS] _irq_demux() Processor[%d,%d,%d] enters at cycle %d\n"
    297363               " irq_type = %s / irq_id = %d / isr_type = %s / channel = %d\n",
     
    360426
    361427    unsigned int value;     // WTI mailbox value
    362     unsigned int save_sr;   // save SR value in pre-empted task stack
    363 
    364     unsigned int ltid       = _get_current_task_id();
     428    unsigned int save_sr;   // save SR value in pre-empted thread stack
     429
     430    unsigned int ltid       = _get_thread_ltid();
    365431
    366432    if ( irq_type != IRQ_TYPE_WTI )
     
    375441    _xcu_get_wti_value( cluster_xy, irq_id, &value );
    376442
    377 #if GIET_DEBUG_SWITCH
    378 _printf("\n[DEBUG SWITCH] P[%d,%d,%d] enters _isr_wakup() at cycle %d\n"
     443#if GIET_DEBUG_IRQS
     444if ( _get_proctime() > GIET_DEBUG_IRQS )
     445_printf("\n[DEBUG IRQS] P[%d,%d,%d] enters _isr_wakup() at cycle %d\n"
    379446        "  WTI index = %d / current ltid = %d / mailbox value = %x\n",
    380447        x , y , p , _get_proctime() , irq_id , ltid , value );
     
    382449
    383450    // enter critical section and swich context (if required)
    384     if ( (ltid == IDLE_TASK_INDEX) || (value != 0) )
     451    if ( (ltid == IDLE_THREAD_INDEX) || (value != 0) )
    385452    {
    386453        _it_disable( &save_sr );
     
    402469    unsigned int p          = gpid & ((1<<P_WIDTH)-1);
    403470
    404     unsigned int save_sr;   // save SR value in pre-empted task stack
     471    unsigned int save_sr;   // save SR value in pre-empted thread stack
    405472
    406473    if ( irq_type != IRQ_TYPE_PTI )
     
    415482    _xcu_timer_reset_irq( cluster_xy, irq_id );
    416483
    417 #if (GIET_DEBUG_SWITCH & 0x1)
    418 unsigned int ltid  = _get_current_task_id();
    419 if ( _get_proctime() > GIET_DEBUG_SWITCH )
    420 _printf("\n[DEBUG SWITCH] P[%d,%d,%d] enters _isr_tick() at cycle %d\n"
     484#if GIET_DEBUG_IRQS
     485unsigned int ltid  = _get_thread_ltid();
     486if ( _get_proctime() > GIET_DEBUG_IRQS )
     487_printf("\n[DEBUG IRQS] P[%d,%d,%d] enters _isr_tick() at cycle %d\n"
    421488        "  WTI index = %d / current ltid = %d\n",
    422489        x , y , p , _get_proctime() , irq_id , ltid );
Note: See TracChangeset for help on using the changeset viewer.