Changeset 443 for trunk/kernel/syscalls
- Timestamp:
- May 16, 2018, 4:15:22 PM (7 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_display.c
r440 r443 30 30 #include <process.h> 31 31 #include <string.h> 32 32 #include <shared_syscalls.h> 33 34 ///////////////////////////////////////////////////////////////////////////////// 35 // This static function returns a printable string for the type of display. 36 ///////////////////////////////////////////////////////////////////////////////// 37 38 #if DEBUG_SYS_DISPLAY 39 static char* display_type_str( uint32_t type ) 40 { 41 if ( type == DISPLAY_STRING ) return "STRING"; 42 else if( type == DISPLAY_VMM ) return "VMM"; 43 else if( type == DISPLAY_SCHED ) return "SCHED"; 44 else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES"; 45 else if( type == DISPLAY_VFS ) return "VFS"; 46 else if( type == DISPLAY_CHDEV ) return "CHDEV"; 47 else if( type == DISPLAY_TXT_PROCESSES ) return "TXT_PROCESSES"; 48 } 49 #endif 33 50 34 51 ///////////////////////////// … … 49 66 tm_start = hal_get_cycles(); 50 67 if( DEBUG_SYS_DISPLAY < tm_start ) 51 printk("\n[DBG] %s : thread %d enter / process %x / type % d/ cycle = %d\n",52 __FUNCTION__, this, this->process->pid, type, (uint32_t)tm_start );68 printk("\n[DBG] %s : thread %d enter / process %x / type %s / cycle = %d\n", 69 __FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start ); 53 70 #endif 54 71 … … 98 115 else if( type == DISPLAY_VMM ) 99 116 { 100 pid_t pid = (pid_t)arg0; 101 102 // get extended pointer on reference process 103 xptr_t process_xp = cluster_get_reference_process_from_pid( pid ); 117 cxy_t cxy = (cxy_t)arg0; 118 pid_t pid = (pid_t)arg1; 119 120 // check cxy argument 121 if( cluster_is_undefined( cxy ) ) 122 { 123 124 #if DEBUG_SYSCALLS_ERROR 125 printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n", 126 __FUNCTION__ , cxy , this->trdid , process->pid ); 127 #endif 128 this->errno = EINVAL; 129 return -1; 130 } 131 132 // get extended pointer on process PID in cluster CXY 133 xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid ); 104 134 105 135 if( process_xp == XPTR_NULL ) … … 107 137 108 138 #if DEBUG_SYSCALLS_ERROR 109 printk("\n[ERROR] in %s : undefined pid argument %d / thread %x / process %x\n", 110 __FUNCTION__ , pid , this->trdid , process->pid ); 111 #endif 112 this->errno = EINVAL; 113 return -1; 114 } 115 116 // get cluster and local pointer on process 117 cxy_t process_cxy = GET_CXY( process_xp ); 118 process_t * process_ptr = (process_t *)GET_PTR( process_xp ); 139 printk("\n[ERROR] in %s : process %x in cluster %x not found / thread %x / process %x\n", 140 __FUNCTION__ , pid , cxy , this->trdid , process->pid ); 141 #endif 142 this->errno = EINVAL; 143 return -1; 144 } 145 146 // get local pointer on process 147 process_t * process = (process_t *)GET_PTR( process_xp ); 119 148 120 149 // call kernel function 121 if( process_cxy == local_cxy )122 { 123 vmm_display( process _ptr, true );150 if( cxy == local_cxy ) 151 { 152 vmm_display( process , true ); 124 153 } 125 154 else 126 155 { 127 rpc_vmm_display_client( process_cxy , process_ptr, true );156 rpc_vmm_display_client( cxy , process , true ); 128 157 } 129 158 } -
trunk/kernel/syscalls/sys_exit.c
r441 r443 51 51 #endif 52 52 53 // get owner process descriptor pointers and cluster54 xptr_t owner_xp = cluster_get_owner_process_from_pid( pid );53 // get owner process descriptor pointers 54 xptr_t owner_xp = process->owner_xp; 55 55 cxy_t owner_cxy = GET_CXY( owner_xp ); 56 56 process_t * owner_ptr = GET_PTR( owner_xp ); … … 62 62 hal_enable_irq( &save_sr ); 63 63 64 // mark for delete all process threads in all clusters 65 // (but the main thread and this calling thread)64 // mark for delete all process threads in all clusters, 65 // but the main thread and this calling thread 66 66 process_sigaction( pid , DELETE_ALL_THREADS ); 67 67 … … 81 81 #if( DEBUG_SYS_EXIT & 1) 82 82 if( tm_start > DEBUG_SYS_EXIT ) 83 printk("\n[DBG] %s : calling thread %x deleted itself/ process %x\n",83 printk("\n[DBG] %s : calling thread %x marked iself for delete / process %x\n", 84 84 __FUNCTION__ , this, pid ); 85 85 #endif -
trunk/kernel/syscalls/sys_fg.c
r438 r443 36 36 int sys_fg( pid_t pid ) 37 37 { 38 xptr_t process_xp; 38 xptr_t process_xp; // extended pointer on reference process descriptor 39 39 process_t * process_ptr; 40 40 cxy_t process_cxy; 41 xptr_t chdev_xp; 41 xptr_t file_xp; // extended pointer on STDIN file descriptor 42 xptr_t chdev_xp; // extended pointer on TXT0_RX chdev 42 43 chdev_t * chdev_ptr; 43 44 cxy_t chdev_cxy; … … 70 71 process_ptr = (process_t *)GET_PTR( process_xp ); 71 72 process_cxy = GET_CXY( process_xp ); 73 74 // get extended pointer on the reference process STDIN file descriptor 75 file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) ); 72 76 73 77 // get extended pointer on TXT_RX chdev 74 chdev_xp = chdev_from_file( XPTR( process_cxy , &process_ptr->fd_array.array[0] ));78 chdev_xp = chdev_from_file( file_xp ); 75 79 76 80 // get chdev cluster and local pointer -
trunk/kernel/syscalls/sys_read.c
r441 r443 147 147 // check file readable 148 148 uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) ); 149 149 150 if( (attr & FD_ATTR_READ_ENABLE) == 0 ) 150 151 { … … 231 232 exit_sys_read = (uint32_t)tm_end; 232 233 233 printk("\n @@@@@@@@@@@@ timing to read character\n"234 printk("\n***** timing to read one character *****\n" 234 235 " - enter_sys_read = %d / delta %d\n" 235 236 " - enter_devfs_read = %d / delta %d\n" -
trunk/kernel/syscalls/sys_thread_cancel.c
r440 r443 37 37 cxy_t target_cxy; // target thread cluster identifier 38 38 ltid_t target_ltid; // target thread local index 39 xptr_t owner_xp; // extended pointer on owner process 39 40 cxy_t owner_cxy; // process owner cluster identifier 40 xptr_t owner_xp; // extended pointer on owner process41 41 42 42 // get killer thread pointers … … 44 44 process_t * process = this->process; 45 45 pid_t pid = process->pid; 46 47 #if DEBUG_SYS_THREAD_CANCEL 48 uint64_t tm_start; 49 uint64_t tm_end; 50 tm_start = hal_get_cycles(); 51 if( DEBUG_SYS_THREAD_CANCEL < tm_start ) 52 printk("\n[DBG] %s : thread %x enter to kill thread %x in process %x / cycle %d\n", 53 __FUNCTION__, this , trdid , pid , (uint32_t)tm_start ); 54 #endif 46 55 47 56 // get extended pointer on target thread … … 59 68 } 60 69 61 #if DEBUG_SYS_THREAD_CANCEL 62 uint64_t tm_start; 63 uint64_t tm_end; 64 tm_start = hal_get_cycles(); 65 if( DEBUG_SYS_THREAD_CANCEL < tm_start ) 66 printk("\n[DBG] %s : thread %x enter to kill thread %x / cycle %d\n", 67 __FUCTION__, this, GET_PTR( target_xp ), (uint32_t)tm_start ); 68 #endif 69 70 // get process owner cluster identifier 71 owner_cxy = CXY_FROM_PID( pid ); 70 // get process owner cluster 71 owner_xp = process->owner_xp; 72 owner_cxy = GET_CXY( owner_xp ); 72 73 73 74 // get target thread ltid and cluster … … 79 80 if( (target_cxy == owner_cxy) && (target_ltid == 0) ) 80 81 { 81 // get extended pointer on owner cluster82 owner_xp = cluster_get_owner_process_from_pid( pid );83 84 82 // mark for delete all threads but the main 85 83 hal_enable_irq( &save_sr ); … … 107 105 tm_end = hal_get_cycles(); 108 106 if( DEBUG_SYS_THREAD_CANCEL < tm_end ) 109 printk("\n[DBG] %s : thread %x exit after kill thread %x / cycle %d\n",110 __FU CTION__, this, GET_PTR( target_xp ), (uint32_t)tm_end );107 printk("\n[DBG] %s : thread %x exit after kill thread %x in process %x / cycle %d\n", 108 __FUNCTION__, this , trdid , pid , (uint32_t)tm_end ); 111 109 #endif 112 110 -
trunk/kernel/syscalls/sys_trace.c
r407 r443 1 1 /* 2 * sys_trace.c - show kernel active processes and threads2 * sys_trace.c - activate / desactivate the context switches trace for a given core 3 3 * 4 * Author Alain Greiner (c) (2016,2017 )4 * Author Alain Greiner (c) (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 27 27 #include <thread.h> 28 28 #include <errno.h> 29 #include <shared_syscalls.h> 29 30 #include <syscalls.h> 30 31 31 /////////////////////////////// ///32 int sys_trace( uint32_t operation,33 pid_t pid,34 uint32_t trdid )32 /////////////////////////////// 33 int sys_trace( bool_t active, 34 cxy_t cxy, 35 lid_t lid ) 35 36 { 36 // get extended pointer on target thread 37 xptr_t thread_xp = thread_get_xptr( pid , trdid ); 37 uint32_t ncores; 38 38 39 if( thread_xp == XPTR_NULL ) 39 thread_t * this = CURRENT_THREAD; 40 process_t * process = this->process; 41 42 #if DEBUG_SYS_TRACE 43 uint64_t tm_start; 44 uint64_t tm_end; 45 tm_start = hal_get_cycles(); 46 if( DEBUG_SYS_TRACE < tm_start ) 47 printk("\n[DBG] %s : thread %d enter / process %x / cycle = %d\n", 48 __FUNCTION__, this, this->process->pid, (uint32_t)tm_start ); 49 #endif 50 51 // check cluster identifier 52 if( cluster_is_undefined( cxy ) ) 40 53 { 41 printk("\n[ERROR] in %s : undefined thread for PID = %x / TRDID = %x\n", 42 __FUNCTION__ , pid , trdid ); 43 CURRENT_THREAD->errno = EINVAL; 54 55 #if DEBUG_SYSCALLS_ERROR 56 printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n", 57 __FUNCTION__ , cxy , this->trdid , process->pid ); 58 #endif 59 this->errno = EINVAL; 44 60 return -1; 45 61 } 46 62 47 if( operation == TRACE_OFF ) 63 // check core local index 64 ncores = hal_remote_lw( XPTR( cxy , &LOCAL_CLUSTER->cores_nr ) ); 65 if( lid >= ncores ) 48 66 { 49 // desactivate thread trace TODO50 67 51 printk("\n[DBG] %s : trace OFF for thread %x in process %x\n", 52 __FUNCTION__ , trdid , pid ); 53 } 54 else if( operation == TRACE_ON ) 55 { 56 // activate thread trace TODO 57 58 printk("\n[DBG] %s : trace ON for thread %x in process %x\n", 59 __FUNCTION__ , trdid , pid ); 60 } 61 else 62 { 63 printk("\n[ERROR] in %s : undefined operation\n", __FUNCTION__ ); 64 CURRENT_THREAD->errno = EINVAL; 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n", 70 __FUNCTION__ , lid , this->trdid , process->pid ); 71 #endif 72 this->errno = EINVAL; 65 73 return -1; 66 74 } 67 75 76 // get local pointer on target core 77 core_t * core = &LOCAL_CLUSTER->core_tbl[lid]; 78 79 // get extended pointer on target scheduler trace field 80 xptr_t trace_xp = XPTR( cxy , &core->scheduler.trace ); 81 82 if ( active ) hal_remote_sw( trace_xp , 1 ); 83 else hal_remote_sw( trace_xp , 0 ); 84 68 85 hal_fence(); 86 87 #if DEBUG_SYS_TRACE 88 tm_end = hal_get_cycles(); 89 if( DEBUG_SYS_TRACE < tm_end ) 90 printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n", 91 __FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end ); 92 #endif 69 93 70 94 return 0; -
trunk/kernel/syscalls/sys_wait.c
r440 r443 73 73 } 74 74 75 // get process owner cluster and calling thread trdid75 // get calling process owner cluster 76 76 cxy_t owner_cxy = CXY_FROM_PID( pid ); 77 trdid_t trdid = this->trdid;78 77 79 // wait must be executed by the main thread 78 // get calling thread trdid 79 trdid_t trdid = this->trdid; 80 81 // this function must be executed by the process main thread 80 82 if( (owner_cxy != local_cxy) || (LTID_FROM_TRDID(trdid) != 0) ) 81 83 { … … 113 115 child_state = (int)hal_remote_lw ( XPTR(child_cxy,&child_ptr->term_state)); 114 116 115 // test if child process is terminated,117 // test if this child process is terminated, 116 118 // but termination not yet reported to parent process 117 119 if( ((child_state & PROCESS_TERM_EXIT) || … … 120 122 ((child_state & PROCESS_TERM_WAIT) == 0) ) 121 123 { 122 // get pointer on main thread and PID from child owner process124 // get pointer on child main thread and PID from child owner process 123 125 child_pid = (pid_t) hal_remote_lw (XPTR( child_cxy , &child_ptr->pid )); 124 126 child_thread = (thread_t *)hal_remote_lpt(XPTR( child_cxy , 125 127 &child_ptr->th_tbl[0] )); 126 128 127 // set the PROCESS_FLAG_WAIT in owner child descriptor129 // set the PROCESS_FLAG_WAIT in owner child process descriptor 128 130 hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ), 129 131 PROCESS_TERM_WAIT ); -
trunk/kernel/syscalls/sys_write.c
r441 r443 103 103 } 104 104 105 // enable IRQs106 hal_enable_irq( &save_sr );107 108 105 // get extended pointer on remote file descriptor 109 106 file_xp = process_fd_get_xptr( process , file_id ); … … 128 125 vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) ); 129 126 130 // action depend on file type 127 // enable IRQs 128 hal_enable_irq( &save_sr ); 129 130 // action depend on file type 131 131 if( type == INODE_TYPE_FILE ) // check file writable & write to mapper 132 132 { … … 152 152 else if( type == INODE_TYPE_DEV ) // check ownership & write to device 153 153 { 154 // check user buffer size for TXT_TX 155 if( (type == INODE_TYPE_DEV) && (count >= CONFIG_TXT_KBUF_SIZE) ) 156 { 157 158 #if DEBUG_SYSCALLS_ERROR 159 printk("\n[ERROR] in %s : user buffer size %x too large / thread %x / process %x\n", 160 __FUNCTION__ , count, this->trdid, process->pid ); 161 #endif 162 this->errno = EINVAL; 163 return -1; 164 } 165 154 166 // move count bytes to device 155 167 nbytes = devfs_user_move( false, // from buffer to device … … 158 170 count ); 159 171 } 160 else 172 else // not FILE and not DEV 161 173 { 162 174 nbytes = 0; … … 192 204 exit_sys_write = (uint32_t)tm_end; 193 205 194 printk("\n @@@@@@@@@@@@ timing to write\n"206 printk("\n***** timing to write a string *****\n" 195 207 " - enter_sys_write = %d / delta %d\n" 196 208 " - enter_devfs_write = %d / delta %d\n" -
trunk/kernel/syscalls/syscalls.h
r440 r443 170 170 * [10] This function implement the exit system call terminating a POSIX process. 171 171 * It can be called by any thread running in any cluster. 172 * It uses both remote accesses to access the owner process descriptor, an sthe173 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors 172 * It uses both remote accesses to access the owner process descriptor, and the 173 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors. 174 174 * In the present implementation, this function implements actually the _exit(): 175 175 * - it does not flush open output streams. … … 600 600 601 601 /****************************************************************************************** 602 * [47] This non-standard function is used to activate / desactivate the trace for a thread603 * identified by the <trdid> and <pid> arguments.602 * [47] This debug function is used to activate / desactivate the context switches trace 603 * for a core identified by the <cxy> and <lid> arguments. 604 604 * It can be called by any other thread in the same process. 605 605 ****************************************************************************************** 606 * @ operation : operation type as defined below.607 * @ pid : processidentifier.608 * @ trdid : thread identifier.606 * @ active : activate trace if true / desactivate trace if false. 607 * @ cxy : cluster identifier. 608 * @ lid : core local index. 609 609 * @ returns O if success / returns -1 if failure. 610 610 *****************************************************************************************/ 611 int sys_trace( uint32_t operation,612 pid_t pid,613 uint32_t trdid );611 int sys_trace( bool_t active, 612 cxy_t cxy, 613 lid_t lid ); 614 614 615 615 /******************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.