Linux2.6-process preemption and context switching

Source: Internet
Author: User

Context switching, that is, switching from one executable process to another, is handled by the context_switch () function defined in kernel/sched. C. Schedule () calls this function whenever a new process is selected to prepare for running. It completes two basic tasks:

1. the call declaration is in switch_mm () in <ASM/mmu_context.h>. This function switches the virtual memory from the previous process ing to the new process. In fact, it switches to the address space of another process, see the example:


2. Call the switch_to () Statement in <ASM/system. h>. This function switches from the last processor status to the processor status of the new process. This includes saving, restoring stack information and register information, and other state information related to the architecture. Each process must be managed and saved as an object. See the following example:


Next let's take a look at the timing of process preemption.

1.User Preemption

When a user space is returned from a system call

Slave interrupt handlingProgramWhen the user space is returned

2.Kernel preemption

The interrupt handler is executing and before returning the kernel space

KernelCodeOnce again

If the task in the kernel displays the call schedule ()

If the task in the kernel is blocked (this also causes schedule () to be called ())

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.