Changeset 409 for trunk/kernel/kern/scheduler.c
- Timestamp:
- Dec 20, 2017, 4:51:09 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/scheduler.c
r408 r409 58 58 list_root_init( &sched->k_root ); 59 59 60 sched->sig_pending = false; // no pending signal 61 60 62 } // end sched_init() 61 63 … … 72 74 if( type == THREAD_USER ) 73 75 { 74 // register thread in scheduler user list75 76 list_add_last( &sched->u_root , &thread->sched_list ); 76 77 sched->u_threads_nr++; 77 78 // initialize u_last field if first user thread79 78 if( sched->u_last == NULL ) sched->u_last = &thread->sched_list; 80 79 } 81 80 else // kernel thread 82 81 { 83 // register thread in scheduler kernel list84 82 list_add_last( &sched->k_root , &thread->sched_list ); 85 83 sched->k_threads_nr++; 86 87 // initialize k_last field if first kernel thread88 84 if( sched->k_last == NULL ) sched->k_last = &thread->sched_list; 89 85 } … … 92 88 spinlock_unlock( &sched->lock ); 93 89 94 } // end sched_register ()90 } // end sched_register_thread() 95 91 96 92 ///////////////////////////////////////////// 97 93 void sched_remove_thread( thread_t * thread ) 98 94 { 99 core_t * core = thread->core; 100 scheduler_t * sched = &core->scheduler; 101 thread_type_t type = thread->type; 95 scheduler_t * sched = &thread->core->scheduler; 96 thread_type_t type = thread->type; 102 97 103 98 // take lock protecting sheduler lists … … 106 101 if( type == THREAD_USER ) 107 102 { 108 // remove thread from user list109 103 list_unlink( &thread->sched_list ); 110 104 sched->u_threads_nr--; 111 112 // reset the u_last field if list empty113 105 if( sched->u_threads_nr == 0 ) sched->u_last = NULL; 114 106 } 115 else // kernel thread 116 { 117 // remove thread from kernel list 107 else // kernel thread 108 { 118 109 list_unlink( &thread->sched_list ); 119 110 sched->k_threads_nr--; 120 121 // reset the k_last field if list empty122 111 if( sched->k_threads_nr == 0 ) sched->k_last = NULL; 123 112 } 124 113 125 // release lock 114 // release lock 126 115 spinlock_unlock( &sched->lock ); 127 116 128 } // end sched_remove ()117 } // end sched_remove_thread() 129 118 130 119 ////////////////////////////////////////////// … … 214 203 } // end sched_select() 215 204 216 ///////////////////////////////////////////217 void sched_kill_thread( thread_t * thread )218 {219 // check locks220 if( thread_can_yield() == false )221 {222 panic("locks not released for thread %x in process %x on core[%x][%d]",223 thread->trdid , thread->process->pid, local_cxy , thread->core->lid );224 }225 226 // remove thread from scheduler227 sched_remove_thread( thread );228 229 // reset the THREAD_SIG_KILL signal230 thread_reset_signal( thread , THREAD_SIG_KILL );231 232 // detached thread can suicide233 if( thread->signals & THREAD_SIG_SUICIDE )234 {235 assert( (thread->flags & THREAD_FLAG_DETACHED), __FUNCTION__,236 "thread must be detached in case of suicide\n" );237 238 // remove thread from process239 process_remove_thread( thread );240 241 // release memory for thread descriptor242 thread_destroy( thread );243 }244 } // end sched_kill_thread()245 246 205 ////////////////////////////////////////// 247 206 void sched_handle_signals( core_t * core ) … … 249 208 list_entry_t * iter; 250 209 thread_t * thread; 210 251 211 scheduler_t * sched = &core->scheduler; 252 253 // signal_dmsg("\n@@@ %s enter at cycle %d\n",254 // __FUNCTION__ , hal_time_stamp() );255 212 256 213 // take lock protecting threads lists … … 261 218 { 262 219 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 263 if( thread->signals ) // sched_kill_thread( thread ); 264 { 265 printk("\n[WARNING] %s : thread %x has signal %x at cycle %d\n", 266 __FUNCTION__, thread, thread->signals, hal_time_stamp() ); 267 } 268 } 269 270 // handle kernel threads 271 LIST_FOREACH( &sched->k_root , iter ) 272 { 273 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 274 if( thread->signals ) // sched_kill_thread( thread ); 275 { 276 printk("\n[WARNING] %s : thread %x has signal %x at cycle %d\n", 277 __FUNCTION__, thread, thread->signals, hal_time_stamp() ); 278 220 221 if( thread->flags & THREAD_FLAG_SIGNAL ) // thread has signal 222 { 223 // decrement response counter to acknowledge signal 224 hal_atomic_add( thread->sig_rsp_count , -1 ); 225 226 // reset signal 227 thread_reset_signal( thread ); 279 228 } 280 229 } … … 283 232 spinlock_unlock( &sched->lock ); 284 233 285 // signal_dmsg("\n@@@ %s exit at cycle %d\n",286 // __FUNCTION__ , hal_time_stamp() );287 288 234 } // end sched_handle_signals() 289 235 … … 293 239 thread_t * next; 294 240 thread_t * current = CURRENT_THREAD; 295 scheduler_t * sched = ¤t->core->scheduler; 241 core_t * core = current->core; 242 scheduler_t * sched = &core->scheduler; 296 243 297 244 #if( CONFIG_SCHED_DEBUG & 0x1 ) 298 if( hal_time_stamp() > CONFIG_SCHED_DEBUG ) sched_display( c urrent->core->lid );245 if( hal_time_stamp() > CONFIG_SCHED_DEBUG ) sched_display( core->lid ); 299 246 #endif 300 247 … … 319 266 assert( (next->blocked == 0) || (next->type = THREAD_IDLE) , __FUNCTION__ , 320 267 "next thread %x (%s) is blocked on core[%x,%d]\n", 321 next->trdid , thread_type_str(next->type) , local_cxy , c urrent->core->lid );268 next->trdid , thread_type_str(next->type) , local_cxy , core->lid ); 322 269 323 270 // switch contexts and update scheduler state if next != current … … 327 274 sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n" 328 275 " thread %x (%s) (%x,%x) => thread %x (%s) (%x,%x) / cycle %d\n", 329 __FUNCTION__, local_cxy, c urrent->core->lid, cause,276 __FUNCTION__, local_cxy, core->lid, cause, 330 277 current, thread_type_str(current->type), current->process->pid, current->trdid, 331 278 next , thread_type_str(next->type) , next->process->pid , next->trdid, … … 352 299 sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n" 353 300 " thread %x (%s) (%x,%x) continue / cycle %d\n", 354 __FUNCTION__, local_cxy, c urrent->core->lid, cause,301 __FUNCTION__, local_cxy, core->lid, cause, 355 302 current, thread_type_str(current->type), current->process->pid, current->trdid, 356 303 (uint32_t)hal_get_cycles() ); 357 304 358 305 } 306 307 // handle signals for all threads executing on this core. 308 sched_handle_signals( core ); 359 309 360 310 // exit critical section / restore SR from next thread context
Note: See TracChangeset
for help on using the changeset viewer.