Process scheduling and switching directly affect the execution efficiency of the process subsystem. Linux rejects the process switching method provided by the i386 hardware. Manually save the process context. On the scheduling strategy, Recent versions have changed a lot. In particular, the 2.6.23 version is far from the previously released 2.6.0. In scheduling. We use 2.6.9 as a benchmark for analysis.
One: Process switching
The process switching process is implemented in Context_switch (). From its code:
static inline void Context_switch (struct rq *rq, struct task_struct *prev, struct task_struct *next) {Stru
CT mm_struct *mm, *OLDMM;
Prepare_task_switch (RQ, Prev, next);
MM = next->mm;
OLDMM = prev->active_mm; * * For Paravirt, this is coupled with a exit in switch_to to * combine the page table reload and the switch Backe
nd into * one hypercall.
* * Arch_enter_lazy_cpu_mode ();
Task->mm is empty. is a kernel thread if (unlikely (!mm)) {//kernel thread shares the last running process of mm NEXT->ACTIVE_MM = OLDMM;
Add Reference Count Atomic_inc (&oldmm->mm_count);
Enter_lazy_tlb (OLDMM, next);
else//If it is a user process, switch the running space switch_mm (OLDMM, MM, next);
If the previous run process is kernel thread if (unlikely (!prev->mm)) {//Assignment active_mm is empty.
prev->active_mm = NULL;
Update the PREV_MM member of the run queue rq->prev_mm = OLDMM; } * * * Since the Runqueue lock'll be released by the next * task (which is a invalid locking op but in the-CAs E * of the scheduLer It's a obvious special-case), so we * do a early LOCKDEP release: * * #ifndef __ARCH_WANT_UNLOCKED_CTXSW
Spin_release (&rq->lock.dep_map, 1, _THIS_IP_); #endif/* We just switch the register state and the stack.
*///switch Process Execution Environment switch_to (prev, Next, prev);
Barrier (); * * THIS_RQ must is evaluated again because Prev may have moved * CPUs since it called schedule (), thus the ' RQ '
Its stack * frame would be invalid.
*///process switch after processing work finish_task_switch (THIS_RQ (), prev); }