Understanding of process context and interrupt context in Linux Kernel

Source: Internet
Author: User

 

Source: http://blog.21ic.com/user1/4132/archives/2010/67653.html

 

Kernel space and user space are the basis of the operating system theory, that is, the kernel function module runs in the kernel space, and the application program runs in the user space. Modern CPUs all have different operation modes, representing different levels. Different levels have different functions, and some operations will be prohibited at a lower level. This hardware feature is used in Linux system design. It uses two levels: the highest level and the lowest level, and the kernel runs at the highest level (kernel state). All operations can be performed at this level, applications run at a low level (User State). At this level, the processor controls direct access to hardware and unauthorized access to memory. The kernel state and user State have their own memory ing, that is, their own address space.

It is with the division of different running states that context is defined. If a user space application wants to request system services, such as operating a physical device or ing a device space address to the user space, it must be implemented through system calls (the interface functions provided by the operating system to the user space. As shown in:

 

Through system calls, applications in the user space will enter the kernel space. The kernel indicates that the process runs in the kernel space, which involves context switching, the user space and the kernel space have different address ing, general or dedicated register groups, while the user space process needs to pass a lot of variables and parameters to the kernel, the kernel also needs to store some registers and variables of the user process so that the system can return to the user space after the call is completed. The so-called process context is when a process is being executed, when the kernel needs to switch to another process, it needs to save all the states of the current process, that is, to save the context of the current process, in this way, when the process is re-executed, the status of the switch can be restored and the process continues to be executed.

Similarly, the hardware calls the interrupt handler through a trigger signal and enters the kernel space. In this process, some hardware variables and parameters must also be passed to the kernel. The kernel uses these parameters for interrupt processing, the interrupt context can be understood as the parameters passed by the hardware and the environment that the kernel needs to save, mainly the environment of the interrupted process.

The Linux kernel works in the process context or interrupt context. The kernel code that provides the system call service indicates that the application initiating the system call runs in the process context; on the other hand, the interrupt processing program runs asynchronously in the interrupt context. The interrupt context is irrelevant to a specific process.

The kernel code running in the process context can be preemptible (2.6 supports preemptible ). However, an interrupt context usually always occupies the CPU (of course, the interrupt can be nested, But we generally do not) and cannot be interrupted. Because of this, the code running in the interrupt context is subject to some restrictions and cannot do the following:

1. Sleep or discard the CPU.

The consequence of doing so is catastrophic, because the kernel will shut down the process scheduling before it enters the interrupted state. Once it sleep or gives up the CPU, the kernel will not be able to schedule other processes for execution, and the system will die.

2. Try to obtain the semaphore

If the semaphore is not obtained, the code will sleep and produce the same situation as above.

3. Execute time-consuming tasks

Interrupt Processing should be as fast as possible, because the kernel needs to respond to a large number of services and requests, and the interruption context takes too long to occupy the CPU, which seriously affects the system functions.

4. Virtual Address used to access the user space

Because the interrupt context is irrelevant to a specific process, it indicates that the hardware runs in the kernel space, so the virtual address of the user space cannot be accessed in the terminal context.

 

 

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.