Changeset 446 for trunk/kernel/syscalls/sys_wait.c
- Timestamp:
- Jun 19, 2018, 5:12:57 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_wait.c
r443 r446 41 41 cxy_t child_cxy; 42 42 pid_t child_pid; 43 intchild_state;43 uint32_t child_state; 44 44 thread_t * child_thread; 45 45 reg_t save_sr; … … 50 50 51 51 #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 ); 52 uint64_t cycle = hal_get_cycles(); 53 if( DEBUG_SYS_WAIT < cycle ) 54 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n", 55 __FUNCTION__, this, process->pid, (uint32_t)cycle ); 58 56 #endif 59 57 … … 83 81 { 84 82 85 #if DEBUG_SYSCALL _ERROR83 #if DEBUG_SYSCALLS_ERROR 86 84 printk("\n[ERROR] in %s : calling thread %x is not thread 0 in owner cluster %x\n", 87 85 __FUNCTION__ , trdid , owner_cxy ); … … 112 110 child_cxy = GET_CXY( child_xp ); 113 111 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] )); 116 116 117 #if (DEBUG_SYS_WAIT &1) 118 cycle = hal_get_cycles(); 119 if( DEBUG_SYS_WAIT < cycle ) 120 printk("\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 117 123 // test if this child process is terminated, 118 124 // but termination not yet reported to parent process … … 122 128 ((child_state & PROCESS_TERM_WAIT) == 0) ) 123 129 { 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 130 131 hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ), 131 132 PROCESS_TERM_WAIT ); 132 133 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)) 134 136 hal_remote_atomic_or( XPTR( child_cxy , &child_thread->flags ) , 135 137 THREAD_FLAG_REQ_DELETE ); … … 139 141 140 142 #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 ); 143 cycle = hal_get_cycles(); 144 if( 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 } 145 156 #endif 146 157 // return child termination state to parent process … … 150 161 } // end loop on children 151 162 163 // block on WAIT condition 164 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_WAIT ); 165 152 166 // release lock protecting children list 153 167 remote_spinlock_unlock( children_lock_xp ); 154 168 155 // deschedule without blocking 156 sched_yield( "parent wait children termination" ); 169 #if (DEBUG_SYS_WAIT & 1) 170 cycle = hal_get_cycles(); 171 if( DEBUG_SYS_WAIT < cycle ) 172 printk("\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) 180 cycle = hal_get_cycles(); 181 if( DEBUG_SYS_WAIT < cycle ) 182 printk("\n[DBG] %s : thread %x in process %x unblock & resume / cycle %d\n", 183 __FUNCTION__, this, process->pid, (uint32_t)cycle ); 184 #endif 157 185 158 186 } // end while
Note: See TracChangeset
for help on using the changeset viewer.