Changeset 584 for trunk/kernel
- Timestamp:
- Nov 1, 2018, 12:13:45 PM (6 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_include/shared_signal.h
r445 r584 27 27 /******************************************************************************************* 28 28 * This defines the signal type mnemonics for the kill() syscall. 29 * WARNING : Only the three SIGKILL / SIGSTOP / SIGCONT are supported (december 2017) 29 * WARNING : Only the three SIGKILL / SIGSTOP / SIGCONT are supported by the 30 * sys_kill() function ( [AG] december 2017 ) 30 31 ******************************************************************************************/ 31 32 -
trunk/kernel/syscalls/shared_include/syscalls_numbers.h
r566 r584 78 78 SYS_GET_CYCLE = 42, 79 79 SYS_DISPLAY = 43, 80 SYS_ UNDEFINED = 44, ///80 SYS_PLACE_FORK = 44, 81 81 SYS_THREAD_SLEEP = 45, 82 82 SYS_THREAD_WAKEUP = 46, -
trunk/kernel/syscalls/sys_display.c
r580 r584 203 203 else if( type == DISPLAY_CLUSTER_PROCESSES ) 204 204 { 205 cxy_t cxy = (cxy_t)arg0; 205 cxy_t cxy = (cxy_t)arg0; 206 bool_t owned = (bool_t)arg1; 206 207 207 208 // check cxy argument … … 217 218 } 218 219 219 cluster_processes_display( cxy );220 cluster_processes_display( cxy , owned ); 220 221 } 221 222 ////////////////////////////// -
trunk/kernel/syscalls/sys_exec.c
r566 r584 196 196 197 197 #if DEBUG_SYSCALLS_ERROR 198 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 198 printk("\n[ERROR] in %s : thread[%x,%x] pathname too long\n", 199 __FUNCTION__, pid, this->trdid ); 199 200 #endif 200 201 this->errno = ENFILE; … … 207 208 #if DEBUG_SYS_EXEC 208 209 if( DEBUG_SYS_EXEC < tm_start ) 209 printk("\n[DBG] %s : thread %x in process %xenter for path <%s> / cycle = %d\n",210 __FUNCTION__, this->trdid, pid, exec_info.path, (uint32_t)tm_start );210 printk("\n[DBG] %s : thread[%x,%x] enter for path <%s> / cycle = %d\n", 211 __FUNCTION__, pid, this->trdid, exec_info.path, (uint32_t)tm_start ); 211 212 #endif 212 213 … … 218 219 219 220 #if DEBUG_SYSCALLS_ERROR 220 printk("\n[ERROR] in %s : thread %x in process %x cannot access args\n",221 __FUNCTION__ , this->trdid, pid);221 printk("\n[ERROR] in %s : thread[%x,%x] cannot access args for <%s>\n", 222 __FUNCTION__, pid, this->trdid, exec_info.path ); 222 223 #endif 223 224 this->errno = EINVAL; … … 233 234 234 235 #if DEBUG_SYSCALLS_ERROR 235 printk("\n[ERROR] in %s : thread %x in process %x cannot access envs\n",236 __FUNCTION__ , this->trdid, pid);236 printk("\n[ERROR] in %s : thread[%x,%x] cannot access envs for <%s>\n", 237 __FUNCTION__ , pid, this->trdid, exec_info.path ); 237 238 #endif 238 239 this->errno = EINVAL; … … 248 249 249 250 #if DEBUG_SYSCALLS_ERROR 250 printk("\n[ERROR] in %s : thread %x in process %xcannot create process for <%s>\n",251 __FUNCTION__, this->trdid, pid, exec_info.path );251 printk("\n[ERROR] in %s : thread[%x,%x] cannot create process for <%s>\n", 252 __FUNCTION__, pid, this->trdid, exec_info.path ); 252 253 #endif 253 254 this->errno = error; -
trunk/kernel/syscalls/sys_exit.c
r566 r584 38 38 int sys_exit( uint32_t status ) 39 39 { 40 reg_t save_sr; // required to enable IRQs41 42 40 xptr_t owner_xp; // extended pointer on owner process 43 41 cxy_t owner_cxy; // owner process cluster … … 60 58 tm_start = hal_get_cycles(); 61 59 if( DEBUG_SYS_EXIT < tm_start ) 62 printk("\n[DBG] %s : thread %x in process %xenter / status %x / cycle %d\n",63 __FUNCTION__, this->trdid, process->pid , status , (uint32_t)tm_start );60 printk("\n[DBG] %s : thread[%x,%x] enter / status %x / cycle %d\n", 61 __FUNCTION__, process->pid, this->trdid , status , (uint32_t)tm_start ); 64 62 #endif 65 63 … … 71 69 #if (DEBUG_SYS_EXIT & 1) 72 70 if( DEBUG_SYS_EXIT < tm_start ) 73 printk("\n[DBG] %s : thread %x in process %xget owner process in cluster %x\n",74 __FUNCTION__, this->trdid, process->pid, owner_cxy );71 printk("\n[DBG] %s : thread[%x,%x] get owner process in cluster %x\n", 72 __FUNCTION__, process->pid, this->trdid, owner_cxy ); 75 73 #endif 76 74 … … 85 83 #if (DEBUG_SYS_EXIT & 1) 86 84 if( DEBUG_SYS_EXIT < tm_start ) 87 printk("\n[DBG] %s : thread %x in process %xget parent process in cluster %x\n",88 __FUNCTION__, this->trdid, process->pid, parent_cxy );85 printk("\n[DBG] %s : thread[%x,%x] get parent process in cluster %x\n", 86 __FUNCTION__, process->pid, this->trdid, parent_cxy ); 89 87 #endif 90 88 … … 98 96 #if( DEBUG_SYS_EXIT & 1) 99 97 if( DEBUG_SYS_EXIT < tm_start ) 100 printk("\n[DBG] %s : thread %x in process %xdetached process from TXT\n",101 __FUNCTION__, this->trdid, process->pid );98 printk("\n[DBG] %s : thread[%x,%x] detached process from TXT\n", 99 __FUNCTION__, process->pid, this->trdid ); 102 100 #endif 103 101 104 102 // mark for delete all process threads in all clusters, 105 103 // but the main thread and this calling thread 106 hal_enable_irq( &save_sr );107 104 process_sigaction( process->pid , DELETE_ALL_THREADS ); 108 hal_restore_irq( save_sr );109 105 110 106 #if( DEBUG_SYS_EXIT & 1) 111 107 if( DEBUG_SYS_EXIT < tm_start ) 112 printk("\n[DBG] %s : thread %x in process %xdeleted all threads but itself\n",113 __FUNCTION__, this->trdid, process->pid );108 printk("\n[DBG] %s : thread[%x,%x] deleted all threads but itself\n", 109 __FUNCTION__, process->pid, this->trdid ); 114 110 #endif 115 111 … … 120 116 #if( DEBUG_SYS_EXIT & 1) 121 117 if( tm_start > DEBUG_SYS_EXIT ) 122 printk("\n[DBG] %s : thread %x in process %xmarked iself for delete\n",123 __FUNCTION__, this->trdid, process->pid );118 printk("\n[DBG] %s : thread[%x,%x] marked iself for delete\n", 119 __FUNCTION__, process->pid, this->trdid ); 124 120 #endif 125 121 thread_delete( XPTR( local_cxy , this ) , pid , true ); … … 131 127 #if( DEBUG_SYS_EXIT & 1) 132 128 if( tm_start > DEBUG_SYS_EXIT ) 133 printk("\n[DBG] %s : thread %x in process %xblocked main thread\n",134 __FUNCTION__, this->trdid, process->pid );129 printk("\n[DBG] %s : thread[%x,%x] blocked main thread\n", 130 __FUNCTION__, process->pid, this->trdid ); 135 131 #endif 136 132 … … 142 138 #if( DEBUG_SYS_EXIT & 1) 143 139 if( tm_start > DEBUG_SYS_EXIT ) 144 printk("\n[DBG] %s : thread %x in process %xset exit status %x in owner process\n",145 __FUNCTION__, this->trdid, process->pid, term_state );140 printk("\n[DBG] %s : thread[%x,%x] set exit status %x in owner process\n", 141 __FUNCTION__, process->pid, this->trdid, term_state ); 146 142 #endif 147 143 … … 151 147 #if( DEBUG_SYS_EXIT & 1) 152 148 if( tm_start > DEBUG_SYS_EXIT ) 153 printk("\n[DBG] %s : thread %x in process %xunblocked parent main thread in process %x\n",154 __FUNCTION__ , this->trdid, process->pid,149 printk("\n[DBG] %s : thread[%x,%x] unblocked parent main thread in process %x\n", 150 __FUNCTION__ , process->pid, this->trdid, 155 151 hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid) ) ); 156 152 #endif … … 161 157 tm_end = hal_get_cycles(); 162 158 if( DEBUG_SYS_EXIT < tm_end ) 163 printk("\n[DBG] %s : thread %x in process %xexit / status %x / cost = %d / cycle %d\n",164 __FUNCTION__, this->trdid, process->pid, status,159 printk("\n[DBG] %s : thread[%x,%x] exit / status %x / cost = %d / cycle %d\n", 160 __FUNCTION__, process->pid, this->trdid, status, 165 161 (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 166 162 #endif -
trunk/kernel/syscalls/sys_fork.c
r566 r584 73 73 #if DEBUG_SYS_FORK 74 74 if( DEBUG_SYS_FORK < tm_start ) 75 printk("\n[DBG] %s : thread %x in process %xenter / cycle = %d\n",76 __FUNCTION__, parent_ thread_ptr->trdid, parent_pid, (uint32_t)tm_start );75 printk("\n[DBG] %s : thread[%x,%x] enter / cycle = %d\n", 76 __FUNCTION__, parent_pid, parent_thread_ptr->trdid, (uint32_t)tm_start ); 77 77 #endif 78 78 … … 88 88 89 89 #if DEBUG_SYSCALLS_ERROR 90 printk("\n[ERROR] in %s : thread %x in process %xcannot fork : too much children\n",91 __FUNCTION__, parent_ thread_ptr->trdid, parent_pid );90 printk("\n[ERROR] in %s : thread[%x,%x] cannot fork : too much children\n", 91 __FUNCTION__, parent_pid, parent_thread_ptr->trdid ); 92 92 #endif 93 93 hal_remote_atomic_add ( children_xp , -1 ); … … 110 110 #if (DEBUG_SYS_FORK & 1 ) 111 111 if( DEBUG_SYS_FORK < tm_start ) 112 printk("\n[DBG] %s : thread %x in process %xselected cluster %x\n",113 __FUNCTION__, parent_ thread_ptr->trdid, parent_pid, child_cxy );112 printk("\n[DBG] %s : thread[%x,%x] selected cluster %x\n", 113 __FUNCTION__, parent_pid, parent_thread_ptr->trdid, child_cxy ); 114 114 #endif 115 115 … … 136 136 137 137 #if DEBUG_SYSCALLS_ERROR 138 printk("\n[ERROR] in %s : thread %x in process %x cannot fork to cluster %x\n",139 __FUNCTION__, parent_ thread_ptr->trdid, parent_pid, local_cxy);138 printk("\n[ERROR] in %s : thread[%x,%x] cannot fork\n", 139 __FUNCTION__, parent_pid, parent_thread_ptr->trdid ); 140 140 #endif 141 141 parent_thread_ptr->errno = EAGAIN; … … 167 167 #if DEBUG_SYS_FORK 168 168 if( DEBUG_SYS_FORK < tm_end ) 169 printk("\n[DBG] %s : thread %x in process %xexit / cycle %d\n",170 __FUNCTION__, current-> trdid, current->process->pid, (uint32_t)tm_end );169 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n", 170 __FUNCTION__, current->process->pid, current->trdid, (uint32_t)tm_end ); 171 171 #endif 172 172 -
trunk/kernel/syscalls/sys_kill.c
r566 r584 35 35 #include <syscalls.h> 36 36 37 38 #if DEBUG_SYS_KILL 39 //////////////////////////////////////////// 40 static char* sig_type_str( uint32_t sig_id ) 41 { 42 switch( sig_id ) 43 { 44 case SIGKILL: return "SIGKILL"; 45 case SIGSTOP: return "SIGSTOP"; 46 case SIGCONT: return "SIGCONT"; 47 default: return "undefined"; 48 } 49 } 50 #endif 51 52 37 53 /////////////////////////// 38 54 int sys_kill( pid_t pid, 39 55 uint32_t sig_id ) 40 56 { 41 reg_t save_sr; // required to enable IRQs42 57 xptr_t owner_xp; // extended pointer on process in owner cluster 43 58 cxy_t owner_cxy; // process owner cluster 44 59 process_t * owner_ptr; // local pointer on process in owner cluster 45 uint32_t retval; // return value for the switch46 60 xptr_t parent_xp; // extended pointer on parent process 47 61 cxy_t parent_cxy; // parent process cluster … … 53 67 process_t * process = this->process; 54 68 69 #if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS) 70 uint64_t tm_start = hal_get_cycles(); 71 #endif 72 55 73 #if DEBUG_SYS_KILL 56 uint64_t tm_start;57 uint64_t tm_end;58 74 tm_start = hal_get_cycles(); 59 75 if( DEBUG_SYS_KILL < tm_start ) 60 printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cycle %d\n", 61 __FUNCTION__ , this, pid, sig_id, (uint32_t)tm_start ); 76 printk("\n[DBG] %s : thread[%x,%x] enter / process %x / %s / cycle %d\n", 77 __FUNCTION__, this->process->pid, this->trdid, pid, 78 sig_type_str(sig_id), (uint32_t)tm_start ); 62 79 #endif 63 80 … … 69 86 #if (DEBUG_SYS_KILL & 1) 70 87 if( DEBUG_SYS_KILL < tm_start ) 71 printk("\n[DBG] %s : thread %xget owner process %x in cluster %x\n",72 __FUNCTION__ , this , owner_ptr, owner_cxy );88 printk("\n[DBG] %s : thread[%x,%x] get owner process %x in cluster %x\n", 89 __FUNCTION__ , this->process->pid, this->trdid, owner_ptr, owner_cxy ); 73 90 #endif 74 91 … … 81 98 #endif 82 99 this->errno = EINVAL; 83 return -1;84 }85 86 // process cannot kill itself87 if( (pid == process->pid) )88 {89 90 #if DEBUG_SYSCALLS_ERROR91 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid );92 #endif93 this->errno = EINVAL;94 return -1;95 }96 97 // processe INIT cannot be killed98 if( pid == 1 )99 {100 101 #if DEBUG_SYSCALLS_ERROR102 printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );103 #endif104 this->errno = EINVAL;105 100 return -1; 106 101 } … … 113 108 #if (DEBUG_SYS_KILL & 1) 114 109 if( DEBUG_SYS_KILL < tm_start ) 115 printk("\n[DBG] %s : thread %xget parent process %x in cluster %x\n",116 __FUNCTION__ , this , parent_ptr, parent_cxy );110 printk("\n[DBG] %s : thread[%x,%x] get parent process %x in cluster %x\n", 111 __FUNCTION__ , this->process->pid, this->trdid, parent_ptr, parent_cxy ); 117 112 #endif 118 113 … … 126 121 case 0 : // does nothing 127 122 { 128 retval = 0;129 123 break; 130 124 } 131 125 case SIGSTOP: // block all target process threads 132 126 { 133 // transfer TXT ownership 134 process_txt_transfer_ownership( owner_xp ); 135 136 // block all threads in all clusters, but the main thread 127 // block all threads in all clusters 137 128 process_sigaction( pid , BLOCK_ALL_THREADS ); 138 139 // block the main thread140 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );141 thread_block( main_xp , THREAD_BLOCKED_GLOBAL );142 129 143 130 // atomically update owner process termination state … … 145 132 PROCESS_TERM_STOP ); 146 133 147 // unblock the parent process main thread 134 // unblock the parent process main thread 148 135 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 149 136 150 retval = 0;151 137 break; 152 138 } … … 159 145 hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) , 160 146 ~PROCESS_TERM_STOP ); 161 retval = 0; 162 break; 163 } 164 break; 147 148 // unblock the parent process main thread 149 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 150 151 break; 152 } 165 153 case SIGKILL: 166 154 { 155 // a process cannot kill itself 156 if( (pid == process->pid) ) 157 { 158 159 #if DEBUG_SYSCALLS_ERROR 160 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid ); 161 #endif 162 this->errno = EINVAL; 163 return -1; 164 } 165 166 // processe INIT cannot be killed 167 if( pid == 1 ) 168 { 169 170 #if DEBUG_SYSCALLS_ERROR 171 printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ ); 172 #endif 173 this->errno = EINVAL; 174 return -1; 175 } 176 167 177 // remove process from TXT list 168 178 process_txt_detach( owner_xp ); 169 179 170 180 // mark for delete all threads in all clusters, but the main 171 hal_enable_irq( &save_sr );172 181 process_sigaction( pid , DELETE_ALL_THREADS ); 173 hal_restore_irq( save_sr );174 182 175 183 // block main thread … … 185 193 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 186 194 187 retval = 0;188 195 break; 189 196 } … … 195 202 #endif 196 203 this->errno = EINVAL; 197 retval = -1; 198 break; 204 return -1; 199 205 } 200 206 } … … 202 208 hal_fence(); 203 209 210 #if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS) 211 uint64_t tm_end = hal_get_cycles(); 212 #endif 213 204 214 #if DEBUG_SYS_KILL 205 tm_end = hal_get_cycles();206 215 if( DEBUG_SYS_KILL < tm_end ) 207 printk("\n[DBG] %s : thread %x exit / process %x / sig %d / cost = %d / cycle %d\n", 208 __FUNCTION__ , this, pid, sig_id, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 209 #endif 210 211 return retval; 216 printk("\n[DBG] %s : thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n", 217 __FUNCTION__ , this->process->pid, this->trdid, pid, 218 sig_type_str(sig_id), (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 219 #endif 220 221 #if CONFIG_INSTRUMENTATION_SYSCALLS 222 hal_atomic_add( &syscalls_cumul_cost[SYS_KILL] , tm_end - tm_start ); 223 hal_atomic_add( &syscalls_occurences[SYS_KILL] , 1 ); 224 #endif 225 226 return 0; 212 227 213 228 } // end sys_kill() -
trunk/kernel/syscalls/sys_read.c
r566 r584 72 72 #if DEBUG_SYS_READ 73 73 if( DEBUG_SYS_READ < tm_start ) 74 printk("\n[DBG] %s : thread %x in process %xenter / vaddr %x / count %d / cycle %d\n",75 __FUNCTION__, this->trdid, process->pid, vaddr, count, (uint32_t)tm_start );74 printk("\n[DBG] %s : thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n", 75 __FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start ); 76 76 #endif 77 77 … … 85 85 86 86 #if DEBUG_SYSCALLS_ERROR 87 printk("\n[ERROR] in %s : illegal file descriptor index = %d\n", __FUNCTION__ , file_id ); 87 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index = %d\n", 88 __FUNCTION__ , process->pid, this->trdid, file_id ); 88 89 #endif 89 90 this->errno = EBADFD; … … 98 99 99 100 #if DEBUG_SYSCALLS_ERROR 100 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process%x\n",101 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid);101 printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n", 102 __FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr ); 102 103 vmm_display( process , false ); 103 104 #endif … … 116 117 117 118 #if DEBUG_SYSCALLS_ERROR 118 printk("\n[ERROR] in %s : undefined fd_id %d in process %x\n",119 __FUNCTION__ , file_id , process->pid );119 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n", 120 __FUNCTION__, process->pid, this->trdid, file_id ); 120 121 #endif 121 122 this->errno = EBADFD; … … 127 128 cxy_t file_cxy = GET_CXY( file_xp ); 128 129 129 // check file readable130 uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );131 if( (attr & FD_ATTR_READ_ENABLE) == 0 )132 {133 134 #if DEBUG_SYSCALLS_ERROR135 printk("\n[ERROR] in %s : file %d not readable in process %x\n",136 __FUNCTION__ , file_id , process->pid );137 #endif138 this->errno = EBADFD;139 return -1;140 }141 142 130 // get file type 143 131 vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); … … 153 141 154 142 #if DEBUG_SYSCALLS_ERROR 155 printk("\n[ERROR] in %s : file %d not readable in process %x\n",156 __FUNCTION__ , file_id , process->pid );143 printk("\n[ERROR] in %s : thread[%x,%x] file %d not readable\n", 144 __FUNCTION__, process->pid, this->trdid, file_id ); 157 145 #endif 158 146 this->errno = EBADFD; … … 185 173 { 186 174 if( (iter & 0xFFF) == 0 ) 187 printk("\n[WARNING] in %s : thread %x in process %xwait TXT_RX / cycle %d\n",188 __FUNCTION__, this->trdid, process->pid, (uint32_t)hal_get_cycles() );175 printk("\n[WARNING] in %s : thread[%x,%x] wait TXT_RX / cycle %d\n", 176 __FUNCTION__, process->pid, this->trdid, (uint32_t)hal_get_cycles() ); 189 177 190 178 // deschedule without blocking … … 216 204 217 205 #if DEBUG_SYSCALLS_ERROR 218 printk("\n[ERROR] in %s cannot read data from file %d in process %x\n",219 __FUNCTION__ , file_id , process->pid );206 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n", 207 __FUNCTION__, process->pid, this->trdid, file_id ); 220 208 #endif 221 209 this->errno = error; … … 234 222 #if DEBUG_SYS_READ 235 223 if( DEBUG_SYS_READ < tm_end ) 236 printk("\n[DBG] %s : thread %x in process %xexit / cycle %d\n",237 __FUNCTION__ , this->trdid, process->pid, (uint32_t)tm_end );224 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n", 225 __FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end ); 238 226 #endif 239 227 -
trunk/kernel/syscalls/sys_thread_exit.c
r566 r584 36 36 int sys_thread_exit( void * exit_value ) 37 37 { 38 reg_t save_sr; // required to enable IRQs39 xptr_t owner_xp; // extended pointer on owner process40 41 38 thread_t * this = CURRENT_THREAD; 42 39 trdid_t trdid = this->trdid; 43 40 process_t * process = this->process; 44 41 pid_t pid = process->pid; 45 cxy_t owner_cxy = CXY_FROM_PID( pid );46 42 47 43 // check exit_value argument … … 57 53 } 58 54 59 #if DEBUG_SYS_THREAD_EXIT60 uint64_t tm_start;61 uint64_t tm_end;62 tm_start = hal_get_cycles();63 if( DEBUG_SYS_THREAD_EXIT < tm_start )64 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",65 __FUNCTION__ , this->trdid, pid , (uint32_t)tm_start );66 #endif67 55 68 56 // If calling thread is the main thread, the process must be deleted. 69 // This require to delete all process threads and synchronise with parent process 70 if( (local_cxy == owner_cxy) && (LTID_FROM_TRDID(trdid) == 0) ) 57 // => delete all process threads and synchronise with parent process. 58 // If calling thread is not the main thread, it must be deleted. 59 // => block the thread and mark it for delete. 60 if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) ) 71 61 { 72 // get extended pointer on owner cluster73 owner_xp = cluster_get_owner_process_from_pid( pid );74 62 75 // mark for delete all threads but the main 76 hal_enable_irq( &save_sr ); 77 process_sigaction( pid , DELETE_ALL_THREADS ); 78 hal_restore_irq( save_sr ); 79 80 // remove process from TXT list 81 process_txt_detach( owner_xp ); 82 83 // block the main thread 84 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_GLOBAL ); 85 86 // atomically update owner process descriptor term_state to ask 87 // the parent process sys_wait() function to delete the main thread 88 hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) , 89 PROCESS_TERM_EXIT ); 63 #if DEBUG_SYS_THREAD_EXIT 64 uint64_t tm_start = hal_get_cycles(); 65 if( DEBUG_SYS_THREAD_EXIT < tm_start ) 66 printk("\n[DBG] %s : thread[%x,%x] / main => delete process / cycle %d\n", 67 __FUNCTION__ , pid , trdid , (uint32_t)tm_start ); 68 #endif 69 // delete process 70 sys_exit( 0 ); 90 71 } 91 72 else 92 73 { 74 75 #if DEBUG_SYS_THREAD_EXIT 76 uint64_t tm_start = hal_get_cycles(); 77 if( DEBUG_SYS_THREAD_EXIT < tm_start ) 78 printk("\n[DBG] %s : thread[%x,%x] / not main => delete thread / cycle %d\n", 79 __FUNCTION__ , pid , trdid , (uint32_t)tm_start ); 80 #endif 93 81 // block calling thread and mark it for delete, 94 82 thread_delete( XPTR( local_cxy , this ) , pid , false ); 83 84 // deschedule 85 sched_yield( "suicide after thread_exit" ); 95 86 } 96 87 97 #if DEBUG_SYS_THREAD_EXIT98 tm_end = hal_get_cycles();99 if( DEBUG_SYS_THREAD_EXIT < tm_end )100 printk("\n[DBG] %s : thread %x in process %x exit / cost %d / cycle %d\n",101 __FUNCTION__, this->trdid, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );102 #endif103 104 // deschedule <=> suicide, because blocked by thread_delete()105 sched_yield( "suicide after thread_exit" );106 107 88 return 0; // never executed but required by compiler 108 89 -
trunk/kernel/syscalls/sys_thread_join.c
r566 r584 67 67 tm_start = hal_get_cycles(); 68 68 if( DEBUG_SYS_THREAD_JOIN < tm_start ) 69 printk("\n[DBG] %s : thread %x in process %x enter / target thread %x / cycle %d\n", 70 __FUNCTION__ , joining_ptr->trdid, process->pid, trdid , (uint32_t)tm_start ); 69 printk("\n[DBG] %s : joining thread[%x,%x] enter / target thread[%x,%x] / cycle %d\n", 70 __FUNCTION__ , process->pid, joining_ptr->trdid, 71 process->pid, trdid, (uint32_t)tm_start ); 71 72 #endif 72 73 73 74 // check trdid argument 74 if( (target_ltid >= CONFIG_THREADS_MAX_PER_CLUSTER) || cluster_is_undefined( target_cxy ) )75 if( (target_ltid >= CONFIG_THREADS_MAX_PER_CLUSTER) || cluster_is_undefined(target_cxy) ) 75 76 { 76 77 77 78 #if DEBUG_SYSCALLS_ERROR 78 printk("\n[ERROR] in %s : illegal trdid argument %x\n", __FUNCTION__, trdid ); 79 printk("\n[ERROR] in %s : illegal trdid argument %x\n", 80 __FUNCTION__, trdid ); 79 81 #endif 80 82 joining_ptr->errno = EINVAL; … … 87 89 88 90 #if DEBUG_SYSCALLS_ERROR 89 printk("\n[ERROR] in %s : exit_value argument must be NULL\n", __FUNCTION__ ); 91 printk("\n[ERROR] in %s : exit_value argument must be NULL\n", 92 __FUNCTION__ ); 90 93 #endif 91 94 joining_ptr->errno = EINVAL; … … 113 116 114 117 #if DEBUG_SYSCALLS_ERROR 115 printk("\n[ERROR] in %s : target thread %x not found\n", __FUNCTION__, trdid ); 118 printk("\n[ERROR] in %s : target thread %x not found\n", 119 __FUNCTION__, trdid ); 116 120 #endif 117 121 joining_ptr->errno = ESRCH; … … 145 149 if( hal_remote_l32( target_flags_xp ) & THREAD_FLAG_KILL_DONE ) // killer thread is first 146 150 { 147 148 #if (DEBUG_SYS_THREAD_JOIN & 1)149 if( DEBUG_SYS_THREAD_JOIN < tm_start )150 printk("\n[DBG] %s : thread %x in process %x / killer thread arrived first\n",151 __FUNCTION__ , joining_ptr->trdid, process->pid );152 #endif153 151 // get pointers on killer thread 154 152 killer_xp = (xptr_t)hal_remote_l64( target_join_xp_xp ); … … 163 161 remote_busylock_release( target_join_lock_xp ); 164 162 165 // restore IRQs 166 hal_restore_irq( save_sr ); 163 #if DEBUG_SYS_THREAD_JOIN 164 tm_end = hal_get_cycles(); 165 if( DEBUG_SYS_THREAD_JOIN < tm_end ) 166 printk("\n[DBG] %s : joining thread[%x,%x] exit / target thread[%x,%x] completed / cycle %d\n", 167 __FUNCTION__, process->pid, joining_ptr->trdid, process->pid, trdid, (uint32_t)tm_end ); 168 #endif 169 167 170 } 168 171 else // joining thread is first 169 172 { 170 171 #if (DEBUG_SYS_THREAD_JOIN & 1)172 if( DEBUG_SYS_THREAD_JOIN < tm_start )173 printk("\n[DBG] %s : thread %x in process %x / joining thread arrived first\n",174 __FUNCTION__ , joining_ptr->trdid, process->pid );175 #endif176 173 // set the join_done flag in target thread 177 174 hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_JOIN_DONE ); … … 186 183 remote_busylock_release( target_join_lock_xp ); 187 184 188 #if (DEBUG_SYS_THREAD_JOIN & 1)185 #if DEBUG_SYS_THREAD_JOIN 189 186 if( DEBUG_SYS_THREAD_JOIN < tm_start ) 190 printk("\n[DBG] %s : thread %x in process %x / joining thread deschedule\n",191 __FUNCTION__ , joining_ptr->trdid, process->pid );187 printk("\n[DBG] %s : joining thread[%x,%x] deschedules / target thread[%x,%x] not completed\n", 188 __FUNCTION__ , process->pid, joining_ptr->trdid, process->pid, trdid ); 192 189 #endif 193 190 // deschedule 194 191 sched_yield( "joining thread waiting killer thread" ); 195 192 196 #if (DEBUG_SYS_THREAD_JOIN & 1) 197 if( DEBUG_SYS_THREAD_JOIN < tm_start ) 198 printk("\n[DBG] %s : thread %x in process %x / joining thread resume\n", 199 __FUNCTION__ , joining_ptr->trdid, process->pid ); 200 #endif 201 // restore IRQs 202 hal_restore_irq( save_sr ); 203 } 204 205 #if DEBUG_SYS_THREAD_JOIN 193 #if DEBUG_SYS_THREAD_JOIN 206 194 tm_end = hal_get_cycles(); 207 195 if( DEBUG_SYS_THREAD_JOIN < tm_end ) 208 printk("\n[DBG] %s : thread %x in process %x exit / target thread %x / cycle %d\n", 209 __FUNCTION__, joining_ptr->trdid, process->pid, (uint32_t)tm_end ); 210 #endif 196 printk("\n[DBG] %s : joining thread[%x,%x] exit / target thread[%x,%x] completed / cycle %d\n", 197 __FUNCTION__ , process->pid, joining_ptr->trdid, process->pid, trdid, (uint32_t)tm_end ); 198 #endif 199 200 } 201 202 // restore IRQs 203 hal_restore_irq( save_sr ); 211 204 212 205 return 0; -
trunk/kernel/syscalls/sys_write.c
r566 r584 71 71 tm_start = hal_get_cycles(); 72 72 if( DEBUG_SYS_WRITE < tm_start ) 73 printk("\n[DBG] %s : thread %x in process %xenter / vaddr %x / count %d / cycle %d\n",74 __FUNCTION__, this->trdid, process->pid, vaddr, count, (uint32_t)tm_start );73 printk("\n[DBG] %s : thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n", 74 __FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start ); 75 75 #endif 76 76 … … 84 84 85 85 #if DEBUG_SYSCALLS_ERROR 86 printk("\n[ERROR] in %s : illegal file descriptor index\n", __FUNCTION__ ); 86 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n", 87 __FUNCTION__, process->pid, this->trdid, file_id ); 87 88 #endif 88 89 this->errno = EBADFD; … … 97 98 98 99 #if DEBUG_SYSCALLS_ERROR 99 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process%x\n",100 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid);100 printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n", 101 __FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr ); 101 102 vmm_display( process , false ); 102 103 #endif … … 112 113 113 114 #if DEBUG_SYSCALLS_ERROR 114 printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n",115 __FUNCTION__ , file_id , process->pid );115 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor index = %d\n", 116 __FUNCTION__, process->pid, this->trdid, file_id ); 116 117 #endif 117 118 this->errno = EBADFD; … … 139 140 140 141 #if DEBUG_SYSCALLS_ERROR 141 printk("\n[ERROR] in %s : file %d not writable in process %x\n",142 __FUNCTION__ , file_id , process->pid );142 printk("\n[ERROR] in %s : thread[%x,%x] file %d not writable\n", 143 __FUNCTION__ , process->pid, this->trdid, file_id ); 143 144 #endif 144 145 this->errno = EBADFD; … … 159 160 160 161 #if DEBUG_SYSCALLS_ERROR 161 printk("\n[ERROR] in %s : user buffer size %x too large / thread %x / process %x\n",162 __FUNCTION__ , count, this->trdid, process->pid);162 printk("\n[ERROR] in %s : thread[%x,%x] user buffer size %x too large\n", 163 __FUNCTION__ , process->pid, this->trdid, count ); 163 164 #endif 164 165 this->errno = EINVAL; … … 182 183 183 184 #if DEBUG_SYSCALLS_ERROR 184 printk("\n[ERROR] in %s cannot write data to file %d in process %x\n",185 __FUNCTION__ , file_id , process->pid );185 printk("\n[ERROR] in %s : thread[%x,‰x] cannot write data to file %d\n", 186 __FUNCTION__ , process->pid, this->trdid, file_id ); 186 187 #endif 187 188 this->errno = error; … … 200 201 #if DEBUG_SYS_WRITE 201 202 if( DEBUG_SYS_WRITE < tm_end ) 202 printk("\n[DBG] %s : thread %x in process %xexit / cycle %d\n",203 __FUNCTION__, this->trdid, process->pid, (uint32_t)tm_end );203 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n", 204 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 204 205 #endif 205 206 -
trunk/kernel/syscalls/syscalls.h
r566 r584 409 409 /****************************************************************************************** 410 410 * [32] This function associate a specific signal handler to a given signal type. 411 * T ee handlers for the SIGKILL and SIGSTOP signals cannot be redefined.411 * The handlers for the SIGKILL and SIGSTOP signals cannot be redefined. 412 412 ****************************************************************************************** 413 413 * @ sig_id : index defining signal type (from 1 to 31). … … 530 530 531 531 /****************************************************************************************** 532 * [40] This function returns the hardware platform parameters. 532 * [40] This function implement the non-standard get_config() syscall. 533 * It returns in <x_size>, <y_size>, <ncores> the hardware platform parameters. 533 534 ****************************************************************************************** 534 535 * @ x_size : [out] number of clusters in a row. … … 542 543 543 544 /****************************************************************************************** 544 * [41] This function returns the calling core cluster and local index. 545 * [41] This function implements the non-standard get_core() syscall. 546 * It returns in <cxy> and <lid> the calling core cluster and local index. 545 547 ****************************************************************************************** 546 548 * @ cxy : [out] cluster identifier (fixed format) … … 552 554 553 555 /****************************************************************************************** 554 * [42] This function returns in a 64 bits user buffer the calling core cycles count. 556 * [42] This function implements the non-standard get_cycle() syscall. 557 * It returns in a 64 bits user buffer the calling core cycles count. 555 558 * It uses both the hardware register and the core descriptor cycles count to take 556 559 * into account a possible harware register overflow in 32 bits architectures. … … 584 587 585 588 /****************************************************************************************** 586 * [44] TBD 589 * [44] This function implements the non-standard place_fork() syscall. 590 * It can be used to specify the target cluster <cxy> for a new process created 591 * by a subsequent fork() syscall. 592 * WARNING: it must be called before each fork() syscall, as the placement specification 593 * is reset by the fork syscall. 587 594 ****************************************************************************************** 588 595 * @ cxy : cluster identifier. 589 * @ lid : core local index. 590 * @ return 0 if success / return -1 if failure. 591 *****************************************************************************************/ 592 int sys_place( uint32_t cxy, 593 uint32_t lid ); 596 * @ return 0 if success / return -1 if failure. 597 *****************************************************************************************/ 598 int sys_place_fork( uint32_t cxy ); 594 599 595 600 /******************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.