Changeset 433 for trunk/kernel/kern/thread.c
- Timestamp:
- Feb 14, 2018, 3:40:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.c
r428 r433 227 227 assert( (attr != NULL) , __FUNCTION__, "pthread attributes must be defined" ); 228 228 229 thread_dmsg("\n[DBG] %s : core[%x,%d] enter for process %x\n", 230 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, process->pid ); 229 #if CONFIG_DEBUG_THREAD_USER_CREATE 230 uint32_t cycle = (uint32_t)hal_get_cycles(); 231 if( CONFIG_DEBUG_THREAD_USER_CREATE < cycle ) 232 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n", 233 __FUNCTION__, CURRENT_THREAD, pid , cycle ); 234 #endif 231 235 232 236 // get process descriptor local copy 233 237 process = process_get_local_copy( pid ); 234 235 238 if( process == NULL ) 236 239 { … … 326 329 dqdt_local_update_threads( 1 ); 327 330 328 thread_dmsg("\n[DBG] %s : core[%x,%d] exit for process %x / trdid = %x / core = %d\n", 329 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, process->pid, thread->trdid, core_lid ); 331 #if CONFIG_DEBUG_THREAD_USER_CREATE 332 cycle = (uint32_t)hal_get_cycles(); 333 if( CONFIG_DEBUG_THREAD_USER_CREATE < cycle ) 334 printk("\n[DBG] %s : thread %x exit / process %x / new_thread %x / core %d / cycle %d\n", 335 __FUNCTION__, CURRENT_THREAD, pid, thread, core_lid, cycle ); 336 #endif 330 337 331 338 *new_thread = thread; … … 359 366 vseg_t * vseg; // child thread STACK vseg 360 367 361 thread_dmsg("\n[DBG] %s : core[%x,%d] enters at cycle %d\n", 362 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , hal_get_cycles() ); 368 #if CONFIG_DEBUG_THREAD_USER_FORK 369 uint32_t cycle = (uint32_t)hal_get_cycles(); 370 if( CONFIG_DEBUG_THREAD_USER_FORK < cycle ) 371 printk("\n[DBG] %s : thread %x enter / child_process %x / cycle %d\n", 372 __FUNCTION__, CURRENT_THREAD, child_process->pid, cycle ); 373 #endif 363 374 364 375 // select a target core in local cluster … … 474 485 } 475 486 476 // increment p age descriptor fork_nr for the referencedpage if mapped487 // increment pending forks counter for the page if mapped 477 488 if( mapped ) 478 489 { … … 480 491 cxy_t page_cxy = GET_CXY( page_xp ); 481 492 page_t * page_ptr = (page_t *)GET_PTR( page_xp ); 482 hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->fork_nr ) , 1 ); 483 484 thread_dmsg("\n[DBG] %s : core[%x,%d] copied PTE to child GPT : vpn %x\n", 485 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , vpn ); 493 hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->forks ) , 1 ); 494 495 #if (CONFIG_DEBUG_THREAD_USER_FORK & 1) 496 cycle = (uint32_t)hal_get_cycles(); 497 if( CONFIG_DEBUG_THREAD_USER_FORK < cycle ) 498 printk("\n[DBG] %s : thread %x copied stack PTE to child GPT : vpn %x\n", 499 __FUNCTION__, CURRENT_THREAD, vpn ); 500 #endif 486 501 487 502 } 488 503 } 489 504 490 // set COW flag for STAK vseg in parent thread GPT 491 hal_gpt_flip_cow( true, // set cow 492 parent_gpt_xp, 493 vpn_base, 494 vpn_size ); 505 // set COW flag for all mapped entries of STAK vseg in parent thread GPT 506 hal_gpt_set_cow( parent_gpt_xp, 507 vpn_base, 508 vpn_size ); 495 509 496 510 // update DQDT for child thread 497 511 dqdt_local_update_threads( 1 ); 498 512 499 thread_dmsg("\n[DBG] %s : core[%x,%d] exit / created main thread %x for process %x\n", 500 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, child_ptr->trdid, child_process->pid ); 513 #if CONFIG_DEBUG_THREAD_USER_FORK 514 cycle = (uint32_t)hal_get_cycles(); 515 if( CONFIG_DEBUG_THREAD_USER_FORK < cycle ) 516 printk("\n[DBG] %s : thread %x exit / child_process %x / child_thread %x / cycle %d\n", 517 __FUNCTION__, CURRENT_THREAD, child_process->pid, child_ptr, cycle ); 518 #endif 501 519 502 520 return 0; … … 514 532 thread_t * thread; // pointer on new thread descriptor 515 533 516 thread_dmsg("\n[DBG] %s : core[%x,%d] enters / type %s / cycle %d\n",517 __FUNCTION__ , local_cxy , core_lid , thread_type_str( type ) , hal_time_stamp() );518 519 534 assert( ( (type == THREAD_IDLE) || (type == THREAD_RPC) || (type == THREAD_DEV) ) , 520 535 __FUNCTION__ , "illegal thread type" ); … … 522 537 assert( (core_lid < LOCAL_CLUSTER->cores_nr) , 523 538 __FUNCTION__ , "illegal core_lid" ); 539 540 #if CONFIG_DEBUG_THREAD_KERNEL_CREATE 541 uint32_t cycle = (uint32_t)hal_get_cycles(); 542 if( CONFIG_DEBUG_THREAD_KERNEL_CREATE < cycle ) 543 printk("\n[DBG] %s : thread %x enter / requested_type %s / cycle %d\n", 544 __FUNCTION__, CURRENT_THREAD, thread, thread_type_str(type), cycle ); 545 #endif 524 546 525 547 // allocate memory for new thread descriptor … … 549 571 dqdt_local_update_threads( 1 ); 550 572 551 thread_dmsg("\n[DBG] %s : core = [%x,%d] exit / trdid = %x / type %s / cycle %d\n", 552 __FUNCTION__, local_cxy, core_lid, thread->trdid, thread_type_str(type), hal_time_stamp() ); 573 #if CONFIG_DEBUG_THREAD_KERNEL_CREATE 574 cycle = (uint32_t)hal_get_cycles(); 575 if( CONFIG_DEBUG_THREAD_KERNEL_CREATE < cycle ) 576 printk("\n[DBG] %s : thread %x exit / new_thread %x / type %s / cycle %d\n", 577 __FUNCTION__, CURRENT_THREAD, thread, thread_type_str(type), cycle ); 578 #endif 553 579 554 580 *new_thread = thread; … … 589 615 void thread_destroy( thread_t * thread ) 590 616 { 591 uint32_t tm_start;592 uint32_t tm_end;593 617 reg_t save_sr; 594 618 … … 596 620 core_t * core = thread->core; 597 621 598 thread_dmsg("\n[DBG] %s : enters for thread %x in process %x / type = %s\n", 599 __FUNCTION__ , thread->trdid , process->pid , thread_type_str( thread->type ) ); 622 #if CONFIG_DEBUG_THREAD_DESTROY 623 uint32_t cycle = (uint32_t)hal_get_cycles(); 624 if( CONFIG_DEBUG_THREAD_DESTROY < cycle ) 625 printk("\n[DBG] %s : thread %x enter to destroy thread %x in process %x / cycle %d\n", 626 __FUNCTION__, CURRENT_THREAD, thread, process->pid, cycle ); 627 #endif 600 628 601 629 assert( (thread->children_nr == 0) , __FUNCTION__ , "still attached children" ); … … 604 632 605 633 assert( (thread->remote_locks == 0) , __FUNCTION__ , "all remote locks not released" ); 606 607 tm_start = hal_get_cycles();608 634 609 635 // update intrumentation values … … 635 661 thread_release( thread ); 636 662 637 tm_end = hal_get_cycles(); 638 639 thread_dmsg("\n[DBG] %s : exit for thread %x in process %x / duration = %d\n", 640 __FUNCTION__, thread->trdid , process->pid , tm_end - tm_start ); 663 #if CONFIG_DEBUG_THREAD_DESTROY 664 cycle = (uint32_t)hal_get_cycles(); 665 if( CONFIG_DEBUG_THREAD_DESTROY < cycle ) 666 printk("\n[DBG] %s : thread %x exit / destroyed thread %x in process %x / cycle %d\n", 667 __FUNCTION__, CURRENT_THREAD, thread, process->pid, cycle ); 668 #endif 641 669 642 670 } // end thread_destroy() … … 779 807 hal_fence(); 780 808 809 #if CONFIG_DEBUG_THREAD_BLOCK 810 uint32_t cycle = (uint32_t)hal_get_cycles(); 811 if( CONFIG_DEBUG_THREAD_BLOCK < cycle ) 812 printk("\n[DBG] %s : thread %x blocked thread %x / cause %x / state %x / cycle %d\n", 813 __FUNCTION__ , CURRENT_THREAD , thread , cause , thread->blocked , cycle ); 814 #endif 815 781 816 } // end thread_block() 782 817 783 ///////////////////////////////////////// 784 uint32_t thread_unblock( xptr_t thread ,818 //////////////////////////////////////////// 819 uint32_t thread_unblock( xptr_t thread_xp, 785 820 uint32_t cause ) 786 821 { 787 822 // get thread cluster and local pointer 788 cxy_t cxy = GET_CXY( thread );789 thread_t * ptr = (thread_t *)GET_PTR( thread);823 cxy_t cxy = GET_CXY( thread_xp ); 824 thread_t * ptr = GET_PTR( thread_xp ); 790 825 791 826 // reset blocking cause … … 793 828 hal_fence(); 794 829 830 #if CONFIG_DEBUG_THREAD_BLOCK 831 uint32_t cycle = (uint32_t)hal_get_cycles(); 832 if( CONFIG_DEBUG_THREAD_BLOCK < cycle ) 833 printk("\n[DBG] %s : thread %x unblocked thread %x / cause %x / state %x / cycle %d\n", 834 __FUNCTION__ , CURRENT_THREAD , ptr , cause , ptr->blocked , cycle ); 835 #endif 836 795 837 // return a non zero value if the cause bit is modified 796 838 return( previous & cause ); … … 805 847 thread_t * killer = CURRENT_THREAD; 806 848 807 thread_dmsg("\n[DBG] %s : killer thread %x enter for target thread %x\n", 808 __FUNCTION__, local_cxy, killer->trdid , target->trdid ); 849 #if CONFIG_DEBUG_THREAD_KILL 850 uint32_t cycle = (uint32_t)hal_get_cycles; 851 if( CONFIG_DEBUG_THREAD_KILL < cycle ) 852 printk("\n[DBG] %s : thread %x enter for target thread %x / cycle %d\n", 853 __FUNCTION__, killer, target, cycle ); 854 #endif 809 855 810 856 // set the global blocked bit in target thread descriptor. … … 835 881 hal_atomic_or( &target->flags , THREAD_FLAG_REQ_DELETE ); 836 882 837 thread_dmsg("\n[DBG] %s : killer thread %x exit for target thread %x\n", 838 __FUNCTION__, local_cxy, killer->trdid , target->trdid ); 883 #if CONFIG_DEBUG_THREAD_KILL 884 cycle = (uint32_t)hal_get_cycles; 885 if( CONFIG_DEBUG_THREAD_KILL < cycle ) 886 printk("\n[DBG] %s : thread %x exit for target thread %x / cycle %d\n", 887 __FUNCTION__, killer, target, cycle ); 888 #endif 839 889 840 890 } // end thread_kill() … … 851 901 { 852 902 853 idle_dmsg("\n[DBG] %s : core[%x][%d] goes to sleep at cycle %d\n", 854 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , hal_get_cycles() ); 903 #if CONFIG_DEBUG_THREAD_IDLE 904 uint32_t cycle = (uint32_t)hal_get_cycles; 905 thread_t * this = CURRENT_THREAD; 906 if( CONFIG_DEBUG_THREAD_IDLE < cycle ) 907 printk("\n[DBG] %s : idle thread %x on core[%x,%d] goes to sleep / cycle %d\n", 908 __FUNCTION__, this, local_cxy, this->core->lid, cycle ); 909 #endif 855 910 856 911 hal_core_sleep(); 857 912 858 idle_dmsg("\n[DBG] %s : core[%x][%d] wake up at cycle %d\n", 859 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , hal_get_cycles() ); 913 #if CONFIG_DEBUG_THREAD_IDLE 914 cycle = (uint32_t)hal_get_cycles; 915 if( CONFIG_DEBUG_THREAD_IDLE < cycle ) 916 printk("\n[DBG] %s : idle thread %x on core[%x,%d] wake up / cycle %d\n", 917 __FUNCTION__, this, local_cxy, this->core->lid, cycle ); 918 #endif 860 919 861 920 }
Note: See TracChangeset
for help on using the changeset viewer.