Changeset 438 for trunk/kernel/syscalls/sys_fork.c
- Timestamp:
- Apr 4, 2018, 2:49:02 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_fork.c
r435 r438 45 45 pid_t parent_pid; // parent process identifier 46 46 thread_t * parent_thread_ptr; // local pointer on local parent thread descriptor 47 cxy_t parent_cxy; // parent thread cluster 47 48 48 49 pid_t child_pid; // child process identifier 49 50 thread_t * child_thread_ptr; // local pointer on remote child thread descriptor 50 cxy_t target_cxy;// target cluster for forked child process51 cxy_t child_cxy; // target cluster for forked child process 51 52 52 53 xptr_t ref_process_xp; // extended pointer on reference parent process … … 62 63 parent_process_ptr = parent_thread_ptr->process; 63 64 parent_pid = parent_process_ptr->pid; 64 65 #if CONFIG_DEBUG_SYS_FORK 65 parent_cxy = local_cxy; 66 67 #if DEBUG_SYS_FORK 66 68 uint64_t tm_start; 67 69 uint64_t tm_end; 68 70 tm_start = hal_get_cycles(); 69 if( CONFIG_DEBUG_SYS_FORK < tm_start )70 printk("\n[DBG] %s : thread %x enter / parent%x / cycle = %d\n",71 if( DEBUG_SYS_FORK < tm_start ) 72 printk("\n[DBG] %s : parent_thread %x enter / parent_pid %x / cycle = %d\n", 71 73 __FUNCTION__, parent_thread_ptr, parent_pid, (uint32_t)tm_start ); 72 74 #endif 73 75 74 // get infos on reference p rocess76 // get infos on reference parent process 75 77 ref_process_xp = parent_process_ptr->ref_xp; 76 78 ref_process_cxy = GET_CXY( ref_process_xp ); … … 82 84 { 83 85 84 #if CONFIG_DEBUG_SYSCALLS_ERROR86 #if DEBUG_SYSCALLS_ERROR 85 87 printk("\n[ERROR] in %s : too much children processes\n", __FUNCTION__); 86 88 #endif … … 91 93 92 94 // Select target cluster for child process and main thread. 93 // If placement is not user-defined, the placement is defined by the DQDT.94 if( parent_thread_ptr->fork_user ) // user defined placement95 { 96 target_cxy = parent_thread_ptr->fork_cxy;95 // If placement is not user-defined, it is defined by the DQDT. 96 if( parent_thread_ptr->fork_user ) 97 { 98 child_cxy = parent_thread_ptr->fork_cxy; 97 99 parent_thread_ptr->fork_user = false; 98 100 } 99 101 else // DQDT placement 100 102 { 101 target_cxy = dqdt_get_cluster_for_process(); 102 } 103 child_cxy = dqdt_get_cluster_for_process(); 104 } 105 106 #if( DEBUG_SYS_FORK & 1) 107 108 // dqdt_display(); 109 110 if( local_cxy == 0 ) 111 { 112 sched_display( 0 ); 113 rpc_sched_display_client( 1 , 0 ); 114 } 115 else 116 { 117 sched_display( 0 ); 118 rpc_sched_display_client( 0 , 0 ); 119 } 120 121 if( DEBUG_SYS_FORK < tm_start ) 122 printk("\n[DBG] %s : parent_thread %x selected cluster %x\n", 123 __FUNCTION__, parent_thread_ptr, child_cxy ); 124 #endif 103 125 104 126 // call process_make_fork in target cluster 105 if( target_cxy == local_cxy )127 if( child_cxy == local_cxy ) 106 128 { 107 129 error = process_make_fork( ref_process_xp, … … 112 134 else 113 135 { 114 rpc_process_make_fork_client( target_cxy,136 rpc_process_make_fork_client( child_cxy, 115 137 ref_process_xp, 116 138 parent_thread_xp, … … 123 145 { 124 146 125 #if CONFIG_DEBUG_SYSCALLS_ERROR147 #if DEBUG_SYSCALLS_ERROR 126 148 printk("\n[ERROR] in %s : cannot fork process %x in cluster %x\n", 127 149 __FUNCTION__, parent_pid, local_cxy ); … … 135 157 if( CURRENT_THREAD->core->fpu_owner == parent_thread_ptr ) 136 158 { 137 hal_fpu_context_save( XPTR( target_cxy , child_thread_ptr ) ); 138 } 139 140 // set remote child CPU context from parent_thread register values 141 hal_cpu_context_fork( XPTR( target_cxy , child_thread_ptr ) ); 142 143 // From this point, both parent and child threads execute the following code. 144 // They can be distinguished by the CURRENT_THREAD value, and child will only 145 // execute it when it is unblocked by parent. 159 hal_fpu_context_save( XPTR( child_cxy , child_thread_ptr ) ); 160 } 161 162 // set remote child CPU context from parent_thread register values 163 hal_cpu_context_fork( XPTR( child_cxy , child_thread_ptr ) ); 164 165 // From this point, both parent and child threads execute the following code, 166 // but they can be distinguished by the (CURRENT_THREAD,local_cxy) values. 146 167 // - parent unblock child, and return child PID to user application. 147 168 // - child thread does nothing, and return 0 to user pplication 169 // The child thread will only execute it when it is unblocked by parent thread. 148 170 149 171 thread_t * current = CURRENT_THREAD; 150 172 151 if( current == parent_thread_ptr ) // current ==parent thread173 if( (current == parent_thread_ptr) && (local_cxy == parent_cxy) ) // parent thread 152 174 { 153 175 // parent_thread unblock child_thread 154 thread_unblock( XPTR( target_cxy , child_thread_ptr ) , THREAD_BLOCKED_GLOBAL );155 156 #if CONFIG_DEBUG_SYS_FORK176 thread_unblock( XPTR( child_cxy , child_thread_ptr ) , THREAD_BLOCKED_GLOBAL ); 177 178 #if DEBUG_SYS_FORK 157 179 tm_end = hal_get_cycles(); 158 if( CONFIG_DEBUG_SYS_FORK < tm_end )159 printk("\n[DBG] %s : parent_thread %x exit / cost = %d / cycle %d\n",160 __FUNCTION__ , parent_thread_ptr, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );180 if( DEBUG_SYS_FORK < tm_end ) 181 printk("\n[DBG] %s : parent_thread %x on cluster %x exit / cost = %d / cycle %d\n", 182 __FUNCTION__, parent_thread_ptr, parent_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 161 183 #endif 162 184 163 185 return child_pid; 164 186 } 165 else // current ==child_thread166 { 167 168 #if CONFIG_DEBUG_SYS_FORK187 else // child_thread 188 { 189 190 #if DEBUG_SYS_FORK 169 191 tm_end = hal_get_cycles(); 170 if( CONFIG_DEBUG_SYS_FORK < tm_end )171 printk("\n[DBG] %s : child_thread %x exit / cost = %d / cycle %d\n",172 __FUNCTION__ , child_thread_ptr, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );192 if( DEBUG_SYS_FORK < tm_end ) 193 printk("\n[DBG] %s : child_thread %x on cluster %x exit / cost = %d / cycle %d\n", 194 __FUNCTION__, child_thread_ptr, child_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 173 195 #endif 174 196
Note: See TracChangeset
for help on using the changeset viewer.