Kernel code that services system calls issued by user applications runs on behalf of the corresponding application processes and is said to execute in process context. Interrupt handlers, on the other hand, run asynchronously in interrupt context. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or reliability of the article or any translations thereof.
If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or complaint, to info-contact alibabacloud.
A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately. 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. A comprehensive suite of global cloud computing services to power your business. Preface Recent knowledge of the Linux kernel often sees user space and kernel space and process context and interrupt context. Kernel state and User state: 1 When a task process executes a system call and is executed in the kernel code, the process is said to be in the Kernel runtime State kernel state.
Process context and interrupt context I'm looking at the third chapter of the book, "Linux kernel design and implementation". Look after still did not figure out, what is the process context, how on Google above a crazy search, summed up as follows: The program in the execution process usually has the user state and the kernel state two states, the CPU is in the kernel state according to the context Environment further subdivision, therefore has the following three kinds of states: 1 kernel state, running in the process context, the kernel represents the process running in the kernel space.
Context: Context is simply an environment. The contents of the excerpt from Linux comments are as follows: Process Context One of the most important parts of a process are the executing program code. Linux kernel space and user space detailedLinux drivers generally work in kernel space, but can also work in user space. Below we will analyze in detail what is kernel space, what is user space, and how to judge them.
The Linux kernel divides this 4G-byte space into two parts. Linux uses level two protection: level 0 for kernel use, and 3 for user programs. The highest 1GB bytes virtual kernel space is shared by all processes and the kernel. Kernel space is the kernel code and data, while the process of user space is stored in the user program code and data.
Both the kernel space and the user space are in virtual space. Although kernel space occupies up to 1GB bytes in each virtual space, mapping to physical memory always starts with the lowest address 0x How is the communication between kernel space and user space?
Kernel space and user space are generally communicated through system calls. How can I tell if a driver is a user-mode driver or a kernel-mode driver? What are the criteria for judging? The driver of the user-space mode typically accomplishes the hardware access through system calls, such as mapping the drive IO space to user space through system calls.
Therefore, the main basis of judgment is the system call. Kernel space and user space are different too much, say no, such as user-state linked list and kernel chain list is not the same, the user state with printf, the kernel state with PRINTK; the user state each application space is virtual, relatively independent, the kernel state is not independent, so programming to be very careful.
Wait a minute. Soft IRQs is the term used for the low level mechanism that implements deferring work from interrupt handlers but that still runs in interrupt context. Since softirqs can reschedule themselves or other interrupts can occur that reschedules them, they can potentially lead to temporary process starvation if checks are not put into place.
Once these limits are reached a special kernel thread, ksoftirqd is wake-up and all of the rest of pending soft irqs will be run from the context of this kernel thread. Soft irqs usage is restricted, they are use by a handful of subsystems that have low latency requirements and high frequency:. The following screencast will look at what happens when we flood the system with a large number of packets. Since at least a part of the packet processing is happening in softirq we should expect the CPU to spend most of the time running softirqs but the majority of that should be in the context of the ksoftirqd thread.
Tasklets are a dynamic type not limited to a fixed number of deferred work running in interrupt context. Workqueues are a type of deferred work that runs in process context. Which of the following phases of interrupt handling runs with interrupts disabled at the CPU level?
The Linux Kernel 5. What is an interrupt? They can also be grouped in two other categories based on the ability to postpone or temporarily disable the interrupt: synchronous , generated by executing an instruction asynchronous , generated by an external event maskable can be ignored signalled via INT pin non-maskable cannot be ignored signalled via NMI pin Synchronous interrupts, usually named exceptions, handle conditions detected by the processor itself in the course of executing an instruction.
Note Once the interrupt is acknowledge by the CPU the interrupt controller can request another interrupt, regardless if the CPU finished handled the previous interrupt or not. Note Not all architectures support interrupt priorities. The CPU can start processing a new interrupt before the current one is finished Interrupts can be disabled at the device level Lower priority interrupts can not preempt handlers for higher priority interrupts Interrupts can be disabled at the interrupt controller level On SMP systems the same interrupt can be routed to different CPUs Interrupts can be disabled at the CPU level.
On x86 an IDT entry has 8 bytes and it is named gate. There can be 3 types of gates: interrupt gate, holds the address of an interupt or exception handler. Jumping to the handler disables maskable interrupts IF flag is cleared. To resume the execution after an interrupt the following sequence is used x86 : pop the eror code in case of an abort call IRET pops values from the stack and restore the following register: CS, EIP, EFLAGS if privilege level changed returns to the old stack and old privilege level.
Note It is possible that one interrupt is associated with multiple devices and in this case it is said that the interrupt is shared.
However it is still possible to have nesting between exceptions and interrupts but the rules are fairly restrictive: an exception e. If a function sleeps, you cannot use it from your interrupt handler - this limits the functions that one can call from an interrupt handler.
Function can be used in the interrupt handler Interrupt context is time critical because the interrupt handler interrupts other code. Code should be quick and simple. Busy looping is discouraged. This is a very important point; always keep in mind that your interrupt handler has interrupted other code possibly even another interrupt handler on a different line! Because of this asynchronous nature, it is imperative required that all interrupt handlers be as quick and as simple as possible.
As much as possible, work should be pushed out from the interrupt handler and performed in a bottom half, which runs at a more convenient time. The setup of an interrupt handler's stacks is a configuration option. Historically, interrupt handlers did not receive their own stacks. Instead, they would share the stack of the process that they interrupted[1].
The kernel stack is two pages in size; typically, that is 8KB on bit architectures and 16KB on bit architectures. Because in this setup interrupt handlers share the stack, they must be exceptionally frugal with what data they allocate there. Of course, the kernel stack is limited to begin with, so all kernel code should be cautious. When nothing else is schedulable, the idle task runs. Early in the 2.
0コメント