Changeset 440 for trunk/kernel/kern/scheduler.c
- Timestamp:
- May 3, 2018, 5:51:22 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/scheduler.c
r438 r440 125 125 thread = LIST_ELEMENT( current , thread_t , sched_list ); 126 126 127 // execute RPC thread if non blocked 128 if( (thread->blocked == 0) && 129 (thread->type == THREAD_RPC) ) 130 { 131 spinlock_unlock( &sched->lock ); 132 return thread; 133 } 134 135 // execute DEV thread if non blocked and waiting queue non empty 136 if( (thread->blocked == 0) && 137 (thread->type == THREAD_DEV) && 138 (xlist_is_empty( XPTR( local_cxy , &thread->chdev->wait_root)) == 0) ) 127 // select kernel thread if non blocked and non IDLE 128 if( (thread->blocked == 0) && (thread->type != THREAD_IDLE) ) 139 129 { 140 130 spinlock_unlock( &sched->lock ); … … 186 176 187 177 list_entry_t * iter; 178 list_entry_t * root; 188 179 thread_t * thread; 189 180 process_t * process; 190 181 182 // get pointer on scheduler 191 183 scheduler_t * sched = &core->scheduler; 184 185 // get pointer on user threads root 186 root = &sched->u_root; 192 187 193 188 // take lock protecting threads lists 194 189 spinlock_lock( &sched->lock ); 195 190 191 // We use a while to scan the user threads, to control the iterator increment, 192 // because some threads will be destroyed, and we cannot use a LIST_FOREACH() 193 194 // initialise list iterator 195 iter = root->next; 196 196 197 // scan all user threads 197 LIST_FOREACH( &sched->u_root , iter ) 198 { 198 while( iter != root ) 199 { 200 // get pointer on thread 199 201 thread = LIST_ELEMENT( iter , thread_t , sched_list ); 202 203 // increment iterator 204 iter = iter->next; 200 205 201 206 // handle REQ_ACK … … 219 224 process = thread->process; 220 225 226 // release FPU if required 227 if( thread->core->fpu_owner == thread ) thread->core->fpu_owner = NULL; 228 229 // remove thread from scheduler (scheduler lock already taken) 230 uint32_t threads_nr = sched->u_threads_nr; 231 232 assert( (threads_nr != 0) , __FUNCTION__ , "u_threads_nr cannot be 0\n" ); 233 234 sched->u_threads_nr = threads_nr - 1; 235 list_unlink( &thread->sched_list ); 236 if( threads_nr == 1 ) sched->u_last = NULL; 237 238 // delete thread 239 thread_destroy( thread ); 240 221 241 #if DEBUG_SCHED_HANDLE_SIGNALS 222 242 uint32_t cycle = (uint32_t)hal_get_cycles(); 223 243 if( DEBUG_SCHED_HANDLE_SIGNALS < cycle ) 224 printk("\n[DBG] %s : thread %x in proces %x must be deleted / cycle %d\n", 225 __FUNCTION__ , thread , process->pid , cycle ); 226 #endif 227 // release FPU if required 228 if( thread->core->fpu_owner == thread ) thread->core->fpu_owner = NULL; 229 230 // detach thread from parent if attached 231 if( (thread->flags & THREAD_FLAG_DETACHED) == 0 ) 232 thread_child_parent_unlink( thread->parent , XPTR( local_cxy , thread ) ); 233 234 // remove thread from scheduler (scheduler lock already taken) 235 uint32_t threads_nr = sched->u_threads_nr; 236 assert( (threads_nr != 0) , __FUNCTION__ , "u_threads_nr cannot be 0\n" ); 237 sched->u_threads_nr = threads_nr - 1; 238 list_unlink( &thread->sched_list ); 239 if( threads_nr == 1 ) sched->u_last = NULL; 240 241 // delete thread 242 thread_destroy( thread ); 243 244 #if DEBUG_SCHED_HANDLE_SIGNALS 245 cycle = (uint32_t)hal_get_cycles(); 246 if( DEBUG_SCHED_HANDLE_SIGNALS < cycle ) 247 printk("\n[DBG] %s : thread %x in process %x has been deleted / cycle %d\n", 248 __FUNCTION__ , thread , process->pid , cycle ); 244 printk("\n[DBG] %s : thread %x in proces %x (%x) deleted / cycle %d\n", 245 __FUNCTION__ , thread , process->pid , process , cycle ); 249 246 #endif 250 247 // destroy process descriptor if no more threads … … 314 311 { 315 312 313 if( (local_cxy == 0X1) && (core->lid == 1) && ((uint32_t)current == 0xcc000) ) 314 printk("\n@@@@@ cc000 exit at cycle %d\n", (uint32_t)hal_get_cycles() ); 315 316 if( (local_cxy == 0X1) && (core->lid == 1) && ((uint32_t)next == 0xcc000) ) 317 printk("\n@@@@@ cc000 enter at cycle %d\n", (uint32_t)hal_get_cycles() ); 318 316 319 #if DEBUG_SCHED_YIELD 317 320 uint32_t cycle = (uint32_t)hal_get_cycles();
Note: See TracChangeset
for help on using the changeset viewer.