Changeset 437 for trunk/kernel/kern/scheduler.c
- Timestamp:
- Mar 28, 2018, 2:40:29 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/scheduler.c
r436 r437 97 97 list_entry_t * current; 98 98 list_entry_t * last; 99 list_entry_t * root; 100 bool_t done; 99 101 100 102 // take lock protecting sheduler lists 101 103 spinlock_lock( &sched->lock ); 102 104 103 // first loop: scan the kernel threads list if not empty105 // first : scan the kernel threads list if not empty 104 106 if( list_is_empty( &sched->k_root ) == false ) 105 107 { 108 root = &sched->k_root; 106 109 last = sched->k_last; 107 current = sched->k_last; 108 do 110 current = last; 111 done = false; 112 113 while( done == false ) 109 114 { 110 115 // get next entry in kernel list 111 current = list_next( &sched->k_root , current ); 116 current = current->next; 117 118 // check exit condition 119 if( current == last ) done = true; 112 120 113 121 // skip the root that does not contain a thread 114 if( current == NULL ) current = sched->k_root.next;122 if( current == root ) continue; 115 123 116 124 // get thread pointer for this entry … … 120 128 switch( thread->type ) 121 129 { 122 case THREAD_IDLE: // skip IDLE thread 123 break; 124 125 case THREAD_RPC: // RPC thread if non blocked and FIFO non-empty 130 case THREAD_RPC: // if non blocked and RPC FIFO non-empty 126 131 if( (thread->blocked == 0) && 127 132 (local_fifo_is_empty( &LOCAL_CLUSTER->rpc_fifo ) == 0) ) … … 132 137 break; 133 138 134 default: // DEV threadif non blocked and waiting queue non empty139 case THREAD_DEV: // if non blocked and waiting queue non empty 135 140 if( (thread->blocked == 0) && 136 141 (xlist_is_empty( XPTR( local_cxy , &thread->chdev->wait_root)) == 0) ) … … 140 145 } 141 146 break; 142 } // end switch type 143 } 144 while( current != last ); 145 } 146 147 // second loop : scan the user threads list if not empty 147 148 default: 149 break; 150 } 151 } // end loop on kernel threads 152 } // end if kernel threads 153 154 // second : scan the user threads list if not empty 148 155 if( list_is_empty( &sched->u_root ) == false ) 149 156 { 157 root = &sched->u_root; 150 158 last = sched->u_last; 151 current = sched->u_last; 152 do 159 current = last; 160 done = false; 161 162 while( done == false ) 153 163 { 154 164 // get next entry in user list 155 current = list_next( &sched->u_root , current ); 165 current = current->next; 166 167 // check exit condition 168 if( current == last ) done = true; 156 169 157 170 // skip the root that does not contain a thread 158 if( current == NULL ) current = sched->u_root.next;171 if( current == root ) continue; 159 172 160 173 // get thread pointer for this entry … … 167 180 return thread; 168 181 } 169 } 170 while( current != last ); 171 } 172 173 // third : return idle thread if no runnable thread 182 } // end loop on user threads 183 } // end if user threads 184 185 // third : return idle thread if no other runnable thread 174 186 spinlock_unlock( &sched->lock ); 175 187 return sched->idle; … … 180 192 void sched_handle_signals( core_t * core ) 181 193 { 194 182 195 list_entry_t * iter; 183 196 thread_t * thread; … … 214 227 process = thread->process; 215 228 229 #if CONFIG_DEBUG_SCHED_HANDLE_SIGNALS 230 uint32_t cycle = (uint32_t)hal_get_cycles(); 231 if( CONFIG_DEBUG_SCHED_HANDLE_SIGNALS < cycle ) 232 printk("\n[DBG] %s : thread %x in proces %x must be deleted / cycle %d\n", 233 __FUNCTION__ , thread , process->pid , cycle ); 234 #endif 216 235 // release FPU if required 217 236 if( thread->core->fpu_owner == thread ) thread->core->fpu_owner = NULL; … … 232 251 233 252 #if CONFIG_DEBUG_SCHED_HANDLE_SIGNALS 234 uint32_tcycle = (uint32_t)hal_get_cycles();253 cycle = (uint32_t)hal_get_cycles(); 235 254 if( CONFIG_DEBUG_SCHED_HANDLE_SIGNALS < cycle ) 236 printk("\n[DBG] %s : thread %x deleted thread %x/ cycle %d\n",237 __FUNCTION__ , CURRENT_THREAD , thread , cycle );255 printk("\n[DBG] %s : thread %x in process %x has been deleted / cycle %d\n", 256 __FUNCTION__ , thread , process->pid , cycle ); 238 257 #endif 239 258 // destroy process descriptor if no more threads … … 246 265 cycle = (uint32_t)hal_get_cycles(); 247 266 if( CONFIG_DEBUG_SCHED_HANDLE_SIGNALS < cycle ) 248 printk("\n[DBG] %s : thread %x deleted process %x/ cycle %d\n",249 __FUNCTION__ , CURRENT_THREAD , process, cycle );267 printk("\n[DBG] %s : process %x has been deleted / cycle %d\n", 268 __FUNCTION__ , process->pid , cycle ); 250 269 #endif 251 270 … … 374 393 remote_spinlock_lock_busy( lock_xp , &save_sr ); 375 394 376 nolock_printk("\n***** scheduler state for core[%x,%d] / cycle %d / current = (%x,%x)\n", 377 local_cxy , core->lid, (uint32_t)hal_get_cycles(), 378 sched->current->process->pid , sched->current->trdid ); 395 nolock_printk("\n***** threads on core[%x,%d] / current %x / cycle %d\n", 396 local_cxy , core->lid, sched->current, (uint32_t)hal_get_cycles() ); 379 397 380 398 // display kernel threads … … 390 408 else 391 409 { 392 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X 410 nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n", 393 411 thread_type_str( thread->type ), thread->process->pid, thread->trdid, 394 thread, thread->blocked, thread->flags 412 thread, thread->blocked, thread->flags ); 395 413 } 396 414 }
Note: See TracChangeset
for help on using the changeset viewer.