Changeset 408 for trunk/kernel/kern/scheduler.c
- Timestamp:
- Dec 5, 2017, 4:20:07 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/scheduler.c
r407 r408 128 128 } // end sched_remove() 129 129 130 //////////////////////////////////////// 131 thread_t * sched_select( core_t * core)132 { 133 thread_t * thread;134 135 scheduler_t * sched = &core->scheduler;130 ////////////////////////////////////////////// 131 thread_t * sched_select( scheduler_t * sched ) 132 { 133 thread_t * thread; 134 list_entry_t * current; 135 list_entry_t * last; 136 136 137 137 // take lock protecting sheduler lists 138 138 spinlock_lock( &sched->lock ); 139 140 list_entry_t * current;141 list_entry_t * last;142 139 143 140 // first loop : scan the kernel threads list if not empty … … 172 169 break; 173 170 174 default: // DEV thread if non blocked 175 if( thread->blocked == 0 ) 171 default: // DEV thread if non blocked and waiting queue non empty 172 if( (thread->blocked == 0) && 173 (xlist_is_empty( XPTR( local_cxy , &thread->chdev->wait_root)) == 0) ) 176 174 { 177 175 spinlock_unlock( &sched->lock ); … … 253 251 scheduler_t * sched = &core->scheduler; 254 252 253 // signal_dmsg("\n@@@ %s enter at cycle %d\n", 254 // __FUNCTION__ , hal_time_stamp() ); 255 255 256 // take lock protecting threads lists 256 257 spinlock_lock( &sched->lock ); … … 260 261 { 261 262 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 262 if( thread->signals ) sched_kill_thread( thread ); 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 } 263 268 } 264 269 … … 267 272 { 268 273 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 269 if( thread->signals ) sched_kill_thread( thread ); 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 279 } 270 280 } 271 281 … … 273 283 spinlock_unlock( &sched->lock ); 274 284 285 // signal_dmsg("\n@@@ %s exit at cycle %d\n", 286 // __FUNCTION__ , hal_time_stamp() ); 287 275 288 } // end sched_handle_signals() 276 289 277 ////////////////////////////////////// 278 void sched_update( thread_t * current, 279 thread_t * next ) 280 { 281 scheduler_t * sched = ¤t->core->scheduler; 282 283 if( current->type == THREAD_USER ) sched->u_last = ¤t->sched_list; 284 else sched->k_last = ¤t->sched_list; 285 286 sched->current = next; 287 } 288 289 ////////////////// 290 void sched_yield() 290 //////////////////////////////// 291 void sched_yield( char * cause ) 291 292 { 292 293 thread_t * next; 293 294 thread_t * current = CURRENT_THREAD; 295 scheduler_t * sched = ¤t->core->scheduler; 294 296 295 297 #if( CONFIG_SCHED_DEBUG & 0x1 ) … … 304 306 } 305 307 308 // enter critical section / save SR in current thread context 309 hal_disable_irq( ¤t->save_sr ); 310 306 311 // loop on threads to select next thread 307 next = sched_select( current->core);312 next = sched_select( sched ); 308 313 309 314 // check next thread attached to same core as the calling thread … … 319 324 if( next != current ) 320 325 { 321 // current thread desactivate IRQs 322 hal_disable_irq( &switch_save_sr[CURRENT_THREAD->core->lid] ); 323 324 sched_dmsg("\n[DBG] %s : core[%x,%d] / trd %x (%s) (%x,%x) => trd %x (%s) (%x,%x) / cycle %d\n", 325 __FUNCTION__, local_cxy, current->core->lid, 326 327 sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n" 328 " thread %x (%s) (%x,%x) => thread %x (%s) (%x,%x) / cycle %d\n", 329 __FUNCTION__, local_cxy, current->core->lid, cause, 326 330 current, thread_type_str(current->type), current->process->pid, current->trdid, 327 331 next , thread_type_str(next->type) , next->process->pid , next->trdid, 328 hal_time_stamp() );332 (uint32_t)hal_get_cycles() ); 329 333 330 334 // update scheduler 331 sched_update( current , next ); 335 sched->current = next; 336 if( next->type == THREAD_USER ) sched->u_last = &next->sched_list; 337 else sched->k_last = &next->sched_list; 332 338 333 339 // handle FPU ownership … … 340 346 // switch CPU from calling thread context to new thread context 341 347 hal_do_cpu_switch( current->cpu_context, next->cpu_context ); 342 343 // restore IRQs when next thread resume344 hal_restore_irq( switch_save_sr[CURRENT_THREAD->core->lid] );345 348 } 346 349 else 347 350 { 348 351 349 sched_dmsg("\n[DBG] %s : core[%x,%d] / thread %x (%s) continue / cycle %d\n", 350 __FUNCTION__, local_cxy, current->core->lid, current->trdid, 351 thread_type_str(current->type) ,hal_time_stamp() ); 352 353 } 352 sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n" 353 " thread %x (%s) (%x,%x) continue / cycle %d\n", 354 __FUNCTION__, local_cxy, current->core->lid, cause, 355 current, thread_type_str(current->type), current->process->pid, current->trdid, 356 (uint32_t)hal_get_cycles() ); 357 358 } 359 360 // exit critical section / restore SR from next thread context 361 hal_restore_irq( next->save_sr ); 362 354 363 } // end sched_yield() 355 364 … … 384 393 385 394 nolock_printk("\n***** scheduler state for core[%x,%d] at cycle %d\n" 386 "kernel_threads = %d / user_threads = %d / current = %x / idle = %x\n",395 "kernel_threads = %d / user_threads = %d / current = (%x,%x)\n", 387 396 local_cxy , core->lid, hal_time_stamp(), 388 397 sched->k_threads_nr, sched->u_threads_nr, 389 sched->current-> trdid , sched->idle->trdid );398 sched->current->process->pid , sched->current->trdid ); 390 399 391 400 // display kernel threads … … 393 402 { 394 403 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 395 nolock_printk(" - type = %s / trdid = %X / pid = %X / func = %X / blocked = %X\n", 396 thread_type_str( thread->type ), thread->trdid, thread->process->pid, 397 thread->entry_func, thread->blocked ); 404 if (thread->type == THREAD_DEV) 405 { 406 nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X / %s\n", 407 thread_type_str( thread->type ), thread->process->pid, thread->trdid, 408 thread, thread->blocked , thread->chdev->name ); 409 } 410 else 411 { 412 nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n", 413 thread_type_str( thread->type ), thread->process->pid, thread->trdid, 414 thread, thread->blocked ); 415 } 398 416 } 399 417 … … 402 420 { 403 421 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 404 nolock_printk(" - type = %s / trdid = %X / pid = %X / func = %X / blocked =%X\n",405 thread_type_str( thread->type ), thread-> trdid, thread->process->pid,406 thread ->entry_func, thread->blocked );422 nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n", 423 thread_type_str( thread->type ), thread->process->pid, thread->trdid, 424 thread, thread->blocked ); 407 425 } 408 426
Note: See TracChangeset
for help on using the changeset viewer.