Changeset 669 for trunk/kernel/kern/thread.c
- Timestamp:
- Nov 19, 2020, 11:44:34 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.c
r662 r669 30 30 #include <hal_remote.h> 31 31 #include <hal_vmm.h> 32 #include <hal_switch.h> 32 33 #include <memcpy.h> 33 34 #include <printk.h> … … 120 121 121 122 // check type and trdid fields are initialized 122 assert( (thread->type == type) , "bad type argument" );123 assert( (thread->trdid == trdid) , "bad trdid argument" );123 assert( __FUNCTION__, (thread->type == type) , "bad type argument" ); 124 assert( __FUNCTION__, (thread->trdid == trdid) , "bad trdid argument" ); 124 125 125 126 #if DEBUG_THREAD_INIT … … 160 161 list_entry_init( &thread->sched_list ); 161 162 163 // initialize the embedded alarm to unlink 164 list_entry_init( &thread->alarm.list ); 165 162 166 // initialize waiting queue entries 163 167 list_entry_init( &thread->wait_list ); … … 220 224 vseg_t * us_vseg; // user stack vseg 221 225 222 assert( (attr != NULL) , "pthread attributes must be defined" );226 assert( __FUNCTION__, (attr != NULL) , "pthread attributes must be defined" ); 223 227 224 228 #if DEBUG_THREAD_USER_CREATE … … 370 374 return -1; 371 375 } 372 hal_cpu_context_init( thread ); 376 hal_cpu_context_init( thread, 377 false , 0 , 0 ); // not a main thread 373 378 374 379 // allocate & initialize FPU context … … 662 667 } // end thread_user_fork() 663 668 664 //////////////////////////////////////////////// 665 error_t thread_user_exec( void * entry_func, 666 uint32_t argc, 667 char ** argv ) 669 ///////////////////////////////////// 670 void thread_user_exec( uint32_t argc, 671 intptr_t argv ) 668 672 { 669 673 thread_t * thread = CURRENT_THREAD; … … 673 677 uint32_t cycle = (uint32_t)hal_get_cycles(); 674 678 if( DEBUG_THREAD_USER_EXEC < cycle ) 675 printk("\n[%s] thread[%x,%x] enter / entry %x /cycle %d\n",676 __FUNCTION__, process->pid, thread->trdid, entry_func ,cycle );679 printk("\n[%s] thread[%x,%x] enter / cycle %d\n", 680 __FUNCTION__, process->pid, thread->trdid, cycle ); 677 681 #endif 678 682 679 683 // check parent thread attributes 680 assert( (thread->type == THREAD_USER ), "bad type" );681 assert( (thread->signature == THREAD_SIGNATURE) , "bad signature" );682 assert( (thread->busylocks == 0) , "bad busylocks" );684 assert( __FUNCTION__, (thread->type == THREAD_USER ) , "bad type" ); 685 assert( __FUNCTION__, (thread->signature == THREAD_SIGNATURE) , "bad signature" ); 686 assert( __FUNCTION__, (thread->busylocks == 0) , "bad busylocks" ); 683 687 684 688 // re-initialize various thread descriptor fields 685 thread->quantum = 0; // TODO 686 thread->ticks_nr = 0; // TODO 687 thread->time_last_check = 0; // TODO 688 689 thread->entry_func = entry_func; 690 thread->main_argc = argc; 691 thread->main_argv = argv; 692 693 // the main thread is always detached 694 thread->flags = THREAD_FLAG_DETACHED; 689 thread->quantum = 0; // TODO 690 thread->ticks_nr = 0; // TODO 691 thread->time_last_check = 0; // TODO 692 thread->entry_func = (void*)process->vmm.entry_point; 693 thread->flags = THREAD_FLAG_DETACHED; // main always detached 695 694 thread->blocked = 0; 696 695 thread->errno = 0; 697 thread->fork_user = 0; // not inherited 698 thread->fork_cxy = 0; // not inherited 699 700 // re-initialize busylocks counters 701 thread->busylocks = 0; 696 thread->fork_user = 0; 697 thread->fork_cxy = 0; 702 698 703 699 // reset thread info … … 707 703 remote_busylock_init( XPTR( local_cxy , &thread->join_lock ), LOCK_THREAD_JOIN ); 708 704 709 // allocate an user stack vseg for main thread710 vseg_t * us_vseg = vmm_create_vseg( process,711 VSEG_TYPE_STACK,712 LTID_FROM_TRDID( thread->trdid ),713 0, // length unused714 0, // file_offset unused715 0, // file_size unused716 XPTR_NULL, // mapper_xp unused717 local_cxy );718 if( us_vseg == NULL )719 {720 printk("\n[ERROR] in %s : cannot create stack vseg for main thread\n", __FUNCTION__ );721 return -1;722 }723 724 // update user stack in thread descriptor725 thread->user_stack_vseg = us_vseg;726 727 705 // release FPU ownership if required 728 706 if( thread->core->fpu_owner == thread ) thread->core->fpu_owner = NULL; 729 707 730 // re-initializeFPU context708 // initialize thread FPU context 731 709 hal_fpu_context_init( thread ); 710 711 // initialize thread CPU context 712 hal_cpu_context_init( thread, 713 true, // main thread 714 argc, 715 argv ); 732 716 733 717 #if DEBUG_THREAD_USER_EXEC 734 718 cycle = (uint32_t)hal_get_cycles(); 735 719 if( DEBUG_THREAD_USER_EXEC < cycle ) 736 printk("\n[%s] thread[%x,%x] set CPU context & jump to user code / cycle %d\n", 737 __FUNCTION__, process->pid, thread->trdid, cycle ); 738 hal_vmm_display( XPTR( local_cxy , process ) , true );739 #endif 740 741 // re-initialize CPU context... and jump to user code742 hal_cpu_context_exec( thread ); 743 744 assert( false, "we should not execute this code"); 745 746 return 0;720 { 721 printk("\n[%s] thread[%x,%x] set CPU context & jump to user code / cycle %d\n", 722 __FUNCTION__, process->pid, thread->trdid, cycle ); 723 724 hal_cpu_context_display( XPTR( local_cxy , thread ) ); 725 hal_vmm_display( XPTR( local_cxy , process ) , true ); 726 } 727 #endif 728 729 // restore CPU registers ... and jump to user code 730 hal_do_cpu_restore( thread->cpu_context ); 747 731 748 732 } // end thread_user_exec() … … 761 745 thread_t * this = CURRENT_THREAD; 762 746 763 assert( ( (type == THREAD_IDLE) || (type == THREAD_RPC) || (type == THREAD_DEV) ) ,747 assert( __FUNCTION__, ( (type == THREAD_IDLE) || (type == THREAD_RPC) || (type == THREAD_DEV) ) , 764 748 "illegal thread type" ); 765 749 766 assert( (core_lid < LOCAL_CLUSTER->cores_nr) ,750 assert( __FUNCTION__, (core_lid < LOCAL_CLUSTER->cores_nr) , 767 751 "illegal core_lid" ); 768 752 … … 829 813 } 830 814 831 hal_cpu_context_init( thread ); 815 hal_cpu_context_init( thread, 816 false , 0 , 0 ); // not a main thread 832 817 833 818 #if DEBUG_THREAD_KERNEL_CREATE … … 854 839 855 840 // check arguments 856 assert( (type == THREAD_IDLE) , "illegal thread type" );857 assert( (core_lid < LOCAL_CLUSTER->cores_nr) , "illegal core index" );841 assert( __FUNCTION__, (type == THREAD_IDLE) , "illegal thread type" ); 842 assert( __FUNCTION__, (core_lid < LOCAL_CLUSTER->cores_nr) , "illegal core index" ); 858 843 859 844 // set type in thread descriptor … … 863 848 error = process_register_thread( &process_zero , thread , &trdid ); 864 849 865 assert( (error == 0), "cannot register idle_thread in kernel process" );850 assert( __FUNCTION__, (error == 0), "cannot register idle_thread in kernel process" ); 866 851 867 852 // set trdid in thread descriptor … … 878 863 NULL ); // no user stack for a kernel thread 879 864 880 assert( (error == 0), "cannot initialize idle_thread" );881 882 // allocate & initialize CPU context if success865 assert( __FUNCTION__, (error == 0), "cannot initialize idle_thread" ); 866 867 // allocate CPU context 883 868 error = hal_cpu_context_alloc( thread ); 884 869 885 assert( (error == 0), "cannot allocate CPU context" ); 886 887 hal_cpu_context_init( thread ); 870 assert( __FUNCTION__, (error == 0), "cannot allocate CPU context" ); 871 872 // initialize CPU context 873 hal_cpu_context_init( thread, 874 false , 0 , 0 ); // not a main thread 888 875 889 876 } // end thread_idle_init() … … 949 936 #endif 950 937 938 // unlink embedded alarm from the list rooted in core when required 939 list_entry_t * entry = &thread->alarm.list; 940 if( (entry->next != NULL) || (entry->pred != NULL) ) list_unlink( entry ); 941 951 942 // remove thread from process th_tbl[] 952 943 count = process_remove_thread( thread ); … … 1028 1019 1029 1020 // check signal pending in scheduler 1030 assert( sched->req_ack_pending , "no pending signal" );1021 assert( __FUNCTION__, sched->req_ack_pending , "no pending signal" ); 1031 1022 1032 1023 // enter critical section … … 1101 1092 1102 1093 ////////////////////////////////////// 1103 void thread_delete ( xptr_t target_xp,1094 void thread_delete_request( xptr_t target_xp, 1104 1095 bool_t is_forced ) 1105 1096 { … … 1150 1141 // check target thread is not the main thread, because the main thread 1151 1142 // must be deleted by the parent process sys_wait() function 1152 assert( ((CXY_FROM_PID( target_pid ) != target_cxy) || (target_ltid != 0)),1143 assert( __FUNCTION__, ((CXY_FROM_PID( target_pid ) != target_cxy) || (target_ltid != 0)), 1153 1144 "target thread cannot be the main thread" ); 1154 1145 … … 1275 1266 1276 1267 } 1277 } // end thread_delete ()1268 } // end thread_delete_request() 1278 1269 1279 1270
Note: See TracChangeset
for help on using the changeset viewer.