comparison packages/kernel/current/src/sched/mlqueue.cxx @ 2348:73a01c1a35ba

* src/sched/mlqueue.cxx (add_thread, yield): * src/sched/sched.cxx (unlock_inner, thread_entry): * include/mlqueue.hxx (class Cyg_SchedThread_Implementation): * include/kapidata.h (CYG_SCHEDTHREAD_TIMESLICE_MEMBER): * include/bitmap.hxx (class Cyg_SchedThread_Implementation): Reimplement timeslicing code. There is now a timeslice_count field in each thread which is moved to and from the per-CPU counter during thread dispatch. This approach has been taken to minimize the changes needed to SMP code. Scheduler specific thread functions handle counter save, restore and reset. These functions are defined (as empty inlines) even when timeslicing is disabled, or in non-timeslicing schedulers, to avoid adding ifdefs to the code (this change actually removes some). * tests/timeslice2.c: * cdl/kernel.cdl: Added timeslice2 test to test behaviour of timeslicing while being preempted.
author nickg
date Mon, 08 Jan 2007 16:20:13 +0000
parents a2c686b87032
children 74dbf4c3f2e1
comparison
equal deleted inserted replaced
2347:f5f9a2e0c73b 2348:73a01c1a35ba
234 234
235 // If the new thread is higher priority than any 235 // If the new thread is higher priority than any
236 // current thread, request a reschedule. 236 // current thread, request a reschedule.
237 237
238 set_need_reschedule(thread); 238 set_need_reschedule(thread);
239
240 // Also reset the timeslice_count so that this thread gets a full
241 // timeslice once it begins to run.
242
243 thread->timeslice_reset();
239 244
240 #ifdef CYGPKG_KERNEL_SMP_SUPPORT 245 #ifdef CYGPKG_KERNEL_SMP_SUPPORT
241 246
242 // If the thread is not currently running, increment the pending 247 // If the thread is not currently running, increment the pending
243 // count for the priority, and if necessary set the bit in the 248 // count for the priority, and if necessary set the bit in the
638 queue->rotate(); 643 queue->rotate();
639 #endif 644 #endif
640 645
641 if( queue->get_head() != thread ) 646 if( queue->get_head() != thread )
642 sched->set_need_reschedule(); 647 sched->set_need_reschedule();
643 648 else
644 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE 649 {
645 // Reset the timeslice counter so that this thread gets a full 650 // Reset the timeslice counter so that this thread gets a
646 // quantum. 651 // full quantum as a reward for yielding when it is
647 else Cyg_Scheduler::reset_timeslice_count(); 652 // eventually rescheduled.
648 #endif 653 thread->timeslice_reset();
654 }
655
649 } 656 }
650 657
651 // Unlock the scheduler and switch threads 658 // Unlock the scheduler and switch threads
652 #ifdef CYGDBG_USE_ASSERTS 659 #ifdef CYGDBG_USE_ASSERTS
653 // This test keeps the assertions in unlock_inner() happy if 660 // This test keeps the assertions in unlock_inner() happy if