Changeset 564 for trunk/kernel/kern/process.c
- Timestamp:
- Oct 4, 2018, 11:47:36 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.c
r527 r564 1 1 /* 2 * process.c - process related management2 * process.c - process related functions definition. 3 3 * 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) … … 43 43 #include <string.h> 44 44 #include <scheduler.h> 45 #include <remote_spinlock.h> 45 #include <busylock.h> 46 #include <queuelock.h> 47 #include <remote_queuelock.h> 48 #include <rwlock.h> 49 #include <remote_rwlock.h> 46 50 #include <dqdt.h> 47 51 #include <cluster.h> … … 114 118 115 119 // get parent_pid 116 parent_pid = hal_remote_l w( XPTR( parent_cxy , &parent_ptr->pid ) );120 parent_pid = hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) ); 117 121 118 122 #if DEBUG_PROCESS_REFERENCE_INIT … … 132 136 // initialize vmm as empty 133 137 error = vmm_init( process ); 134 assert( (error == 0) , "cannot initialize VMM\n" ); 138 139 assert( (error == 0) , "cannot initialize VMM\n" ); 135 140 136 141 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) … … 138 143 if( DEBUG_PROCESS_REFERENCE_INIT ) 139 144 printk("\n[DBG] %s : thread %x in process %x / vmm empty for process %x / cycle %d\n", 140 __FUNCTION__, CURRENT_THREAD->trdid, parent_pid , cycle );145 __FUNCTION__, CURRENT_THREAD->trdid, parent_pid , pid, cycle ); 141 146 #endif 142 147 … … 160 165 __FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, txt_id, cycle ); 161 166 #endif 162 163 164 165 167 // build path to TXT_RX[i] and TXT_TX[i] chdevs 166 168 snprintf( rx_path , 40 , "/dev/external/txt%d_rx", txt_id ); … … 175 177 &stdin_id ); 176 178 177 178 179 assert( (error == 0) , "cannot open stdin pseudo file" ); 180 assert( (stdin_id == 0) , "stdin index must be 0" ); 179 181 180 182 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) … … 225 227 { 226 228 // get extended pointer on stdin pseudo file in parent process 227 file_xp = (xptr_t)hal_remote_l wd( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) );229 file_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) ); 228 230 229 231 // get extended pointer on parent process TXT chdev … … 234 236 chdev_ptr = GET_PTR( chdev_xp ); 235 237 236 // get TXT terminal index237 txt_id = hal_remote_l w( XPTR( chdev_cxy , &chdev_ptr->channel ) );238 239 // attach process to TXT[txt_id]238 // get parent process TXT terminal index 239 txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) ); 240 241 // attach child process to parent process TXT terminal 240 242 process_txt_attach( process , txt_id ); 241 243 … … 246 248 247 249 // initialize specific inodes root and cwd 248 process->vfs_root_xp = (xptr_t)hal_remote_l wd( XPTR( parent_cxy,250 process->vfs_root_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy, 249 251 &parent_ptr->vfs_root_xp ) ); 250 process->vfs_cwd_xp = (xptr_t)hal_remote_l wd( XPTR( parent_cxy,252 process->vfs_cwd_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy, 251 253 &parent_ptr->vfs_cwd_xp ) ); 252 254 vfs_inode_remote_up( process->vfs_root_xp ); 253 255 vfs_inode_remote_up( process->vfs_cwd_xp ); 254 256 255 remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) );257 remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ), LOCK_PROCESS_CWD ); 256 258 257 259 #if (DEBUG_PROCESS_REFERENCE_INIT & 1) 258 260 cycle = (uint32_t)hal_get_cycles(); 259 261 if( DEBUG_PROCESS_REFERENCE_INIT ) 260 printk("\n[DBG] %s : thread %x /fd_array for process %x / cycle %d\n",261 __FUNCTION__ , CURRENT_THREAD, pid , cycle );262 printk("\n[DBG] %s : thread %x in process %x / set fd_array for process %x / cycle %d\n", 263 __FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid , cycle ); 262 264 #endif 263 265 … … 265 267 xlist_root_init( XPTR( local_cxy , &process->children_root ) ); 266 268 process->children_nr = 0; 267 remote_ spinlock_init( XPTR( local_cxy , &process->children_lock ));269 remote_queuelock_init( XPTR( local_cxy , &process->children_lock ), LOCK_PROCESS_CHILDREN ); 268 270 269 271 // reset semaphore / mutex / barrier / condvar list roots … … 272 274 xlist_root_init( XPTR( local_cxy , &process->barrier_root ) ); 273 275 xlist_root_init( XPTR( local_cxy , &process->condvar_root ) ); 274 remote_ spinlock_init( XPTR( local_cxy , &process->sync_lock ));276 remote_queuelock_init( XPTR( local_cxy , &process->sync_lock ), LOCK_PROCESS_USERSYNC ); 275 277 276 278 // register new process in the local cluster manager pref_tbl[] … … 284 286 cluster_process_copies_link( process ); 285 287 286 // reset th_tbl[] array as empty in process descriptor288 // initialize th_tbl[] array and associated threads 287 289 uint32_t i; 288 for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ ) 290 291 for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ ) 289 292 { 290 293 process->th_tbl[i] = NULL; 291 294 } 292 295 process->th_nr = 0; 293 spinlock_init( &process->th_lock);296 rwlock_init( &process->th_lock , LOCK_PROCESS_THTBL ); 294 297 295 298 hal_fence(); … … 298 301 cycle = (uint32_t)hal_get_cycles(); 299 302 if( DEBUG_PROCESS_REFERENCE_INIT ) 300 printk("\n[DBG] %s : thread %x exit /process %x / cycle %d\n",301 __FUNCTION__ , CURRENT_THREAD , pid, cycle );303 printk("\n[DBG] %s : thread %x in process %x exit for process %x / cycle %d\n", 304 __FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle ); 302 305 #endif 303 306 … … 315 318 316 319 // initialize PID, REF_XP, PARENT_XP, and STATE 317 local_process->pid = hal_remote_l w( XPTR( ref_cxy , &ref_ptr->pid ) );318 local_process->parent_xp = hal_remote_l wd( XPTR( ref_cxy , &ref_ptr->parent_xp ) );320 local_process->pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) ); 321 local_process->parent_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->parent_xp ) ); 319 322 local_process->ref_xp = reference_process_xp; 320 323 local_process->owner_xp = reference_process_xp; 321 324 local_process->term_state = 0; 322 325 323 #if DEBUG_PROCESS_COPY_INIT 326 #if DEBUG_PROCESS_COPY_INIT 327 thread_t * this = CURRET_THREAD; 324 328 uint32_t cycle = (uint32_t)hal_get_cycles(); 325 329 if( DEBUG_PROCESS_COPY_INIT ) 326 printk("\n[DBG] %s : thread %x enter for process %x\n", 327 __FUNCTION__ , CURRENT_THREAD , local_process->pid ); 328 #endif 330 printk("\n[DBG] %s : thread %x in process %x enter for process %x / cycle %d\n", 331 __FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle ); 332 #endif 333 334 // check user process 335 assert( (local_process->pid != 0), "PID cannot be 0" ); 329 336 330 337 // reset local process vmm … … 336 343 337 344 // reset vfs_root_xp / vfs_bin_xp / vfs_cwd_xp fields 338 local_process->vfs_root_xp = hal_remote_l wd( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) );339 local_process->vfs_bin_xp = hal_remote_l wd( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) );345 local_process->vfs_root_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) ); 346 local_process->vfs_bin_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) ); 340 347 local_process->vfs_cwd_xp = XPTR_NULL; 341 348 … … 343 350 xlist_root_init( XPTR( local_cxy , &local_process->children_root ) ); 344 351 local_process->children_nr = 0; 345 remote_spinlock_init( XPTR( local_cxy , &local_process->children_lock ) ); 352 remote_queuelock_init( XPTR( local_cxy , &local_process->children_lock ), 353 LOCK_PROCESS_CHILDREN ); 346 354 347 355 // reset children_list (not used in a process descriptor copy) … … 354 362 xlist_root_init( XPTR( local_cxy , &local_process->condvar_root ) ); 355 363 356 // reset th_tbl[] array as empty364 // initialize th_tbl[] array and associated fields 357 365 uint32_t i; 358 for( i = 0 ; i < CONFIG_THREAD _MAX_PER_CLUSTER ; i++ )366 for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ ) 359 367 { 360 368 local_process->th_tbl[i] = NULL; 361 369 } 362 370 local_process->th_nr = 0; 363 spinlock_init( &local_process->th_lock ); 371 rwlock_init( &local_process->th_lock , LOCK_PROCESS_THTBL ); 372 364 373 365 374 // register new process descriptor in local cluster manager local_list … … 374 383 cycle = (uint32_t)hal_get_cycles(); 375 384 if( DEBUG_PROCESS_COPY_INIT ) 376 printk("\n[DBG] %s : thread %x exit for process %x\n",377 __FUNCTION__ , CURRENT_THREAD , local_process->pid);385 printk("\n[DBG] %s : thread %x in process %x exit for process %x / cycle %d\n", 386 __FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle ); 378 387 #endif 379 388 … … 399 408 uint32_t cycle = (uint32_t)hal_get_cycles(); 400 409 if( DEBUG_PROCESS_DESTROY ) 401 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",402 __FUNCTION__ , CURRENT_THREAD , pid , local_cxy, cycle );410 printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n", 411 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle ); 403 412 #endif 404 413 … … 423 432 424 433 // remove process from children_list 425 remote_ spinlock_lock( children_lock_xp );434 remote_queuelock_acquire( children_lock_xp ); 426 435 xlist_unlink( XPTR( local_cxy , &process->children_list ) ); 427 436 hal_remote_atomic_add( children_nr_xp , -1 ); 428 remote_spinlock_unlock( children_lock_xp ); 429 430 // release the process PID to cluster manager 431 cluster_pid_release( pid ); 432 433 } 434 435 // FIXME close all open files and update dirty [AG] 437 remote_queuelock_release( children_lock_xp ); 438 439 // release the process PID to cluster manager 440 cluster_pid_release( pid ); 441 } 442 443 // FIXME close all open files and synchronize dirty [AG] 436 444 437 445 // decrease refcount for bin file, root file and cwd file … … 449 457 cycle = (uint32_t)hal_get_cycles(); 450 458 if( DEBUG_PROCESS_DESTROY ) 451 printk("\n[DBG] %s : thread %x exit / destroyedprocess %x in cluster %x / cycle %d\n",452 __FUNCTION__ , CURRENT_THREAD, pid, local_cxy, cycle );459 printk("\n[DBG] %s : thread %x in process %x exit / process %x in cluster %x / cycle %d\n", 460 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle ); 453 461 #endif 454 462 … … 491 499 remote_nr = 0; 492 500 501 // check calling thread can yield 502 assert( (client->busylocks == 0), 503 "cannot yield : busylocks = %d\n", client->busylocks ); 504 493 505 #if DEBUG_PROCESS_SIGACTION 494 506 uint32_t cycle = (uint32_t)hal_get_cycles(); … … 517 529 518 530 // The client thread send parallel RPCs to all remote clusters containing 519 // target process copies, wait all responses, and then handles directly the520 // th reads in local cluster, when required.531 // target process copies, wait all responses, and then handles directly 532 // the threads in local cluster, when required. 521 533 // The client thread allocates a - shared - RPC descriptor in the stack, 522 534 // because all parallel, non-blocking, server threads use the same input … … 529 541 thread_block( client_xp , THREAD_BLOCKED_RPC ); 530 542 531 // take the lock protecting thecopies532 remote_ spinlock_lock( lock_xp );543 // take the lock protecting process copies 544 remote_queuelock_acquire( lock_xp ); 533 545 534 546 // initialize shared RPC descriptor … … 573 585 574 586 // release the lock protecting process copies 575 remote_ spinlock_unlock( lock_xp );587 remote_queuelock_release( lock_xp ); 576 588 577 589 // restore IRQs … … 620 632 thread_t * target; // pointer on target thread 621 633 thread_t * this; // pointer on calling thread 622 uint32_t ltid; // index in process th_tbl 634 uint32_t ltid; // index in process th_tbl[] 623 635 cxy_t owner_cxy; // target process owner cluster 624 636 uint32_t count; // requests counter … … 628 640 this = CURRENT_THREAD; 629 641 642 #if DEBUG_PROCESS_SIGACTION 643 pid_t pid = process->pid; 644 uint32_t cycle = (uint32_t)hal_get_cycles(); 645 if( DEBUG_PROCESS_SIGACTION < cycle ) 646 printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n", 647 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle ); 648 #endif 649 650 // check target process is an user process 651 assert( ( process->pid != 0 ), 652 "target process must be an user process" ); 653 630 654 // get target process owner cluster 631 655 owner_cxy = CXY_FROM_PID( process->pid ); 632 656 633 #if DEBUG_PROCESS_SIGACTION634 uint32_t cycle = (uint32_t)hal_get_cycles();635 if( DEBUG_PROCESS_SIGACTION < cycle )636 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",637 __FUNCTION__ , this , process->pid , local_cxy , cycle );638 #endif639 640 657 // get lock protecting process th_tbl[] 641 spinlock_lock( &process->th_lock );658 rwlock_rd_acquire( &process->th_lock ); 642 659 643 660 // loop on target process local threads … … 680 697 681 698 // release lock protecting process th_tbl[] 682 spinlock_unlock( &process->th_lock ); 683 684 // wait acknowledges 699 rwlock_rd_release( &process->th_lock ); 700 701 // busy waiting acknowledges 702 // TODO this could be improved... 685 703 while( 1 ) 686 704 { … … 695 713 cycle = (uint32_t)hal_get_cycles(); 696 714 if( DEBUG_PROCESS_SIGACTION < cycle ) 697 printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",698 __FUNCTION__ , this , process->pid, local_cxy , cycle );715 printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n", 716 __FUNCTION__, this, this->process->pid, pid, local_cxy , cycle ); 699 717 #endif 700 718 … … 719 737 720 738 #if DEBUG_PROCESS_SIGACTION 739 pid_t pid = process->pid; 721 740 uint32_t cycle = (uint32_t)hal_get_cycles(); 722 741 if( DEBUG_PROCESS_SIGACTION < cycle ) 723 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n", 724 __FUNCTION__ , this , process->pid , local_cxy , cycle ); 725 #endif 742 printk("\n[DBG] %s : thread %x n process %x enter for process %x in cluster %x / cycle %d\n", 743 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle ); 744 #endif 745 746 // check target process is an user process 747 assert( ( process->pid != 0 ), 748 "target process must be an user process" ); 726 749 727 750 // get lock protecting process th_tbl[] 728 spinlock_lock( &process->th_lock );751 rwlock_rd_acquire( &process->th_lock ); 729 752 730 753 // loop on target process local threads … … 739 762 target_xp = XPTR( local_cxy , target ); 740 763 741 // main thread and client thread should not be blocked764 // main thread and client thread should not be deleted 742 765 if( ((ltid != 0) || (owner_cxy != local_cxy)) && // not main thread 743 766 (client_xp) != target_xp ) // not client thread … … 750 773 751 774 // release lock protecting process th_tbl[] 752 spinlock_unlock( &process->th_lock );775 rwlock_rd_release( &process->th_lock ); 753 776 754 777 #if DEBUG_PROCESS_SIGACTION 755 778 cycle = (uint32_t)hal_get_cycles(); 756 779 if( DEBUG_PROCESS_SIGACTION < cycle ) 757 printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",758 __FUNCTION__ , this , process->pid, local_cxy , cycle );780 printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n", 781 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle ); 759 782 #endif 760 783 … … 773 796 774 797 #if DEBUG_PROCESS_SIGACTION 798 pid_t pid = process->pid; 775 799 uint32_t cycle = (uint32_t)hal_get_cycles(); 776 800 if( DEBUG_PROCESS_SIGACTION < cycle ) 777 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n", 778 __FUNCTION__ , this , process->pid , local_cxy , cycle ); 779 #endif 801 printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n", 802 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle ); 803 #endif 804 805 // check target process is an user process 806 assert( ( process->pid != 0 ), 807 "target process must be an user process" ); 780 808 781 809 // get lock protecting process th_tbl[] 782 spinlock_lock( &process->th_lock );810 rwlock_rd_acquire( &process->th_lock ); 783 811 784 812 // loop on process threads to unblock all threads … … 798 826 799 827 // release lock protecting process th_tbl[] 800 spinlock_unlock( &process->th_lock );828 rwlock_rd_release( &process->th_lock ); 801 829 802 830 #if DEBUG_PROCESS_SIGACTION 803 831 cycle = (uint32_t)hal_get_cycles(); 804 832 if( DEBUG_PROCESS_SIGACTION < cycle ) 805 printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",806 __FUNCTION__ , this , process->pid , local_cxy, cycle );833 printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n", 834 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle ); 807 835 #endif 808 836 … … 818 846 cluster_t * cluster = LOCAL_CLUSTER; 819 847 848 #if DEBUG_PROCESS_GET_LOCAL_COPY 849 thread_t * this = CURRENT_THREAD; 850 uint32_t cycle = (uint32_t)hal_get_cycles(); 851 if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle ) 852 printk("\n[DBG] %s : thread %x in cluster %x enter for process %x in cluster %x / cycle %d\n", 853 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle ); 854 #endif 855 820 856 // get lock protecting local list of processes 821 remote_ spinlock_lock( XPTR( local_cxy , &cluster->pmgr.local_lock ) );857 remote_queuelock_acquire( XPTR( local_cxy , &cluster->pmgr.local_lock ) ); 822 858 823 859 // scan the local list of process descriptors to find the process … … 836 872 837 873 // release lock protecting local list of processes 838 remote_ spinlock_unlock( XPTR( local_cxy , &cluster->pmgr.local_lock ) );874 remote_queuelock_release( XPTR( local_cxy , &cluster->pmgr.local_lock ) ); 839 875 840 876 // allocate memory for a new local process descriptor … … 859 895 860 896 #if DEBUG_PROCESS_GET_LOCAL_COPY 861 uint32_tcycle = (uint32_t)hal_get_cycles();897 cycle = (uint32_t)hal_get_cycles(); 862 898 if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle ) 863 printk("\n[DBG] %s : enter in cluster %x / pid%x / process %x / cycle %d\n",864 __FUNCTION__ , local_cxy , pid , process_ptr, cycle );899 printk("\n[DBG] %s : thread %x in cluster %x exit in cluster %x / process %x / cycle %d\n", 900 __FUNCTION__, this->trdid, this->process->pid, local_cxy, process_ptr, cycle ); 865 901 #endif 866 902 … … 883 919 884 920 // get pointers on parent process 885 parent_xp = (xptr_t)hal_remote_l wd( XPTR( process_cxy , &process_ptr->parent_xp ) );921 parent_xp = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->parent_xp ) ); 886 922 parent_cxy = GET_CXY( parent_xp ); 887 923 parent_ptr = GET_PTR( parent_xp ); 888 924 889 return hal_remote_l w( XPTR( parent_cxy , &parent_ptr->pid ) );925 return hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) ); 890 926 } 891 927 … … 899 935 uint32_t fd; 900 936 901 remote_ spinlock_init( XPTR( local_cxy , &process->fd_array.lock ));937 remote_queuelock_init( XPTR( local_cxy , &process->fd_array.lock ), LOCK_PROCESS_FDARRAY ); 902 938 903 939 process->fd_array.current = 0; … … 909 945 } 910 946 } 911 912 //////////////////////////////913 bool_t process_fd_array_full( void )914 {915 // get extended pointer on reference process916 xptr_t ref_xp = CURRENT_THREAD->process->ref_xp;917 918 // get reference process cluster and local pointer919 process_t * ref_ptr = GET_PTR( ref_xp );920 cxy_t ref_cxy = GET_CXY( ref_xp );921 922 // get number of open file descriptors from reference fd_array923 uint32_t current = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->fd_array.current ) );924 925 return ( current >= CONFIG_PROCESS_FILE_MAX_NR );926 }927 928 947 ///////////////////////////////////////////////// 929 948 error_t process_fd_register( process_t * process, … … 933 952 bool_t found; 934 953 uint32_t id; 954 uint32_t count; 935 955 xptr_t xp; 936 956 … … 941 961 942 962 // take lock protecting reference fd_array 943 remote_ spinlock_lock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );963 remote_queuelock_acquire( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) ); 944 964 945 965 found = false; … … 947 967 for ( id = 0; id < CONFIG_PROCESS_FILE_MAX_NR ; id++ ) 948 968 { 949 xp = hal_remote_l wd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) );969 xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) ); 950 970 if ( xp == XPTR_NULL ) 951 971 { 972 // update reference fd_array 973 hal_remote_s64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp ); 974 count = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) ) + 1; 975 hal_remote_s32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , count ); 976 977 // update local fd_array copy if required 978 if( ref_cxy != local_cxy ) 979 { 980 process->fd_array.array[id] = file_xp; 981 process->fd_array.current = count; 982 } 983 984 // exit 985 *fdid = id; 952 986 found = true; 953 hal_remote_swd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp );954 hal_remote_atomic_add( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , 1 );955 *fdid = id;956 987 break; 957 988 } … … 959 990 960 991 // release lock protecting reference fd_array 961 remote_ spinlock_unlock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );992 remote_queuelock_release( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) ); 962 993 963 994 if ( !found ) return -1; … … 970 1001 { 971 1002 xptr_t file_xp; 1003 xptr_t lock_xp; 972 1004 973 1005 // access local copy of process descriptor … … 981 1013 process_t * ref_ptr = GET_PTR( ref_xp ); 982 1014 1015 // build extended pointer on lock protecting reference fd_array 1016 lock_xp = XPTR( ref_cxy , &ref_ptr->fd_array.lock ); 1017 1018 // take lock protecting reference fd_array 1019 remote_queuelock_acquire( lock_xp ); 1020 983 1021 // access reference process descriptor 984 file_xp = hal_remote_l wd( XPTR( ref_cxy , &ref_ptr->fd_array.array[fdid] ) );1022 file_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->fd_array.array[fdid] ) ); 985 1023 986 1024 // update local fd_array if found 987 if( file_xp != XPTR_NULL ) 988 {989 process->fd_array.array[fdid] = file_xp;990 } 1025 if( file_xp != XPTR_NULL ) process->fd_array.array[fdid] = file_xp; 1026 1027 // release lock protecting reference fd_array 1028 remote_queuelock_release( lock_xp ); 991 1029 } 992 1030 … … 1011 1049 1012 1050 // get the remote lock protecting the src fd_array 1013 remote_ spinlock_lock( XPTR( src_cxy , &src_ptr->lock ) );1051 remote_queuelock_acquire( XPTR( src_cxy , &src_ptr->lock ) ); 1014 1052 1015 1053 // loop on all fd_array entries 1016 1054 for( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ ) 1017 1055 { 1018 entry = (xptr_t)hal_remote_l wd( XPTR( src_cxy , &src_ptr->array[fd] ) );1056 entry = (xptr_t)hal_remote_l64( XPTR( src_cxy , &src_ptr->array[fd] ) ); 1019 1057 1020 1058 if( entry != XPTR_NULL ) … … 1024 1062 1025 1063 // copy entry in destination process fd_array 1026 hal_remote_s wd( XPTR( dst_cxy , &dst_ptr->array[fd] ) , entry );1064 hal_remote_s64( XPTR( dst_cxy , &dst_ptr->array[fd] ) , entry ); 1027 1065 } 1028 1066 } 1029 1067 1030 1068 // release lock on source process fd_array 1031 remote_ spinlock_unlock( XPTR( src_cxy , &src_ptr->lock ) );1069 remote_queuelock_release( XPTR( src_cxy , &src_ptr->lock ) ); 1032 1070 1033 1071 } // end process_fd_remote_copy() 1072 1073 1074 //////////////////////////////////// 1075 bool_t process_fd_array_full( void ) 1076 { 1077 // get extended pointer on reference process 1078 xptr_t ref_xp = CURRENT_THREAD->process->ref_xp; 1079 1080 // get reference process cluster and local pointer 1081 process_t * ref_ptr = GET_PTR( ref_xp ); 1082 cxy_t ref_cxy = GET_CXY( ref_xp ); 1083 1084 // get number of open file descriptors from reference fd_array 1085 uint32_t current = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) ); 1086 1087 return ( current >= CONFIG_PROCESS_FILE_MAX_NR ); 1088 } 1089 1034 1090 1035 1091 //////////////////////////////////////////////////////////////////////////////////// … … 1043 1099 { 1044 1100 ltid_t ltid; 1045 reg_t save_sr;1046 1101 bool_t found = false; 1047 1102 1048 1049 assert( (process != NULL) , "process argument is NULL" ); 1050 1051 assert( (thread != NULL) , "thread argument is NULL" ); 1052 1053 // take lock protecting th_tbl, depending on thread type: 1054 // we don't want to use a descheduling policy for idle thread initialisation 1055 if ( thread->type == THREAD_IDLE ) { 1056 spinlock_lock_busy( &process->th_lock , &save_sr ); 1057 } else { 1058 spinlock_lock( &process->th_lock ); 1059 } 1060 1061 // search a free slot in th_tbl[] 1062 for( ltid = 0 ; ltid < CONFIG_THREAD_MAX_PER_CLUSTER ; ltid++ ) 1103 // check arguments 1104 assert( (process != NULL) , "process argument is NULL" ); 1105 assert( (thread != NULL) , "thread argument is NULL" ); 1106 1107 // get the lock protecting th_tbl for all threads 1108 // but the idle thread executing kernel_init (cannot yield) 1109 if( thread->type != THREAD_IDLE ) rwlock_wr_acquire( &process->th_lock ); 1110 1111 // scan kth_tbl 1112 for( ltid = 0 ; ltid < CONFIG_THREADS_MAX_PER_CLUSTER ; ltid++ ) 1063 1113 { 1064 1114 if( process->th_tbl[ltid] == NULL ) … … 1079 1129 } 1080 1130 1081 // release lock protecting th_tbl 1082 hal_fence(); 1083 if( thread->type == THREAD_IDLE ) { 1084 spinlock_unlock_busy( &process->th_lock , save_sr ); 1085 } else { 1086 spinlock_unlock( &process->th_lock ); 1087 } 1088 1089 return (found) ? 0 : ENOMEM; 1131 // get the lock protecting th_tbl for all threads 1132 // but the idle thread executing kernel_init (cannot yield) 1133 if( thread->type != THREAD_IDLE ) rwlock_wr_release( &process->th_lock ); 1134 1135 return (found) ? 0 : 0xFFFFFFFF; 1090 1136 1091 1137 } // end process_register_thread() … … 1096 1142 uint32_t count; // number of threads in local process descriptor 1097 1143 1098 assert( (thread != NULL) , "thread argument is NULL" ); 1144 // check argument 1145 assert( (thread != NULL) , "thread argument is NULL" ); 1099 1146 1100 1147 process_t * process = thread->process; … … 1102 1149 // get thread local index 1103 1150 ltid_t ltid = LTID_FROM_TRDID( thread->trdid ); 1104 1105 // take lock protecting th_tbl 1106 spinlock_lock( &process->th_lock ); 1107 1151 1152 // the lock depends on thread user/kernel type, because we cannot 1153 // use a descheduling policy for the lock protecting the kth_tbl 1154 1155 // get the lock protecting th_tbl[] 1156 rwlock_wr_acquire( &process->th_lock ); 1157 1158 // get number of kernel threads 1108 1159 count = process->th_nr; 1109 1160 1110 assert( (count > 0) , "process th_nr cannot be 0\n" ); 1161 // check th_nr value 1162 assert( (count > 0) , "process kth_nr cannot be 0\n" ); 1111 1163 1112 1164 // remove thread from th_tbl[] … … 1114 1166 process->th_nr = count-1; 1115 1167 1116 // release lock protecting th_tbl 1117 hal_fence(); 1118 spinlock_unlock( &process->th_lock ); 1168 // release lock protecting kth_tbl 1169 rwlock_wr_release( &process->th_lock ); 1119 1170 1120 1171 return (count == 1); … … 1141 1192 1142 1193 // get parent process PID and extended pointer on .elf file 1143 parent_pid = hal_remote_lw (XPTR( parent_process_cxy , &parent_process_ptr->pid)); 1144 vfs_bin_xp = hal_remote_lwd(XPTR( parent_process_cxy , &parent_process_ptr->vfs_bin_xp)); 1145 1146 // check parent process is the reference process 1147 ref_xp = hal_remote_lwd( XPTR( parent_process_cxy , &parent_process_ptr->ref_xp ) ); 1148 1149 assert( (parent_process_xp == ref_xp ) , 1150 "parent process must be the reference process\n" ); 1194 parent_pid = hal_remote_l32 (XPTR( parent_process_cxy , &parent_process_ptr->pid)); 1195 vfs_bin_xp = hal_remote_l64(XPTR( parent_process_cxy , &parent_process_ptr->vfs_bin_xp)); 1196 1197 // get extended pointer on reference process 1198 ref_xp = hal_remote_l64( XPTR( parent_process_cxy , &parent_process_ptr->ref_xp ) ); 1199 1200 // check parent process is the reference process 1201 assert( (parent_process_xp == ref_xp ) , 1202 "parent process must be the reference process\n" ); 1151 1203 1152 1204 #if DEBUG_PROCESS_MAKE_FORK … … 1195 1247 #endif 1196 1248 1197 // give TXT ownership to child process1198 process_txt_set_ownership( XPTR( local_cxy , process ) );1199 1249 1200 1250 // copy VMM from parent descriptor to child descriptor … … 1218 1268 #endif 1219 1269 1220 // parent process gives TXT ownership to child process if required 1221 if( process_txt_is_owner(parent_process_xp) ) 1270 // if parent_process is INIT, or if parent_process is the TXT owner, 1271 // the child_process becomes the owner of its TXT terminal 1272 if( (parent_pid == 1) || process_txt_is_owner( parent_process_xp ) ) 1222 1273 { 1223 1274 process_txt_set_ownership( XPTR( local_cxy , process ) ); … … 1226 1277 cycle = (uint32_t)hal_get_cycles(); 1227 1278 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1228 printk("\n[DBG] %s : thread %x in process %x gives TXT from parent %x to child %x / cycle %d\n", 1229 __FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, 1230 parent_pid, new_pid, cycle ); 1279 printk("\n[DBG] %s : thread %x in process %x / child takes TXT ownership / cycle %d\n", 1280 __FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle ); 1231 1281 #endif 1232 1282 … … 1249 1299 } 1250 1300 1251 // check main thread LTID 1252 assert( (LTID_FROM_TRDID(thread->trdid) == 0) , 1253 "main thread must have LTID == 0\n" ); 1254 1255 //#if( DEBUG_PROCESS_MAKE_FORK & 1 ) 1256 #if DEBUG_PROCESS_MAKE_FORK 1301 // check main thread LTID 1302 assert( (LTID_FROM_TRDID(thread->trdid) == 0) , 1303 "main thread must have LTID == 0\n" ); 1304 1305 #if( DEBUG_PROCESS_MAKE_FORK & 1 ) 1257 1306 cycle = (uint32_t)hal_get_cycles(); 1258 1307 if( DEBUG_PROCESS_MAKE_FORK < cycle ) … … 1289 1338 1290 1339 // register process in parent children list 1291 remote_ spinlock_lock( children_lock_xp );1340 remote_queuelock_acquire( children_lock_xp ); 1292 1341 xlist_add_last( children_root_xp , XPTR( local_cxy , &process->children_list ) ); 1293 1342 hal_remote_atomic_add( children_nr_xp , 1 ); 1294 remote_ spinlock_unlock( children_lock_xp );1343 remote_queuelock_release( children_lock_xp ); 1295 1344 1296 1345 // return success … … 1341 1390 // open the file identified by <path> 1342 1391 file_xp = XPTR_NULL; 1343 file_id = -1;1392 file_id = 0xFFFFFFFF; 1344 1393 error = vfs_open( process, 1345 1394 path, … … 1442 1491 uint32_t cycle = (uint32_t)hal_get_cycles(); 1443 1492 if( DEBUG_PROCESS_ZERO_CREATE < cycle ) 1444 printk("\n[DBG] %s : thread %x enter / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle ); 1493 printk("\n[DBG] %s : enter / cluster %x / cycle %d\n", 1494 __FUNCTION__, local_cxy, cycle ); 1445 1495 #endif 1446 1496 … … 1452 1502 process->term_state = 0; 1453 1503 1454 // reset th_tbl[] array a s empty1504 // reset th_tbl[] array and associated fields 1455 1505 uint32_t i; 1456 for( i = 0 ; i < CONFIG_THREAD _MAX_PER_CLUSTER ; i++ )1506 for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ ) 1457 1507 { 1458 1508 process->th_tbl[i] = NULL; 1459 1509 } 1460 1510 process->th_nr = 0; 1461 spinlock_init( &process->th_lock ); 1511 rwlock_init( &process->th_lock , LOCK_PROCESS_THTBL ); 1512 1462 1513 1463 1514 // reset children list as empty 1464 1515 xlist_root_init( XPTR( local_cxy , &process->children_root ) ); 1465 remote_spinlock_init( XPTR( local_cxy , &process->children_lock ) );1466 1516 process->children_nr = 0; 1517 remote_queuelock_init( XPTR( local_cxy , &process->children_lock ), 1518 LOCK_PROCESS_CHILDREN ); 1467 1519 1468 1520 hal_fence(); … … 1471 1523 cycle = (uint32_t)hal_get_cycles(); 1472 1524 if( DEBUG_PROCESS_ZERO_CREATE < cycle ) 1473 printk("\n[DBG] %s : thread %x exit / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle ); 1525 printk("\n[DBG] %s : exit / cluster %x / cycle %d\n", 1526 __FUNCTION__, local_cxy, cycle ); 1474 1527 #endif 1475 1528 1476 1529 } // end process_zero_init() 1477 1530 1478 ////////////////////////// 1531 //////////////////////////////// 1479 1532 void process_init_create( void ) 1480 1533 { … … 1498 1551 process = process_alloc(); 1499 1552 1500 assert( (process != NULL), 1501 "no memory for process descriptor in cluster %x\n", local_cxy ); 1553 // check memory allocator 1554 assert( (process != NULL), 1555 "no memory for process descriptor in cluster %x\n", local_cxy ); 1502 1556 1503 1557 // get PID from local cluster 1504 1558 error = cluster_pid_alloc( process , &pid ); 1505 1559 1506 assert( (error == 0), 1507 "cannot allocate PID in cluster %x\n", local_cxy ); 1508 1509 assert( (pid == 1) , 1510 "process INIT must be first process in cluster 0\n" ); 1560 // check PID allocator 1561 assert( (error == 0), 1562 "cannot allocate PID in cluster %x\n", local_cxy ); 1563 1564 // check PID value 1565 assert( (pid == 1) , 1566 "process INIT must be first process in cluster 0\n" ); 1511 1567 1512 1568 // initialize process descriptor / parent is local process_zero … … 1514 1570 pid, 1515 1571 XPTR( local_cxy , &process_zero ) ); 1572 1573 #if(DEBUG_PROCESS_INIT_CREATE & 1) 1574 if( DEBUG_PROCESS_INIT_CREATE < cycle ) 1575 printk("\n[DBG] %s : thread %x in process %x initialized process descriptor\n", 1576 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ); 1577 #endif 1516 1578 1517 1579 // open the file identified by CONFIG_PROCESS_INIT_PATH … … 1525 1587 &file_id ); 1526 1588 1527 assert( (error == 0), 1528 "failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1529 1530 // register "code" and "data" vsegs as well as entry-point 1589 assert( (error == 0), 1590 "failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1591 1592 #if(DEBUG_PROCESS_INIT_CREATE & 1) 1593 if( DEBUG_PROCESS_INIT_CREATE < cycle ) 1594 printk("\n[DBG] %s : thread %x in process %x open .elf file decriptor\n", 1595 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ); 1596 #endif 1597 1598 // register "code" and "data" vsegs as well as entry-point 1531 1599 // in process VMM, using information contained in the elf file. 1532 1600 error = elf_load_process( file_xp , process ); 1533 1601 1534 assert( (error == 0), 1535 "cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1602 assert( (error == 0), 1603 "cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1604 1605 #if(DEBUG_PROCESS_INIT_CREATE & 1) 1606 if( DEBUG_PROCESS_INIT_CREATE < cycle ) 1607 printk("\n[DBG] %s : thread %x in process %x registered code/data vsegs in VMM\n", 1608 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ); 1609 #endif 1536 1610 1537 1611 // get extended pointers on process_zero children_root, children_lock … … 1539 1613 xptr_t children_lock_xp = XPTR( local_cxy , &process_zero.children_lock ); 1540 1614 1615 // take lock protecting kernel process children list 1616 remote_queuelock_acquire( children_lock_xp ); 1617 1541 1618 // register process INIT in parent local process_zero 1542 remote_spinlock_lock( children_lock_xp );1543 1619 xlist_add_last( children_root_xp , XPTR( local_cxy , &process->children_list ) ); 1544 1620 hal_atomic_add( &process_zero.children_nr , 1 ); 1545 remote_spinlock_unlock( children_lock_xp ); 1621 1622 // release lock protecting kernel process children list 1623 remote_queuelock_release( children_lock_xp ); 1624 1625 #if(DEBUG_PROCESS_INIT_CREATE & 1) 1626 if( DEBUG_PROCESS_INIT_CREATE < cycle ) 1627 printk("\n[DBG] %s : thread %x in process %x registered init process in parent\n", 1628 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ); 1629 #endif 1546 1630 1547 1631 // select a core in local cluster to execute the main thread … … 1560 1644 &thread ); 1561 1645 1562 assert( (error == 0), 1563 "cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1564 1565 assert( (thread->trdid == 0), 1566 "main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1646 assert( (error == 0), 1647 "cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1648 1649 assert( (thread->trdid == 0), 1650 "main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH ); 1651 1652 #if(DEBUG_PROCESS_INIT_CREATE & 1) 1653 if( DEBUG_PROCESS_INIT_CREATE < cycle ) 1654 printk("\n[DBG] %s : thread %x in process %x created main thread\n", 1655 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ); 1656 #endif 1567 1657 1568 1658 // activate thread … … 1618 1708 1619 1709 // get PID and state 1620 pid = hal_remote_l w( XPTR( process_cxy , &process_ptr->pid ) );1621 state = hal_remote_l w( XPTR( process_cxy , &process_ptr->term_state ) );1710 pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ); 1711 state = hal_remote_l32( XPTR( process_cxy , &process_ptr->term_state ) ); 1622 1712 1623 1713 // get PPID 1624 parent_xp = hal_remote_l wd( XPTR( process_cxy , &process_ptr->parent_xp ) );1714 parent_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->parent_xp ) ); 1625 1715 parent_cxy = GET_CXY( parent_xp ); 1626 1716 parent_ptr = GET_PTR( parent_xp ); 1627 ppid = hal_remote_l w( XPTR( parent_cxy , &parent_ptr->pid ) );1717 ppid = hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) ); 1628 1718 1629 1719 // get number of threads 1630 th_nr = hal_remote_l w( XPTR( process_cxy , &process_ptr->th_nr ) );1720 th_nr = hal_remote_l32( XPTR( process_cxy , &process_ptr->th_nr ) ); 1631 1721 1632 1722 // get pointers on owner process descriptor 1633 owner_xp = hal_remote_l wd( XPTR( process_cxy , &process_ptr->owner_xp ) );1723 owner_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->owner_xp ) ); 1634 1724 owner_cxy = GET_CXY( owner_xp ); 1635 1725 owner_ptr = GET_PTR( owner_xp ); 1636 1726 1637 1727 // get extended pointer on TXT_RX file descriptor attached to process 1638 txt_file_xp = hal_remote_l wd( XPTR( owner_cxy , &owner_ptr->fd_array.array[0] ) );1728 txt_file_xp = hal_remote_l64( XPTR( owner_cxy , &owner_ptr->fd_array.array[0] ) ); 1639 1729 1640 1730 assert( (txt_file_xp != XPTR_NULL) , … … 1650 1740 XPTR( txt_chdev_cxy , txt_chdev_ptr->name ) ); 1651 1741 1652 txt_owner_xp = (xptr_t)hal_remote_l wd( XPTR( txt_chdev_cxy,1742 txt_owner_xp = (xptr_t)hal_remote_l64( XPTR( txt_chdev_cxy, 1653 1743 &txt_chdev_ptr->ext.txt.owner_xp ) ); 1654 1744 1655 1745 // get process .elf name 1656 elf_file_xp = hal_remote_l wd( XPTR( process_cxy , &process_ptr->vfs_bin_xp ) );1746 elf_file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->vfs_bin_xp ) ); 1657 1747 elf_file_cxy = GET_CXY( elf_file_xp ); 1658 1748 elf_file_ptr = (vfs_file_t *)GET_PTR( elf_file_xp ); … … 1718 1808 xptr_t lock_xp; // extended pointer on list lock in chdev 1719 1809 1720 1721 1722 1723 1724 1725 1726 1810 // check process is in owner cluster 1811 assert( (CXY_FROM_PID( process->pid ) == local_cxy) , 1812 "process descriptor not in owner cluster" ); 1813 1814 // check terminal index 1815 assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) , 1816 "illegal TXT terminal index" ); 1727 1817 1728 1818 // get pointers on TXT_RX[txt_id] chdev … … 1735 1825 lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock ); 1736 1826 1827 // get lock protecting list of processes attached to TXT 1828 remote_busylock_acquire( lock_xp ); 1829 1737 1830 // insert process in attached process list 1738 remote_spinlock_lock( lock_xp );1739 1831 xlist_add_last( root_xp , XPTR( local_cxy , &process->txt_list ) ); 1740 remote_spinlock_unlock( lock_xp ); 1832 1833 // release lock protecting list of processes attached to TXT 1834 remote_busylock_release( lock_xp ); 1741 1835 1742 1836 #if DEBUG_PROCESS_TXT … … 1765 1859 process_cxy = GET_CXY( process_xp ); 1766 1860 process_ptr = GET_PTR( process_xp ); 1767 1768 // check process descriptor in owner cluster 1769 process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) ); 1770 1771 1861 process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ); 1862 1863 // check process descriptor in owner cluster 1864 assert( (CXY_FROM_PID( process_pid ) == process_cxy ) , 1865 "process descriptor not in owner cluster" ); 1772 1866 1773 1867 // release TXT ownership (does nothing if not TXT owner) … … 1775 1869 1776 1870 // get extended pointer on process stdin file 1777 file_xp = (xptr_t)hal_remote_l wd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );1871 file_xp = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) ); 1778 1872 1779 1873 // get pointers on TXT_RX chdev … … 1785 1879 lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock ); 1786 1880 1881 // get lock protecting list of processes attached to TXT 1882 remote_busylock_acquire( lock_xp ); 1883 1787 1884 // unlink process from attached process list 1788 remote_spinlock_lock( lock_xp );1789 1885 xlist_unlink( XPTR( process_cxy , &process_ptr->txt_list ) ); 1790 remote_spinlock_unlock( lock_xp ); 1886 1887 // release lock protecting list of processes attached to TXT 1888 remote_busylock_release( lock_xp ); 1791 1889 1792 1890 #if DEBUG_PROCESS_TXT 1793 1891 uint32_t cycle = (uint32_t)hal_get_cycles(); 1794 uint32_t txt_id = hal_remote_l w( XPTR( chdev_cxy , &chdev_ptr->channel ) );1892 uint32_t txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) ); 1795 1893 if( DEBUG_PROCESS_TXT < cycle ) 1796 1894 printk("\n[DBG] %s : thread %x in process %x detached process %x from TXT %d / cycle %d\n", … … 1815 1913 process_cxy = GET_CXY( process_xp ); 1816 1914 process_ptr = GET_PTR( process_xp ); 1817 process_pid = hal_remote_l w( XPTR( process_cxy , &process_ptr->pid ) );1915 process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ); 1818 1916 1819 1917 // check owner cluster … … 1822 1920 1823 1921 // get extended pointer on stdin pseudo file 1824 file_xp = hal_remote_l wd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );1922 file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) ); 1825 1923 1826 1924 // get pointers on TXT chdev … … 1830 1928 1831 1929 // set owner field in TXT chdev 1832 hal_remote_s wd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp );1930 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp ); 1833 1931 1834 1932 #if DEBUG_PROCESS_TXT 1835 1933 uint32_t cycle = (uint32_t)hal_get_cycles(); 1836 uint32_t txt_id = hal_remote_l w( XPTR( txt_cxy , &txt_ptr->channel ) );1934 uint32_t txt_id = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) ); 1837 1935 if( DEBUG_PROCESS_TXT < cycle ) 1838 1936 printk("\n[DBG] %s : thread %x in process %x give TXT %d to process %x / cycle %d\n", … … 1868 1966 process_cxy = GET_CXY( process_xp ); 1869 1967 process_ptr = GET_PTR( process_xp ); 1870 process_pid = hal_remote_l w( XPTR( process_cxy , &process_ptr->pid ) );1968 process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ); 1871 1969 1872 1970 // check owner cluster … … 1875 1973 1876 1974 // get extended pointer on stdin pseudo file 1877 file_xp = hal_remote_l wd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );1975 file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) ); 1878 1976 1879 1977 // get pointers on TXT chdev … … 1883 1981 1884 1982 // get extended pointer on TXT_RX owner and TXT channel 1885 owner_xp = hal_remote_l wd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );1886 txt_id = hal_remote_l w( XPTR( txt_cxy , &txt_ptr->channel ) );1983 owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) ); 1984 txt_id = hal_remote_l32 ( XPTR( txt_cxy , &txt_ptr->channel ) ); 1887 1985 1888 1986 // transfer ownership only if process is the TXT owner … … 1894 1992 1895 1993 // get lock 1896 remote_ spinlock_lock( lock_xp );1994 remote_busylock_acquire( lock_xp ); 1897 1995 1898 1996 if( process_get_ppid( process_xp ) != 1 ) // process is not KSH … … 1908 2006 { 1909 2007 // release lock 1910 remote_ spinlock_unlock( lock_xp );2008 remote_busylock_release( lock_xp ); 1911 2009 1912 2010 // set owner field in TXT chdev 1913 hal_remote_s wd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );2011 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp ); 1914 2012 1915 2013 #if DEBUG_PROCESS_TXT 1916 2014 cycle = (uint32_t)hal_get_cycles(); 1917 uint32_t ksh_pid = hal_remote_l w( XPTR( current_cxy , ¤t_ptr->pid ) );2015 uint32_t ksh_pid = hal_remote_l32( XPTR( current_cxy , ¤t_ptr->pid ) ); 1918 2016 if( DEBUG_PROCESS_TXT < cycle ) 1919 2017 printk("\n[DBG] %s : thread %x in process %x release TXT %d to KSH %x / cycle %d\n", … … 1926 2024 1927 2025 // release lock 1928 remote_ spinlock_unlock( lock_xp );2026 remote_busylock_release( lock_xp ); 1929 2027 1930 2028 // PANIC if KSH not found … … 1945 2043 { 1946 2044 // release lock 1947 remote_ spinlock_unlock( lock_xp );2045 remote_busylock_release( lock_xp ); 1948 2046 1949 2047 // set owner field in TXT chdev 1950 hal_remote_s wd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );2048 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp ); 1951 2049 1952 2050 #if DEBUG_PROCESS_TXT 1953 2051 cycle = (uint32_t)hal_get_cycles(); 1954 uint32_t new_pid = hal_remote_l w( XPTR( current_cxy , ¤t_ptr->pid ) );2052 uint32_t new_pid = hal_remote_l32( XPTR( current_cxy , ¤t_ptr->pid ) ); 1955 2053 if( DEBUG_PROCESS_TXT < cycle ) 1956 2054 printk("\n[DBG] %s : thread %x in process %x release TXT %d to process %x / cycle %d\n", … … 1963 2061 1964 2062 // release lock 1965 remote_ spinlock_unlock( lock_xp );2063 remote_busylock_release( lock_xp ); 1966 2064 1967 2065 // no more owner for TXT if no other process found 1968 hal_remote_s wd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );2066 hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL ); 1969 2067 1970 2068 #if DEBUG_PROCESS_TXT … … 1993 2091 1994 2092 1995 //////////////////////////////////////////////// //1996 uint32_t process_txt_is_owner( xptr_t process_xp )2093 //////////////////////////////////////////////// 2094 bool_t process_txt_is_owner( xptr_t process_xp ) 1997 2095 { 1998 2096 // get local pointer and cluster of process in owner cluster … … 2000 2098 process_t * process_ptr = GET_PTR( process_xp ); 2001 2099 2002 // checkowner cluster2003 pid_t process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );2004 2005 2100 // check calling thread execute in target process owner cluster 2101 pid_t process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ); 2102 assert( (process_cxy == CXY_FROM_PID( process_pid )) , 2103 "process descriptor not in owner cluster\n" ); 2006 2104 2007 2105 // get extended pointer on stdin pseudo file 2008 xptr_t file_xp = hal_remote_l wd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );2106 xptr_t file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) ); 2009 2107 2010 2108 // get pointers on TXT chdev … … 2014 2112 2015 2113 // get extended pointer on TXT_RX owner process 2016 xptr_t owner_xp = hal_remote_l wd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );2114 xptr_t owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) ); 2017 2115 2018 2116 return (process_xp == owner_xp); … … 2027 2125 chdev_t * txt_rx_ptr = GET_PTR( txt_rx_xp ); 2028 2126 2029 return (xptr_t)hal_remote_l wd( XPTR( txt_rx_cxy , &txt_rx_ptr->ext.txt.owner_xp ) );2127 return (xptr_t)hal_remote_l64( XPTR( txt_rx_cxy , &txt_rx_ptr->ext.txt.owner_xp ) ); 2030 2128 2031 2129 } // end process_txt_get_owner() … … 2045 2143 xptr_t txt0_xp; 2046 2144 xptr_t txt0_lock_xp; 2047 reg_t txt0_save_sr; // save SR to take TXT0 lock in busy mode2048 2145 2049 2146 assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) , … … 2068 2165 2069 2166 // get lock on attached process list 2070 remote_ spinlock_lock( lock_xp );2167 remote_busylock_acquire( lock_xp ); 2071 2168 2072 2169 // get TXT0 lock in busy waiting mode 2073 remote_ spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr);2170 remote_busylock_acquire( txt0_lock_xp ); 2074 2171 2075 2172 // display header … … 2085 2182 2086 2183 // release TXT0 lock in busy waiting mode 2087 remote_ spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr);2184 remote_busylock_release( txt0_lock_xp ); 2088 2185 2089 2186 // release lock on attached process list 2090 remote_ spinlock_unlock( lock_xp );2187 remote_busylock_release( lock_xp ); 2091 2188 2092 2189 } // end process_txt_display
Note: See TracChangeset
for help on using the changeset viewer.