Changeset 446 for trunk/kernel/syscalls
- Timestamp:
- Jun 19, 2018, 5:12:57 PM (7 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_exit.c
r445 r446 36 36 int sys_exit( uint32_t status ) 37 37 { 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 39 51 40 52 thread_t * this = CURRENT_THREAD; … … 52 64 53 65 // get owner process descriptor pointers 54 xptr_towner_xp = process->owner_xp;55 cxy_towner_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 ); 57 69 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) 71 if( DEBUG_SYS_EXIT < tm_start ) 72 printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n", 73 __FUNCTION__ , this, owner_ptr, owner_cxy ); 75 74 #endif 76 75 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] ) ); 80 78 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) 85 if( DEBUG_SYS_EXIT < tm_start ) 86 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n", 87 __FUNCTION__ , this, parent_ptr, parent_cxy ); 85 88 #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 ); 88 96 89 97 // remove process from TXT list … … 96 104 #endif 97 105 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) 113 if( tm_start > DEBUG_SYS_EXIT ) 114 printk("\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) 123 if( tm_start > DEBUG_SYS_EXIT ) 124 printk("\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 ); 100 132 101 133 #if( DEBUG_SYS_EXIT & 1) … … 107 139 // atomically update owner process descriptor term_state to ask 108 140 // 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 ); 111 143 112 144 #if( DEBUG_SYS_EXIT & 1) 113 145 if( 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 ); 146 printk("\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) 156 if( tm_start > DEBUG_SYS_EXIT ) 157 printk("\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 ); 116 159 #endif 117 160 -
trunk/kernel/syscalls/sys_fg.c
r443 r446 33 33 #include <rpc.h> 34 34 35 /////////////////////// ///36 int sys_fg( pid_t 35 /////////////////////// 36 int sys_fg( pid_t pid ) 37 37 { 38 38 xptr_t process_xp; // extended pointer on reference process descriptor … … 85 85 hal_remote_swd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) , process_xp ); 86 86 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 87 91 hal_fence(); 88 92 -
trunk/kernel/syscalls/sys_kill.c
r440 r446 37 37 uint32_t sig_id ) 38 38 { 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 43 50 44 51 thread_t * this = CURRENT_THREAD; … … 59 66 owner_ptr = GET_PTR( owner_xp ); 60 67 68 #if (DEBUG_SYS_KILL & 1) 69 if( DEBUG_SYS_KILL < tm_start ) 70 printk("\n[DBG] %s : thread %x found process %x in cluster %x\n", 71 __FUNCTION__ , this, owner_ptr, owner_cxy ); 72 #endif 73 61 74 // check process found 62 75 if( owner_xp == XPTR_NULL) … … 92 105 } 93 106 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) 113 if( DEBUG_SYS_KILL < tm_start ) 114 printk("\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 94 125 // analyse signal type / supported values are : 0, SIGSTOP, SIGCONT, SIGKILL 95 126 switch( sig_id ) … … 108 139 process_sigaction( pid , BLOCK_ALL_THREADS ); 109 140 110 // get pointer on target processmain thread141 // block the main thread 111 142 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 112 113 // block main thread114 143 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 115 144 … … 117 146 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 118 147 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 119 154 retval = 0; 120 155 break; … … 137 172 process_txt_detach( owner_xp ); 138 173 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 ); 140 176 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 143 180 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 144 145 // block main thread146 181 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 147 182 … … 150 185 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 151 186 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 152 193 retval = 0; 153 194 break; -
trunk/kernel/syscalls/sys_read.c
r443 r446 63 63 reg_t save_sr; // required to enable IRQs during syscall 64 64 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; 67 68 68 69 #if DEBUG_SYS_READ … … 165 166 count ); 166 167 } 167 else if( type == INODE_TYPE_DEV ) // check ownership & read from fromdevice168 else if( type == INODE_TYPE_DEV ) // check ownership & read from device 168 169 { 169 170 // get cluster and pointers on TXT_RX chdev … … 172 173 chdev_t * chdev_ptr = GET_PTR( chdev_xp ); 173 174 174 volatile xptr_t owner_xp; 175 volatile xptr_t txt_owner_xp; 176 uint32_t iter = 0; 175 177 176 178 while( 1 ) 177 179 { 178 // extended pointer on owner process179 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 ) ); 180 182 181 183 // check TXT_RX ownership 182 if ( XPTR( local_cxy , process ) !=owner_xp )184 if ( process_owner_xp != txt_owner_xp ) 183 185 { 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 184 190 // deschedule without blocking 185 sched_yield( "wait TXT ownership" ); 191 sched_yield( "wait TXT_RX ownership" ); 192 193 iter++; 186 194 } 187 195 else … … 191 199 } 192 200 201 printk("\n###### in %s : thread %x in process %x got TXT_RX ownership\n", 202 __FUNCTION__, this->trdid, process->pid ); 203 193 204 // move count bytes from device 194 205 nbytes = devfs_user_move( true, // from device to buffer -
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.