diff packages/kernel/current/src/sched/sched.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 1406c9fadbf3
children 74dbf4c3f2e1
line wrap: on
line diff
--- a/packages/kernel/current/src/sched/sched.cxx
+++ b/packages/kernel/current/src/sched/sched.cxx
@@ -198,7 +198,8 @@ void Cyg_Scheduler::unlock_inner( cyg_uc
 #ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
                 next->check_stack(); // before running it
 #endif
-
+                current->timeslice_save();
+                
                 // Switch contexts
                 HAL_THREAD_SWITCH_CONTEXT( &current->stack_ptr,
                                            &next->stack_ptr );
@@ -221,14 +222,10 @@ void Cyg_Scheduler::unlock_inner( cyg_uc
                 CYG_ASSERTCLASS( current, "Bad current thread" );
 
                 current_thread[CYG_KERNEL_CPU_THIS()] = current;   // restore current thread pointer
+
+                current->timeslice_restore();
             }
 
-#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
-            // Reset the timeslice counter so that this thread gets a full
-            // quantum. 
-            reset_timeslice_count();
-#endif
-
             clear_need_reschedule();    // finished rescheduling
         }
 
@@ -318,12 +315,9 @@ void Cyg_Scheduler::thread_entry( Cyg_Th
     set_current_thread(thread);         // restore current thread pointer
 
     CYG_INSTRUMENT_THREAD(ENTER,thread,0);
-    
-#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
-    // Reset the timeslice counter so that this thread gets a full
-    // quantum. 
-    reset_timeslice_count();
-#endif
+
+    thread->timeslice_reset();
+    thread->timeslice_restore();
     
     // Finally unlock the scheduler. As well as clearing the scheduler
     // lock this allows any pending DSRs to execute. The new thread