Changeset 435 for trunk/kernel/kern/process.c
- Timestamp:
- Feb 20, 2018, 5:32:17 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.c
r433 r435 51 51 #include <elf.h> 52 52 #include <syscalls.h> 53 #include <s ignal.h>53 #include <shared_syscalls.h> 54 54 55 55 ////////////////////////////////////////////////////////////////////////////////////////// … … 114 114 // get model process cluster and local pointer 115 115 model_cxy = GET_CXY( model_xp ); 116 model_ptr = (process_t *)GET_PTR( model_xp );116 model_ptr = GET_PTR( model_xp ); 117 117 118 118 // get parent process cluster and local pointer 119 119 parent_cxy = GET_CXY( parent_xp ); 120 parent_ptr = (process_t *)GET_PTR( parent_xp );120 parent_ptr = GET_PTR( parent_xp ); 121 121 122 122 // get model_pid and parent_pid … … 209 209 // get cluster and local pointer on chdev 210 210 chdev_cxy = GET_CXY( chdev_xp ); 211 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );211 chdev_ptr = GET_PTR( chdev_xp ); 212 212 213 213 // get TXT terminal index … … 289 289 // get reference process cluster and local pointer 290 290 cxy_t ref_cxy = GET_CXY( reference_process_xp ); 291 process_t * ref_ptr = (process_t *)GET_PTR( reference_process_xp );291 process_t * ref_ptr = GET_PTR( reference_process_xp ); 292 292 293 293 // initialize PID, REF_XP, PARENT_XP, and STATE … … 364 364 process_t * parent_ptr; 365 365 cxy_t parent_cxy; 366 xptr_t parent_thread_xp;367 366 xptr_t children_lock_xp; 368 367 xptr_t copies_lock_xp; … … 450 449 } 451 450 452 //////////////////////////////////////// ////453 void process_sigaction( p rocess_t * process,451 //////////////////////////////////////// 452 void process_sigaction( pid_t pid, 454 453 uint32_t action_type ) 455 454 { … … 467 466 rpc_desc_t rpc; // rpc descriptor allocated in stack 468 467 468 thread_t * client = CURRENT_THREAD; 469 469 470 #if CONFIG_DEBUG_PROCESS_SIGACTION 470 471 uint32_t cycle = (uint32_t)hal_get_cycles(); 471 472 if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle ) 472 printk("\n[DBG] %s : thread %x enter to %s process %x in cluster %x / cycle %d\n", 473 __FUNCTION__ , CURRENT_THREAD, process_action_str( action_type ) , 474 process->pid , local_cxy , cycle ); 475 #endif 476 477 thread_t * client = CURRENT_THREAD; 473 printk("\n[DBG] %s : thread %x enter to %s process %x / cycle %d\n", 474 __FUNCTION__ , client, process_action_str( action_type ) , pid , cycle ); 475 #endif 478 476 479 477 // get local pointer on local cluster manager … … 481 479 482 480 // get owner cluster identifier and process lpid 483 owner_cxy = CXY_FROM_PID( p rocess->pid );484 lpid = LPID_FROM_PID( p rocess->pid );485 486 // checkowner cluster487 assert( (owner_cxy == local_cxy) , __FUNCTION__ , "must be executed in owner cluster\n" );488 489 // get number of remote copies490 responses = cluster->pmgr.copies_nr[lpid] - 1; 481 owner_cxy = CXY_FROM_PID( pid ); 482 lpid = LPID_FROM_PID( pid ); 483 484 // get root of list of copies, lock, and number of copies from owner cluster 485 responses = hal_remote_lw ( XPTR( owner_cxy , &cluster->pmgr.copies_nr[lpid] ) ); 486 root_xp = hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] ) ); 487 lock_xp = hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] ) ); 488 491 489 rsp_count = 0; 492 490 … … 502 500 rpc.thread = client; 503 501 504 // get extended pointers on copies root and lock505 root_xp = XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] );506 lock_xp = XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] );507 508 502 // take the lock protecting the copies 509 503 remote_spinlock_lock( lock_xp ); … … 514 508 process_xp = XLIST_ELEMENT( iter_xp , process_t , copies_list ); 515 509 process_cxy = GET_CXY( process_xp ); 516 process_ptr = (process_t *)GET_PTR( process_xp ); 517 518 // send RPC to remote clusters 519 if( process_cxy != local_cxy ) 520 { 510 process_ptr = GET_PTR( process_xp ); 521 511 522 512 #if CONFIG_DEBUG_PROCESS_SIGACTION 523 513 if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle ) 524 printk("\n[DBG] %s : send RPC to remote cluster %x\n", __FUNCTION__ , process_cxy ); 525 #endif 526 527 rpc.args[0] = (uint64_t)action_type; 528 rpc.args[1] = (uint64_t)(intptr_t)process_ptr; 529 rpc_process_sigaction_client( process_cxy , &rpc ); 530 rsp_count++; 531 } 514 printk("\n[DBG] %s : send RPC to cluster %x\n", __FUNCTION__ , process_cxy ); 515 #endif 516 517 // check PID 518 assert( (hal_remote_lw( XPTR( process_cxy , &process_ptr->pid) ) == pid), 519 __FUNCTION__ , "unconsistent PID value\n" ); 520 521 rpc.args[0] = (uint64_t)action_type; 522 rpc.args[1] = (uint64_t)pid; 523 rpc_process_sigaction_client( process_cxy , &rpc ); 524 rsp_count++; 532 525 } 533 526 … … 540 533 rsp_count , responses ); 541 534 542 // block and deschedule to wait RPC responses if required 543 if( responses ) 544 { 545 thread_block( CURRENT_THREAD , THREAD_BLOCKED_RPC ); 546 sched_yield("BLOCKED on RPC_PROCESS_SIGACTION"); 547 } 548 549 #if CONFIG_DEBUG_PROCESS_SIGACTION 550 if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle ) 551 printk("\n[DBG] %s : make action in owner cluster %x\n", __FUNCTION__ , local_cxy ); 552 #endif 553 554 // call directly the relevant function in local owner cluster 555 if (action_type == DELETE_ALL_THREADS ) process_delete_threads ( process ); 556 else if (action_type == BLOCK_ALL_THREADS ) process_block_threads ( process ); 557 else if (action_type == UNBLOCK_ALL_THREADS ) process_unblock_threads( process ); 535 // block and deschedule to wait RPC responses 536 thread_block( CURRENT_THREAD , THREAD_BLOCKED_RPC ); 537 sched_yield("BLOCKED on RPC_PROCESS_SIGACTION"); 558 538 559 539 #if CONFIG_DEBUG_PROCESS_SIGACTION … … 561 541 if( CONFIG_DEBUG_PROCESS_SIGACTION < cycle ) 562 542 printk("\n[DBG] %s : thread %x exit after %s process %x in cluster %x / cycle %d\n", 563 __FUNCTION__ , CURRENT_THREAD, process_action_str( action_type ) ,543 __FUNCTION__ , client, process_action_str( action_type ) , 564 544 process->pid , local_cxy , cycle ); 565 545 #endif … … 778 758 { 779 759 process_xp = XLIST_ELEMENT( iter , process_t , local_list ); 780 process_ptr = (process_t *)GET_PTR( process_xp );760 process_ptr = GET_PTR( process_xp ); 781 761 if( process_ptr->pid == pid ) 782 762 { … … 838 818 839 819 // get reference process cluster and local pointer 840 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );820 process_t * ref_ptr = GET_PTR( ref_xp ); 841 821 cxy_t ref_cxy = GET_CXY( ref_xp ); 842 822 … … 858 838 // get reference process cluster and local pointer 859 839 xptr_t ref_xp = process->ref_xp; 860 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );840 process_t * ref_ptr = GET_PTR( ref_xp ); 861 841 cxy_t ref_cxy = GET_CXY( ref_xp ); 862 842 … … 900 880 xptr_t ref_xp = process->ref_xp; 901 881 cxy_t ref_cxy = GET_CXY( ref_xp ); 902 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );882 process_t * ref_ptr = GET_PTR( ref_xp ); 903 883 904 884 // access reference process descriptor … … 925 905 // get cluster and local pointer for src fd_array 926 906 cxy_t src_cxy = GET_CXY( src_xp ); 927 fd_array_t * src_ptr = (fd_array_t *)GET_PTR( src_xp );907 fd_array_t * src_ptr = GET_PTR( src_xp ); 928 908 929 909 // get cluster and local pointer for dst fd_array 930 910 cxy_t dst_cxy = GET_CXY( dst_xp ); 931 fd_array_t * dst_ptr = (fd_array_t *)GET_PTR( dst_xp );911 fd_array_t * dst_ptr = GET_PTR( dst_xp ); 932 912 933 913 // get the remote lock protecting the src fd_array … … 1044 1024 // get cluster and local pointer for parent process 1045 1025 cxy_t parent_process_cxy = GET_CXY( parent_process_xp ); 1046 process_t * parent_process_ptr = (process_t *)GET_PTR( parent_process_xp );1026 process_t * parent_process_ptr = GET_PTR( parent_process_xp ); 1047 1027 1048 1028 // get parent process PID and extended pointer on .elf file … … 1349 1329 } // end process_make_exec() 1350 1330 1351 ////////////////////////////////////////////1352 void process_make_kill( process_t * process,1353 bool_t is_exit,1354 uint32_t exit_status )1355 {1356 thread_t * this = CURRENT_THREAD;1357 1358 assert( (CXY_FROM_PID( process->pid ) == local_cxy) , __FUNCTION__ ,1359 "must be executed in process owner cluster\n" );1360 1361 assert( ( this->type == THREAD_RPC ) , __FUNCTION__ ,1362 "must be executed by an RPC thread\n" );1363 1364 #if CONFIG_DEBUG_PROCESS_MAKE_KILL1365 uint32_t cycle = (uint32_t)hal_get_cycles();1366 if( CONFIG_DEBUG_PROCESS_MAKE_KILL < cycle )1367 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",1368 __FUNCTION__, this , process->pid , cycle );1369 #endif1370 1371 // register exit_status in owner process descriptor1372 if( is_exit ) process->term_state = exit_status;1373 1374 // atomically update owner process descriptor flags1375 if( is_exit ) hal_atomic_or( &process->term_state , PROCESS_FLAG_EXIT );1376 else hal_atomic_or( &process->term_state , PROCESS_FLAG_KILL );1377 1378 // remove TXT ownership from owner process descriptor1379 process_txt_reset_ownership( XPTR( local_cxy , process ) );1380 1381 // block all process threads in all clusters1382 process_sigaction( process , BLOCK_ALL_THREADS );1383 1384 // mark all process threads in all clusters for delete1385 process_sigaction( process , DELETE_ALL_THREADS );1386 1387 /* unused if sys_wait deschedules without blocking [AG]1388 1389 // get cluster and pointers on reference parent process1390 xptr_t parent_xp = process->parent_xp;1391 process_t * parent_ptr = GET_PTR( parent_xp );1392 cxy_t parent_cxy = GET_CXY( parent_xp );1393 1394 // get loal pointer on parent main thread1395 thread_t * main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );1396 1397 // reset THREAD_BLOCKED_WAIT bit in parent process main thread1398 thread_unblock( XPTR( parent_cxy , main_ptr ) , THREAD_BLOCKED_WAIT );1399 */1400 1401 #if CONFIG_DEBUG_PROCESS_MAKE_KILL1402 cycle = (uint32_t)hal_get_cycles();1403 if( CONFIG_DEBUG_PROCESS_MAKE_KILL < cycle )1404 printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n",1405 __FUNCTION__, this, process->pid , cycle );1406 #endif1407 1408 } // end process_make_kill()1409 1410 1331 /////////////////////////////////////////////// 1411 1332 void process_zero_create( process_t * process ) … … 1679 1600 if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle ) 1680 1601 printk("\n[DBG] %s : thread %x enter for process %x / txt_id = %d / cycle %d\n", 1681 __FUNCTION__, CURRENT_THREAD, process ->pid, txt_id, cycle );1602 __FUNCTION__, CURRENT_THREAD, process, txt_id, cycle ); 1682 1603 #endif 1683 1604 … … 1708 1629 if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle ) 1709 1630 printk("\n[DBG] %s : thread %x exit for process %x / txt_id = %d / cycle %d\n", 1710 __FUNCTION__, CURRENT_THREAD, process ->pid, txt_id , cycle );1631 __FUNCTION__, CURRENT_THREAD, process, txt_id , cycle ); 1711 1632 #endif 1712 1633 … … 1721 1642 xptr_t lock_xp; // extended pointer on list lock in chdev 1722 1643 1723 #if CONFIG_DEBUG_PROCESS_TXT_ DETACH1644 #if CONFIG_DEBUG_PROCESS_TXT_ATTACH 1724 1645 uint32_t cycle = (uint32_t)hal_get_cycles(); 1725 if( CONFIG_DEBUG_PROCESS_TXT_ DETACH < cycle )1646 if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle ) 1726 1647 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n", 1727 __FUNCTION__, CURRENT_THREAD, process ->pid, cycle );1648 __FUNCTION__, CURRENT_THREAD, process, cycle ); 1728 1649 #endif 1729 1650 … … 1745 1666 remote_spinlock_unlock( lock_xp ); 1746 1667 1747 #if CONFIG_DEBUG_PROCESS_TXT_ DETACH1748 cycle = (uint32_t)hal_get_cycles(); 1749 if( CONFIG_DEBUG_PROCESS_TXT_ DETACH < cycle )1668 #if CONFIG_DEBUG_PROCESS_TXT_ATTACH 1669 cycle = (uint32_t)hal_get_cycles(); 1670 if( CONFIG_DEBUG_PROCESS_TXT_ATTACH < cycle ) 1750 1671 printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n", 1751 __FUNCTION__, CURRENT_THREAD, process ->pid, cycle );1672 __FUNCTION__, CURRENT_THREAD, process, cycle ); 1752 1673 #endif 1753 1674 … … 1766 1687 // get cluster and local pointer on process 1767 1688 process_cxy = GET_CXY( process_xp ); 1768 process_ptr = (process_t *)GET_PTR( process_xp );1689 process_ptr = GET_PTR( process_xp ); 1769 1690 1770 1691 // get extended pointer on stdin pseudo file … … 1774 1695 txt_xp = chdev_from_file( file_xp ); 1775 1696 txt_cxy = GET_CXY( txt_xp ); 1776 txt_ptr = (chdev_t *)GET_PTR( txt_xp );1697 txt_ptr = GET_PTR( txt_xp ); 1777 1698 1778 1699 // set owner field in TXT chdev … … 1804 1725 // get cluster and local pointer on process 1805 1726 process_cxy = GET_CXY( process_xp ); 1806 process_ptr = (process_t *)GET_PTR( process_xp );1727 process_ptr = GET_PTR( process_xp ); 1807 1728 1808 1729 // get extended pointer on stdin pseudo file … … 1831 1752 current_ptr = GET_PTR( current_xp ); 1832 1753 parent_xp = hal_remote_lwd( XPTR( current_cxy , ¤t_ptr->parent_xp ) ); 1833 1834 1754 parent_cxy = GET_CXY( parent_xp ); 1835 1755 parent_ptr = GET_PTR( parent_xp ); 1836 1756 ppid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) ); 1757 1758 printk("\n@@@ %s : pid = %x / process = %x\n", __FUNCTION__ , current_ptr->pid, current_ptr ); 1837 1759 1838 1760 if( ppid == 1 ) // current is KSH … … 1849 1771 1850 1772 1851 1773 ////////////////////////////////////////////////////// 1774 inline pid_t process_get_txt_owner( uint32_t channel ) 1775 { 1776 xptr_t txt_rx_xp = chdev_dir.txt_rx[channel]; 1777 cxy_t txt_rx_cxy = GET_CXY( txt_rx_xp ); 1778 chdev_t * txt_rx_ptr = GET_PTR( txt_rx_xp ); 1779 1780 xptr_t process_xp = (xptr_t)hal_remote_lwd( XPTR( txt_rx_cxy, 1781 &txt_rx_ptr->ext.txt.owner_xp ) ); 1782 1783 cxy_t process_cxy = GET_CXY( process_xp ); 1784 process_t * process_ptr = GET_PTR( process_xp ); 1785 1786 return (pid_t)hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) ); 1787 } 1788 1789 /////////////////////////////////////////// 1790 void process_txt_display( uint32_t txt_id ) 1791 { 1792 xptr_t chdev_xp; 1793 cxy_t chdev_cxy; 1794 chdev_t * chdev_ptr; 1795 xptr_t root_xp; 1796 xptr_t lock_xp; 1797 xptr_t current_xp; 1798 xptr_t iter_xp; 1799 1800 // check terminal index 1801 assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) , 1802 __FUNCTION__ , "illegal TXT terminal index" ); 1803 1804 // get pointers on TXT_RX[txt_id] chdev 1805 chdev_xp = chdev_dir.txt_rx[txt_id]; 1806 chdev_cxy = GET_CXY( chdev_xp ); 1807 chdev_ptr = GET_PTR( chdev_xp ); 1808 1809 // get extended pointer on root & lock of attached process list 1810 root_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.root ); 1811 lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock ); 1812 1813 // display header 1814 printk("\n***** processes attached to TXT_%d\n", txt_id ); 1815 1816 // get lock 1817 remote_spinlock_lock( lock_xp ); 1818 1819 // scan attached process list to find KSH process 1820 XLIST_FOREACH( root_xp , iter_xp ) 1821 { 1822 current_xp = XLIST_ELEMENT( iter_xp , process_t , txt_list ); 1823 process_display( current_xp ); 1824 } 1825 1826 // release lock 1827 remote_spinlock_unlock( lock_xp ); 1828 1829 } // end process_txt_display
Note: See TracChangeset
for help on using the changeset viewer.