Changeset 172
- Timestamp:
- Jul 11, 2017, 10:32:25 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.c
r124 r172 1 1 /* 2 2 * process.c - process related management 3 * 3 * 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Mohamed Lamine Karaoui (2015) … … 10 10 * This file is part of ALMOS-MKH.. 11 11 * 12 * ALMOS-MKH .is free software; you can redistribute it and/or modify it12 * ALMOS-MKH is free software; you can redistribute it and/or modify it 13 13 * under the terms of the GNU General Public License as published by 14 14 * the Free Software Foundation; version 2.0 of the License. 15 15 * 16 * ALMOS-MKH .is distributed in the hope that it will be useful, but16 * ALMOS-MKH is distributed in the hope that it will be useful, but 17 17 * WITHOUT ANY WARRANTY; without even the implied warranty of 18 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 20 20 * 21 21 * You should have received a copy of the GNU General Public License 22 * along with ALMOS-MKH .; if not, write to the Free Software Foundation,22 * along with ALMOS-MKH; if not, write to the Free Software Foundation, 23 23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 24 */ … … 95 95 // get parent process cluster, local pointer, and pid 96 96 // for all processes other than process_zero 97 if( process == &process_zero ) 97 if( process == &process_zero ) 98 98 { 99 99 assert( (pid == 0) , __FUNCTION__ , "process_zero must have PID = 0\n"); … … 113 113 if( pid ) vmm_init( process ); 114 114 115 // reset reference process file descriptors array 115 // reset reference process file descriptors array 116 116 process_fd_init( process ); 117 117 … … 140 140 xlist_add_first( root , entry ); 141 141 } 142 142 143 143 // reset th_tbl[] array as empty 144 144 uint32_t i; … … 154 154 process->ppid = parent_pid; 155 155 156 // set ref_xp field 156 // set ref_xp field 157 157 process->ref_xp = XPTR( local_cxy , process ); 158 158 … … 163 163 cluster_process_copies_link( process ); 164 164 165 // init alise signal manager TODO [AG]165 // initialize signal manager TODO [AG] 166 166 167 167 hal_fence(); … … 169 169 process_dmsg("\n[INFO] %s : exit for process %x in cluster %x\n", 170 170 __FUNCTION__ , pid ); 171 172 } // end process_reference_init() 171 } 173 172 174 173 ///////////////////////////////////////////////////// … … 180 179 process_t * ref_ptr = (process_t *)GET_PTR( reference_process_xp ); 181 180 182 // reset local process vmm 181 // reset local process vmm 183 182 vmm_init( local_process ); 184 183 185 // reset process file descriptors array 184 // reset process file descriptors array 186 185 process_fd_init( local_process ); 187 186 … … 198 197 // reset children list root (not used in a process descriptor copy) 199 198 xlist_root_init( XPTR( local_cxy , &local_process->children_root ) ); 200 local_process->children_nr = 0; 199 local_process->children_nr = 0; 201 200 202 201 // reset brothers list (not used in a process descriptor copy) … … 224 223 cluster_process_copies_link( local_process ); 225 224 226 // init alise signal manager TODO [AG]225 // initialize signal manager TODO [AG] 227 226 228 227 hal_fence(); 229 228 230 229 return 0; 231 232 } // end process_copy_init() 230 } 233 231 234 232 /////////////////////////////////////////// 235 233 void process_destroy( process_t * process ) 236 234 { 237 if( process->th_nr != 0 ) 235 if( process->th_nr != 0 ) 238 236 { 239 237 printk("\n[PANIC] in %s : process %x in cluster %x has still active threads\n", … … 248 246 remote_spinlock_lock( XPTR( local_cxy , &pmgr->local_lock ) ); 249 247 250 // remove the process descriptor from local_list in local cluster manager 248 // remove the process descriptor from local_list in local cluster manager 251 249 xlist_unlink( XPTR( local_cxy , &process->local_list ) ); 252 250 … … 263 261 xlist_unlink( XPTR( local_cxy , &process->copies_list ) ); 264 262 remote_spinlock_unlock( copies_lock ); 265 263 266 264 // synchronize memory 267 265 hal_fence(); 268 266 269 // From this point, the process descriptor is unreachable 267 // From this point, the process descriptor is unreachable 270 268 271 269 // close all open files and update dirty TODO [AG] … … 283 281 process_dmsg("\n[INFO] %s for pid %d / page_faults = %d\n", 284 282 __FUNCTION__ , process->pid, process->vmm.pgfault_nr ); 285 286 } // end process_destroy() 283 } 287 284 288 285 //////////////////////////////////////// … … 298 295 // first loop on threads to send the THREAD_SIG_KILL signal to all process threads 299 296 // we use both "ltid" and "count" indexes, because it can exist "holes" in th_tbl 300 for( ltid = 0 , count = 0 ; 301 (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ; 297 for( ltid = 0 , count = 0 ; 298 (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ; 302 299 ltid++ ) 303 300 { … … 309 306 count++; 310 307 } 311 } 312 308 } 309 313 310 volatile uint32_t ko; 314 311 315 312 // second loop on threads to wait acknowledge from scheduler, 316 313 // unlink thread from process and parent thread, and release thread descriptor 317 for( ltid = 0 , count = 0 ; 314 for( ltid = 0 , count = 0 ; 318 315 (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ; 319 316 ltid++ ) … … 327 324 328 325 // unlink thread from brothers list if required 329 if( (thread->flags & THREAD_FLAG_DETACHED) == 0 ) 326 if( (thread->flags & THREAD_FLAG_DETACHED) == 0 ) 330 327 xlist_unlink( XPTR( local_cxy , &thread->brothers_list ) ); 331 328 … … 345 342 // release memory allocated for process descriptor 346 343 process_destroy( process ); 347 348 } // end process_kill() 349 350 344 } 351 345 352 346 /////////////////////////////////////////////// … … 354 348 { 355 349 error_t error; 356 process_t * process_ptr; // local pointer on process 350 process_t * process_ptr; // local pointer on process 357 351 xptr_t process_xp; // extended pointer on process 358 352 pid_t process_pid; // process identifier … … 370 364 process_xp = XLIST_ELEMENT( iter , process_t , local_list ); 371 365 process_ptr = (process_t *)GET_PTR( process_xp ); 372 process_pid = hal_remote_lw( XPTR( local_cxy , &process_ptr->pid ) ); 366 process_pid = hal_remote_lw( XPTR( local_cxy , &process_ptr->pid ) ); 373 367 if( process_ptr->pid == pid ) 374 368 { … … 381 375 remote_spinlock_unlock( XPTR( local_cxy , &cluster->pmgr.local_lock ) ); 382 376 383 // allocate memory for a new local process descriptor 377 // allocate memory for a new local process descriptor 384 378 // and initialise it from reference cluster if required 385 379 if( !found ) … … 400 394 401 395 return process_ptr; 402 } // end process_get_local_copy() 403 396 } 404 397 405 398 ////////////////////////////////////////////////////////////////////////////////////////// … … 423 416 } 424 417 425 426 418 ////////////////////////////// 427 419 bool_t process_fd_array_full() 428 420 { 429 // get extended pointer on reference process 421 // get extended pointer on reference process 430 422 xptr_t ref_xp = CURRENT_THREAD->process->ref_xp; 431 423 … … 437 429 uint32_t current = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->fd_array.current ) ); 438 430 439 return ( current >= CONFIG_PROCESS_FILE_MAX_NR ); 431 return ( current >= CONFIG_PROCESS_FILE_MAX_NR ); 440 432 } 441 433 442 434 ///////////////////////////////////////////////// 443 error_t process_fd_register( xptr_t file_xp, 435 error_t process_fd_register( xptr_t file_xp, 444 436 uint32_t * file_id ) 445 437 { … … 448 440 xptr_t xp; 449 441 450 // get extended pointer on reference process 442 // get extended pointer on reference process 451 443 xptr_t ref_xp = CURRENT_THREAD->process->ref_xp; 452 444 … … 478 470 if ( !found ) return EMFILE; 479 471 else return 0; 480 481 } // end process_fd_register() 482 483 //////////////////////////////////////////////// 472 } 473 474 //////////////////////////////////////////////// 484 475 xptr_t process_fd_get_xptr( process_t * process, 485 476 uint32_t file_id ) … … 508 499 509 500 return file_xp; 510 511 } // end process_fd_get_xptr() 501 } 512 502 513 503 /////////////////////////////////////////// … … 529 519 remote_spinlock_lock( XPTR( src_cxy , &src_ptr->lock ) ); 530 520 531 // loop on all entries in source process fd_array 521 // loop on all entries in source process fd_array 532 522 for( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ ) 533 523 { … … 546 536 // release lock on source process fd_array 547 537 remote_spinlock_unlock( XPTR( src_cxy , &src_ptr->lock ) ); 548 } 549 550 538 } 551 539 552 540 //////////////////////////////////////////////////////////////////////////////////// … … 588 576 589 577 return (found) ? 0 : ENOMEM; 590 591 } // process_register_thread() 592 578 } 593 579 /////////////////////////////////////////////// 594 580 void process_remove_thread( thread_t * thread ) … … 599 585 hal_core_sleep(); 600 586 } 601 587 602 588 process_t * process = thread->process; 603 589 … … 608 594 process->th_tbl[ltid] = NULL; 609 595 process->th_nr--; 610 611 } // process_remove_thread() 612 596 } 613 597 614 598 ///////////////////////////////////////////////////// … … 616 600 { 617 601 char * path; // pathname to .elf file 618 process_t * process; // local pointer on new process 602 process_t * process; // local pointer on new process 619 603 pid_t pid; // new process pid 620 604 xptr_t parent_xp; // extended pointer on parent process … … 626 610 core_t * core; // pointer on selected core 627 611 lid_t lid; // selected core local index 628 error_t error; 612 error_t error; 629 613 630 614 // get parent and .elf pathname from exec_info … … 636 620 parent_ptr = (process_t *)GET_PTR( parent_xp ); 637 621 parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) ); 638 622 639 623 exec_dmsg("\n[INFO] %s enters in cluster %x for path = %s\n", 640 624 __FUNCTION__ , local_cxy , path ); … … 650 634 } 651 635 652 // get a pid from the local cluster 636 // get a pid from the local cluster 653 637 error = cluster_pid_alloc( XPTR( local_cxy , process ) , &pid ); 654 638 655 639 if( error ) 656 640 { 657 printk("\n[ERROR] in %s : cannot get PID / cluster = %x / ppid = %x / path = %s\n", 641 printk("\n[ERROR] in %s : cannot get PID / cluster = %x / ppid = %x / path = %s\n", 658 642 __FUNCTION__ , local_cxy , parent_pid , path ); 659 643 return ENOMEM; 660 644 } 661 645 662 646 // initialize the process descriptor as the reference 663 647 process_reference_init( process , pid , parent_xp ); 664 648 665 649 exec_dmsg("\n[INFO] %s created process %x cluster %x / path = %s\n", 666 650 __FUNCTION__, parent_pid , local_cxy , path ); 667 651 668 // initialize svfs_root and vfs_cwd from parent process652 // initialize vfs_root and vfs_cwd from parent process 669 653 xptr_t vfs_root_xp = hal_remote_lwd( XPTR( parent_cxy , &parent_ptr->vfs_root_xp ) ); 670 654 vfs_file_count_up( vfs_root_xp ); … … 688 672 __FUNCTION__ , local_cxy , pid , path ); 689 673 690 // register "code" and "data" vsegs as well a the process entry-point in VMM,691 // using information scontained in the elf file.674 // register "code" and "data" vsegs as well as the process entry-point in VMM, 675 // using information contained in the elf file. 692 676 error = elf_load_process( path , process ); 693 677 694 678 if( error ) 695 679 { 696 printk("\n[ERROR] in %s : failed to access elf file for process %x / path = %s\n", 680 printk("\n[ERROR] in %s : failed to access elf file for process %x / path = %s\n", 697 681 __FUNCTION__, pid , path ); 698 682 process_destroy( process ); … … 722 706 attr.lid = lid; 723 707 724 // create and initiali se thread descriptor708 // create and initialize thread descriptor 725 709 error = thread_user_create( pid, 726 710 (void *)process->vmm.entry_point, 727 711 exec_info->args_pointers, 728 712 &attr, 729 &thread ); 713 &thread ); 730 714 if( error ) 731 715 { … … 741 725 hal_remote_atomic_add( XPTR( parent_cxy , &parent_ptr->children_nr) , 1 ); 742 726 743 // Register thread in scheduler727 // register thread in scheduler 744 728 sched_register_thread( core , thread ); 745 729 … … 747 731 __FUNCTION__ , pid , core->lid , local_cxy ); 748 732 749 // activate new thread 733 // activate new thread 750 734 thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL ); 751 735 752 736 return 0; 753 754 } // end process_make_exec() 737 } 755 738 756 739 ////////////////////////// … … 765 748 xptr_t stdout_xp; 766 749 xptr_t stderr_xp; 767 uint32_t stdin_id; 768 uint32_t stdout_id; 769 uint32_t stderr_id; 750 uint32_t stdin_id; 751 uint32_t stdout_id; 752 uint32_t stderr_id; 770 753 771 754 process_dmsg("\n[INFO] %s enters in cluster %x\n", __FUNCTION__ , local_cxy ); … … 816 799 817 800 hal_fence(); 818 819 } // end process_init_create() 820 821 801 } 802
Note: See TracChangeset
for help on using the changeset viewer.