Changeset 625 for trunk/kernel/kern/process.c
- Timestamp:
- Apr 10, 2019, 10:09:39 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.c
r624 r625 91 91 } 92 92 93 ///////////////////////////////////////////////// 94 void process_reference_init( process_t * process, 95 pid_t pid, 96 xptr_t parent_xp ) 97 { 93 //////////////////////////////////////////////////// 94 error_t process_reference_init( process_t * process, 95 pid_t pid, 96 xptr_t parent_xp ) 97 { 98 error_t error; 98 99 xptr_t process_xp; 99 100 cxy_t parent_cxy; … … 105 106 uint32_t stdout_id; 106 107 uint32_t stderr_id; 107 error_t error;108 108 uint32_t txt_id; 109 109 char rx_path[40]; … … 111 111 xptr_t file_xp; 112 112 xptr_t chdev_xp; 113 chdev_t *chdev_ptr;113 chdev_t * chdev_ptr; 114 114 cxy_t chdev_cxy; 115 115 pid_t parent_pid; 116 vmm_t * vmm; 116 117 117 118 // build extended pointer on this reference process 118 119 process_xp = XPTR( local_cxy , process ); 120 121 // get pointer on process vmm 122 vmm = &process->vmm; 119 123 120 124 // get parent process cluster and local pointer … … 129 133 uint32_t cycle = (uint32_t)hal_get_cycles(); 130 134 if( DEBUG_PROCESS_REFERENCE_INIT < cycle ) 131 printk("\n[%s] thread[%x,%x] enter to init alialize process %x / cycle %d\n",132 __FUNCTION__, parent_pid, this->trdid, pid, cycle );135 printk("\n[%s] thread[%x,%x] enter to initialize process %x / cycle %d\n", 136 __FUNCTION__, this->process->pid, this->trdid, pid, cycle ); 133 137 #endif 134 138 … … 144 148 process->cwd_xp = hal_remote_l64( XPTR( parent_cxy, &parent_ptr->cwd_xp ) ); 145 149 146 // initialize vmm as empty 147 error = vmm_init( process ); 148 149 assert( (error == 0) , "cannot initialize VMM\n" ); 150 // initialize VSL as empty 151 vmm->vsegs_nr = 0; 152 xlist_root_init( XPTR( local_cxy , &vmm->vsegs_root ) ); 153 154 // create an empty GPT as required by the architecture 155 error = hal_gpt_create( &vmm->gpt ); 156 if( error ) 157 { 158 printk("\n[ERROR] in %s : cannot create empty GPT\n", __FUNCTION__ ); 159 return -1; 160 } 161 162 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) 163 if( DEBUG_PROCESS_REFERENCE_INIT < cycle ) 164 printk("\n[%s] thread[%x,%x] created empty GPT for process %x\n", 165 __FUNCTION__, parent_pid, this->trdid, pid ); 166 #endif 167 168 // initialize GPT and VSL locks 169 remote_rwlock_init( XPTR( local_cxy , &vmm->gpt_lock ) , LOCK_VMM_GPT ); 170 remote_rwlock_init( XPTR( local_cxy , &vmm->vsl_lock ) , LOCK_VMM_VSL ); 171 172 // register kernel vsegs in VMM as required by the architecture 173 error = hal_vmm_kernel_update( process ); 174 if( error ) 175 { 176 printk("\n[ERROR] in %s : cannot register kernel vsegs in VMM\n", __FUNCTION__ ); 177 return -1; 178 } 179 180 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) 181 if( DEBUG_PROCESS_REFERENCE_INIT < cycle ) 182 printk("\n[%s] thread[%x,%x] registered kernel vsegs for process %x\n", 183 __FUNCTION__, parent_pid, this->trdid, pid ); 184 #endif 185 186 // create "args" and "envs" vsegs 187 // create "stacks" and "mmap" vsegs allocators 188 // initialize locks protecting GPT and VSL 189 error = vmm_user_init( process ); 190 if( error ) 191 { 192 printk("\n[ERROR] in %s : cannot register user vsegs in VMM\n", __FUNCTION__ ); 193 return -1; 194 } 150 195 151 196 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) 152 197 cycle = (uint32_t)hal_get_cycles(); 153 198 if( DEBUG_PROCESS_REFERENCE_INIT < cycle ) 154 printk("\n[%s] thread[%x,%x] / vmm empty for process %x / cycle %d\n",155 __FUNCTION__, parent_pid, this->trdid, pid , cycle);199 printk("\n[%s] thread[%x,%x] initialized vmm for process %x\n", 200 __FUNCTION__, parent_pid, this->trdid, pid ); 156 201 #endif 157 202 … … 187 232 &stdin_xp, 188 233 &stdin_id ); 189 190 assert( (error == 0) , "cannot open stdin pseudo file" ); 234 if( error ) 235 { 236 printk("\n[ERROR] in %s : cannot open stdout pseudo-file\n", __FUNCTION__ ); 237 return -1; 238 } 239 191 240 assert( (stdin_id == 0) , "stdin index must be 0" ); 192 241 … … 206 255 &stdout_xp, 207 256 &stdout_id ); 208 209 assert( (error == 0) , "cannot open stdout pseudo file" ); 210 assert( (stdout_id == 1) , "stdout index must be 1" ); 257 if( error ) 258 { 259 printk("\n[ERROR] in %s : cannot open stdout pseudo-file\n", __FUNCTION__ ); 260 return -1; 261 } 262 263 assert( (stdout_id == 1) , "stdout index must be 1" ); 211 264 212 265 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) … … 225 278 &stderr_xp, 226 279 &stderr_id ); 227 228 assert( (error == 0) , "cannot open stderr pseudo file" ); 229 assert( (stderr_id == 2) , "stderr index must be 2" ); 280 if( error ) 281 { 282 printk("\n[ERROR] in %s : cannot open stderr pseudo-file\n", __FUNCTION__ ); 283 return -1; 284 } 285 286 assert( (stderr_id == 2) , "stderr index must be 2" ); 230 287 231 288 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) … … 240 297 { 241 298 // get extended pointer on stdin pseudo file in parent process 242 file_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) ); 299 file_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy, 300 &parent_ptr->fd_array.array[0] ) ); 243 301 244 302 // get extended pointer on parent process TXT chdev … … 261 319 262 320 // initialize lock protecting CWD changes 263 remote_busylock_init( XPTR( local_cxy , &process->cwd_lock ), LOCK_PROCESS_CWD ); 321 remote_busylock_init( XPTR( local_cxy , 322 &process->cwd_lock ), LOCK_PROCESS_CWD ); 264 323 265 324 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) … … 273 332 xlist_root_init( XPTR( local_cxy , &process->children_root ) ); 274 333 process->children_nr = 0; 275 remote_queuelock_init( XPTR( local_cxy , &process->children_lock ), LOCK_PROCESS_CHILDREN ); 334 remote_queuelock_init( XPTR( local_cxy, 335 &process->children_lock ), LOCK_PROCESS_CHILDREN ); 276 336 277 337 // reset semaphore / mutex / barrier / condvar list roots and lock … … 280 340 xlist_root_init( XPTR( local_cxy , &process->barrier_root ) ); 281 341 xlist_root_init( XPTR( local_cxy , &process->condvar_root ) ); 282 remote_queuelock_init( XPTR( local_cxy , &process->sync_lock ), LOCK_PROCESS_USERSYNC ); 342 remote_queuelock_init( XPTR( local_cxy , 343 &process->sync_lock ), LOCK_PROCESS_USERSYNC ); 283 344 284 345 // reset open directories root and lock 285 346 xlist_root_init( XPTR( local_cxy , &process->dir_root ) ); 286 remote_queuelock_init( XPTR( local_cxy , &process->dir_lock ), LOCK_PROCESS_DIR ); 347 remote_queuelock_init( XPTR( local_cxy , 348 &process->dir_lock ), LOCK_PROCESS_DIR ); 287 349 288 350 // register new process in the local cluster manager pref_tbl[] … … 315 377 #endif 316 378 379 return 0; 380 317 381 } // process_reference_init() 318 382 … … 321 385 xptr_t reference_process_xp ) 322 386 { 323 error_t error; 387 error_t error; 388 vmm_t * vmm; 324 389 325 390 // get reference process cluster and local pointer 326 391 cxy_t ref_cxy = GET_CXY( reference_process_xp ); 327 392 process_t * ref_ptr = GET_PTR( reference_process_xp ); 393 394 // get pointer on process vmm 395 vmm = &local_process->vmm; 328 396 329 397 // initialize PID, REF_XP, PARENT_XP, and STATE … … 343 411 344 412 // check user process 345 assert( (local_process->pid != 0), "PID cannot be 0" ); 346 347 // reset local process vmm 348 error = vmm_init( local_process ); 349 assert( (error == 0) , "cannot initialize VMM\n"); 350 351 // reset process file descriptors array 413 assert( (local_process->pid != 0), "LPID cannot be 0" ); 414 415 // initialize VSL as empty 416 vmm->vsegs_nr = 0; 417 xlist_root_init( XPTR( local_cxy , &vmm->vsegs_root ) ); 418 419 // create an empty GPT as required by the architecture 420 error = hal_gpt_create( &vmm->gpt ); 421 if( error ) 422 { 423 printk("\n[ERROR] in %s : cannot create empty GPT\n", __FUNCTION__ ); 424 return -1; 425 } 426 427 // initialize GPT and VSL locks 428 remote_rwlock_init( XPTR( local_cxy , &vmm->gpt_lock ) , LOCK_VMM_GPT ); 429 remote_rwlock_init( XPTR( local_cxy , &vmm->vsl_lock ) , LOCK_VMM_VSL ); 430 431 // register kernel vsegs in VMM as required by the architecture 432 error = hal_vmm_kernel_update( local_process ); 433 if( error ) 434 { 435 printk("\n[ERROR] in %s : cannot register kernel vsegs in VMM\n", __FUNCTION__ ); 436 return -1; 437 } 438 439 // create "args" and "envs" vsegs 440 // create "stacks" and "mmap" vsegs allocators 441 // initialize locks protecting GPT and VSL 442 error = vmm_user_init( local_process ); 443 if( error ) 444 { 445 printk("\n[ERROR] in %s : cannot register user vsegs in VMM\n", __FUNCTION__ ); 446 return -1; 447 } 448 449 #if (DEBUG_PROCESS_COPY_INIT & 1) 450 cycle = (uint32_t)hal_get_cycles(); 451 if( DEBUG_PROCESS_COPY_INIT < cycle ) 452 printk("\n[%s] thread[%x,%x] initialized vmm for process %x / cycle %d\n", 453 __FUNCTION__, parent_pid, this->trdid, pid, cycle ); 454 #endif 455 456 // set process file descriptors array 352 457 process_fd_init( local_process ); 353 458 354 // reset vfs_root_xp / vfs_bin_xp / cwd_xp fields459 // set vfs_root_xp / vfs_bin_xp / cwd_xp fields 355 460 local_process->vfs_root_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) ); 356 461 local_process->vfs_bin_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) ); … … 380 485 local_process->th_nr = 0; 381 486 rwlock_init( &local_process->th_lock , LOCK_PROCESS_THTBL ); 382 383 487 384 488 // register new process descriptor in local cluster manager local_list … … 451 555 #endif 452 556 453 // remove process from children_list 454 // and release PID if owner cluster 557 // when target process cluster is the owner cluster 558 // - remove process from TXT list and transfer ownership 559 // - remove process from children_list 560 // - release PID 455 561 if( CXY_FROM_PID( pid ) == local_cxy ) 456 562 { 563 process_txt_detach( XPTR( local_cxy , process ) ); 564 565 #if (DEBUG_PROCESS_DESTROY & 1) 566 if( DEBUG_PROCESS_DESTROY < cycle ) 567 printk("\n[%s] thread[%x,%x] removed process %x from TXT list\n", 568 __FUNCTION__, this->process->pid, this->trdid, pid ); 569 #endif 570 457 571 // get pointers on parent process 458 572 parent_xp = process->parent_xp; … … 472 586 #if (DEBUG_PROCESS_DESTROY & 1) 473 587 if( DEBUG_PROCESS_DESTROY < cycle ) 474 printk("\n[%s] thread[%x,%x] removed process %x in cluster %x fromchildren list\n",475 __FUNCTION__, this->process->pid, this->trdid, pid , local_cxy);588 printk("\n[%s] thread[%x,%x] removed process %x from parent process children list\n", 589 __FUNCTION__, this->process->pid, this->trdid, pid ); 476 590 #endif 477 591 … … 777 891 uint32_t cycle = (uint32_t)hal_get_cycles(); 778 892 if( DEBUG_PROCESS_SIGACTION < cycle ) 779 printk("\n[%s] thread[%x,%x] enter in cluster %x for process%x / cycle %d\n",780 __FUNCTION__, this->process->pid, this->trdid, local_cxy, process->pid, cycle );893 printk("\n[%s] thread[%x,%x] enter for process %x n cluster %x / cycle %d\n", 894 __FUNCTION__, this->process->pid, this->trdid, process->pid, local_cxy, cycle ); 781 895 #endif 782 896 … … 1189 1303 } // end process_register_thread() 1190 1304 1191 ///////////////////////////////////////////////// 1192 bool_t process_remove_thread( thread_t * thread )1305 /////////////////////////////////////////////////// 1306 uint32_t process_remove_thread( thread_t * thread ) 1193 1307 { 1194 1308 uint32_t count; // number of threads in local process descriptor 1309 1310 // check thread 1311 assert( (thread != NULL) , "thread argument is NULL" ); 1195 1312 1196 1313 process_t * process = thread->process; … … 1205 1322 count = process->th_nr; 1206 1323 1207 // check thread1208 assert( (thread != NULL) , "thread argument is NULL" );1209 1210 1324 // check th_nr value 1211 1325 assert( (count > 0) , "process th_nr cannot be 0" ); … … 1218 1332 rwlock_wr_release( &process->th_lock ); 1219 1333 1220 return (count == 1);1334 return count; 1221 1335 1222 1336 } // end process_remove_thread() … … 1283 1397 cycle = (uint32_t)hal_get_cycles(); 1284 1398 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1285 printk("\n[%s] thread[%x,%x] allocated process %x / cycle %d\n",1399 printk("\n[%s] thread[%x,%x] allocated child_process %x / cycle %d\n", 1286 1400 __FUNCTION__, pid, trdid, new_pid, cycle ); 1287 1401 #endif 1288 1402 1289 1403 // initializes child process descriptor from parent process descriptor 1290 process_reference_init( process, 1291 new_pid, 1292 parent_process_xp ); 1404 error = process_reference_init( process, 1405 new_pid, 1406 parent_process_xp ); 1407 if( error ) 1408 { 1409 printk("\n[ERROR] in %s : cannot initialize child process in cluster %x\n", 1410 __FUNCTION__, local_cxy ); 1411 process_free( process ); 1412 return -1; 1413 } 1293 1414 1294 1415 #if( DEBUG_PROCESS_MAKE_FORK & 1 ) … … 1298 1419 __FUNCTION__, pid, trdid, new_pid, cycle ); 1299 1420 #endif 1300 1301 1421 1302 1422 // copy VMM from parent descriptor to child descriptor … … 1361 1481 #endif 1362 1482 1363 // set C opy_On_Write flag in parent process GPT1364 // this includes all replicated GPT copies1483 // set COW flag in DATA, ANON, REMOTE vsegs for parent process VMM 1484 // this includes all parnet process copies in all clusters 1365 1485 if( parent_process_cxy == local_cxy ) // reference is local 1366 1486 { … … 1373 1493 } 1374 1494 1375 // set C opy_On_Write flag in child process GPT1495 // set COW flag in DATA, ANON, REMOTE vsegs for child process VMM 1376 1496 vmm_set_cow( process ); 1377 1497 … … 1423 1543 char ** args_pointers; // array of pointers on main thread arguments 1424 1544 1425 // get thread, process, pid and ref_xp1545 // get calling thread, process, pid and ref_xp 1426 1546 thread = CURRENT_THREAD; 1427 1547 process = thread->process; … … 1470 1590 cycle = (uint32_t)hal_get_cycles(); 1471 1591 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1472 printk("\n[%s] thread[%x,%x] deleted allthreads / cycle %d\n",1592 printk("\n[%s] thread[%x,%x] deleted existing threads / cycle %d\n", 1473 1593 __FUNCTION__, pid, thread->trdid, cycle ); 1474 1594 #endif 1475 1595 1476 // reset localprocess VMM1477 vmm_ destroy( process );1596 // reset calling process VMM 1597 vmm_user_reset( process ); 1478 1598 1479 1599 #if( DEBUG_PROCESS_MAKE_EXEC & 1 ) 1480 1600 cycle = (uint32_t)hal_get_cycles(); 1481 1601 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1482 printk("\n[%s] thread[%x,%x] reset VMM/ cycle %d\n",1602 printk("\n[%s] thread[%x,%x] completed VMM reset / cycle %d\n", 1483 1603 __FUNCTION__, pid, thread->trdid, cycle ); 1484 1604 #endif 1485 1605 1486 // re-initialize the VMM ( kentry/args/envs vsegs registration)1487 error = vmm_ init( process );1606 // re-initialize the VMM (args/envs vsegs registration) 1607 error = vmm_user_init( process ); 1488 1608 if( error ) 1489 1609 { … … 1497 1617 cycle = (uint32_t)hal_get_cycles(); 1498 1618 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1499 printk("\n[%s] thread[%x,%x] / kentry/args/envs vsegs registered/ cycle %d\n",1619 printk("\n[%s] thread[%x,%x] registered args/envs vsegs / cycle %d\n", 1500 1620 __FUNCTION__, pid, thread->trdid, cycle ); 1501 1621 #endif … … 1515 1635 cycle = (uint32_t)hal_get_cycles(); 1516 1636 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1517 printk("\n[%s] thread[%x,%x] / code/data vsegs registered/ cycle %d\n",1637 printk("\n[%s] thread[%x,%x] registered code/data vsegs / cycle %d\n", 1518 1638 __FUNCTION__, pid, thread->trdid, cycle ); 1519 1639 #endif … … 1577 1697 vmm->vsegs_nr = 0; 1578 1698 xlist_root_init( XPTR( local_cxy , &vmm->vsegs_root ) ); 1579 remote_rwlock_init( XPTR( local_cxy , &vmm->vsegs_lock ) , LOCK_VMM_VSL );1580 1699 1581 1700 // initialise GPT as empty 1582 1701 error = hal_gpt_create( &vmm->gpt ); 1583 1584 1702 if( error ) 1585 1703 { … … 1588 1706 } 1589 1707 1590 // initialize GPT lock 1708 // initialize VSL and GPT locks 1709 remote_rwlock_init( XPTR( local_cxy , &vmm->vsl_lock ) , LOCK_VMM_VSL ); 1591 1710 remote_rwlock_init( XPTR( local_cxy , &vmm->gpt_lock ) , LOCK_VMM_GPT ); 1592 1711 1593 1712 // create kernel vsegs in GPT and VSL, as required by the hardware architecture 1594 1713 error = hal_vmm_kernel_init( info ); 1595 1596 1714 if( error ) 1597 1715 { … … 1652 1770 // allocates memory for process descriptor from local cluster 1653 1771 process = process_alloc(); 1654 1655 // check memory allocator 1656 assert( (process != NULL), 1657 "no memory for process descriptor in cluster %x", local_cxy ); 1772 if( process == NULL ) 1773 { 1774 printk("\n[PANIC] in %s : cannot allocate process\n", __FUNCTION__ ); 1775 hal_core_sleep(); 1776 } 1658 1777 1659 1778 // set the CWD and VFS_ROOT fields in process descriptor … … 1663 1782 // get PID from local cluster 1664 1783 error = cluster_pid_alloc( process , &pid ); 1665 1666 // check PID allocator 1667 assert( (error == 0), 1668 "cannot allocate PID in cluster %x", local_cxy ); 1669 1670 // check PID value 1671 assert( (pid == 1) , 1672 "process INIT must be first process in cluster 0" ); 1784 if( error ) 1785 { 1786 printk("\n[PANIC] in %s : cannot allocate PID\n", __FUNCTION__ ); 1787 hal_core_sleep(); 1788 } 1789 if( pid != 1 ) 1790 { 1791 printk("\n[PANIC] in %s : process PID must be 0x1\n", __FUNCTION__ ); 1792 hal_core_sleep(); 1793 } 1673 1794 1674 1795 // initialize process descriptor / parent is local process_zero 1675 process_reference_init( process, 1676 pid, 1677 XPTR( local_cxy , &process_zero ) ); 1796 error = process_reference_init( process, 1797 pid, 1798 XPTR( local_cxy , &process_zero ) ); 1799 if( error ) 1800 { 1801 printk("\n[PANIC] in %s : cannot initialize process\n", __FUNCTION__ ); 1802 hal_core_sleep(); 1803 } 1678 1804 1679 1805 #if(DEBUG_PROCESS_INIT_CREATE & 1) … … 1693 1819 &file_xp, 1694 1820 &file_id ); 1695 1696 assert( (error == 0), 1697 "failed to open file <%s>", CONFIG_PROCESS_INIT_PATH ); 1821 if( error ) 1822 { 1823 printk("\n[PANIC] in %s : cannot open file <%s>\n", 1824 __FUNCTION__, CONFIG_PROCESS_INIT_PATH ); 1825 hal_core_sleep(); 1826 } 1698 1827 1699 1828 #if(DEBUG_PROCESS_INIT_CREATE & 1) … … 1703 1832 #endif 1704 1833 1705 // register "code" and "data" vsegs as well as entry-point1834 // register "code" and "data" vsegs as well as entry-point 1706 1835 // in process VMM, using information contained in the elf file. 1707 1836 error = elf_load_process( file_xp , process ); 1708 1837 1709 assert( (error == 0), 1710 "cannot access .elf file <%s>", CONFIG_PROCESS_INIT_PATH ); 1838 if( error ) 1839 { 1840 printk("\n[PANIC] in %s : cannot access file <%s>\n", 1841 __FUNCTION__, CONFIG_PROCESS_INIT_PATH ); 1842 hal_core_sleep(); 1843 } 1844 1711 1845 1712 1846 #if(DEBUG_PROCESS_INIT_CREATE & 1) … … 1714 1848 printk("\n[%s] thread[%x,%x] registered code/data vsegs in VMM\n", 1715 1849 __FUNCTION__, this->process->pid, this->trdid ); 1850 #endif 1851 1852 #if (DEBUG_PROCESS_INIT_CREATE & 1) 1853 hal_vmm_display( process , true ); 1716 1854 #endif 1717 1855 … … 1751 1889 &thread ); 1752 1890 1753 assert( (error == 0), 1754 "cannot create main thread for <%s>", CONFIG_PROCESS_INIT_PATH ); 1755 1756 assert( (thread->trdid == 0), 1757 "main thread must have index 0 for <%s>", CONFIG_PROCESS_INIT_PATH ); 1891 if( error ) 1892 { 1893 printk("\n[PANIC] in %s : cannot create main thread\n", __FUNCTION__ ); 1894 hal_core_sleep(); 1895 } 1896 if( thread->trdid != 0 ) 1897 { 1898 printk("\n[PANIC] in %s : bad main thread trdid\n", __FUNCTION__ ); 1899 hal_core_sleep(); 1900 } 1758 1901 1759 1902 #if(DEBUG_PROCESS_INIT_CREATE & 1) … … 1989 2132 process_txt_transfer_ownership( process_xp ); 1990 2133 1991 // get extended pointer on process stdin file2134 // get extended pointer on process stdin pseudo file 1992 2135 file_xp = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) ); 1993 2136 … … 2014 2157 uint32_t txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) ); 2015 2158 if( DEBUG_PROCESS_TXT < cycle ) 2016 printk("\n[%s] thread[%x,%x] detached process %x from TXT 2159 printk("\n[%s] thread[%x,%x] detached process %x from TXT%d / cycle %d\n", 2017 2160 __FUNCTION__, this->process->pid, this->trdid, process_pid, txt_id, cycle ); 2018 2161 #endif … … 2056 2199 uint32_t txt_id = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) ); 2057 2200 if( DEBUG_PROCESS_TXT < cycle ) 2058 printk("\n[%s] thread[%x,%x] give TXT %dto process %x / cycle %d\n",2201 printk("\n[%s] thread[%x,%x] give TXT%d ownership to process %x / cycle %d\n", 2059 2202 __FUNCTION__, this->process->pid, this->trdid, txt_id, process_pid, cycle ); 2060 2203 #endif … … 2078 2221 xptr_t iter_xp; // iterator for xlist 2079 2222 xptr_t current_xp; // extended pointer on current process 2080 process_t * current_ptr; // local pointer on current process 2081 cxy_t current_cxy; // cluster for current process 2223 bool_t found; 2082 2224 2083 2225 #if DEBUG_PROCESS_TXT … … 2086 2228 #endif 2087 2229 2088 // get pointers on process in owner cluster2230 // get pointers on target process 2089 2231 process_cxy = GET_CXY( process_xp ); 2090 2232 process_ptr = GET_PTR( process_xp ); 2091 2233 process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ); 2092 2234 2093 2094 2095 2235 // check owner cluster 2236 assert( (process_cxy == CXY_FROM_PID( process_pid )) , 2237 "process descriptor not in owner cluster" ); 2096 2238 2097 2239 // get extended pointer on stdin pseudo file … … 2103 2245 txt_ptr = GET_PTR( txt_xp ); 2104 2246 2105 // get extended pointer on TXT_RX owner and TXT channel2247 // get relevant infos from chdev descriptor 2106 2248 owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) ); 2107 txt_id = hal_remote_l32 2108 2109 // transfer ownership only if process is the TXT owner2249 txt_id = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) ); 2250 2251 // transfer ownership only if target process is the TXT owner 2110 2252 if( (owner_xp == process_xp) && (txt_id > 0) ) 2111 2253 { … … 2114 2256 lock_xp = XPTR( txt_cxy , &txt_ptr->ext.txt.lock ); 2115 2257 2116 // get lock 2117 remote_busylock_acquire( lock_xp ); 2118 2119 if( process_get_ppid( process_xp ) != 1 ) // process is not KSH 2258 if( process_get_ppid( process_xp ) != 1 ) // target process is not KSH 2120 2259 { 2260 // get lock 2261 remote_busylock_acquire( lock_xp ); 2262 2121 2263 // scan attached process list to find KSH process 2122 XLIST_FOREACH( root_xp , iter_xp ) 2264 found = false; 2265 for( iter_xp = hal_remote_l64( root_xp ) ; 2266 (iter_xp != root_xp) && (found == false) ; 2267 iter_xp = hal_remote_l64( iter_xp ) ) 2268 { 2269 current_xp = XLIST_ELEMENT( iter_xp , process_t , txt_list ); 2270 2271 if( process_get_ppid( current_xp ) == 1 ) // current is KSH 2272 { 2273 // set owner field in TXT chdev 2274 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp ); 2275 2276 #if DEBUG_PROCESS_TXT 2277 cycle = (uint32_t)hal_get_cycles(); 2278 if( DEBUG_PROCESS_TXT < cycle ) 2279 printk("\n[%s] thread[%x,%x] transfered TXT%d ownership to KSH / cycle %d\n", 2280 __FUNCTION__, this->process->pid, this->trdid, txt_id, cycle ); 2281 #endif 2282 found = true; 2283 } 2284 } 2285 2286 // release lock 2287 remote_busylock_release( lock_xp ); 2288 2289 // It must exist a KSH process for each user TXT channel 2290 assert( (found == true), "KSH process not found for TXT%d", txt_id ); 2291 2292 } 2293 else // target process is KSH 2294 { 2295 // get lock 2296 remote_busylock_acquire( lock_xp ); 2297 2298 // scan attached process list to find another process 2299 found = false; 2300 for( iter_xp = hal_remote_l64( root_xp ) ; 2301 (iter_xp != root_xp) && (found == false) ; 2302 iter_xp = hal_remote_l64( iter_xp ) ) 2123 2303 { 2124 2304 current_xp = XLIST_ELEMENT( iter_xp , process_t , txt_list ); 2125 current_cxy = GET_CXY( current_xp ); 2126 current_ptr = GET_PTR( current_xp ); 2127 2128 if( process_get_ppid( current_xp ) == 1 ) // current is KSH 2305 2306 if( current_xp != process_xp ) // current is not KSH 2129 2307 { 2130 // release lock2131 remote_busylock_release( lock_xp );2132 2133 2308 // set owner field in TXT chdev 2134 2309 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp ); 2135 2310 2136 2311 #if DEBUG_PROCESS_TXT 2137 cycle = (uint32_t)hal_get_cycles(); 2138 uint32_t ksh_pid = hal_remote_l32( XPTR( current_cxy , ¤t_ptr->pid ) ); 2312 cycle = (uint32_t)hal_get_cycles(); 2313 cxy_t current_cxy = GET_CXY( current_xp ); 2314 process_t * current_ptr = GET_PTR( current_xp ); 2315 uint32_t new_pid = hal_remote_l32( XPTR( current_cxy , ¤t_ptr->pid ) ); 2139 2316 if( DEBUG_PROCESS_TXT < cycle ) 2140 printk("\n[%s] thread[%x,%x] release TXT %d to KSH %x / cycle %d\n", 2141 __FUNCTION__, this->process->pid, this->trdid, txt_id, ksh_pid, cycle ); 2142 process_txt_display( txt_id ); 2143 #endif 2144 return; 2317 printk("\n[%s] thread[%x,%x] transfered TXT%d ownership to process %x / cycle %d\n", 2318 __FUNCTION__,this->process->pid, this->trdid, txt_id, new_pid, cycle ); 2319 #endif 2320 found = true; 2145 2321 } 2146 2322 } 2147 2323 2148 2324 // release lock 2149 2325 remote_busylock_release( lock_xp ); 2150 2326 2151 // PANIC if KSH not found 2152 assert( false , "KSH process not found for TXT %d" ); 2153 2154 return; 2327 // no more owner for TXT if no other process found 2328 if( found == false ) 2329 { 2330 // set owner field in TXT chdev 2331 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL ); 2332 2333 #if DEBUG_PROCESS_TXT 2334 cycle = (uint32_t)hal_get_cycles(); 2335 if( DEBUG_PROCESS_TXT < cycle ) 2336 printk("\n[%s] thread[%x,%x] released TXT%d (no attached process) / cycle %d\n", 2337 __FUNCTION__, this->process->pid, this->trdid, txt_id, cycle ); 2338 #endif 2339 } 2155 2340 } 2156 else // process is KSH 2157 { 2158 // scan attached process list to find another process 2159 XLIST_FOREACH( root_xp , iter_xp ) 2160 { 2161 current_xp = XLIST_ELEMENT( iter_xp , process_t , txt_list ); 2162 current_cxy = GET_CXY( current_xp ); 2163 current_ptr = GET_PTR( current_xp ); 2164 2165 if( current_xp != process_xp ) // current is not KSH 2166 { 2167 // release lock 2168 remote_busylock_release( lock_xp ); 2169 2170 // set owner field in TXT chdev 2171 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp ); 2341 } 2342 else 2343 { 2172 2344 2173 2345 #if DEBUG_PROCESS_TXT 2174 cycle = (uint32_t)hal_get_cycles(); 2175 uint32_t new_pid = hal_remote_l32( XPTR( current_cxy , ¤t_ptr->pid ) ); 2346 cycle = (uint32_t)hal_get_cycles(); 2176 2347 if( DEBUG_PROCESS_TXT < cycle ) 2177 printk("\n[%s] thread[%x,%x] release TXT %d to process %x / cycle %d\n", 2178 __FUNCTION__,this->process->pid, this->trdid, txt_id, new_pid, cycle ); 2179 process_txt_display( txt_id ); 2180 #endif 2181 return; 2182 } 2183 } 2184 2185 // release lock 2186 remote_busylock_release( lock_xp ); 2187 2188 // no more owner for TXT if no other process found 2189 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL ); 2190 2191 #if DEBUG_PROCESS_TXT 2192 cycle = (uint32_t)hal_get_cycles(); 2193 if( DEBUG_PROCESS_TXT < cycle ) 2194 printk("\n[%s] thread[%x,%x] release TXT %d to nobody / cycle %d\n", 2195 __FUNCTION__, this->process->pid, this->trdid, txt_id, cycle ); 2196 process_txt_display( txt_id ); 2197 #endif 2198 return; 2199 } 2200 } 2201 else 2202 { 2203 2204 #if DEBUG_PROCESS_TXT 2205 cycle = (uint32_t)hal_get_cycles(); 2206 if( DEBUG_PROCESS_TXT < cycle ) 2207 printk("\n[%s] thread %x in process %d does nothing (not TXT owner) / cycle %d\n", 2208 __FUNCTION__, this->trdid, process_pid, cycle ); 2209 process_txt_display( txt_id ); 2210 #endif 2211 2212 } 2348 printk("\n[%s] thread[%x,%x] does nothing for process %x (not TXT owner) / cycle %d\n", 2349 __FUNCTION__, this->process->pid, this->trdid, process_pid, cycle ); 2350 #endif 2351 2352 } 2353 2213 2354 } // end process_txt_transfer_ownership() 2214 2355
Note: See TracChangeset
for help on using the changeset viewer.