Changeset 446 for trunk/kernel


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

miscelaneous...

Location:
trunk/kernel
Files:
12 edited

Legend:

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

    r440 r446  
    198198    hal_disable_irq( &save_sr );
    199199
    200     // take the lock
     200    // take the lock protecting chdev waiting queue
    201201    remote_spinlock_lock( lock_xp );
    202202
     
    204204    thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO );
    205205
     206    // unblock server thread if required
    206207    if( hal_remote_lw( blocked_xp ) & THREAD_BLOCKED_IDLE )
    207208    thread_unblock( server_xp , THREAD_BLOCKED_IDLE );
  • trunk/kernel/kern/printk.c

    r445 r446  
    2828#include <remote_spinlock.h>
    2929#include <cluster.h>
     30#include <thread.h>
    3031#include <chdev.h>
    3132#include <printk.h>
     
    399400        chdev_t * txt0_ptr = GET_PTR( txt0_xp );
    400401
    401         // get extended pointer on remote TXT0 chdev lock
     402        // get extended pointer on remote TXT0 lock
    402403        xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
    403404
     
    406407
    407408        // call nolock_printk to print function_name
    408         nolock_printk("\n[PANIC] in %s : " , function_name );
     409        nolock_printk("\n[PANIC] on core[%x,%d] in %s : " ,
     410        local_cxy , CURRENT_THREAD->core->lid , function_name );
    409411
    410412        // call kernel_printf on TXT0, in busy waiting to print format
     
    417419
    418420        // suicide
    419         sys_exit( EXIT_FAILURE );
     421        while( 1 ) asm volatile ("nop");
    420422    }
    421423}
  • trunk/kernel/kern/process.c

    r445 r446  
    392392    cxy_t       parent_cxy;
    393393    xptr_t      children_lock_xp;
     394    xptr_t      children_nr_xp;
    394395
    395396    pid_t       pid = process->pid;
     
    421422        // get extended pointer on children_lock in parent process
    422423        children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     424        children_nr_xp   = XPTR( parent_cxy , &parent_ptr->children_nr );
    423425
    424426        // remove process from children_list
    425427        remote_spinlock_lock( children_lock_xp );
    426428        xlist_unlink( XPTR( local_cxy , &process->children_list ) );
     429            hal_remote_atomic_add( children_nr_xp , -1 );
    427430        remote_spinlock_unlock( children_lock_xp );
    428431    }
     
    12371240    thread_t       * new_thread;              // local pointer on new thread
    12381241    xptr_t           parent_xp;               // extended pointer on parent process
     1242    process_t      * parent_ptr;              // local pointer on parent process
     1243    cxy_t            parent_cxy;              // parent process cluster identifier
     1244    xptr_t           children_lock_xp;        // extended pointer on children lock in parent
     1245    xptr_t           children_root_xp;        // extended pointer on children root in parent
     1246    xptr_t           children_nr_xp;          // extended pointer on children number in parent
     1247    thread_t       * parent_main_ptr;         // local pointer on parent main thread
     1248    xptr_t           parent_main_xp;          // extended pointer on parent main thread
    12391249    pthread_attr_t   attr;                    // new thread attributes
    12401250    lid_t            lid;                     // selected core local index
    12411251        error_t          error;                   // value returned by called functions
    12421252   
    1243     // get old_thread / old_process / PID / parent_xp
     1253    // get old_thread, old_process & PID
    12441254    old_thread  = CURRENT_THREAD;
    12451255    old_process = old_thread->process;
    12461256    pid         = old_process->pid;
    1247     parent_xp   = old_process->parent_xp;
    1248    
     1257
    12491258        // get .elf pathname from exec_info
    1250         path        = exec_info->path;
     1259        path = exec_info->path;
    12511260
    12521261    // this function must be executed by a thread running in owner cluster
     
    12601269uint32_t cycle = (uint32_t)hal_get_cycles();
    12611270if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1262 printk("\n[DBG] %s : thread %x enters for process %x / %s / cycle %d\n",
    1263 __FUNCTION__, old_thread, pid, path, cycle );
    1264 #endif
     1271printk("\n[DBG] %s : thread %x in process %x enters / path %s / cycle %d\n",
     1272__FUNCTION__, old_thread->trdid, pid, path, cycle );
     1273#endif
     1274
     1275    // get parent process pointers
     1276    parent_xp   = old_process->parent_xp;
     1277    parent_cxy  = GET_CXY( parent_xp );
     1278    parent_ptr  = GET_PTR( parent_xp );
     1279   
     1280#if (DEBUG_PROCESS_MAKE_EXEC & 1)
     1281if( DEBUG_PROCESS_MAKE_EXEC < cycle )
     1282printk("\n[DBG] %s : thread %x in process %x get parent process %x in cluster %x\n",
     1283__FUNCTION__, old_thread->trdid, pid, parent_ptr, parent_cxy );
     1284#endif
     1285
     1286    // get extended pointers on parent children_root, children_lock and children_nr
     1287    children_root_xp = XPTR( parent_cxy , &parent_ptr->children_root );
     1288    children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     1289    children_nr_xp   = XPTR( parent_cxy , &parent_ptr->children_nr   );
     1290
     1291    // get pointers on the parent process main thread
     1292    parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );
     1293    parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
    12651294
    12661295     // allocate memory for new_process descriptor
     
    12981327cycle = (uint32_t)hal_get_cycles();
    12991328if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1300 printk("\n[DBG] %s : thread %x created new process %x / cycle %d \n",
    1301 __FUNCTION__ , old_thread , new_process , cycle );
     1329printk("\n[DBG] %s : thread %x in process %x created new process %x\n",
     1330__FUNCTION__ , old_thread->trdid, pid, new_process );
    13021331#endif
    13031332
     
    13581387#endif
    13591388
    1360     // get cluster and local pointer on parent process
    1361     process_t * parent_ptr = GET_PTR( parent_xp );
    1362     cxy_t       parent_cxy = GET_CXY( parent_xp );
    1363 
    1364     // get extended pointers on parent children_root, children_lock and children_nr
    1365     xptr_t root_xp = XPTR( parent_cxy , &parent_ptr->children_root );
    1366     xptr_t lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
    1367     xptr_t nr_xp   = XPTR( parent_cxy , &parent_ptr->children_nr   );
    1368 
    13691389    // register new_process in parent children list
    1370     remote_spinlock_lock( lock_xp );
    1371         xlist_add_last( root_xp , XPTR( local_cxy , &new_process->children_list ) );
    1372         hal_remote_atomic_add( nr_xp , 1 );
    1373     remote_spinlock_unlock( lock_xp );
     1390    remote_spinlock_lock( children_lock_xp );
     1391        xlist_add_last( children_root_xp , XPTR( local_cxy , &new_process->children_list ) );
     1392        hal_remote_atomic_add( children_nr_xp , 1 );
     1393    remote_spinlock_unlock( children_lock_xp );
    13741394
    13751395    // activate new thread
     
    13791399    process_txt_detach( XPTR( local_cxy , old_process ) );
    13801400
    1381     // block this old_thread
     1401    // block old_thread
    13821402    thread_block( XPTR( local_cxy , old_thread ) , THREAD_BLOCKED_GLOBAL );
    13831403
    1384     // atomically update old_process descriptor term_state to ask
    1385     // the parent process (wait() function) to delete this old_thread
     1404    // atomically update old_process termination state
    13861405    hal_atomic_or( &old_process->term_state , PROCESS_TERM_EXIT );
     1406
     1407    // take the children lock and unblock the parent process main thread
     1408    remote_spinlock_lock( children_lock_xp );
     1409    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     1410    remote_spinlock_unlock( children_lock_xp );
    13871411
    13881412    hal_fence();
     
    16211645    if( txt_owner_xp == process_xp )
    16221646    {
    1623         nolock_printk("PID %X | PPID %X | STS %X | %s (FG) | %X | %d | %s\n",
     1647        nolock_printk("PID %X | PPID %X | TS %X | %s (FG) | %X | %d | %s\n",
    16241648        pid, ppid, state, txt_name, process_ptr, th_nr, elf_name );
    16251649    }
    16261650    else
    16271651    {
    1628         nolock_printk("PID %X | PPID %X | STS %X | %s (BG) | %X | %d | %s\n",
     1652        nolock_printk("PID %X | PPID %X | TS %X | %s (BG) | %X | %d | %s\n",
    16291653        pid, ppid, state, txt_name, process_ptr, th_nr, elf_name );
    16301654    }
     
    16761700    xptr_t      lock_xp;      // extended pointer on list lock in chdev
    16771701
    1678 #if DEBUG_PROCESS_TXT_ATTACH
     1702#if DEBUG_PROCESS_TXT
    16791703uint32_t cycle = (uint32_t)hal_get_cycles();
    1680 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1704if( DEBUG_PROCESS_TXT < cycle )
    16811705printk("\n[DBG] %s : thread %x enter for process %x / txt_id = %d  / cycle %d\n",
    16821706__FUNCTION__, CURRENT_THREAD, process->pid, txt_id, cycle );
     
    17051729    remote_spinlock_unlock( lock_xp );
    17061730
    1707 #if DEBUG_PROCESS_TXT_ATTACH
    1708 cycle = (uint32_t)hal_get_cycles();
    1709 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1731#if DEBUG_PROCESS_TXT
     1732cycle = (uint32_t)hal_get_cycles();
     1733if( DEBUG_PROCESS_TXT < cycle )
    17101734printk("\n[DBG] %s : thread %x exit for process %x / txt_id = %d / cycle %d\n",
    17111735__FUNCTION__, CURRENT_THREAD, process->pid, txt_id , cycle );
     
    17351759    "process descriptor not in owner cluster" );
    17361760
    1737 #if DEBUG_PROCESS_TXT_ATTACH
     1761#if DEBUG_PROCESS_TXT
    17381762uint32_t cycle = (uint32_t)hal_get_cycles();
    1739 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1763if( DEBUG_PROCESS_TXT < cycle )
    17401764printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    17411765__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    17611785    remote_spinlock_unlock( lock_xp );
    17621786
    1763 #if DEBUG_PROCESS_TXT_ATTACH
     1787#if DEBUG_PROCESS_TXT
    17641788cycle  = (uint32_t)hal_get_cycles();
    17651789uint32_t txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    1766 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1790if( DEBUG_PROCESS_TXT < cycle )
    17671791printk("\n[DBG] %s : thread %x exit / process %x detached from TXT %d / cycle %d\n",
    17681792__FUNCTION__, CURRENT_THREAD, process_pid, txt_id, cycle );
     
    17931817    "process descriptor not in owner cluster\n" );
    17941818
    1795 #if DEBUG_PROCESS_TXT_ATTACH
     1819#if DEBUG_PROCESS_TXT
    17961820uint32_t cycle = (uint32_t)hal_get_cycles();
    1797 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1821if( DEBUG_PROCESS_TXT < cycle )
    17981822printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    17991823__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    18111835    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp );
    18121836
    1813 #if DEBUG_PROCESS_TXT_ATTACH
    1814 cycle = (uint32_t)hal_get_cycles();
    1815 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1837#if DEBUG_PROCESS_TXT
     1838cycle = (uint32_t)hal_get_cycles();
     1839if( DEBUG_PROCESS_TXT < cycle )
    18161840printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n",
    18171841__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    18501874    "process descriptor not in owner cluster\n" );
    18511875
    1852 #if DEBUG_PROCESS_TXT_ATTACH
     1876#if DEBUG_PROCESS_TXT
    18531877uint32_t cycle = (uint32_t)hal_get_cycles();
    1854 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1878if( DEBUG_PROCESS_TXT < cycle )
    18551879printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    18561880__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    18691893    txt_id   = hal_remote_lw ( XPTR( txt_cxy , &txt_ptr->channel ) );
    18701894
    1871 #if( DEBUG_PROCESS_TXT_ATTACH & 1 )
    1872 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1895#if( DEBUG_PROCESS_TXT & 1 )
     1896if( DEBUG_PROCESS_TXT < cycle )
    18731897printk("\n[DBG] %s : file_ptr %x / txt_ptr %x / txt_id %d / owner_ptr = %x\n",
    18741898__FUNCTION__, GET_PTR(file_xp), txt_ptr, txt_id, GET_PTR(owner_xp) );
     
    18881912        {
    18891913
    1890 #if( DEBUG_PROCESS_TXT_ATTACH & 1 )
    1891 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1914#if( DEBUG_PROCESS_TXT & 1 )
     1915if( DEBUG_PROCESS_TXT < cycle )
    18921916printk("\n[DBG] %s : process is not the KSH process => search the KSH\n", __FUNCTION__ );
    18931917#endif
     
    19071931                    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
    19081932
    1909 #if DEBUG_PROCESS_TXT_ATTACH
    1910 cycle = (uint32_t)hal_get_cycles();
    1911 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1933#if DEBUG_PROCESS_TXT
     1934cycle = (uint32_t)hal_get_cycles();
     1935if( DEBUG_PROCESS_TXT < cycle )
    19121936printk("\n[DBG] %s : thread %x exit / process %x to KSH process %x / cycle %d\n",
    19131937__FUNCTION__, CURRENT_THREAD, process_pid,
     
    19291953        {
    19301954
    1931 #if( DEBUG_PROCESS_TXT_ATTACH & 1 )
    1932 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1955#if( DEBUG_PROCESS_TXT & 1 )
     1956if( DEBUG_PROCESS_TXT < cycle )
    19331957printk("\n[DBG] %s : process is the KSH process => search another\n", __FUNCTION__ );
    19341958#endif
     
    19491973                    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
    19501974
    1951 #if DEBUG_PROCESS_TXT_ATTACH
    1952 cycle = (uint32_t)hal_get_cycles();
    1953 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1975#if DEBUG_PROCESS_TXT
     1976cycle = (uint32_t)hal_get_cycles();
     1977if( DEBUG_PROCESS_TXT < cycle )
    19541978printk("\n[DBG] %s : thread %x exit / KSH process %x to process %x / cycle %d\n",
    19551979__FUNCTION__, CURRENT_THREAD, process_pid,
     
    19661990            hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
    19671991
    1968 #if DEBUG_PROCESS_TXT_ATTACH
    1969 cycle = (uint32_t)hal_get_cycles();
    1970 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1992#if DEBUG_PROCESS_TXT
     1993cycle = (uint32_t)hal_get_cycles();
     1994if( DEBUG_PROCESS_TXT < cycle )
    19711995printk("\n[DBG] %s : thread %x exit / KSH process %x to nobody / cycle %d\n",
    19721996__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    19782002    {
    19792003
    1980 #if DEBUG_PROCESS_TXT_ATTACH
    1981 cycle = (uint32_t)hal_get_cycles();
    1982 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     2004#if DEBUG_PROCESS_TXT
     2005cycle = (uint32_t)hal_get_cycles();
     2006if( DEBUG_PROCESS_TXT < cycle )
    19832007printk("\n[DBG] %s : thread %x exit / process %x is not TXT owner / cycle %d\n",
    19842008__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
  • trunk/kernel/kern/process.h

    r445 r446  
    405405                            struct thread_s ** child_thread_ptr );
    406406
     407
    407408/********************   File Management Operations   ****************************************/
    408409
     
    535536/*********************************************************************************************
    536537 * This function detach a process, identified by the <process_xp> argument,
    537  * from the list of process attached to a given TXT terminal. It transfer the TXT ownership,
    538  * if the detached process is the TXT owner.
    539  * The target process descriptor must be in the owner cluster, but the calling thread can
    540  * be running in any cluster.
     538 * from the list of process attached to a given TXT terminal. It transfer the TXT ownership
     539 * to another process, if the detached process is the TXT owner.
     540 * The process descriptor identified by the <process_xp> argument must be in the owner
     541 * cluster, but the calling thread can be running in any cluster.
    541542 *********************************************************************************************
    542543 * @ process_xp  : extended pointer on process descriptor.
  • trunk/kernel/kern/thread.c

    r443 r446  
    4242#include <ppm.h>
    4343#include <thread.h>
     44#include <rpc.h>
    4445
    4546//////////////////////////////////////////////////////////////////////////////////////
     
    799800uint32_t cycle = (uint32_t)hal_get_cycles();
    800801if( DEBUG_THREAD_BLOCK < cycle )
    801 printk("\n[DBG] %s : thread %x blocked thread %x / cause %x / cycle %d\n",
    802 __FUNCTION__ , CURRENT_THREAD , ptr , cause , cycle );
     802printk("\n[@@@] %s : thread %x  in cxy %x blocked thread %x in cxy %x / cause %x / cycle %d\n",
     803__FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle );
    803804#endif
    804805
    805806#if (DEBUG_THREAD_BLOCK & 1)
    806807if( DEBUG_THREAD_BLOCK < cycle )
    807 sched_display( ptr->core->lid );
     808{
     809    if( cxy == local_cxy)
     810    {
     811        sched_display( ptr->core->lid );
     812    }
     813    else
     814    {
     815        core_t * core = hal_remote_lpt( XPTR( cxy , &ptr->core ) );
     816        lid_t    lid  = hal_remote_lw ( XPTR( cxy , &core->lid ) );
     817        rpc_sched_display_client( cxy , lid );
     818    }
     819}
    808820#endif
    809821
     
    825837uint32_t cycle = (uint32_t)hal_get_cycles();
    826838if( DEBUG_THREAD_BLOCK < cycle )
    827 printk("\n[DBG] %s : thread %x unblocked thread %x / cause %x / cycle %d\n",
    828 __FUNCTION__ , CURRENT_THREAD , ptr , cause , cycle );
     839printk("\n[@@@] %s : thread %x  in cxy %x unblocked thread %x in cxy %x / cause %x / cycle %d\n",
     840__FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle );
    829841#endif
    830842
    831843#if (DEBUG_THREAD_BLOCK & 1)
    832844if( DEBUG_THREAD_BLOCK < cycle )
    833 sched_display( ptr->core->lid );
     845{
     846    if( cxy == local_cxy)
     847    {
     848        sched_display( ptr->core->lid );
     849    }
     850    else
     851    {
     852        core_t * core = hal_remote_lpt( XPTR( cxy , &ptr->core ) );
     853        lid_t    lid  = hal_remote_lw ( XPTR( cxy , &core->lid ) );
     854        rpc_sched_display_client( cxy , lid );
     855    }
     856}
    834857#endif
    835858
     
    838861
    839862}  // end thread_unblock()
    840 
    841 /*
    842 
    843 ////////////////////////////////////
    844 void thread_kill( xptr_t  target_xp,
    845                   bool_t  is_exit,
    846                   bool_t  is_forced )
    847 {
    848     reg_t       save_sr;                // for critical section
    849     bool_t      attached;               // target thread in attached mode
    850     bool_t      join_done;              // joining thread arrived first
    851     xptr_t      killer_xp;              // extended pointer on killer thread (this)
    852     thread_t  * killer_ptr;             // pointer on killer thread (this)
    853     cxy_t       target_cxy;             // target thread cluster     
    854     thread_t  * target_ptr;             // pointer on target thread
    855     xptr_t      joining_xp;             // extended pointer on joining thread
    856     thread_t  * joining_ptr;            // pointer on joining thread
    857     cxy_t       joining_cxy;            // joining thread cluster
    858     pid_t       target_pid;             // target process PID
    859     cxy_t       owner_cxy;              // target process owner cluster
    860     trdid_t     target_trdid;           // target thread identifier
    861     ltid_t      target_ltid;            // target thread local index
    862     xptr_t      process_state_xp;       // extended pointer on <term_state> in process
    863 
    864     xptr_t      target_flags_xp;        // extended pointer on target thread <flags>
    865     xptr_t      target_join_lock_xp;    // extended pointer on target thread <join_lock>
    866     xptr_t      target_join_xp_xp;      // extended pointer on target thread <join_xp>
    867     xptr_t      target_process_xp;      // extended pointer on target thread <process>
    868 
    869     process_t * target_process;         // pointer on target thread process
    870 
    871     // get target thread pointer and cluster
    872     target_cxy = GET_CXY( target_xp );
    873     target_ptr = GET_PTR( target_xp );
    874 
    875     // get killer thread pointers
    876     killer_ptr = CURRENT_THREAD;
    877     killer_xp  = XPTR( local_cxy , killer_ptr );
    878 
    879 #if DEBUG_THREAD_DELETE
    880 uint32_t cycle  = (uint32_t)hal_get_cycles;
    881 if( DEBUG_THREAD_DELETE < cycle )
    882 printk("\n[DBG] %s : thread %x enter for target thread %x / cycle %d\n",
    883 __FUNCTION__, killer_ptr, target_ptr, cycle );
    884 #endif
    885 
    886     // block the target thread
    887     thread_block( target_xp , THREAD_BLOCKED_GLOBAL );
    888 
    889     // get target thread attached mode
    890     target_flags_xp = XPTR( target_cxy , &target_ptr->flags );
    891     attached = ((hal_remote_lw( target_flags_xp ) & THREAD_FLAG_DETACHED) == 0);
    892 
    893     // synchronize with the joining thread
    894     // if the target thread is attached && not forced
    895 
    896     if( attached  && (is_forced == false) )
    897     {
    898         // build extended pointers on target thread join fields
    899         target_join_lock_xp  = XPTR( target_cxy , &target_ptr->join_lock );
    900         target_join_xp_xp    = XPTR( target_cxy , &target_ptr->join_xp );
    901 
    902         // enter critical section
    903         hal_disable_irq( &save_sr );
    904 
    905         // take the join_lock in target thread descriptor
    906         remote_spinlock_lock( target_join_lock_xp );
    907 
    908         // get join_done from target thread descriptor
    909         join_done = ((hal_remote_lw( target_flags_xp ) & THREAD_FLAG_JOIN_DONE) != 0);
    910    
    911         if( join_done )     // joining thread arrived first
    912         {
    913             // get extended pointer on joining thread
    914             joining_xp  = (xptr_t)hal_remote_lwd( target_join_xp_xp );
    915             joining_ptr = GET_PTR( joining_xp );
    916             joining_cxy = GET_CXY( joining_xp );
    917            
    918             // reset the join_done flag in target thread
    919             hal_remote_atomic_and( target_flags_xp , ~THREAD_FLAG_JOIN_DONE );
    920 
    921             // unblock the joining thread
    922             thread_unblock( joining_xp , THREAD_BLOCKED_JOIN );
    923 
    924             // release the join_lock in target thread descriptor
    925             remote_spinlock_unlock( target_join_lock_xp );
    926 
    927             // restore IRQs
    928             hal_restore_irq( save_sr );
    929         }
    930         else                // this thread arrived first
    931         {
    932             // set the kill_done flag in target thread
    933             hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_KILL_DONE );
    934 
    935             // block this thread on BLOCKED_JOIN
    936             thread_block( killer_xp , THREAD_BLOCKED_JOIN );
    937 
    938             // set extended pointer on killer thread in target thread
    939             hal_remote_swd( target_join_xp_xp , killer_xp );
    940 
    941             // release the join_lock in target thread descriptor
    942             remote_spinlock_unlock( target_join_lock_xp );
    943 
    944             // deschedule
    945             sched_yield( "killer thread wait joining thread" );
    946 
    947             // restore IRQs
    948             hal_restore_irq( save_sr );
    949         }
    950     }  // end if attached
    951 
    952     // - if the target thread is the main thread
    953     //   => synchronize with the parent process main thread
    954     // - if the target thread is not the main thread
    955     //   => simply mark the target thread for delete
    956 
    957     // get pointer on target thread process
    958     target_process_xp  = XPTR( target_cxy , &target_ptr->process );
    959     target_process     = (process_t *)hal_remote_lpt( target_process_xp );
    960 
    961         // get target process owner cluster
    962         target_pid = hal_remote_lw( XPTR( target_cxy , &target_process->pid ) );
    963     owner_cxy = CXY_FROM_PID( target_pid );
    964 
    965     // get target thread local index
    966     target_trdid = hal_remote_lw( XPTR( target_cxy , &target_ptr->trdid ) );
    967     target_ltid  = LTID_FROM_TRDID( target_trdid );
    968 
    969     if( (owner_cxy == target_cxy) && (target_ltid == 0) )     // main thread
    970     {
    971         // get extended pointer on term_state in target process owner cluster
    972         process_state_xp = XPTR( owner_cxy , &target_process->term_state );
    973 
    974         // set termination info in target process owner 
    975         if( is_exit ) hal_remote_atomic_or( process_state_xp , PROCESS_TERM_EXIT );
    976         else          hal_remote_atomic_or( process_state_xp , PROCESS_TERM_KILL );
    977 
    978 #if DEBUG_THREAD_DELETE
    979 cycle  = (uint32_t)hal_get_cycles;
    980 if( DEBUG_THREAD_DELETE < cycle )
    981 printk("\n[DBG] %s : thread %x exit for thread %x / main thread / cycle %d\n",
    982 __FUNCTION__, killer_ptr, target_ptr, cycle );
    983 #endif
    984 
    985     }
    986     else                                                      // main thread
    987     {
    988         // set the REQ_DELETE flag in target thread descriptor
    989         hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_REQ_DELETE );
    990 
    991 #if DEBUG_THREAD_DELETE
    992 cycle  = (uint32_t)hal_get_cycles;
    993 if( DEBUG_THREAD_DELETE < cycle )
    994 printk("\n[DBG] %s : thread %x exit for thread %x / not the main thread / cycle %d\n",
    995 __FUNCTION__, killer_ptr, target_ptr, cycle );
    996 #endif
    997 
    998     }
    999 
    1000 }  // end thread_kill()
    1001 
    1002 */
    1003863
    1004864//////////////////////////////////////
     
    1131991void thread_idle_func()
    1132992{
     993
     994#if DEBUG_THREAD_IDLE
     995uint32_t cycle;
     996#endif
     997
    1133998    while( 1 )
    1134999    {
     
    11401005        {
    11411006
    1142 #if DEBUG_THREAD_IDLE
    1143 uint32_t cycle  = (uint32_t)hal_get_cycles;
    1144 thread_t * this = CURRENT_THREAD;
    1145 if( DEBUG_THREAD_IDLE < cycle )
    1146 printk("\n[DBG] %s : idle thread %x on core[%x,%d] goes to sleep / cycle %d\n",
    1147 __FUNCTION__, this, local_cxy, this->core->lid, cycle );
    1148 #endif
    1149 
    1150             hal_core_sleep();
    1151 
    1152 #if DEBUG_THREAD_IDLE
     1007#if (DEBUG_THREAD_IDLE & 1)
    11531008cycle  = (uint32_t)hal_get_cycles;
    11541009if( DEBUG_THREAD_IDLE < cycle )
    1155 printk("\n[DBG] %s : idle thread %x on core[%x,%d] wake up / cycle %d\n",
     1010printk("\n[DBG] %s : idle thread on core[%x,%d] goes to sleep / cycle %d\n",
     1011__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cycle );
     1012#endif
     1013
     1014            hal_core_sleep();
     1015
     1016#if (DEBUG_THREAD_IDLE & 1)
     1017cycle  = (uint32_t)hal_get_cycles;
     1018if( DEBUG_THREAD_IDLE < cycle )
     1019printk("\n[DBG] %s : idle thread on core[%x,%d] wake up / cycle %d\n",
    11561020__FUNCTION__, this, local_cxy, this->core->lid, cycle );
    11571021#endif
    11581022
    11591023        }
     1024
     1025#if DEBUG_THREAD_IDLE
     1026sched_display( CURRENT_THREAD->core->lid );
     1027#endif     
    11601028
    11611029        // search a runable thread
  • trunk/kernel/kern/thread.h

    r443 r446  
    9191#define THREAD_BLOCKED_RPC       0x0200  /*! thread wait RPC completion               */
    9292#define THREAD_BLOCKED_ISR       0x0400  /*! thread DEV wait ISR                      */
    93 #define THREAD_BLOCKED_WAIT      0x0800  /*! thread parent wait child termination     */
     93#define THREAD_BLOCKED_WAIT      0x0800  /*! thread wait child process termination    */
    9494
    9595/***************************************************************************************
  • trunk/kernel/kernel_config.h

    r445 r446  
    3636////////////////////////////////////////////////////////////////////////////////////////////
    3737
    38 
    39 
    4038#define DEBUG_CHDEV_CMD_RX             0
    4139#define DEBUG_CHDEV_CMD_TX             0
     
    9795#define DEBUG_PROCESS_GET_LOCAL_COPY   0
    9896#define DEBUG_PROCESS_INIT_CREATE      0
    99 #define DEBUG_PROCESS_MAKE_EXEC        1
     97#define DEBUG_PROCESS_MAKE_EXEC        0
    10098#define DEBUG_PROCESS_MAKE_FORK        0
    10199#define DEBUG_PROCESS_REFERENCE_INIT   0
     
    118116#define DEBUG_RPC_VMM_GET_VSEG         0
    119117
    120 #define DEBUG_SCHED_HANDLE_SIGNALS     2
    121 #define DEBUG_SCHED_YIELD              2    // dynamically activated by the trace() syscall
     118#define DEBUG_SCHED_HANDLE_SIGNALS     1
     119#define DEBUG_SCHED_YIELD              1    // must be activated by the trace() syscall
    122120
    123121#define DEBUG_SYSCALLS_ERROR           2
     
    127125#define DEBUG_SYS_EXIT                 1
    128126#define DEBUG_SYS_FG                   0
    129 #define DEBUG_SYS_FORK                 0
     127#define DEBUG_SYS_FORK                 1
    130128#define DEBUG_SYS_GET_CONFIG           0
    131129#define DEBUG_SYS_ISATTY               0
    132 #define DEBUG_SYS_KILL                 2
     130#define DEBUG_SYS_KILL                 1
    133131#define DEBUG_SYS_MMAP                 0
    134 #define DEBUG_SYS_READ                 0
     132#define DEBUG_SYS_READ                 2
    135133#define DEBUG_SYS_THREAD_CANCEL        0
    136134#define DEBUG_SYS_THREAD_CREATE        0
     
    139137#define DEBUG_SYS_THREAD_SLEEP         0
    140138#define DEBUG_SYS_THREAD_WAKEUP        0
    141 #define DEBUG_SYS_THREAD_YIELD         2
     139#define DEBUG_SYS_THREAD_YIELD         0
    142140#define DEBUG_SYS_TRACE                0
    143141#define DEBUG_SYS_WAIT                 0
    144 #define DEBUG_SYS_WRITE                0
     142#define DEBUG_SYS_WRITE                2
    145143
    146144#define DEBUG_SPINLOCKS                0
     
    154152#define DEBUG_THREAD_KERNEL_CREATE     0
    155153#define DEBUG_THREAD_KILL              0
    156 #define DEBUG_THREAD_USER_CREATE       2
     154#define DEBUG_THREAD_USER_CREATE       0
    157155#define DEBUG_THREAD_USER_FORK         0
    158 #define DEBUG_THREAD_BLOCK             0
     156#define DEBUG_THREAD_BLOCK             15000001
    159157
    160158#define DEBUG_VFS_INODE_CREATE         0
  • trunk/kernel/syscalls/sys_exit.c

    r445 r446  
    3636int sys_exit( uint32_t status )
    3737{
    38     reg_t       save_sr;       // required to enable IRQs
     38    reg_t       save_sr;           // required to enable IRQs
     39
     40    xptr_t      owner_xp;          // extended pointer on owner process
     41    cxy_t       owner_cxy;         // owner process cluster
     42    process_t * owner_ptr;         // local pointer on owner process
     43    thread_t  * main_ptr;          // local pointer on process main thread
     44    xptr_t      parent_xp;         // extended pointer on parent process
     45    cxy_t       parent_cxy;        // parent process cluster
     46    process_t * parent_ptr;        // local pointer on parent process
     47    xptr_t      children_lock_xp;  // extended pointer on children locki
     48    thread_t  * parent_main_ptr;   // local pointer on parent main thread
     49    xptr_t      parent_main_xp;    // extended pointer on parent main thread
     50    uint32_t    term_state;        // termination status for owner process
    3951
    4052    thread_t  * this    = CURRENT_THREAD;
     
    5264
    5365    // get owner process descriptor pointers
    54     xptr_t      owner_xp  = process->owner_xp;
    55     cxy_t       owner_cxy = GET_CXY( owner_xp );
    56     process_t * owner_ptr = GET_PTR( owner_xp );
     66    owner_xp  = process->owner_xp;
     67    owner_cxy = GET_CXY( owner_xp );
     68    owner_ptr = GET_PTR( owner_xp );
    5769
    58     // get pointers on the process main thread
    59     thread_t * main    = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) );
    60 
    61     // enable IRQs
    62     hal_enable_irq( &save_sr );
    63 
    64     // mark for delete all process threads in all clusters,
    65     // but the main thread and this calling thread
    66     process_sigaction( pid , DELETE_ALL_THREADS );
    67 
    68     // disable IRQs
    69     hal_restore_irq( save_sr );
    70 
    71 #if( DEBUG_SYS_EXIT & 1)
    72 if( tm_start > DEBUG_SYS_EXIT )
    73 printk("\n[DBG] %s : thread %x deleted threads / process %x\n",
    74 __FUNCTION__ , this, pid );
     70#if (DEBUG_SYS_EXIT & 1)
     71if( DEBUG_SYS_EXIT < tm_start )
     72printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n",
     73__FUNCTION__ , this, owner_ptr, owner_cxy );
    7574#endif
    7675
    77     // mark for delete this calling thread when it is not the main
    78     if( (owner_cxy != local_cxy) || (main != this) )
    79     {
     76    // get pointer on the process main thread
     77    main_ptr  = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) );
    8078
    81 #if( DEBUG_SYS_EXIT & 1)
    82 if( tm_start > DEBUG_SYS_EXIT )
    83 printk("\n[DBG] %s : calling thread %x marked iself for delete / process %x\n",
    84 __FUNCTION__ , this, pid );
     79    // get parent process descriptor pointers
     80    parent_xp  = process->parent_xp;
     81    parent_cxy = GET_CXY( parent_xp );
     82    parent_ptr = GET_PTR( parent_xp );
     83
     84#if (DEBUG_SYS_EXIT & 1)
     85if( DEBUG_SYS_EXIT < tm_start )
     86printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",
     87__FUNCTION__ , this, parent_ptr, parent_cxy );
    8588#endif
    86         thread_delete( XPTR( local_cxy , this ) , pid , true );
    87     }
     89
     90    // get extended pointer on lock protecting children list in parent process
     91    children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     92
     93    // get pointers on the parent process main thread
     94    parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );
     95    parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
    8896
    8997    // remove process from TXT list
     
    96104#endif
    97105
    98     // block the main thread
    99     thread_block( XPTR( owner_cxy , main ) , THREAD_BLOCKED_GLOBAL );
     106    // mark for delete all process threads in all clusters,
     107    // but the main thread and this calling thread
     108    hal_enable_irq( &save_sr );
     109    process_sigaction( pid , DELETE_ALL_THREADS );
     110    hal_restore_irq( save_sr );
     111
     112#if( DEBUG_SYS_EXIT & 1)
     113if( tm_start > DEBUG_SYS_EXIT )
     114printk("\n[DBG] %s : thread %x deleted threads for process %x\n",
     115__FUNCTION__ , this, pid );
     116#endif
     117
     118    // mark for delete this calling thread when it is not the main
     119    if( (owner_cxy != local_cxy) || (main_ptr != this) )
     120    {
     121
     122#if( DEBUG_SYS_EXIT & 1)
     123if( tm_start > DEBUG_SYS_EXIT )
     124printk("\n[DBG] %s : calling thread %x marked iself for delete in process %x\n",
     125__FUNCTION__ , this, pid );
     126#endif
     127        thread_delete( XPTR( local_cxy , this ) , pid , true );
     128    }
     129
     130    // block this main thread
     131    thread_block( XPTR( owner_cxy , main_ptr ) , THREAD_BLOCKED_GLOBAL );
    100132
    101133#if( DEBUG_SYS_EXIT & 1)
     
    107139    // atomically update owner process descriptor term_state to ask
    108140    // the parent process sys_wait() function to delete the main thread
    109     hal_remote_atomic_or( XPTR( owner_cxy , &process->term_state ) ,
    110                           PROCESS_TERM_EXIT | (status & 0xFF) );
     141    term_state = (status & 0xFF) | PROCESS_TERM_EXIT;
     142    hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , term_state );
    111143
    112144#if( DEBUG_SYS_EXIT & 1)
    113145if( tm_start > DEBUG_SYS_EXIT )
    114 printk("\n[DBG] %s : thread %x set exit status in process %x term_state\n",
    115 __FUNCTION__ , this, pid );
     146printk("\n[DBG] %s : thread %x set exit status in process %x / term_state %x\n",
     147__FUNCTION__ , this, pid, term_state );
     148#endif
     149
     150    // take the children lock and unblock the parent process main thread
     151    remote_spinlock_lock( children_lock_xp );
     152    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     153    remote_spinlock_unlock( children_lock_xp );
     154
     155#if( DEBUG_SYS_EXIT & 1)
     156if( tm_start > DEBUG_SYS_EXIT )
     157printk("\n[DBG] %s : thread %x in cluster %x unblock parent main thread %x in cluster %x\n",
     158__FUNCTION__ , this, local_cxy, parent_main_ptr, parent_cxy );
    116159#endif
    117160
  • trunk/kernel/syscalls/sys_fg.c

    r443 r446  
    3333#include <rpc.h>
    3434
    35 //////////////////////////
    36 int sys_fg( pid_t    pid )
     35///////////////////////
     36int sys_fg( pid_t pid )
    3737{
    3838    xptr_t      process_xp;     // extended pointer on reference process descriptor
     
    8585    hal_remote_swd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) , process_xp );
    8686
     87    // reset PROCESS_TERM_WAIT and PROCESS_TERM_STOP flags in process term_state
     88    hal_remote_atomic_and( XPTR( process_cxy , &process_ptr->term_state ),
     89                                 ~(PROCESS_TERM_WAIT | PROCESS_TERM_STOP) );
     90 
    8791    hal_fence();
    8892
  • trunk/kernel/syscalls/sys_kill.c

    r440 r446  
    3737              uint32_t sig_id )
    3838{
    39     xptr_t      owner_xp;      // extended pointer on target process in owner cluster
    40     cxy_t       owner_cxy;     // target process in owner cluster
    41     process_t * owner_ptr;     // local pointer on target process in owner cluster
    42     uint32_t    retval;        // return value for the switch
     39    reg_t       save_sr;           // required to enable IRQs
     40    xptr_t      owner_xp;          // extended pointer on process in owner cluster
     41    cxy_t       owner_cxy;         // process owner cluster
     42    process_t * owner_ptr;         // local pointer on process in owner cluster
     43    uint32_t    retval;            // return value for the switch
     44    xptr_t      parent_xp;         // extended pointer on parent process
     45    cxy_t       parent_cxy;        // parent process cluster
     46    process_t * parent_ptr;        // local pointer on parent process
     47    xptr_t      children_lock_xp;  // extended pointer on children lock in parent
     48    thread_t  * parent_main_ptr;   // local pointer on parent main thread
     49    xptr_t      parent_main_xp;    // extended pointer on parent main thread
    4350
    4451    thread_t  * this    = CURRENT_THREAD;
     
    5966    owner_ptr = GET_PTR( owner_xp );
    6067   
     68#if (DEBUG_SYS_KILL & 1)
     69if( DEBUG_SYS_KILL < tm_start )
     70printk("\n[DBG] %s : thread %x found process %x in cluster %x\n",
     71__FUNCTION__ , this, owner_ptr, owner_cxy );
     72#endif
     73
    6174    // check process found
    6275    if( owner_xp == XPTR_NULL)
     
    92105    }
    93106
     107    // get parent process descriptor pointers
     108    parent_xp  = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) );
     109    parent_cxy = GET_CXY( parent_xp );
     110    parent_ptr = GET_PTR( parent_xp );
     111
     112#if (DEBUG_SYS_KILL & 1)
     113if( DEBUG_SYS_KILL < tm_start )
     114printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",
     115__FUNCTION__ , this, parent_ptr, parent_cxy );
     116#endif
     117
     118    // get extended pointer on lock protecting children list in parent process
     119    children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     120
     121    // get pointers on the parent process main thread
     122    parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );
     123    parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
     124
    94125    // analyse signal type / supported values are : 0, SIGSTOP, SIGCONT, SIGKILL
    95126    switch( sig_id )
     
    108139            process_sigaction( pid , BLOCK_ALL_THREADS );
    109140
    110             // get pointer on target process main thread
     141            // block the main thread
    111142            xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );
    112 
    113             // block main thread
    114143            thread_block( main_xp , THREAD_BLOCKED_GLOBAL );
    115144
     
    117146            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    118147                                  PROCESS_TERM_STOP );
     148
     149            // take the children lock and unblock the parent process main thread
     150            remote_spinlock_lock( children_lock_xp );
     151            thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     152            remote_spinlock_unlock( children_lock_xp );
     153
    119154            retval = 0;
    120155            break;
     
    137172            process_txt_detach( owner_xp );
    138173
    139             // mark for delete all process threads in all clusters, but the main
     174            // mark for delete all threads in all clusters, but the main
     175            hal_enable_irq( &save_sr );
    140176            process_sigaction( pid , DELETE_ALL_THREADS );
    141 
    142             // get pointer on target process main thread
     177            hal_restore_irq( save_sr );
     178
     179            // block main thread
    143180            xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );
    144 
    145             // block main thread
    146181            thread_block( main_xp , THREAD_BLOCKED_GLOBAL );
    147182
     
    150185            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    151186                                  PROCESS_TERM_KILL );
     187
     188            // take the children lock and unblock the parent process main thread
     189            remote_spinlock_lock( children_lock_xp );
     190            thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     191            remote_spinlock_unlock( children_lock_xp );
     192
    152193            retval = 0;
    153194            break;
  • trunk/kernel/syscalls/sys_read.c

    r443 r446  
    6363    reg_t        save_sr;     // required to enable IRQs during syscall
    6464
    65         thread_t  *  this    = CURRENT_THREAD;
    66         process_t *  process = this->process;
     65        thread_t  *  this             = CURRENT_THREAD;
     66        process_t *  process          = this->process;
     67    xptr_t       process_owner_xp = process->owner_xp;
    6768 
    6869#if DEBUG_SYS_READ
     
    165166                                count );
    166167    }
    167     else if( type == INODE_TYPE_DEV )  // check ownership & read from from device
     168    else if( type == INODE_TYPE_DEV )  // check ownership & read from device
    168169    {
    169170        // get cluster and pointers on TXT_RX chdev
     
    172173        chdev_t * chdev_ptr = GET_PTR( chdev_xp );
    173174
    174         volatile xptr_t    owner_xp;   
     175        volatile xptr_t    txt_owner_xp;   
     176        uint32_t           iter = 0;
    175177
    176178        while( 1 )
    177179        {
    178             // extended pointer on owner process
    179             owner_xp  = hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
     180            // extended pointer on TXT owner process
     181            txt_owner_xp  = hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
    180182
    181183            // check TXT_RX ownership
    182             if ( XPTR( local_cxy , process ) != owner_xp )
     184            if ( process_owner_xp != txt_owner_xp )
    183185            {
     186                if( (iter & 0xFFF) == 0 )
     187                printk("\n[WARNING] in %s : thread %x in process %x wait TXT_RX / cycle %d\n",
     188                __FUNCTION__, this->trdid, process->pid, (uint32_t)hal_get_cycles() );
     189
    184190                // deschedule without blocking
    185                 sched_yield( "wait TXT ownership" );
     191                sched_yield( "wait TXT_RX ownership" );
     192
     193                iter++;
    186194            }
    187195            else
     
    191199        }
    192200
     201printk("\n###### in %s : thread %x in process %x got TXT_RX ownership\n",
     202__FUNCTION__, this->trdid, process->pid );
     203               
    193204        // move count bytes from device
    194205        nbytes = devfs_user_move( true,             // from device to buffer
  • trunk/kernel/syscalls/sys_wait.c

    r443 r446  
    4141    cxy_t       child_cxy;
    4242    pid_t       child_pid;
    43     int         child_state;
     43    uint32_t    child_state;
    4444    thread_t  * child_thread;
    4545    reg_t       save_sr;
     
    5050
    5151#if DEBUG_SYS_WAIT
    52 uint64_t    tm_start;
    53 uint64_t    tm_end;
    54 tm_start = hal_get_cycles();
    55 if( DEBUG_SYS_WAIT < tm_start )
    56 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    57 __FUNCTION__, this, process->pid, (uint32_t)tm_start );
     52uint64_t    cycle = hal_get_cycles();
     53if( DEBUG_SYS_WAIT < cycle )
     54printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
     55__FUNCTION__, this, process->pid, (uint32_t)cycle );
    5856#endif
    5957
     
    8381    {
    8482
    85 #if DEBUG_SYSCALL_ERROR
     83#if DEBUG_SYSCALLS_ERROR
    8684printk("\n[ERROR] in %s : calling thread %x is not thread 0 in owner cluster %x\n",
    8785__FUNCTION__ , trdid , owner_cxy );
     
    112110            child_cxy = GET_CXY( child_xp );
    113111
    114             // get term_state from child owner process
    115             child_state = (int)hal_remote_lw ( XPTR(child_cxy,&child_ptr->term_state));
     112            // get PID, term_state, and main thread from child process
     113            child_pid    = hal_remote_lw (XPTR( child_cxy , &child_ptr->pid ));
     114            child_state  = hal_remote_lw ( XPTR(child_cxy , &child_ptr->term_state ) );
     115            child_thread = hal_remote_lpt(XPTR( child_cxy , &child_ptr->th_tbl[0] ));
    116116
     117#if (DEBUG_SYS_WAIT &1)
     118cycle = hal_get_cycles();
     119if( DEBUG_SYS_WAIT < cycle )
     120printk("\n[DBG] %s : thread %x in process %x check child %x / state %x\n",
     121__FUNCTION__, this, process->pid, child_pid, child_state );
     122#endif
    117123            // test if this child process is terminated,
    118124            // but termination not yet reported to parent process
     
    122128                 ((child_state & PROCESS_TERM_WAIT) == 0) )
    123129            {
    124                 // get pointer on child main thread and PID from child owner process
    125                 child_pid    = (pid_t)     hal_remote_lw (XPTR( child_cxy , &child_ptr->pid ));
    126                 child_thread = (thread_t *)hal_remote_lpt(XPTR( child_cxy ,
    127                                                                 &child_ptr->th_tbl[0] ));
    128 
    129                 // set the PROCESS_FLAG_WAIT in owner child process descriptor
     130                // set the PROCESS_FLAG_WAIT in child process descriptor
    130131                hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ),
    131132                                      PROCESS_TERM_WAIT );
    132133
    133                 // set the THREAD_FLAG_REQ_DELETE in child main thread
     134                // set the THREAD_FLAG_REQ_DELETE in main thread if kill or exit
     135                if((child_state & PROCESS_TERM_EXIT) || (child_state & PROCESS_TERM_KILL))
    134136                hal_remote_atomic_or( XPTR( child_cxy , &child_thread->flags ) ,
    135137                                            THREAD_FLAG_REQ_DELETE );
     
    139141
    140142#if DEBUG_SYS_WAIT
    141 tm_end = hal_get_cycles();
    142 if( DEBUG_SYS_WAIT < tm_end )
    143 printk("\n[DBG] %s : thread %x exit / parent %x / child %x / cycle %d\n",
    144 __FUNCTION__, this, process->pid, child_pid, (uint32_t)tm_end );
     143cycle = hal_get_cycles();
     144if( DEBUG_SYS_WAIT < cycle )
     145{
     146    if     ( child_state & PROCESS_TERM_EXIT )
     147        printk("\n[DBG] %s : thread %x in process %x exit / child %x exit / cycle %d\n",
     148        __FUNCTION__, this, process->pid, child_pid, (uint32_t)cycle );
     149    if( child_state & PROCESS_TERM_KILL )
     150        printk("\n[DBG] %s : thread %x in process %x exit / child %x killed / cycle %d\n",
     151        __FUNCTION__, this, process->pid, child_pid, (uint32_t)cycle );
     152    if( child_state & PROCESS_TERM_STOP )
     153        printk("\n[DBG] %s : thread %x in process %x exit / child %x stopped / cycle %d\n",
     154        __FUNCTION__, this, process->pid, child_pid, (uint32_t)cycle );
     155}
    145156#endif
    146157                 // return child termination state  to parent process
     
    150161        }  // end loop on children
    151162       
     163        // block on WAIT condition
     164        thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_WAIT );
     165
    152166        // release lock protecting children list
    153167        remote_spinlock_unlock( children_lock_xp );
    154168
    155         // deschedule without blocking
    156         sched_yield( "parent wait children termination" );
     169#if (DEBUG_SYS_WAIT & 1)
     170cycle = hal_get_cycles();
     171if( DEBUG_SYS_WAIT < cycle )
     172printk("\n[DBG] %s : thread %x in process %x block & deschedule / cycle %d\n",
     173__FUNCTION__, this, process->pid, (uint32_t)cycle );
     174#endif
     175
     176        // deschedule
     177        sched_yield( "parent process wait children processes termination" );
     178
     179#if (DEBUG_SYS_WAIT & 1)
     180cycle = hal_get_cycles();
     181if( DEBUG_SYS_WAIT < cycle )
     182printk("\n[DBG] %s : thread %x in process %x unblock & resume / cycle %d\n",
     183__FUNCTION__, this, process->pid, (uint32_t)cycle );
     184#endif
    157185
    158186    }  // end while
Note: See TracChangeset for help on using the changeset viewer.