"Linux kernel Analysis" the eighth Week learning summary process switching and the general implementation process of the system

Source: Internet
Author: User
Tags prev

Process switching and general execution of the system

First, the process of scheduling the three time:

1. Interrupt processing (including clock interrupts, I/O interrupts, system calls, and exceptions), call schedule () directly, or call schedule () based on the need_resched tag when returning to the user state;

2. Kernel thread can directly call schedule () for process switching, can also be scheduled during interrupt processing, that is, the kernel thread as a class of special processes can be active scheduling, can also be passive scheduling;

3. The user-state process can not realize the active scheduling, only through the kernel state after a certain point in time to dispatch, that is, in the interrupt processing process scheduling.

Second, switch_to to complete the switch of register

Switch_to (Prev,next,prev);

Process switching: To control the execution of a process, the kernel must have the ability to suspend a process that is running on the CPU and resume execution of a previously suspended process. This behavior is called process switch,

Task switch, or context switch.

The schedule () function selects a new process to run, calling switch_to for critical context switching.

Switch_to Complete Register Switching: First save the current process register, and then the stack switch, since then all the stack is in the new process, and then switch the EIP, so that the current process

You can recover from the new process, as well as other necessary switches.

The process context contains all the information that the process needs to perform, including:

1. User address space: Including program code, data, user stack, etc.

2. Control information: Process descriptor, kernel stack, etc.

3. Hardware context (different from the method of saving hardware contexts)

Third, the general implementation of the Linux system (the most general case)

Running user-state process x switching to the process of running user-state process y

Running user-state process X

Interrupt occurred--

Save Cs:eip/esp/eflags (current) to kernel stack;

Then load CS:EIP (start of system call, entry of a specific ISR) and SS:ESP (point to kernel stack)

Enter kernel code, Save_all//save site

(This step may also not occur) during interrupt processing or when the interrupt is returned before the call to schedule (), where the switch_to does a critical process context switch

Label 1 starts running the user-state process y selected in the previous step (where Y has been switched out through the above steps so you can continue from label 1)

Restore_all//Recovery site

Iret-pop cs:eip/ss:esp/eflags from kernel stack

Continue to run user-state process y

Four, the experiment:

1. Download the menu system:

2. Start GDB for debugging:

3. Set the breakpoint at schedule and click C to run:

4. Stop at the breakpoint 1:schedule

5. Stop at the breakpoint 2:context_switch

6. Press N to step into the execution:

Five, Summary:

General execution procedures for Linux systems: see three.

"Linux kernel Analysis" the eighth Week learning summary process switching and the general implementation process of the system

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.