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

Fix a bad bug in scheduler...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.