Changeset 435 for trunk/kernel/kern


Ignore:
Timestamp:
Feb 20, 2018, 5:32:17 PM (6 years ago)
Author:
alain
Message:

Fix a bad bug in scheduler...

Location:
trunk/kernel/kern
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/chdev.c

    r433 r435  
    3939extern chdev_directory_t    chdev_dir;   // allocated in kernel_init.c
    4040
    41 #if CONFIG_READ_DEBUG
    42 extern uint32_t enter_chdev_cmd;
    43 extern uint32_t exit_chdev_cmd;
    44 extern uint32_t enter_chdev_server;
    45 extern uint32_t exit_chdev_server;
     41#if (CONFIG_DEBUG_SYS_READ & 1)
     42extern uint32_t enter_chdev_cmd_read;
     43extern uint32_t exit_chdev_cmd_read;
     44extern uint32_t enter_chdev_server_read;
     45extern uint32_t exit_chdev_server_read;
     46#endif
     47
     48#if (CONFIG_DEBUG_SYS_WRITE & 1)
     49extern uint32_t enter_chdev_cmd_write;
     50extern uint32_t exit_chdev_cmd_write;
     51extern uint32_t enter_chdev_server_write;
     52extern uint32_t exit_chdev_server_write;
    4653#endif
    4754
     
    123130    uint32_t   save_sr;       // for critical section
    124131
    125 #if CONFIG_READ_DEBUG
    126 enter_chdev_cmd = hal_time_stamp();
     132#if (CONFIG_DEBUG_SYS_READ & 1)
     133enter_chdev_cmd_read = (uint32_t)hal_get_cycles();
     134#endif
     135
     136#if (CONFIG_DEBUG_SYS_WRITE & 1)
     137enter_chdev_cmd_write = (uint32_t)hal_get_cycles();
    127138#endif
    128139
     
    178189    if( different ) dev_pic_send_ipi( chdev_cxy , lid );
    179190   
     191    // deschedule
     192    assert( thread_can_yield( this ) , __FUNCTION__ , "illegal sched_yield\n" );
     193    sched_yield("blocked on I/O");
     194
     195    // exit critical section
     196    hal_restore_irq( save_sr );
     197
    180198#if CONFIG_DEBUG_CHDEV_REGISTER_COMMAND
    181199cycle = (uint32_t)hal_get_cycles();
     
    185203#endif
    186204
    187     // deschedule
    188     assert( thread_can_yield( this ) , __FUNCTION__ , "illegal sched_yield\n" );
    189     sched_yield("blocked on I/O");
    190 
    191     // exit critical section
    192     hal_restore_irq( save_sr );
    193 
    194 #if CONFIG_DEBUG_CHDEV_REGISTER_COMMAND
    195 cycle = (uint32_t)hal_get_cycles();
    196 if( CONFIG_DEBUG_CHDEV_REGISTER_COMMAND < cycle )
    197 printk("\n[DBG] %s : client_thread %x (%s) resumes / cycle %d\n",
    198 __FUNCTION__, this, thread_type_str(this->type) , cycle );
    199 #endif
    200 
    201 #if CONFIG_READ_DEBUG
    202 exit_chdev_cmd = hal_time_stamp();
     205#if (CONFIG_DEBUG_SYS_READ & 1)
     206exit_chdev_cmd_read = (uint32_t)hal_get_cycles();
     207#endif
     208
     209#if (CONFIG_DEBUG_SYS_WRITE & 1)
     210exit_chdev_cmd_write = (uint32_t)hal_get_cycles();
    203211#endif
    204212
     
    240248            remote_spinlock_unlock( lock_xp );
    241249
    242 chdev_dmsg("\n[DBG] %s : thread %x deschedule /cycle %d\n",
    243 __FUNCTION__ , server , hal_time_stamp() );
    244 
    245250            // deschedule
    246251            sched_yield("I/O queue empty");
    247 
    248 chdev_dmsg("\n[DBG] %s : thread %x resume /cycle %d\n",
    249 __FUNCTION__ , server , hal_time_stamp() );
    250 
    251252        }
    252253        else                            // waiting queue not empty
    253254        {
    254255
    255 #if CONFIG_READ_DEBUG
    256 enter_chdev_server = hal_time_stamp();
    257 #endif
     256#if (CONFIG_DEBUG_SYS_READ & 1)
     257enter_chdev_server_read = (uint32_t)hal_get_cycles();
     258#endif
     259
     260#if (CONFIG_DEBUG_SYS_WRITE & 1)
     261enter_chdev_server_write = (uint32_t)hal_get_cycles();
     262#endif
     263
    258264            // release lock
    259265            remote_spinlock_unlock( lock_xp );
     
    284290#endif
    285291
    286 #if CONFIG_READ_DEBUG
    287 exit_chdev_server = hal_time_stamp();
     292#if (CONFIG_DEBUG_SYS_READ & 1)
     293exit_chdev_server_read = (uint32_t)hal_get_cycles();
     294#endif
     295
     296#if (CONFIG_DEBUG_SYS_WRITE & 1)
     297exit_chdev_server_write = (uint32_t)hal_get_cycles();
    288298#endif
    289299
  • trunk/kernel/kern/kernel_init.c

    r428 r435  
    123123
    124124
    125 // TODO remove these debug variables used dans sys_read()
     125// these debug variables are used to analyse the sys_read() syscall timing
    126126
    127127#if CONFIG_READ_DEBUG   
     
    129129uint32_t   exit_sys_read;
    130130
    131 uint32_t   enter_devfs_move;
    132 uint32_t   exit_devfs_move;
     131uint32_t   enter_devfs_read;
     132uint32_t   exit_devfs_read;
    133133
    134134uint32_t   enter_txt_read;
    135135uint32_t   exit_txt_read;
    136136
    137 uint32_t   enter_chdev_cmd;
    138 uint32_t   exit_chdev_cmd;
    139 
    140 uint32_t   enter_chdev_server;
    141 uint32_t   exit_chdev_server;
    142 
    143 uint32_t   enter_tty_cmd;
    144 uint32_t   exit_tty_cmd;
    145 
    146 uint32_t   enter_tty_isr;
    147 uint32_t   exit_tty_isr;
     137uint32_t   enter_chdev_cmd_read;
     138uint32_t   exit_chdev_cmd_read;
     139
     140uint32_t   enter_chdev_server_read;
     141uint32_t   exit_chdev_server_read;
     142
     143uint32_t   enter_tty_cmd_read;
     144uint32_t   exit_tty_cmd_read;
     145
     146uint32_t   enter_tty_isr_read;
     147uint32_t   exit_tty_isr_read;
     148#endif
     149
     150// these debug variables are used to analyse the sys_write() syscall timing
     151
     152#if CONFIG_WRITE_DEBUG   
     153uint32_t   enter_sys_write;
     154uint32_t   exit_sys_write;
     155
     156uint32_t   enter_devfs_write;
     157uint32_t   exit_devfs_write;
     158
     159uint32_t   enter_txt_write;
     160uint32_t   exit_txt_write;
     161
     162uint32_t   enter_chdev_cmd_write;
     163uint32_t   exit_chdev_cmd_write;
     164
     165uint32_t   enter_chdev_server_write;
     166uint32_t   exit_chdev_server_write;
     167
     168uint32_t   enter_tty_cmd_write;
     169uint32_t   exit_tty_cmd_write;
     170
     171uint32_t   enter_tty_isr_write;
     172uint32_t   exit_tty_isr_write;
    148173#endif
    149174
  • trunk/kernel/kern/process.c

    r433 r435  
    5151#include <elf.h>
    5252#include <syscalls.h>
    53 #include <signal.h>
     53#include <shared_syscalls.h>
    5454
    5555//////////////////////////////////////////////////////////////////////////////////////////
     
    114114    // get model process cluster and local pointer
    115115    model_cxy = GET_CXY( model_xp );
    116     model_ptr = (process_t *)GET_PTR( model_xp );
     116    model_ptr = GET_PTR( model_xp );
    117117
    118118    // get parent process cluster and local pointer
    119119    parent_cxy = GET_CXY( parent_xp );
    120     parent_ptr = (process_t *)GET_PTR( parent_xp );
     120    parent_ptr = GET_PTR( parent_xp );
    121121
    122122    // get model_pid and parent_pid
     
    209209        // get cluster and local pointer on chdev
    210210        chdev_cxy = GET_CXY( chdev_xp );
    211         chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     211        chdev_ptr = GET_PTR( chdev_xp );
    212212 
    213213        // get TXT terminal index
     
    289289    // get reference process cluster and local pointer
    290290    cxy_t       ref_cxy = GET_CXY( reference_process_xp );
    291     process_t * ref_ptr = (process_t *)GET_PTR( reference_process_xp );
     291    process_t * ref_ptr = GET_PTR( reference_process_xp );
    292292
    293293    // initialize PID, REF_XP, PARENT_XP, and STATE
     
    364364    process_t * parent_ptr;
    365365    cxy_t       parent_cxy;
    366     xptr_t      parent_thread_xp;
    367366    xptr_t      children_lock_xp;
    368367    xptr_t      copies_lock_xp;
     
    450449}
    451450
    452 ////////////////////////////////////////////
    453 void process_sigaction( process_t * process,
     451////////////////////////////////////////
     452void process_sigaction( pid_t       pid,
    454453                        uint32_t    action_type )
    455454{
     
    467466    rpc_desc_t         rpc;               // rpc descriptor allocated in stack
    468467
     468    thread_t * client = CURRENT_THREAD;
     469
    469470#if CONFIG_DEBUG_PROCESS_SIGACTION
    470471uint32_t cycle = (uint32_t)hal_get_cycles();
    471472if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle )
    472 printk("\n[DBG] %s : thread %x enter to %s process %x in cluster %x / cycle %d\n",
    473 __FUNCTION__ , CURRENT_THREAD, process_action_str( action_type ) ,
    474 process->pid , local_cxy , cycle );
    475 #endif
    476 
    477     thread_t         * client = CURRENT_THREAD;
     473printk("\n[DBG] %s : thread %x enter to %s process %x / cycle %d\n",
     474__FUNCTION__ , client, process_action_str( action_type ) , pid , cycle );
     475#endif
    478476
    479477    // get local pointer on local cluster manager
     
    481479
    482480    // get owner cluster identifier and process lpid
    483     owner_cxy = CXY_FROM_PID( process->pid );
    484     lpid      = LPID_FROM_PID( process->pid );
    485 
    486     // check owner cluster
    487     assert( (owner_cxy == local_cxy) , __FUNCTION__ , "must be executed in owner cluster\n" );
    488    
    489     // get number of remote copies
    490     responses = cluster->pmgr.copies_nr[lpid] - 1;
     481    owner_cxy = CXY_FROM_PID( pid );
     482    lpid      = LPID_FROM_PID( pid );
     483
     484    // get root of list of copies, lock, and number of copies from owner cluster
     485    responses = hal_remote_lw ( XPTR( owner_cxy , &cluster->pmgr.copies_nr[lpid] ) );
     486    root_xp   = hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] ) );
     487    lock_xp   = hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] ) );
     488
    491489    rsp_count = 0;
    492490
     
    502500    rpc.thread   = client;
    503501
    504     // get extended pointers on copies root and lock
    505     root_xp   = XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] );
    506     lock_xp   = XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] );
    507 
    508502    // take the lock protecting the copies
    509503    remote_spinlock_lock( lock_xp );
     
    514508        process_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
    515509        process_cxy = GET_CXY( process_xp );
    516         process_ptr = (process_t *)GET_PTR( process_xp );
    517 
    518         // send RPC to remote clusters
    519         if( process_cxy != local_cxy ) 
    520         {
     510        process_ptr = GET_PTR( process_xp );
    521511
    522512#if CONFIG_DEBUG_PROCESS_SIGACTION
    523513if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle )
    524 printk("\n[DBG] %s : send RPC to remote cluster %x\n", __FUNCTION__ , process_cxy );
    525 #endif
    526 
    527             rpc.args[0] = (uint64_t)action_type;
    528             rpc.args[1] = (uint64_t)(intptr_t)process_ptr;
    529             rpc_process_sigaction_client( process_cxy , &rpc );
    530             rsp_count++;
    531         }
     514printk("\n[DBG] %s : send RPC to cluster %x\n", __FUNCTION__ , process_cxy );
     515#endif
     516
     517        // check PID
     518        assert( (hal_remote_lw( XPTR( process_cxy , &process_ptr->pid) ) == pid),
     519        __FUNCTION__ , "unconsistent PID value\n" );
     520
     521        rpc.args[0] = (uint64_t)action_type;
     522        rpc.args[1] = (uint64_t)pid;
     523        rpc_process_sigaction_client( process_cxy , &rpc );
     524        rsp_count++;
    532525    }
    533526   
     
    540533    rsp_count , responses );
    541534
    542     // block and deschedule to wait RPC responses if required
    543     if( responses )
    544     {   
    545         thread_block( CURRENT_THREAD , THREAD_BLOCKED_RPC );
    546         sched_yield("BLOCKED on RPC_PROCESS_SIGACTION");
    547     }
    548 
    549 #if CONFIG_DEBUG_PROCESS_SIGACTION
    550 if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle )
    551 printk("\n[DBG] %s : make action in owner cluster %x\n", __FUNCTION__ , local_cxy );
    552 #endif
    553 
    554     // call directly the relevant function in local owner cluster
    555     if      (action_type == DELETE_ALL_THREADS  ) process_delete_threads ( process );
    556     else if (action_type == BLOCK_ALL_THREADS   ) process_block_threads  ( process );
    557     else if (action_type == UNBLOCK_ALL_THREADS ) process_unblock_threads( process );
     535    // block and deschedule to wait RPC responses
     536    thread_block( CURRENT_THREAD , THREAD_BLOCKED_RPC );
     537    sched_yield("BLOCKED on RPC_PROCESS_SIGACTION");
    558538
    559539#if CONFIG_DEBUG_PROCESS_SIGACTION
     
    561541if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle )
    562542printk("\n[DBG] %s : thread %x exit after %s process %x in cluster %x / cycle %d\n",
    563 __FUNCTION__ , CURRENT_THREAD, process_action_str( action_type ) ,
     543__FUNCTION__ , client, process_action_str( action_type ) ,
    564544process->pid , local_cxy , cycle );
    565545#endif
     
    778758    {
    779759        process_xp  = XLIST_ELEMENT( iter , process_t , local_list );
    780         process_ptr = (process_t *)GET_PTR( process_xp );
     760        process_ptr = GET_PTR( process_xp );
    781761        if( process_ptr->pid == pid )
    782762        {
     
    838818
    839819    // get reference process cluster and local pointer
    840     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     820    process_t * ref_ptr = GET_PTR( ref_xp );
    841821    cxy_t       ref_cxy = GET_CXY( ref_xp );
    842822
     
    858838    // get reference process cluster and local pointer
    859839    xptr_t ref_xp = process->ref_xp;
    860     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     840    process_t * ref_ptr = GET_PTR( ref_xp );
    861841    cxy_t       ref_cxy = GET_CXY( ref_xp );
    862842
     
    900880        xptr_t      ref_xp  = process->ref_xp;
    901881        cxy_t       ref_cxy = GET_CXY( ref_xp );
    902         process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     882        process_t * ref_ptr = GET_PTR( ref_xp );
    903883
    904884        // access reference process descriptor
     
    925905    // get cluster and local pointer for src fd_array
    926906    cxy_t        src_cxy = GET_CXY( src_xp );
    927     fd_array_t * src_ptr = (fd_array_t *)GET_PTR( src_xp );
     907    fd_array_t * src_ptr = GET_PTR( src_xp );
    928908
    929909    // get cluster and local pointer for dst fd_array
    930910    cxy_t        dst_cxy = GET_CXY( dst_xp );
    931     fd_array_t * dst_ptr = (fd_array_t *)GET_PTR( dst_xp );
     911    fd_array_t * dst_ptr = GET_PTR( dst_xp );
    932912
    933913    // get the remote lock protecting the src fd_array
     
    10441024    // get cluster and local pointer for parent process
    10451025    cxy_t       parent_process_cxy = GET_CXY( parent_process_xp );
    1046     process_t * parent_process_ptr = (process_t *)GET_PTR( parent_process_xp );
     1026    process_t * parent_process_ptr = GET_PTR( parent_process_xp );
    10471027
    10481028    // get parent process PID and extended pointer on .elf file
     
    13491329}  // end process_make_exec()
    13501330
    1351 ////////////////////////////////////////////
    1352 void process_make_kill( process_t * process,
    1353                         bool_t      is_exit,
    1354                         uint32_t    exit_status )
    1355 {
    1356     thread_t * this = CURRENT_THREAD;
    1357 
    1358     assert( (CXY_FROM_PID( process->pid ) == local_cxy) , __FUNCTION__ ,
    1359     "must be executed in process owner cluster\n" );
    1360 
    1361     assert( ( this->type == THREAD_RPC ) , __FUNCTION__ ,
    1362     "must be executed by an RPC thread\n" );
    1363 
    1364 #if CONFIG_DEBUG_PROCESS_MAKE_KILL
    1365 uint32_t cycle = (uint32_t)hal_get_cycles();
    1366 if( CONFIG_DEBUG_PROCESS_MAKE_KILL < cycle )
    1367 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    1368 __FUNCTION__, this , process->pid , cycle );
    1369 #endif
    1370 
    1371     // register exit_status in owner process descriptor
    1372     if( is_exit ) process->term_state = exit_status;
    1373 
    1374     // atomically update owner process descriptor flags
    1375     if( is_exit ) hal_atomic_or( &process->term_state , PROCESS_FLAG_EXIT );
    1376     else          hal_atomic_or( &process->term_state , PROCESS_FLAG_KILL );
    1377 
    1378     // remove TXT ownership from owner process descriptor
    1379     process_txt_reset_ownership( XPTR( local_cxy , process ) );
    1380 
    1381     // block all process threads in all clusters
    1382     process_sigaction( process , BLOCK_ALL_THREADS );
    1383 
    1384     // mark all process threads in all clusters for delete
    1385     process_sigaction( process , DELETE_ALL_THREADS );
    1386 
    1387 /* unused if sys_wait deschedules without blocking [AG]
    1388 
    1389     // get cluster and pointers on reference parent process
    1390     xptr_t      parent_xp  = process->parent_xp;
    1391     process_t * parent_ptr = GET_PTR( parent_xp );
    1392     cxy_t       parent_cxy = GET_CXY( parent_xp );
    1393 
    1394     // get loal pointer on parent main thread
    1395     thread_t * main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );
    1396  
    1397     // reset THREAD_BLOCKED_WAIT bit in parent process main thread
    1398     thread_unblock( XPTR( parent_cxy , main_ptr ) , THREAD_BLOCKED_WAIT );
    1399 */
    1400 
    1401 #if CONFIG_DEBUG_PROCESS_MAKE_KILL
    1402 cycle = (uint32_t)hal_get_cycles();
    1403 if( CONFIG_DEBUG_PROCESS_MAKE_KILL < cycle )
    1404 printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n",
    1405 __FUNCTION__, this, process->pid , cycle );
    1406 #endif
    1407 
    1408 }  // end process_make_kill()
    1409 
    14101331///////////////////////////////////////////////
    14111332void process_zero_create( process_t * process )
     
    16791600if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle )
    16801601printk("\n[DBG] %s : thread %x enter for process %x / txt_id = %d  / cycle %d\n",
    1681 __FUNCTION__, CURRENT_THREAD, process->pid, txt_id, cycle );
     1602__FUNCTION__, CURRENT_THREAD, process, txt_id, cycle );
    16821603#endif
    16831604
     
    17081629if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle )
    17091630printk("\n[DBG] %s : thread %x exit for process %x / txt_id = %d / cycle %d\n",
    1710 __FUNCTION__, CURRENT_THREAD, process->pid, txt_id , cycle );
     1631__FUNCTION__, CURRENT_THREAD, process, txt_id , cycle );
    17111632#endif
    17121633
     
    17211642    xptr_t      lock_xp;      // extended pointer on list lock in chdev
    17221643
    1723 #if CONFIG_DEBUG_PROCESS_TXT_DETACH
     1644#if CONFIG_DEBUG_PROCESS_TXT_ATTACH
    17241645uint32_t cycle = (uint32_t)hal_get_cycles();
    1725 if( CONFIG_DEBUG_PROCESS_TXT_DETACH < cycle )
     1646if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle )
    17261647printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    1727 __FUNCTION__, CURRENT_THREAD, process->pid , cycle );
     1648__FUNCTION__, CURRENT_THREAD, process, cycle );
    17281649#endif
    17291650
     
    17451666    remote_spinlock_unlock( lock_xp );
    17461667   
    1747 #if CONFIG_DEBUG_PROCESS_TXT_DETACH
    1748 cycle = (uint32_t)hal_get_cycles();
    1749 if( CONFIG_DEBUG_PROCESS_TXT_DETACH < cycle )
     1668#if CONFIG_DEBUG_PROCESS_TXT_ATTACH
     1669cycle = (uint32_t)hal_get_cycles();
     1670if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle )
    17501671printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n",
    1751 __FUNCTION__, CURRENT_THREAD, process->pid, cycle );
     1672__FUNCTION__, CURRENT_THREAD, process, cycle );
    17521673#endif
    17531674
     
    17661687    // get cluster and local pointer on process
    17671688    process_cxy = GET_CXY( process_xp );
    1768     process_ptr = (process_t *)GET_PTR( process_xp );
     1689    process_ptr = GET_PTR( process_xp );
    17691690
    17701691    // get extended pointer on stdin pseudo file
     
    17741695    txt_xp  = chdev_from_file( file_xp );
    17751696    txt_cxy = GET_CXY( txt_xp );
    1776     txt_ptr = (chdev_t *)GET_PTR( txt_xp );
     1697    txt_ptr = GET_PTR( txt_xp );
    17771698
    17781699    // set owner field in TXT chdev
     
    18041725    // get cluster and local pointer on process
    18051726    process_cxy = GET_CXY( process_xp );
    1806     process_ptr = (process_t *)GET_PTR( process_xp );
     1727    process_ptr = GET_PTR( process_xp );
    18071728
    18081729    // get extended pointer on stdin pseudo file
     
    18311752            current_ptr = GET_PTR( current_xp );
    18321753            parent_xp   = hal_remote_lwd( XPTR( current_cxy , &current_ptr->parent_xp ) );
    1833 
    18341754            parent_cxy  = GET_CXY( parent_xp );
    18351755            parent_ptr  = GET_PTR( parent_xp );
    18361756            ppid        = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
     1757
     1758printk("\n@@@ %s : pid = %x / process = %x\n", __FUNCTION__ , current_ptr->pid, current_ptr );
    18371759
    18381760            if( ppid == 1 )  // current is KSH
     
    18491771
    18501772
    1851      
     1773//////////////////////////////////////////////////////     
     1774inline pid_t process_get_txt_owner( uint32_t channel )
     1775{
     1776    xptr_t      txt_rx_xp  = chdev_dir.txt_rx[channel];
     1777    cxy_t       txt_rx_cxy = GET_CXY( txt_rx_xp );
     1778    chdev_t *   txt_rx_ptr = GET_PTR( txt_rx_xp );
     1779
     1780    xptr_t process_xp = (xptr_t)hal_remote_lwd( XPTR( txt_rx_cxy,
     1781                                                &txt_rx_ptr->ext.txt.owner_xp ) );
     1782
     1783    cxy_t       process_cxy = GET_CXY( process_xp );
     1784    process_t * process_ptr = GET_PTR( process_xp );
     1785
     1786    return (pid_t)hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
     1787}
     1788
     1789///////////////////////////////////////////
     1790void process_txt_display( uint32_t txt_id )
     1791{
     1792    xptr_t      chdev_xp;
     1793    cxy_t       chdev_cxy;
     1794    chdev_t   * chdev_ptr;
     1795    xptr_t      root_xp;
     1796    xptr_t      lock_xp;
     1797    xptr_t      current_xp;
     1798    xptr_t      iter_xp;
     1799
     1800    // check terminal index
     1801    assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
     1802    __FUNCTION__ , "illegal TXT terminal index" );
     1803
     1804    // get pointers on TXT_RX[txt_id] chdev
     1805    chdev_xp  = chdev_dir.txt_rx[txt_id];
     1806    chdev_cxy = GET_CXY( chdev_xp );
     1807    chdev_ptr = GET_PTR( chdev_xp );
     1808
     1809    // get extended pointer on root & lock of attached process list
     1810    root_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.root );
     1811    lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock );
     1812
     1813    // display header
     1814    printk("\n***** processes attached to TXT_%d\n", txt_id );
     1815
     1816    // get lock
     1817    remote_spinlock_lock( lock_xp );
     1818
     1819    // scan attached process list to find KSH process
     1820    XLIST_FOREACH( root_xp , iter_xp )
     1821    {
     1822        current_xp  = XLIST_ELEMENT( iter_xp , process_t , txt_list );
     1823        process_display( current_xp );
     1824    }
     1825
     1826    // release lock
     1827    remote_spinlock_unlock( lock_xp );
     1828
     1829}  // end process_txt_display
  • trunk/kernel/kern/process.h

    r433 r435  
    3636#include <hal_atomic.h>
    3737#include <vmm.h>
    38 #include <signal.h>
    3938#include <cluster.h>
    4039#include <vfs.h>
     
    6362    DELETE_ALL_THREADS   = 33,
    6463};
    65 
    66 /*********************************************************************************************
    67  * The termination state is a 32 bits word:
    68  * - the 8 LSB bits contain the user defined exit status
    69  * - the 24 other bits contain the flags defined below
    70  ********************************************************************************************/
    71 
    72 #define PROCESS_FLAG_BLOCK 0x100  /*! process received as SIGSTOP signal                    */
    73 #define PROCESS_FLAG_KILL  0x200  /*! process terminated by a sys_kill()                    */
    74 #define PROCESS_FLAG_EXIT  0x400  /*! process terminated by a sys_exit()                    */
    75 #define PROCESS_FLAG_WAIT  0x800  /*! parent process executed successfully a sys_wait()     */
    7664
    7765/*********************************************************************************************
     
    291279
    292280/*********************************************************************************************
    293  * This function allows a client thread running in the owner cluster of a process identified
    294  * by the <process> argument to block, unblock or delete all threads of the target process,
    295  * depending on the <action_type> argument.  The scenario is the following:
     281 * This function allows a client thread running in any cluster to block, unblock or delete
     282 * all threads of a process identified by the <pid> argument, depending on the
     283 * <action_type> argument.  The scenario is the following:
    296284 * - It uses the multicast, non blocking rpc_process_sigaction_client() function to send
    297285 *   parallel requests to all remote clusters containing a process copy. Then it blocks
     
    305293 * It is used by the sys_kill() & sys_exit() functions to handle the "kill" & "exit" syscalls.
    306294 * It is also used by the process_make_exec() function to handle the "exec" syscall.
    307  * WARNING : the DELETE and the BLOCK actions are NOT executed on the client thread.
    308  *********************************************************************************************
    309  * @ process     : pointer on the process descriptor in owner cluster.
     295 * It is also called by the TXT device to execute the ctrl C & ctrl Z commands.
     296 * WARNING : the DELETE action is NOT executed on the main thread (thread 0 in owner cluster).
     297 *********************************************************************************************
     298 * @ pid         : target process identifier.
    310299 * @ action_type : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
    311300 ********************************************************************************************/
    312 void process_sigaction( process_t * process,
     301void process_sigaction( pid_t       pid,
    313302                        uint32_t    action_type );
    314303
     
    403392                            struct thread_s ** child_thread_ptr );
    404393
    405 /*********************************************************************************************
    406  * This function is called by both the sys_kill() and sys_exit() system calls.
    407  * It must be executed by an RPC thread running in the target process owner cluster.
    408  * It uses twice the process_sigaction() function:
    409  * - first, to block all target process threads, in all clusters.
    410  * - second, to delete all target process threads in all clusters.
    411  * Finally, it synchronizes with the parent process sys_wait() function that MUST be called
    412  * by the parent process main thread.
    413  *********************************************************************************************
    414  * @ process      : pointer on process descriptor in owner cluster.
    415  * @ is_exit      : true when called by sys_exit() / false when called by sys_kill().
    416  * @ exit_status  : exit status, when called by sys_exit().
    417  ********************************************************************************************/
    418 void process_make_kill( process_t * process,
    419                         bool_t      is_exit,
    420                         uint32_t    exit_status );
    421 
    422394
    423395/********************   File Management Operations   ****************************************/
     
    573545void process_txt_reset_ownership( xptr_t process_xp );
    574546
     547/*********************************************************************************************
     548 * This function returns the terminal owner process (foreground process)
     549 * for a given TXT terminal identified by its <channel> index.
     550 *********************************************************************************************
     551 * @ channel  : TXT terminal channel.
     552 * @ return owner process identifier.
     553 ********************************************************************************************/
     554pid_t process_get_txt_owner( uint32_t channel );
     555
     556/*********************************************************************************************
     557 * This debug function diplays on the kernel terminal the list of processes attached
     558 * to a given terminal identified by the <txt_id> argument.
     559 *********************************************************************************************
     560 * @ txt_id  : TXT terminal channel.
     561 ********************************************************************************************/
     562void process_txt_display( uint32_t txt_id );
     563
     564
    575565#endif  /* _PROCESS_H_ */
  • trunk/kernel/kern/rpc.c

    r433 r435  
    3939#include <vfs.h>
    4040#include <fatfs.h>
    41 #include <signal.h>
    4241#include <rpc.h>
    4342
     
    8079    &rpc_process_make_fork_server,      // 3
    8180    &rpc_undefined,                     // 4    unused slot
    82     &rpc_process_make_kill_server,      // 5
     81    &rpc_undefined,                     // 5    unused slot
    8382    &rpc_thread_user_create_server,     // 6
    8483    &rpc_thread_kernel_create_server,   // 7
     
    610609
    611610/////////////////////////////////////////////////////////////////////////////////////////
    612 // [5]      Marshaling functions attached to RPC_PROCESS_MAKE_KILL (blocking)
    613 /////////////////////////////////////////////////////////////////////////////////////////
    614 
    615 ///////////////////////////////////////////////////
    616 void rpc_process_make_kill_client( cxy_t       cxy,
    617                                    process_t * process,
    618                                    bool_t      is_exit,
    619                                    uint32_t    status )
    620 {
    621 rpc_dmsg("\n[DBG] %s : enter / thread %x on core[%x,%d] / cycle %d\n",
    622 __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy,
    623 CURRENT_THREAD->core->lid , hal_time_stamp() );
    624 
    625     // initialise RPC descriptor header
    626     rpc_desc_t  rpc;
    627     rpc.index    = RPC_PROCESS_MAKE_KILL;
    628     rpc.response = 1;
    629     rpc.blocking = true;
    630 
    631     // set input arguments in RPC descriptor 
    632     rpc.args[0] = (uint64_t)(intptr_t)process;
    633     rpc.args[1] = (uint64_t)is_exit;
    634     rpc.args[2] = (uint64_t)status;
    635 
    636     // register RPC request in remote RPC fifo (blocking function)
    637     rpc_send( cxy , &rpc );
    638 
    639 rpc_dmsg("\n[DBG] %s : exit / thread %x on core[%x,%d] / cycle %d\n",
    640 __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy,
    641 CURRENT_THREAD->core->lid , hal_time_stamp() );
    642 
    643 
    644 //////////////////////////////////////////////
    645 void rpc_process_make_kill_server( xptr_t xp )
    646 {
    647 rpc_dmsg("\n[DBG] %s : enter / thread %x on core[%x,%d] / cycle %d\n",
    648 __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy,
    649 CURRENT_THREAD->core->lid , hal_time_stamp() );
    650 
    651     process_t * process;
    652     bool_t      is_exit;
    653     uint32_t    status;
    654 
    655     // get client cluster identifier and pointer on RPC descriptor
    656     cxy_t        client_cxy  = (cxy_t)GET_CXY( xp );
    657     rpc_desc_t * desc        = (rpc_desc_t *)GET_PTR( xp );
    658 
    659     // get arguments from RPC descriptor
    660     process = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) );
    661     is_exit = (bool_t)               hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) );
    662     status  = (uint32_t)             hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) );
    663 
    664     // call local kernel function
    665     process_make_kill( process , is_exit , status );
    666 
    667 rpc_dmsg("\n[DBG] %s : exit / thread %x on core[%x,%d] / cycle %d\n",
    668 __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy,
    669 CURRENT_THREAD->core->lid , hal_time_stamp() );
    670 }
     611// [5]      undefined slot
     612/////////////////////////////////////////////////////////////////////////////////////////
    671613
    672614/////////////////////////////////////////////////////////////////////////////////////////
     
    906848                                   rpc_desc_t * rpc_ptr )
    907849{
    908 sigaction_dmsg("\n[DBG] %s : enter to %s process %x in cluster %x / cycle %d\n",
     850rpc_dmsg("\n[DBG] %s : enter to %s process %x in cluster %x / cycle %d\n",
    909851__FUNCTION__ , process_action_str( (uint32_t)rpc_ptr->args[0] ) ,
    910852((process_t *)(intptr_t)rpc_ptr->args[1])->pid , cxy , (uint32_t)hal_get_cycles() );
     
    913855    rpc_send( cxy , rpc_ptr );
    914856
    915 sigaction_dmsg("\n[DBG] %s : exit after %s process %x in cluster %x / cycle %d\n",
     857rpc_dmsg("\n[DBG] %s : exit after %s process %x in cluster %x / cycle %d\n",
    916858__FUNCTION__ , process_action_str( (uint32_t)rpc_ptr->args[0] ) ,
    917859((process_t *)(intptr_t)rpc_ptr->args[1])->pid , cxy , (uint32_t)hal_get_cycles() );
     
    921863void rpc_process_sigaction_server( xptr_t xp )
    922864{
     865    pid_t        pid;              // target process identifier
    923866    process_t  * process;          // pointer on local process descriptor
    924867    uint32_t     action;           // sigaction index
     
    934877
    935878    // get arguments from RPC descriptor
    936     action      = (uint32_t)             hal_remote_lwd( XPTR( client_cxy , &rpc->args[0] ) );
    937     process     = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &rpc->args[1] ) );
     879    action      = (uint32_t)  hal_remote_lwd( XPTR( client_cxy , &rpc->args[0] ) );
     880    pid         = (pid_t)     hal_remote_lwd( XPTR( client_cxy , &rpc->args[1] ) );
    938881    client_ptr  = (thread_t *)hal_remote_lpt( XPTR( client_cxy , &rpc->thread ) );
     882
     883rpc_dmsg("\n[DBG] %s : enter to %s process %x / cycle %d\n",
     884__FUNCTION__ , process_action_str( action ) , pid , (uint32_t)hal_get_cycles() );
     885
     886    // get local process descriptor
     887    process = process_get_local_copy( pid );
    939888
    940889    // build extended pointer on client thread
    941890    client_xp = XPTR( client_cxy , client_ptr );
    942 
    943 sigaction_dmsg("\n[DBG] %s : enter to %s process %x / cycle %d\n",
    944 __FUNCTION__ , process_action_str( action ) , process->pid , (uint32_t)hal_get_cycles() );
    945891
    946892    // call relevant kernel function
     
    958904    }
    959905
    960 sigaction_dmsg("\n[DBG] %s : exit after %s process %x / cycle %d\n",
    961 __FUNCTION__ , process_action_str( action ) , process->pid , (uint32_t)hal_get_cycles() );
     906rpc_dmsg("\n[DBG] %s : exit after %s process %x / cycle %d\n",
     907__FUNCTION__ , process_action_str( action ) , pid , (uint32_t)hal_get_cycles() );
    962908}
    963909
  • trunk/kernel/kern/rpc.h

    r433 r435  
    3232#include <vseg.h>
    3333#include <remote_fifo.h>
    34 #include <signal.h>
    3534
    3635/**** Forward declarations ****/
     
    6564    RPC_PROCESS_MAKE_FORK      = 3,
    6665    RPC_UNDEFINED_4            = 4,
    67     RPC_PROCESS_MAKE_KILL      = 5,
     66    RPC_UNDEFINED_5            = 5,
    6867    RPC_THREAD_USER_CREATE     = 6,
    6968    RPC_THREAD_KERNEL_CREATE   = 7,
     
    242241
    243242/***********************************************************************************
    244  * [5] The RPC_PROCESS_MAKE_KILL can be called by any thread to request the owner
    245  * cluster to execute the process_make_kill() function for a target process.
    246  ***********************************************************************************
    247  * @ cxy      : owner cluster identifier.
    248  * @ process  : pointer on process in owner cluster.
    249  * @ is_exit  : true if called by sys_exit() / false if called by sys_kill()
    250  * @ status   : exit status (only when called by sys_exit()
    251  **********************************************************************************/
    252 void rpc_process_make_kill_client( cxy_t              cxy,
    253                                    struct process_s * process,
    254                                    bool_t             is_exit,
    255                                    uint32_t           status );
    256 
    257 void rpc_process_make_kill_server( xptr_t xp );
     243 * [5] undefined slot
     244 **********************************************************************************/
    258245
    259246/***********************************************************************************
     
    314301/***********************************************************************************
    315302 * [9] The RPC_PROCESS_SIGACTION allows the owner cluster to request any other
    316  * cluster to execute a given sigaction (BLOCK / UNBLOCK / DELETE) for all threads
    317  * of a given process.
     303 * cluster to execute a given sigaction (BLOCK / UNBLOCK / DELETE) for all
     304 * threads of a given process.
    318305 *
    319306 * WARNING : It is implemented as a NON BLOCKING multicast RPC, that can be sent
  • trunk/kernel/kern/scheduler.c

    r433 r435  
    280280    }
    281281
    282     // enter critical section / save SR in current thread context
    283     hal_disable_irq( &current->save_sr );
     282    // enter critical section / save SR in current thread descriptor
     283    hal_disable_irq( &CURRENT_THREAD->save_sr );
    284284
    285285    // loop on threads to select next thread
     
    321321        }
    322322
    323         // switch CPU from calling thread context to new thread context
     323        // switch CPU from current thread context to new thread context
    324324        hal_do_cpu_switch( current->cpu_context, next->cpu_context );
    325325    }
     
    330330uint32_t cycle = (uint32_t)hal_get_cycles();
    331331if( CONFIG_DEBUG_SCHED_YIELD < cycle )
    332 printk("\n[DBG] %s : core[%x,%d] / cause = %s / thread %x (%s) (%x,%x) continue / cycle %d\n",
     332printk("\n[DBG] %s : core[%x,%d] / cause = %s\n"
     333"      thread %x (%s) (%x,%x) continue / cycle %d\n",
    333334__FUNCTION__, local_cxy, core->lid, cause,
    334335current, thread_type_str(current->type), current->process->pid, current->trdid, cycle );
     
    340341    sched_handle_signals( core );
    341342
    342     // exit critical section / restore SR from next thread context
    343     hal_restore_irq( next->save_sr );
     343    // exit critical section / restore SR from current thread descriptor
     344    hal_restore_irq( CURRENT_THREAD->save_sr );
    344345
    345346}  // end sched_yield()
  • trunk/kernel/kern/signal.h

    r409 r435  
    2828
    2929#include <hal_types.h>
    30 
    31 #define SIG_DEFAULT    (void*)0L
    32 #define SIG_IGNORE     (void*)1L
    33 #define SIG_ERROR     -1L
    34 
    35 #define SIGHUP     1       /*! hangup                                                     */
    36 #define SIGINT     2       /*! interrupt                                                  */
    37 #define SIGQUIT    3       /*! quit                                                       */
    38 #define SIGILL     4       /*! illegal instruction (not reset when caught)                */
    39 #define SIGTRAP    5       /*! trace trap (not reset when caught)                         */
    40 #define SIGIOT     6       /*! IOT instruction                                            */
    41 #define SIGABRT    6       /*! used by abort, replace SIGIOT in the future                */
    42 #define SIGEMT     7       /*! EMT instruction                                            */
    43 #define SIGFPE     8       /*! floating point exception                                   */
    44 #define SIGKILL    9       /*! kill (cannot be caught or ignored)                         */
    45 #define SIGBUS     10      /*! bus error                                                  */
    46 #define SIGSEGV    11      /*! segmentation violation                                     */
    47 #define SIGSYS     12      /*! bad argument to system call                                */
    48 #define SIGPIPE    13      /*! write on a pipe with no one to read it                     */
    49 #define SIGALRM    14      /*! alarm clock                                                */
    50 #define SIGTERM    15      /*! software termination signal from kill                      */
    51 #define SIGURG     16      /*! urgent condition on IO channel                             */
    52 #define SIGSTOP    17      /*! sendable stop signal not from tty                          */
    53 #define SIGTSTP    18      /*! stop signal from tty                                       */
    54 #define SIGCONT    19      /*! continue a stopped process                                 */
    55 #define SIGCHLD    20      /*! to parent on child stop or exit                            */
    56 #define SIGCLD     20      /*! System V name for SIGCHLD                                  */
    57 #define SIGTTIN    21      /*! to readers pgrp upon background tty read                   */
    58 #define SIGTTOU    22      /*! like TTIN for output if (tp->t_local&LTOSTOP)              */
    59 #define SIGIO      23      /*! input/output possible signal                               */
    60 #define SIGPOLL    SIGIO   /*! System V name for SIGIO                                    */
    61 #define SIGXCPU    24      /*! exceeded CPU time limit                                    */
    62 #define SIGXFSZ    25      /*! exceeded file size limit                                   */
    63 #define SIGVTALRM  26      /*! virtual time alarm                                         */
    64 #define SIGPROF    27      /*! profiling time alarm                                       */
    65 #define SIGWINCH   28      /*! window changed                                             */
    66 #define SIGLOST    29      /*! resource lost (eg, record-lock lost)                       */
    67 #define SIGUSR1    30      /*! user defined signal 1                                      */
    68 #define SIGUSR2    31      /*! user defined signal 2                                      */
    69 #define SIG_NR     32      /*! signal 0 implied                                           */
    70 
    71 #define SIG_DEFAULT_MASK         0xFFEEFFFF
    7230
    7331
Note: See TracChangeset for help on using the changeset viewer.