Ignore:
Timestamp:
Jun 19, 2018, 5:12:57 PM (6 years ago)
Author:
alain
Message:

miscelaneous...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/drivers/soclib_tty.c

    r440 r446  
    124124
    125125#if DEBUG_HAL_TXT_RX
    126 uint32_t cycle = (uint32_t)hal_get_cycles();
    127 if( (DEBUG_HAL_TXT_RX < cycle) && (type == TXT_READ) )
     126uint32_t rx_cycle = (uint32_t)hal_get_cycles();
     127if( (DEBUG_HAL_TXT_RX < rx_cycle) && (type == TXT_READ) )
    128128printk("\n[DBG] %s : thread %x enter for RX / cycle %d\n",
    129 __FUNCTION__ , CURRENT_THREAD , cycle );
     129__FUNCTION__ , CURRENT_THREAD , rx_cycle );
    130130#endif
    131131
    132132#if DEBUG_HAL_TXT_TX
    133 uint32_t cycle = (uint32_t)hal_get_cycles();
    134 if( (DEBUG_HAL_TXT_TX < cycle) && (type == TXT_WRITE) )
     133uint32_t tx_cycle = (uint32_t)hal_get_cycles();
     134if( (DEBUG_HAL_TXT_TX < tx_cycle) && (type == TXT_WRITE) )
    135135printk("\n[DBG] %s : thread %x enter for TX / cycle %d\n",
    136 __FUNCTION__ , CURRENT_THREAD , cycle );
     136__FUNCTION__ , CURRENT_THREAD , tx_cycle );
    137137#endif
    138138
     
    224224   
    225225                // deschedule
    226                 sched_yield( "TTY_TX_FIFO_RX empty" );
     226                sched_yield( "TTY_RX_FIFO empty" );
    227227            }
    228228        }  // end while
     
    237237
    238238#if DEBUG_HAL_TXT_RX
    239 cycle = (uint32_t)hal_get_cycles();
    240 if( (DEBUG_HAL_TXT_RX < cycle) && (type == TXT_READ) )
     239rx_cycle = (uint32_t)hal_get_cycles();
     240if( (DEBUG_HAL_TXT_RX < rx_cycle) && (type == TXT_READ) )
    241241printk("\n[DBG] %s : thread %x exit after RX / cycle %d\n",
    242 __FUNCTION__ , CURRENT_THREAD , cycle );
     242__FUNCTION__ , CURRENT_THREAD , rx_cycle );
    243243#endif
    244244
    245245#if DEBUG_HAL_TXT_TX
    246 cycle = (uint32_t)hal_get_cycles();
    247 if( (DEBUG_HAL_TXT_TX < cycle) && (type == TXT_WRITE) )
     246tx_cycle = (uint32_t)hal_get_cycles();
     247if( (DEBUG_HAL_TXT_TX < tx_cycle) && (type == TXT_WRITE) )
    248248printk("\n[DBG] %s : thread %x exit after TX / cycle %d\n",
    249 __FUNCTION__ , CURRENT_THREAD , cycle );
     249__FUNCTION__ , CURRENT_THREAD , tx_cycle );
    250250#endif
    251251
     
    263263void __attribute__ ((noinline)) soclib_tty_isr( chdev_t * chdev )
    264264{
    265     thread_t   * server;       // pointer on TXT chdev server thread
    266     lid_t        server_lid;   // local index of core running the server thread
    267     uint32_t     channel;      // TXT chdev channel
    268     bool_t       is_rx;        // TXT chdev direction
    269     char         byte;         // byte value
    270     xptr_t       owner_xp;     // extended pointer on foreground process in owner cluster
    271     cxy_t        owner_cxy;   
    272     process_t  * owner_ptr;
    273     pid_t        owner_pid;
    274     tty_fifo_t * fifo;         // pointer on TTY_TX or TTY_RX FIFO
    275     cxy_t        tty_cxy;      // soclib_tty cluster
    276     uint32_t *   tty_ptr;      // soclib_tty segment base address
    277     uint32_t   * base;         // soclib_tty channel base address
    278     xptr_t       status_xp;    // extended pointer on TTY_STATUS register
    279     xptr_t       write_xp;     // extended pointer on TTY_WRITE register
    280     xptr_t       read_xp;      // extended pointer on TTY_READ register
     265    thread_t   * server;            // pointer on TXT chdev server thread
     266    lid_t        server_lid;        // local index of core running the server thread
     267    uint32_t     channel;           // TXT chdev channel
     268    bool_t       is_rx;             // TXT chdev direction
     269    char         byte;              // byte value
     270    xptr_t       owner_xp;          // extended pointer on TXT owner process
     271    cxy_t        owner_cxy;         // TXT owner process cluster
     272    process_t  * owner_ptr;         // local pointer on TXT owner process
     273    pid_t        owner_pid;         // TXT owner process identifier
     274    tty_fifo_t * fifo;              // pointer on TTY_TX or TTY_RX FIFO
     275    cxy_t        tty_cxy;           // soclib_tty cluster
     276    uint32_t   * tty_ptr;           // soclib_tty segment base address
     277    uint32_t   * base;              // soclib_tty channel base address
     278    xptr_t       status_xp;         // extended pointer on TTY_STATUS register
     279    xptr_t       write_xp;          // extended pointer on TTY_WRITE register
     280    xptr_t       read_xp;           // extended pointer on TTY_READ register
     281    xptr_t       parent_xp;         // extended pointer on parent process
     282    cxy_t        parent_cxy;        // parent process cluster
     283    process_t  * parent_ptr;        // local pointer on parent process
     284    xptr_t       children_lock_xp;  // extended pointer on children processes lock
     285    thread_t   * parent_main_ptr;   // extended pointer on parent process main thread
     286    xptr_t       parent_main_xp;    // local pointer on parent process main thread
    281287
    282288    // get TXT chdev channel, direction and server thread
     
    295301
    296302#if DEBUG_HAL_TXT_RX
    297 uint32_t cycle = (uint32_t)hal_get_cycles();
    298 if( (DEBUG_HAL_TXT_RX < cycle) && is_rx )
    299 printk("\n[DBG] %s : enter for RX / cycle %d\n", __FUNCTION__ , cycle );
     303uint32_t rx_cycle = (uint32_t)hal_get_cycles();
    300304#endif
    301305
    302306#if DEBUG_HAL_TXT_TX
    303 uint32_t cycle = (uint32_t)hal_get_cycles();
    304 if( (DEBUG_HAL_TXT_TX < cycle) && (is_rx == 0) )
    305 printk("\n[DBG] %s : enter for TX / cycle %d\n", __FUNCTION__ , cycle );
     307uint32_t tx_cycle = (uint32_t)hal_get_cycles();
    306308#endif
    307309
     
    329331            byte = (char)hal_remote_lb( read_xp );
    330332
    331             // filter special character ^Z
     333            // filter special character ^Z  => block TXT owner process
    332334            if( byte == 0x1A )
    333335            {
     336
     337#if DEBUG_HAL_TXT_RX
     338if( DEBUG_HAL_TXT_RX < rx_cycle )
     339printk("\n[DBG] %s : read ^Z character from TXT%d\n", __FUNCTION__, channel );
     340#endif
    334341                // get pointers on TXT owner process in owner cluster
    335342                owner_xp  = process_txt_get_owner( channel );
     
    339346                "TXT owner process not found\n" );
    340347
    341                 // get relevant infos on owner process
    342                 owner_cxy = GET_CXY( owner_xp );
    343                 owner_ptr = GET_PTR( owner_xp );
    344                 owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) );
    345 
    346                 // block owner process only if it is not INIT or KSH
    347                 if( process_get_ppid( owner_xp ) > 1 )
    348                 {
    349                     // send stop signal to owner process
    350                     process_sigaction( owner_pid , BLOCK_ALL_THREADS );
    351 
    352                     // atomically update owner process termination state
    353                     hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    354                                           PROCESS_TERM_STOP );
    355                     return;
    356                 }
    357             }
    358 
    359             // filter special character ^C
    360             if( byte == 0x03 )
    361             {
    362                 // get pointer on TXT owner process in owner cluster
    363                 owner_xp  = process_txt_get_owner( channel );
    364 
    365                 // check process exist
    366                 assert( (owner_xp != XPTR_NULL) , __FUNCTION__,
    367                 "TXT owner process not found\n" );
    368 
    369348                // get relevant infos on TXT owner process
    370349                owner_cxy = GET_CXY( owner_xp );
     
    372351                owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) );
    373352
    374                 // kill TXT owner process only if it is not INIT
     353                // block TXT owner process only if it is not the INIT process
    375354                if( owner_pid != 1 )
    376355                {
     356                    // get parent process descriptor pointers
     357                    parent_xp  = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) );
     358                    parent_cxy = GET_CXY( parent_xp );
     359                    parent_ptr = GET_PTR( parent_xp );
     360
     361                    // get extended pointer on lock protecting children list in parent process
     362                    children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     363
     364                    // get pointers on the parent process main thread
     365                    parent_main_ptr = hal_remote_lpt(XPTR(parent_cxy,&parent_ptr->th_tbl[0]));
     366                    parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
     367
     368                    // transfer TXT ownership
     369                    process_txt_transfer_ownership( owner_xp );
     370
     371                    // block all threads in all clusters, but the main thread
     372                    process_sigaction( owner_pid , BLOCK_ALL_THREADS );
     373
     374                    // block the main thread
     375                    xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );
     376                    thread_block( main_xp , THREAD_BLOCKED_GLOBAL );
     377
     378                    // atomically update owner process termination state
     379                    hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
     380                                          PROCESS_TERM_STOP );
     381
     382                    // take the children lock and unblock the parent process main thread
     383                    remote_spinlock_lock( children_lock_xp );
     384                    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     385                    remote_spinlock_unlock( children_lock_xp );
     386
     387                    return;
     388                }
     389            }
     390
     391            // filter special character ^C  => kill TXT owner process
     392            if( byte == 0x03 )
     393            {
     394
     395#if DEBUG_HAL_TXT_RX
     396if( DEBUG_HAL_TXT_RX < rx_cycle )
     397printk("\n[DBG] %s : read ^C character from TXT%d\n", __FUNCTION__, channel );
     398#endif
     399                // get pointer on TXT owner process in owner cluster
     400                owner_xp  = process_txt_get_owner( channel );
     401
     402                // check process exist
     403                assert( (owner_xp != XPTR_NULL) , __FUNCTION__,
     404                "TXT owner process not found\n" );
     405
     406                // get relevant infos on TXT owner process
     407                owner_cxy = GET_CXY( owner_xp );
     408                owner_ptr = GET_PTR( owner_xp );
     409                owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) );
     410
     411                // kill TXT owner process only if it is not the INIT process
     412                if( owner_pid != 1 )
     413                {
     414                    // get parent process descriptor pointers
     415                    parent_xp  = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) );
     416                    parent_cxy = GET_CXY( parent_xp );
     417                    parent_ptr = GET_PTR( parent_xp );
     418
     419                    // get extended pointer on lock protecting children list in parent process
     420                    children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     421
     422                    // get pointers on the parent process main thread
     423                    parent_main_ptr = hal_remote_lpt(XPTR(parent_cxy,&parent_ptr->th_tbl[0]));
     424                    parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
     425
    377426                    // remove process from TXT list
    378427                    process_txt_detach( owner_xp );
     
    381430                    process_sigaction( owner_pid , DELETE_ALL_THREADS );
    382431               
    383                     // get pointer on target process main thread
     432                    // block main thread
    384433                    xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );
    385 
    386                     // block main thread
    387434                    thread_block( main_xp , THREAD_BLOCKED_GLOBAL );
    388435
     
    390437                    hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    391438                                          PROCESS_TERM_KILL );
     439
     440                    // take the children lock and unblock the parent process main thread
     441                    remote_spinlock_lock( children_lock_xp );
     442                    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     443                    remote_spinlock_unlock( children_lock_xp );
     444
    392445                    return;
    393446                }
     
    397450            if ( fifo->sts < TTY_FIFO_DEPTH )
    398451            {
     452
     453#if DEBUG_HAL_TXT_RX
     454if( DEBUG_HAL_TXT_RX < rx_cycle )
     455printk("\n[DBG] %s : read character %c from TXT%d\n", __FUNCTION__, byte, channel );
     456#endif
    399457                // store byte into FIFO
    400458                fifo->data[fifo->ptw] = (char)byte;
     
    430488        while( fifo->sts > 0 )
    431489        {
    432             // write one byte to TTY_WRITE register if empty / exit while if full
     490            // write one byte to TTY_WRITE register if empty / exit loop if full
    433491            if( (hal_remote_lw( status_xp ) & TTY_STATUS_TX_FULL) == 0 )
    434492            {
     
    436494                byte = fifo->data[fifo->ptr];
    437495
     496#if DEBUG_HAL_TXT_TX
     497if( DEBUG_HAL_TXT_TX < tx_cycle )
     498printk("\n[DBG] %s : write character %c to TXT%d\n", __FUNCTION__, byte, channel );
     499#endif
    438500                // update TX_FIFO state
    439501                fifo->ptr = (fifo->ptr + 1) % TTY_FIFO_DEPTH;
     
    453515        // send IPI to core running server thread
    454516        dev_pic_send_ipi( local_cxy , server_lid );
     517
    455518    }  // end TX
    456519
    457520    hal_fence();
    458 
    459 #if DEBUG_HAL_TXT_RX
    460 cycle = (uint32_t)hal_get_cycles();
    461 if( (DEBUG_HAL_TXT_RX < cycle) && is_rx )
    462 printk("\n[DBG] %s : exit after RX / cycle %d\n", __FUNCTION__, cycle );
    463 #endif
    464 
    465 #if DEBUG_HAL_TXT_TX
    466 cycle = (uint32_t)hal_get_cycles();
    467 if( (DEBUG_HAL_TXT_TX < cycle) && (is_rx == 0) )
    468 printk("\n[DBG] %s : exit after TX / cycle %d\n", __FUNCTION__, cycle );
    469 #endif
    470521
    471522#if (DEBUG_SYS_READ & 1)
Note: See TracChangeset for help on using the changeset viewer.