Changeset 416 for trunk/kernel/kern/scheduler.c
- Timestamp:
- Jan 4, 2018, 10:05:47 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/scheduler.c
r409 r416 58 58 list_root_init( &sched->k_root ); 59 59 60 sched-> sig_pending = false; // no pending signal60 sched->req_ack_pending = false; // no pending request 61 61 62 62 } // end sched_init() … … 89 89 90 90 } // end sched_register_thread() 91 92 /////////////////////////////////////////////93 void sched_remove_thread( thread_t * thread )94 {95 scheduler_t * sched = &thread->core->scheduler;96 thread_type_t type = thread->type;97 98 // take lock protecting sheduler lists99 spinlock_lock( &sched->lock );100 101 if( type == THREAD_USER )102 {103 list_unlink( &thread->sched_list );104 sched->u_threads_nr--;105 if( sched->u_threads_nr == 0 ) sched->u_last = NULL;106 }107 else // kernel thread108 {109 list_unlink( &thread->sched_list );110 sched->k_threads_nr--;111 if( sched->k_threads_nr == 0 ) sched->k_last = NULL;112 }113 114 // release lock115 spinlock_unlock( &sched->lock );116 117 } // end sched_remove_thread()118 91 119 92 ////////////////////////////////////////////// … … 203 176 } // end sched_select() 204 177 205 ////////////////////////////////////////// 206 void sched_handle_ signals( core_t * core )178 /////////////////////////////////////////// 179 void sched_handle_requests( core_t * core ) 207 180 { 208 181 list_entry_t * iter; 209 182 thread_t * thread; 210 183 184 // printk("\n@@@ %s : current thread %x enter at cycle %d\n", 185 // __FUNCTION__ , CURRENT_THREAD , hal_time_stamp() ); 186 211 187 scheduler_t * sched = &core->scheduler; 212 188 … … 214 190 spinlock_lock( &sched->lock ); 215 191 216 // handleuser threads192 // scan all user threads 217 193 LIST_FOREACH( &sched->u_root , iter ) 218 194 { 219 195 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 220 196 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 ); 197 // handle REQ_ACK 198 if( thread->flags & THREAD_FLAG_REQ_ACK ) 199 { 200 // check thread blocked 201 assert( (thread->blocked & THREAD_BLOCKED_GLOBAL) , 202 __FUNCTION__ , "thread not blocked" ); 203 204 // decrement response counter 205 hal_atomic_add( thread->ack_rsp_count , -1 ); 206 207 // reset REQ_ACK in thread descriptor 208 thread_reset_req_ack( thread ); 209 } 210 211 // handle REQ_DELETE 212 if( thread->flags & THREAD_FLAG_REQ_DELETE ) 213 { 214 215 sched_dmsg("\n[DBG] %s : current thread %x delete thread %x at cycle %d\n", 216 __FUNCTION__ , CURRENT_THREAD , thread , hal_time_stamp() ); 217 218 // release FPU if required 219 if( thread->core->fpu_owner == thread ) thread->core->fpu_owner = NULL; 220 221 // detach thread from parent if attached 222 if( (thread->flags & THREAD_FLAG_DETACHED) == 0 ) 223 thread_child_parent_unlink( thread->parent , XPTR( local_cxy , thread ) ); 224 225 // detach thread from process 226 process_remove_thread( thread ); 227 228 // remove thread from scheduler 229 list_unlink( &thread->sched_list ); 230 sched->u_threads_nr--; 231 if( sched->u_threads_nr == 0 ) sched->u_last = NULL; 232 233 // release memory allocated to thread 234 thread_destroy( thread ); 235 236 // destroy process descriptor if no more threads 237 if (thread->process->th_nr == 0) process_destroy( thread->process ); 228 238 } 229 239 } … … 232 242 spinlock_unlock( &sched->lock ); 233 243 234 } // end sched_handle_signals() 244 // printk("\n@@@ %s : current thread %x exit at cycle %d\n", 245 // __FUNCTION__ , CURRENT_THREAD , hal_time_stamp() ); 246 247 } // end sched_handle_requests() 235 248 236 249 //////////////////////////////// … … 305 318 } 306 319 307 // handle signals for all threads executing on this core.308 sched_handle_ signals( core );320 // handle pending requests for all threads executing on this core. 321 sched_handle_requests( core ); 309 322 310 323 // exit critical section / restore SR from next thread context … … 354 367 if (thread->type == THREAD_DEV) 355 368 { 356 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block ed%X / %s\n",369 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X / %s\n", 357 370 thread_type_str( thread->type ), thread->process->pid, thread->trdid, 358 thread, thread->blocked 371 thread, thread->blocked, thread->flags, thread->chdev->name ); 359 372 } 360 373 else 361 374 { 362 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block ed %X\n",375 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X \n", 363 376 thread_type_str( thread->type ), thread->process->pid, thread->trdid, 364 thread, thread->blocked );377 thread, thread->blocked, thread->flags ); 365 378 } 366 379 } … … 370 383 { 371 384 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 372 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block ed%X\n",385 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n", 373 386 thread_type_str( thread->type ), thread->process->pid, thread->trdid, 374 thread, thread->blocked );387 thread, thread->blocked, thread->flags ); 375 388 } 376 389
Note: See TracChangeset
for help on using the changeset viewer.