Changeset 409 for trunk/kernel/kern/process.c
- Timestamp:
- Dec 20, 2017, 4:51:09 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.c
r408 r409 8 8 * Copyright (c) UPMC Sorbonne Universites 9 9 * 10 * This file is part of ALMOS-MKH. .10 * This file is part of ALMOS-MKH. 11 11 * 12 12 * ALMOS-MKH is free software; you can redistribute it and/or modify it … … 28 28 #include <hal_remote.h> 29 29 #include <hal_uspace.h> 30 #include <hal_irqmask.h> 30 31 #include <errno.h> 31 32 #include <printk.h> … … 49 50 #include <elf.h> 50 51 #include <syscalls.h> 52 #include <signal.h> 51 53 52 54 ////////////////////////////////////////////////////////////////////////////////////////// … … 124 126 uint32_t stderr_id; 125 127 126 process_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x \n",127 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pid );128 process_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / ppid = %x\n", 129 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pid , ppid ); 128 130 129 131 // get model process cluster and local pointer … … 136 138 process->ref_xp = XPTR( local_cxy , process ); 137 139 138 // initialize vmm 140 // initialize vmm as empty 139 141 vmm_init( process ); 140 142 … … 142 144 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pid ); 143 145 144 // initialize fd_array (not for kernel)146 // initialize fd_array as empty 145 147 process_fd_init( process ); 146 148 147 149 // create stdin / stdout / stderr pseudo-files 148 if( ppid == 0 ) 150 if( ppid == 0 ) // process_init 149 151 { 150 152 error1 = vfs_open( process, … … 169 171 &stderr_id ); 170 172 } 171 else // other user process173 else // any other process 172 174 { 173 175 error1 = vfs_open( process, … … 199 201 "bad indexes : stdin %d / stdout %d / stderr %d \n", stdin_id , stdout_id , stderr_id ); 200 202 201 // initialize specific files, cwd_lock, and fd_array203 // initialize specific inodes root and cwd 202 204 process->vfs_root_xp = (xptr_t)hal_remote_lwd( XPTR( model_cxy, 203 205 &model_ptr->vfs_root_xp ) ); 204 206 process->vfs_cwd_xp = (xptr_t)hal_remote_lwd( XPTR( model_cxy, 205 207 &model_ptr->vfs_cwd_xp ) ); 206 process->vfs_bin_xp = (xptr_t)hal_remote_lwd( XPTR( model_cxy,207 &model_ptr->vfs_bin_xp ));208 vfs_file_count_up( process->vfs_root_xp ); 209 vfs_file_count_up( process->vfs_cwd_xp);210 vfs_file_count_up( process->vfs_bin_xp ); 211 208 vfs_inode_remote_up( process->vfs_root_xp ); 209 vfs_inode_remote_up( process->vfs_cwd_xp ); 210 211 remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) ); 212 213 // copy all open file descriptors (other than stdin / stdout / stderr) 212 214 process_fd_remote_copy( XPTR( local_cxy , &process->fd_array ), 213 215 XPTR( model_cxy , &model_ptr->fd_array ) ); 214 216 215 remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) ); 216 217 process_dmsg("\n[DBG] %s : core[%x,%d] / fd array initialised for process %x\n", 217 process_dmsg("\n[DBG] %s : core[%x,%d] / fd array for process %x\n", 218 218 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pid ); 219 219 … … 352 352 remote_spinlock_unlock( copies_lock ); 353 353 354 // synchronize memory355 354 hal_fence(); 356 355 357 356 // From this point, the process descriptor is unreachable 358 357 359 // close all open files and update dirty TODO [AG] 360 361 // release signal manager TODO [AG] 358 // FIXME close all open files and update dirty [AG] 362 359 363 360 // Decrease refcount for bin file, root file and cwd file … … 374 371 } // end process_destroy() 375 372 373 ///////////////////////////////////////////////// 374 char * process_action_str( uint32_t action_type ) 375 { 376 if ( action_type == BLOCK_ALL_THREADS ) return "BLOCK"; 377 else if( action_type == UNBLOCK_ALL_THREADS ) return "UNBLOCK"; 378 else if( action_type == DELETE_ALL_THREADS ) return "DELETE"; 379 else return "undefined"; 380 } 381 382 //////////////////////////////////////////// 383 void process_sigaction( process_t * process, 384 uint32_t action_type ) 385 { 386 cxy_t owner_cxy; // owner cluster identifier 387 lpid_t lpid; // process index in owner cluster 388 cluster_t * cluster; // pointer on cluster manager 389 xptr_t root_xp; // extended pointer on root of copies 390 xptr_t lock_xp; // extended pointer on lock protecting copies 391 xptr_t client_xp; // extended pointer on client thread 392 uint32_t rsp_count; // number of expected responses 393 xptr_t rsp_xp; // extended pointer on responses counter 394 xptr_t iter_xp; // iterator on copies list 395 xptr_t process_xp; // extended pointer on process copy 396 cxy_t process_cxy; // process copy cluster identifier 397 process_t * process_ptr; // local pointer on process copy 398 399 signal_dmsg("\n[DBG] %s : enter for signal %s to process %x in cluster %x\n", 400 __FUNCTION__ , process_action_str( action_type ) , process , local_cxy ); 401 402 thread_t * this = CURRENT_THREAD; 403 404 // get extended pointer on client thread and response counter 405 client_xp = XPTR( local_cxy , this ); 406 rsp_xp = XPTR( local_cxy , &rsp_count ); 407 408 // get owner cluster identifier and process lpid 409 owner_cxy = CXY_FROM_PID( process->pid ); 410 lpid = LPID_FROM_PID( process->pid ); 411 412 assert( (owner_cxy == local_cxy) , __FUNCTION__ , "illegal cluster\n" ); 413 414 // get local pointer on local cluster manager 415 cluster = LOCAL_CLUSTER; 416 417 // get extended pointers on copies root, copies lock, and number of copies 418 root_xp = XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] ); 419 lock_xp = XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ); 420 421 // initialize responses number 422 rsp_count = cluster->pmgr.copies_nr[lpid]; 423 424 // take the lock protecting the copies 425 remote_spinlock_lock( lock_xp ); 426 427 // send RPCs to all process copies 428 XLIST_FOREACH( root_xp , iter_xp ) 429 { 430 process_xp = XLIST_ELEMENT( iter_xp , process_t , copies_list ); 431 process_cxy = GET_CXY( process_xp ); 432 process_ptr = (process_t *)GET_PTR( process_xp ); 433 434 printk("\n @@@ %s : process = %x / pid = %x / ppid = %x\n", 435 __FUNCTION__ , process_ptr , process_ptr->pid , process_ptr->ppid ); 436 437 rpc_process_sigaction_client( process_cxy, 438 process_ptr, 439 action_type, 440 rsp_xp, 441 client_xp ); 442 } 443 444 // release the lock protecting process copies 445 remote_spinlock_unlock( lock_xp ); 446 447 // block and deschedule to wait response 448 thread_block( CURRENT_THREAD , THREAD_BLOCKED_RPC ); 449 sched_yield("BLOCKED on RPC"); 450 451 signal_dmsg("\n[DBG] %s : exit for signal %s to process %x in cluster %x\n", 452 __FUNCTION__ , process_action_str( action_type ) , process , local_cxy ); 453 454 } // end process_sigaction() 455 376 456 //////////////////////////////////////// 377 void process_kill( process_t * process ) 378 { 379 thread_t * thread; // pointer on current thead descriptor 380 uint32_t ltid; // index in process th_tbl 381 uint32_t count; // thread counter 382 383 printk("\n[@@@] %s enter\n", __FUNCTION__ ); 384 385 // get lock protecting th_tbl[] 457 void process_block( process_t * process, 458 xptr_t rsp_xp, 459 xptr_t client_xp ) 460 { 461 thread_t * target; // pointer on target thread 462 uint32_t ltid; // index in process th_tbl 463 thread_t * killer; // killer thread pointer 464 uint32_t count; // requests counter 465 volatile uint32_t sig_rsp_count; // responses counter 466 cxy_t client_cxy; // client thread cluster identifier 467 thread_t * client_ptr; // client thread pointer 468 core_t * client_core; // client thread core pointer 469 470 // get local killer thread pointer 471 killer = CURRENT_THREAD; 472 473 signal_dmsg("\n[DBG] %s : enter for process %x in cluster %x\n", 474 __FUNCTION__ , process->pid , local_cxy ); 475 476 // get lock protecting process th_tbl[] 386 477 spinlock_lock( &process->th_lock ); 387 478 388 // first loop on threads to send the THREAD_SIG_KILL signal to all process threads 389 // we use both "ltid" and "count" indexes, because it can exist "holes" in th_tbl 390 for( ltid = 0 , count = 0 ; 391 (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ; 479 // initialize local responses counter 480 sig_rsp_count = process->th_nr; 481 482 // loop on process threads to block and deschedule all threads in cluster 483 // we use both "ltid" and "count" because it can exist "holes" in th_tbl 484 for( ltid = 0 , count = 0 ; count < process->th_nr ; ltid++ ) 485 { 486 target = process->th_tbl[ltid]; 487 488 if( target != NULL ) // thread found 489 { 490 count++; 491 492 // set signal in target thread descriptor 493 thread_set_signal( target , (uint32_t *)sig_rsp_count ); 494 495 // set the global blocked bit in target thread descriptor. 496 thread_block( target , THREAD_BLOCKED_GLOBAL ); 497 498 // - if the killer thread and the target thread are not on the same core 499 // we want the scheduler of target thread to acknowlege the signal 500 // to be sure that the target thread is descheduled 501 // - if the killer thread and the target thread are on the same core 502 // we simply decrement the response counter. 503 if( killer->core->lid != target->core->lid ) 504 { 505 dev_pic_send_ipi( local_cxy , target->core->lid ); 506 } 507 else 508 { 509 hal_atomic_add( (void *)&sig_rsp_count , -1 ); 510 } 511 } 512 } 513 514 // poll the reponses counter 515 while( 1 ) 516 { 517 // exit loop when all responses received 518 if ( sig_rsp_count == 0 ) break; 519 520 // wait 1000 cycles before retry 521 hal_fixed_delay( 1000 ); 522 } 523 524 // acknowledge client thread & unblock client thread if last response 525 client_cxy = GET_CXY( client_xp ); 526 client_ptr = (thread_t *)GET_PTR( client_xp ); 527 client_core = (core_t *)hal_remote_lpt( XPTR( client_cxy , &client_ptr->core ) ); 528 if( hal_remote_atomic_add( rsp_xp , -1 ) == 1 ) 529 { 530 thread_unblock( client_xp , THREAD_BLOCKED_RPC); 531 dev_pic_send_ipi( client_cxy , client_core->lid ); 532 } 533 534 signal_dmsg("\n[DBG] %s : exit for process %x in cluster %x / %d threads blocked\n", 535 __FUNCTION__ , process->pid , local_cxy , count ); 536 537 } // end process_block() 538 539 ////////////////////////////////////////// 540 void process_unblock( process_t * process, 541 xptr_t rsp_xp, 542 xptr_t client_xp ) 543 { 544 thread_t * target; // pointer on target thead 545 uint32_t ltid; // index in process th_tbl 546 thread_t * killer; // killer thread pointer 547 uint32_t req_count; // requests counter 548 cxy_t client_cxy; // client thread cluster identifier 549 thread_t * client_ptr; // client thread pointer 550 core_t * client_core; // client thread core pointer 551 552 // get local killer thread pointer 553 killer = CURRENT_THREAD; 554 555 signal_dmsg("\n[DBG] %s : enter for process %x in cluster %x\n", 556 __FUNCTION__ , process->pid , local_cxy ); 557 558 // get lock protecting process th_tbl[] 559 spinlock_lock( &process->th_lock ); 560 561 // loop on process threads to unblock all threads in cluster 562 // we use both "ltid" and "req_count" because it can exist "holes" in th_tbl 563 for( ltid = 0 , req_count = 0 ; 564 req_count < process->th_nr ; 392 565 ltid++ ) 393 566 { 567 target = process->th_tbl[ltid]; 568 569 if( target != NULL ) // thread found 570 { 571 req_count++; 572 573 // reset the global blocked bit in target thread descriptor. 574 thread_unblock( XPTR( local_cxy , target ) , THREAD_BLOCKED_GLOBAL ); 575 } 576 } 577 578 // acknowledge client thread & unblock client thread if last response 579 client_cxy = GET_CXY( client_xp ); 580 client_ptr = (thread_t *)GET_PTR( client_xp ); 581 client_core = (core_t *)hal_remote_lpt( XPTR( client_cxy , &client_ptr->core ) ); 582 if( hal_remote_atomic_add( rsp_xp , -1 ) == 1 ) 583 { 584 thread_unblock( client_xp , THREAD_BLOCKED_RPC); 585 dev_pic_send_ipi( client_cxy , client_core->lid ); 586 } 587 588 signal_dmsg("\n[DBG] %s : exit for process %x in cluster %x / %d threads blocked\n", 589 __FUNCTION__ , process->pid , local_cxy , req_count ); 590 591 } // end process_unblock() 592 593 ///////////////////////////////////////// 594 void process_delete( process_t * process, 595 xptr_t rsp_xp, 596 xptr_t client_xp ) 597 { 598 thread_t * thread; // pointer on target thread 599 uint32_t ltid; // index in process th_tbl 600 uint32_t count; // request counter 601 pid_t pid; // process PID 602 cxy_t client_cxy; // client thread cluster identifier 603 thread_t * client_ptr; // client thread pointer 604 core_t * client_core; // client thread core pointer 605 606 // get process PID 607 pid = process->pid; 608 609 signal_dmsg("\n[DBG] %s : enter for process %x in cluster %x at cycle %d\n", 610 __FUNCTION__ , pid , local_cxy , (uint32_t)hal_get_cycles() ); 611 612 // loop on threads to release memory allocated to threads 613 for( ltid = 0 , count = 0 ; count < process->th_nr ; ltid++ ) 614 { 394 615 thread = process->th_tbl[ltid]; 395 616 396 if( thread != NULL ) 617 if( thread != NULL ) // thread found 397 618 { 398 thread_kill( thread );399 619 count++; 620 621 // detach thread from parent if attached 622 if( (thread->flags & THREAD_FLAG_DETACHED) == 0 ) 623 thread_child_parent_unlink( thread->parent , XPTR( local_cxy , thread ) ); 624 625 // detach thread from process 626 process_remove_thread( thread ); 627 628 // remove thread from scheduler 629 sched_remove_thread( thread ); 630 631 // release memory allocated to thread 632 thread_destroy( thread ); 400 633 } 401 634 } 402 635 403 printk("\n[@@@] %s : %d signal(s) sent\n", __FUNCTION__, count ); 404 405 // second loop on threads to wait acknowledge from scheduler, 406 // unlink thread from process and parent thread, and release thread descriptor 407 for( ltid = 0 , count = 0 ; 408 (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ; 409 ltid++ ) 410 { 411 thread = process->th_tbl[ltid]; 412 413 if( thread != NULL ) 414 { 415 416 printk("\n[@@@] %s start polling at cycle %d\n", __FUNCTION__ , hal_time_stamp() ); 417 418 // poll the THREAD_SIG_KILL bit until reset 419 while( thread->signals & THREAD_SIG_KILL ) asm volatile( "nop" ); 420 421 printk("\n[@@@] %s exit polling\n", __FUNCTION__ ); 422 423 // detach target thread from parent if attached 424 if( (thread->flags & THREAD_FLAG_DETACHED) != 0 ) 425 thread_child_parent_unlink( thread->parent , XPTR( local_cxy , thread ) ); 426 427 // unlink thread from process 428 process_remove_thread( thread ); 429 430 // release memory for thread descriptor 431 thread_destroy( thread ); 432 433 count++; 434 } 435 } 436 437 printk("\n[@@@] %s : %d ack(s) received\n", __FUNCTION__, count ); 438 439 // release lock protecting th_tbl[] 440 spinlock_unlock( &process->th_lock ); 441 442 // release memory allocated for process descriptor 443 process_destroy( process ); 444 445 printk("\n[DBG] %s : core[%x,%d] exit\n", 446 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid ); 447 448 } // end process_kill() 636 // release memory allocated to process descriptors 637 // for all clusters other than the owner cluster 638 if( local_cxy != CXY_FROM_PID( process->pid ) ) process_destroy( process ); 639 640 // acknowledge client thread & unblock client thread if last response 641 client_cxy = GET_CXY( client_xp ); 642 client_ptr = (thread_t *)GET_PTR( client_xp ); 643 client_core = (core_t *)hal_remote_lpt( XPTR( client_cxy , &client_ptr->core ) ); 644 if( hal_remote_atomic_add( rsp_xp , -1 ) == 1 ) 645 { 646 thread_unblock( client_xp , THREAD_BLOCKED_RPC); 647 dev_pic_send_ipi( client_cxy , client_core->lid ); 648 } 649 650 signal_dmsg("\n[DBG] %s : exit for process %x in cluster %x at cycle %d\n", 651 __FUNCTION__ , pid , local_cxy , (uint32_t)hal_get_cycles() ); 652 653 } // end process_delete() 449 654 450 655 /////////////////////////////////////////////// … … 496 701 497 702 return process_ptr; 498 } 703 704 } // end process_get_local_copy() 499 705 500 706 ////////////////////////////////////////////////////////////////////////////////////////// … … 621 827 remote_spinlock_lock( XPTR( src_cxy , &src_ptr->lock ) ); 622 828 623 // loop on all entries in source process fd_array 624 for( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ ) 829 // loop on all entries other than 830 // the three first entries: stdin/stdout/stderr 831 for( fd = 3 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ ) 625 832 { 626 833 entry = (xptr_t)hal_remote_lwd( XPTR( src_cxy , &src_ptr->array[fd] ) ); … … 724 931 "parent process must be the reference process\n" ); 725 932 726 process_dmsg("\n[DBG] %s : core[%x,%d] enter at cycle %d\n",727 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid , hal_get_cycles() );933 fork_dmsg("\n[DBG] %s : core[%x,%d] enter at cycle %d\n", 934 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid , (uint32_t)hal_get_cycles() ); 728 935 729 936 // allocate a process descriptor … … 736 943 } 737 944 738 process_dmsg("\n[DBG] %s : core[%x,%d] child process descriptor allocated at cycle %d\n",739 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );945 fork_dmsg("\n[DBG] %s : core[%x,%d] child process descriptor allocated at cycle %d\n", 946 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, (uint32_t)hal_get_cycles() ); 740 947 741 948 // allocate a child PID from local cluster … … 749 956 } 750 957 751 process_dmsg("\n[DBG] %s : core[%x, %d] child process PID allocated = %x at cycle %d\n",752 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, new_pid , hal_get_cycles() );958 fork_dmsg("\n[DBG] %s : core[%x, %d] child process PID allocated = %x at cycle %d\n", 959 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, new_pid , (uint32_t)hal_get_cycles() ); 753 960 754 961 // initializes child process descriptor from parent process descriptor … … 758 965 parent_process_xp ); 759 966 760 process_dmsg("\n[DBG] %s : core[%x, %d] child process initialised at cycle %d\n",967 fork_dmsg("\n[DBG] %s : core[%x, %d] child process initialised at cycle %d\n", 761 968 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() ); 762 969 … … 773 980 } 774 981 775 process_dmsg("\n[DBG] %s : core[%x, %d] child process VMM copied at cycle %d\n",776 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );982 fork_dmsg("\n[DBG] %s : core[%x, %d] child process VMM copied at cycle %d\n", 983 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, (uint32_t)hal_get_cycles() ); 777 984 778 985 // create child thread descriptor from parent thread descriptor … … 789 996 } 790 997 791 process_dmsg("\n[DBG] %s : core[%x,%d] child thread created at cycle %d\n",792 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );998 fork_dmsg("\n[DBG] %s : core[%x,%d] child thread created at cycle %d\n", 999 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, (uint32_t)hal_get_cycles() ); 793 1000 794 1001 // update parent process GPT to set Copy_On_Write for shared data vsegs … … 804 1011 } 805 1012 806 process_dmsg("\n[DBG] %s : core[%x,%d] COW set in parent_process at cycle %d\n",807 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );1013 fork_dmsg("\n[DBG] %s : core[%x,%d] COW set in parent_process at cycle %d\n", 1014 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, (uint32_t)hal_get_cycles() ); 808 1015 809 1016 // update children list in parent process … … 821 1028 *child_pid = new_pid; 822 1029 1030 fork_dmsg("\n[DBG] %s : core[%x,%d] exit at cycle %d\n", 1031 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, (uint32_t)hal_get_cycles() ); 1032 823 1033 return 0; 824 1034 825 1035 } // end process_make_fork() 1036 1037 /* deprecated because we don't wand to destroy the existing process descriptor 826 1038 827 1039 ///////////////////////////////////////////////////// … … 841 1053 pid = exec_info->pid; 842 1054 843 // check local cluster is oldprocess owner1055 // check local cluster is process owner 844 1056 assert( (CXY_FROM_PID( pid ) == local_cxy), __FUNCTION__, 845 1057 "local cluster %x is not owner for process %x\n", local_cxy, pid ); … … 876 1088 } 877 1089 878 exec_dmsg("\n[DBG] %s : core[%x,%d] registered code/data vsegs / process %x/ path = %s\n",879 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, p id, path );1090 exec_dmsg("\n[DBG] %s : core[%x,%d] vsegs registered / path = %s\n", 1091 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path ); 880 1092 881 1093 // select a core in local cluster to execute the main thread … … 908 1120 XPTR( local_cxy , &new->brothers_list ) ); 909 1121 910 // FIXME request destruction of old process copies and threads in all clusters 1122 // request destruction of old process copies and threads in all clusters 1123 process_sigaction( old , SIGKILL ); 911 1124 912 1125 // activate new thread … … 920 1133 } // end process_make_exec() 921 1134 1135 */ 1136 1137 ///////////////////////////////////////////////////// 1138 error_t process_make_exec( exec_info_t * exec_info ) 1139 { 1140 char * path; // pathname to .elf file 1141 process_t * process; // local pointer on old process 1142 pid_t pid; // old process identifier 1143 thread_t * thread; // pointer on new main thread 1144 pthread_attr_t attr; // main thread attributes 1145 lid_t lid; // selected core local index 1146 error_t error; 1147 1148 // get .elf pathname and PID from exec_info 1149 path = exec_info->path; 1150 pid = exec_info->pid; 1151 1152 // check local cluster is process owner 1153 assert( (CXY_FROM_PID( pid ) == local_cxy), __FUNCTION__, 1154 "local cluster %x is not owner for process %x\n", local_cxy, pid ); 1155 1156 exec_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / path = %s\n", 1157 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, pid , path ); 1158 1159 // get process local pointer 1160 process = (process_t *)cluster_get_local_process_from_pid( pid ); 1161 1162 assert( (process != NULL ) , __FUNCTION__ , 1163 "process %x not found in cluster %x\n", pid , local_cxy ); 1164 1165 // reset the existing vmm 1166 vmm_destroy( process ); 1167 1168 exec_dmsg("\n[DBG] %s : core[%x,%d] VMM cleared\n", 1169 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid ); 1170 1171 // block all existing process threads 1172 process_sigaction( process , BLOCK_ALL_THREADS ); 1173 1174 // kill all existing threads and process descriptors (other than owner) 1175 process_sigaction( process , DELETE_ALL_THREADS ); 1176 1177 // check no threads 1178 assert( (process->th_nr == 0) , __FUNCTION__ , "no threads at this point" ); 1179 1180 exec_dmsg("\n[DBG] %s : core[%x,%d] all threads deleted\n", 1181 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid ); 1182 1183 // re-initialize VMM 1184 vmm_init( process ); 1185 1186 // register "code" and "data" vsegs as well as entry-point and vfs_bin_xp 1187 // in VMM, using information contained in the elf file. 1188 if( elf_load_process( path , process ) ) 1189 { 1190 printk("\n[ERROR] in %s : failed to access .elf file for process %x / path = %s\n", 1191 __FUNCTION__, pid , path ); 1192 process_destroy( process ); 1193 return -1; 1194 } 1195 1196 exec_dmsg("\n[DBG] %s : core[%x,%d] new vsegs registered / path = %s\n", 1197 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path ); 1198 1199 // @@@ 1200 vmm_display( process , true ); 1201 // @@@ 1202 1203 // select a core in local cluster to execute the new main thread 1204 lid = cluster_select_local_core(); 1205 1206 // initialize pthread attributes for new main thread 1207 attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED | PT_ATTR_CORE_DEFINED; 1208 attr.cxy = local_cxy; 1209 attr.lid = lid; 1210 1211 // create and initialize thread descriptor 1212 error = thread_user_create( pid, 1213 (void *)process->vmm.entry_point, 1214 exec_info->args_pointers, 1215 &attr, 1216 &thread ); 1217 if( error ) 1218 { 1219 printk("\n[ERROR] in %s : cannot create thread for process %x / path = %s\n", 1220 __FUNCTION__, pid , path ); 1221 process_destroy( process ); 1222 return -1; 1223 } 1224 1225 exec_dmsg("\n[DBG] %s : core[%x,%d] created main thread %x for new process %x\n", 1226 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, thread->trdid, pid ); 1227 1228 // activate new thread 1229 thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL ); 1230 1231 exec_dmsg("\n[DBG] %s : core[%x,%d] exit for path = %s\n", 1232 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path ); 1233 1234 return 0; 1235 1236 } // end process_make_exec() 1237 1238 //////////////////////////////////////////// 1239 void process_make_kill( process_t * process, 1240 uint32_t sig_id ) 1241 { 1242 // this function must be executed by a thread running in owner cluster 1243 assert( (CXY_FROM_PID( process->pid ) == local_cxy) , __FUNCTION__ , 1244 "must execute in owner cluster" ); 1245 1246 // analyse signal type 1247 switch( sig_id ) 1248 { 1249 case SIGSTOP: // block all threads 1250 { 1251 process_sigaction( process , BLOCK_ALL_THREADS ); 1252 } 1253 break; 1254 case SIGCONT: // unblock all threads 1255 { 1256 process_sigaction( process , UNBLOCK_ALL_THREADS ); 1257 } 1258 break; 1259 case SIGKILL: // block all threads, then delete all threads 1260 { 1261 process_sigaction( process , BLOCK_ALL_THREADS ); 1262 process_sigaction( process , DELETE_ALL_THREADS ); 1263 process_destroy( process ); 1264 } 1265 break; 1266 } 1267 } // end process_make_kill() 1268 1269 //////////////////////////////////////////// 1270 void process_make_exit( process_t * process, 1271 uint32_t status ) 1272 { 1273 // this function must be executed by a thread running in owner cluster 1274 assert( (CXY_FROM_PID( process->pid ) == local_cxy) , __FUNCTION__ , 1275 "must execute in owner cluster" ); 1276 1277 // block all threads in all clusters 1278 process_sigaction( process , BLOCK_ALL_THREADS ); 1279 1280 // delete all threads in all clusters 1281 process_sigaction( process , DELETE_ALL_THREADS ); 1282 1283 // delete local process descriptor 1284 process_destroy( process ); 1285 1286 } // end process_make_exit() 1287 922 1288 ////////////////////////// 923 1289 void process_init_create() 924 1290 { 925 exec_info_t exec_info; // structure to be passed to process_make_exec() 926 process_t * process; // local pointer on process_init descriptor 927 pid_t pid; // process_init identifier 928 error_t error; 929 930 process_dmsg("\n[DBG] %s : enters in cluster %x\n", 931 __FUNCTION__ , local_cxy ); 1291 process_t * process; // local pointer on process_init descriptor 1292 pid_t pid; // process_init identifier 1293 thread_t * thread; // local pointer on main thread 1294 pthread_attr_t attr; // main thread attributes 1295 lid_t lid; // selected core local index for main thread 1296 error_t error; 1297 1298 kinit_dmsg("\n[DBG] %s : core[%x,%d] enters\n", 1299 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid ); 932 1300 933 1301 // allocates memory for process descriptor from local cluster … … 936 1304 { 937 1305 printk("\n[PANIC] in %s : no memory for process descriptor in cluster %x\n", 938 __FUNCTION__, local_cxy );939 } 940 941 // get newPID from local cluster1306 __FUNCTION__, local_cxy ); 1307 } 1308 1309 // get PID from local cluster 942 1310 error = cluster_pid_alloc( XPTR( local_cxy , process ) , &pid ); 943 1311 if( error ) … … 945 1313 printk("\n[PANIC] in %s : cannot allocate PID in cluster %x\n", 946 1314 __FUNCTION__, local_cxy ); 947 } 948 949 // initialise the process desciptor (parent is local kernel process) 950 process_reference_init( process, 1315 process_destroy( process ); 1316 } 1317 1318 assert( (LPID_FROM_PID(pid) == 1) , __FUNCTION__ , "LPID must be 1 for process_init" ); 1319 1320 // initialize process descriptor / parent is local process_zero 1321 process_reference_init( process, 951 1322 pid, 952 process_zero.pid,1323 0, 953 1324 XPTR( local_cxy , &process_zero ) ); 954 1325 955 // initialize the exec_info structure 956 exec_info.pid = pid; 957 exec_info.args_nr = 0; 958 exec_info.envs_nr = 0; 959 strcpy( exec_info.path , CONFIG_PROCESS_INIT_PATH ); 960 961 // update process descriptor and create thread descriptor 962 error = process_make_exec( &exec_info ); 963 1326 kinit_dmsg("\n[DBG] %s : core[%x,%d] / process initialised\n", 1327 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid ); 1328 1329 // register "code" and "data" vsegs as well as entry-point 1330 // in process VMM, using information contained in the elf file. 1331 if( elf_load_process( CONFIG_PROCESS_INIT_PATH , process ) ) 1332 { 1333 printk("\n[PANIC] in %s : cannot access .elf file / path = %s\n", 1334 __FUNCTION__, CONFIG_PROCESS_INIT_PATH ); 1335 process_destroy( process ); 1336 } 1337 1338 kinit_dmsg("\n[DBG] %s : core[%x,%d] vsegs registered / path = %s\n", 1339 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, CONFIG_PROCESS_INIT_PATH ); 1340 1341 // select a core in local cluster to execute the main thread 1342 lid = cluster_select_local_core(); 1343 1344 // initialize pthread attributes for main thread 1345 attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED | PT_ATTR_CORE_DEFINED; 1346 attr.cxy = local_cxy; 1347 attr.lid = lid; 1348 1349 // create and initialize thread descriptor 1350 error = thread_user_create( pid, 1351 (void *)process->vmm.entry_point, 1352 NULL, 1353 &attr, 1354 &thread ); 964 1355 if( error ) 965 { 966 printk("\n[PANIC] in %s : cannot exec %s in cluster %x\n", 967 __FUNCTION__, CONFIG_PROCESS_INIT_PATH , local_cxy ); 968 } 969 970 process_dmsg("\n[DBG] %s : exit in cluster %x\n", 971 __FUNCTION__ , local_cxy ); 972 1356 { 1357 printk("\n[PANIC] in %s : cannot create main thread / path = %s\n", 1358 __FUNCTION__, CONFIG_PROCESS_INIT_PATH ); 1359 process_destroy( process ); 1360 } 1361 1362 // activate thread 1363 thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL ); 1364 973 1365 hal_fence(); 974 1366 1367 kinit_dmsg("\n[DBG] %s : core[%x,%d] exit / main thread = %x\n", 1368 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, thread ); 1369 975 1370 } // end process_init_create() 976 1371
Note: See TracChangeset
for help on using the changeset viewer.