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

miscelaneous...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.