Changeset 683 for trunk/kernel/kern/thread.c
- Timestamp:
- Jan 13, 2021, 12:36:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.c
r669 r683 3 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017,2018,2019,2020)5 * Alain Greiner (2016,2017,2018,2019,2020) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 67 67 } 68 68 } 69 70 /////////////////////////////////////////////////////////////////////////////////////71 // This static function allocates physical memory for a thread descriptor.72 // It can be called by the three functions:73 // - thread_user_create()74 // - thread_user_fork()75 // - thread_kernel_create()76 /////////////////////////////////////////////////////////////////////////////////////77 // @ return pointer on thread descriptor if success / return NULL if failure.78 /////////////////////////////////////////////////////////////////////////////////////79 static thread_t * thread_alloc( void )80 {81 kmem_req_t req; // kmem request82 83 // allocates memory for thread descriptor + kernel stack84 req.type = KMEM_PPM;85 req.order = CONFIG_THREAD_DESC_ORDER;86 req.flags = AF_KERNEL | AF_ZERO;87 88 return kmem_alloc( &req );89 90 } // end thread_alloc()91 92 69 93 70 ///////////////////////////////////////////////////////////////////////////////////// … … 144 121 145 122 #if DEBUG_BUSYLOCK 146 123 xlist_root_init( XPTR( local_cxy , &thread->busylocks_root ) ); 147 124 #endif 148 125 … … 161 138 list_entry_init( &thread->sched_list ); 162 139 163 // initialize the embedded alarm to unlink140 // initialize the embedded alarm 164 141 list_entry_init( &thread->alarm.list ); 165 142 … … 187 164 dqdt_increment_threads(); 188 165 166 // nitialize timer alarm 167 alarm_init( &thread->alarm ); 168 189 169 #if CONFIG_INSTRUMENTATION_PGFAULTS 190 191 192 193 194 195 196 197 198 170 thread->info.false_pgfault_nr = 0; 171 thread->info.false_pgfault_cost = 0; 172 thread->info.false_pgfault_max = 0; 173 thread->info.local_pgfault_nr = 0; 174 thread->info.local_pgfault_cost = 0; 175 thread->info.local_pgfault_max = 0; 176 thread->info.global_pgfault_nr = 0; 177 thread->info.global_pgfault_cost = 0; 178 thread->info.global_pgfault_max = 0; 199 179 #endif 200 180 … … 273 253 274 254 // allocate memory for thread descriptor 275 thread = thread_alloc();255 thread = kmem_alloc( CONFIG_THREAD_DESC_ORDER , AF_ZERO ); 276 256 277 257 if( thread == NULL ) … … 467 447 468 448 // allocate memory for child thread descriptor 469 child_ptr = thread_alloc();449 child_ptr = kmem_alloc( CONFIG_THREAD_DESC_ORDER , AF_ZERO ); 470 450 471 451 if( child_ptr == NULL ) … … 677 657 uint32_t cycle = (uint32_t)hal_get_cycles(); 678 658 if( DEBUG_THREAD_USER_EXEC < cycle ) 679 printk("\n[%s] thread[%x,%x] enter / cycle %d\n",680 __FUNCTION__, process->pid, thread->trdid, cycle );659 printk("\n[%s] thread[%x,%x] enter / argc %d / argv %x / cycle %d\n", 660 __FUNCTION__, process->pid, thread->trdid, argc, argv, cycle ); 681 661 #endif 682 662 … … 727 707 #endif 728 708 729 // restore CPU registers ... andjump to user code709 // restore CPU registers => jump to user code 730 710 hal_do_cpu_restore( thread->cpu_context ); 731 711 … … 759 739 760 740 // allocate memory for new thread descriptor 761 thread = thread_alloc();741 thread = kmem_alloc( CONFIG_THREAD_DESC_ORDER , AF_ZERO ); 762 742 763 743 if( thread == NULL ) … … 839 819 840 820 // check arguments 841 assert( __FUNCTION__, (type == THREAD_IDLE) , "illegal thread type" ); 842 assert( __FUNCTION__, (core_lid < LOCAL_CLUSTER->cores_nr) , "illegal core index" ); 821 assert( __FUNCTION__, (type == THREAD_IDLE), 822 "illegal thread type" ); 823 824 assert( __FUNCTION__, (core_lid < LOCAL_CLUSTER->cores_nr), 825 "illegal core index" ); 843 826 844 827 // set type in thread descriptor … … 848 831 error = process_register_thread( &process_zero , thread , &trdid ); 849 832 850 assert( __FUNCTION__, (error == 0), "cannot register idle_thread in kernel process" ); 833 assert( __FUNCTION__, (error == 0), 834 "cannot register idle_thread in kernel process" ); 851 835 852 836 // set trdid in thread descriptor … … 863 847 NULL ); // no user stack for a kernel thread 864 848 865 assert( __FUNCTION__, (error == 0), "cannot initialize idle_thread" ); 849 assert( __FUNCTION__, (error == 0), 850 "cannot initialize idle_thread" ); 866 851 867 852 // allocate CPU context 868 853 error = hal_cpu_context_alloc( thread ); 869 854 870 assert( __FUNCTION__, (error == 0), "cannot allocate CPU context" ); 855 assert( __FUNCTION__,(error == 0), 856 "cannot allocate CPU context" ); 871 857 872 858 // initialize CPU context … … 963 949 964 950 // release memory for thread descriptor (including kernel stack) 965 kmem_req_t req; 966 req.type = KMEM_PPM; 967 req.ptr = thread; 968 kmem_free( &req ); 951 kmem_free( thread , CONFIG_THREAD_DESC_ORDER ); 969 952 970 953 #if DEBUG_THREAD_DESTROY … … 1091 1074 } // end thread_unblock() 1092 1075 1093 ////////////////////////////////////// 1076 ////////////////////////////////////////////// 1094 1077 void thread_delete_request( xptr_t target_xp, 1095 bool_t is_forced )1078 bool_t is_forced ) 1096 1079 { 1097 1080 reg_t save_sr; // for critical section … … 1475 1458 thread->busylocks - 1, (uint32_t)hal_get_cycles() ); 1476 1459 1477 #if DEBUG_BUSYLOCK 1460 #if DEBUG_BUSYLOCK_TYPE 1478 1461 1479 1462 // scan list of busylocks
Note: See TracChangeset
for help on using the changeset viewer.