프로세스 디스패처

 

 가장 적절한 프로세스에 실행권한을 주기위해, CPU동작을 중단하고 새로운 프로세스를 수행한다.

프로세스 전환(Process Switch, 프로세스 관리(Process Dispatch), Process Dispatcher 라고 한다.

 

 

 static inline void context_switch(struct rq *rq, struct task_struct *prev, struct task_struct *next)
{
    struct mm_struct *mm, *oldmm;

    prepare_task_switch(rq, prev, next);
    trace_sched_switch(rq, prev, next);
    mm = next->mm;
    oldmm = prev->active_mm;
    /*
     * For paravirt, this is coupled with an exit in switch_to to
     * combine the page table reload and the switch backend into
     * one hypercall.
     */

    arch_start_context_switch(prev);

    if (unlikely(!mm)) {
        next->active_mm = oldmm;
        atomic_inc(&oldmm->mm_count);
        enter_lazy_tlb(oldmm, next);
    } else
        switch_mm(oldmm, mm, next);    // 프로세스 공간의 전환처리

    if (unlikely(!prev->mm)) {
        prev->active_mm = NULL;
        rq->prev_mm = oldmm;
    }
    /*
     * Since the runqueue lock will be released by the next
     * task (which is an invalid locking op but in the case
     * of the scheduler it's an obvious special-case), so we
     * do an early lockdep release here:
     */

#ifndef __ARCH_WANT_UNLOCKED_CTXSW
    spin_release(&rq->lock.dep_map, 1, _THIS_IP_);
#endif

    /* Here we just switch the register state and the stack. */
    switch_to(prev, next, prev);         // 각종 레지스터의 전환처리

    barrier();
    /*
     * this_rq must be evaluated again because prev may have moved
     * CPUs since it called schedule(), thus the 'rq' on its stack
     * frame will be invalid.
     */

    finish_task_switch(this_rq(), prev);
}

 

'리눅스커널' 카테고리의 다른 글

systemcall  (0) 2015.04.15
스와퍼(Swapper)프로세스  (0) 2015.04.15
schedule()함수  (0) 2015.04.15
프로세스1-1(프로세스디스크립터, 상태전이)  (0) 2015.04.14
불연속메모리할당  (1) 2015.04.10

+ Recent posts