In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how the Linux kernel handles interrupts". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how the Linux kernel handles interrupts".
Interrupts are an important part of the way modern CPU works. For example, every time you press a key on the keyboard, the CPU is interrupted so that PC can read the user's keyboard input. This process happens so fast that you don't feel any change or damage in the experience.
In addition, the keyboard is not the only component that causes the interruption. In general, there are three types of events that cause interruptions in CPU: hardware interrupts, software interrupts, and exceptions. Before I can cover the different types of interrupts, I need to define some terms.
Define
The interrupt request interrupt request (IRQ) is initiated by the programmable interrupt controller programmable interrupt controlle (PIC) for the purpose of interrupting CPU and executing the interrupt service program interrupt service routine (ISR). An interrupt service program (ISR) is a small program that processes specific data depending on the cause of the interrupt request (IRQ). Previously running processes are interrupted before the interrupt service program (ISR) ends.
In the past, interrupt requests were processed by a separate chip (interrupt controller chip PIC), and the Imax O device was directly connected to the interrupt controller (PIC). The interrupt controller (PIC) manages the interrupt request (IRQ) of a variety of hardware and can communicate directly with CPU. When an interrupt request (IRQ) is generated, the interrupt controller (PIC) writes data to the CPU and triggers the interrupt request pin (INTR).
Nowadays, interrupt requests (IRQ) are handled by the advanced programmable interrupt controller advanced programmable interrupt controller (APIC) part of CPU. Each core has its own advanced programmable interrupt controller.
Type of interrupt
As I mentioned earlier, interrupts can be divided into three types according to their source.
Hardware interrupt
When a hardware device wants to tell CPU that some data that needs to be processed is ready (for example, when the keyboard is pressed or a packet is on the network interface), it will send an interrupt request (IRQ) to tell CPU that the data is available. The corresponding interrupt service program (ISR) registered by the device driver at kernel startup is then called.
Software interruption
When you are playing a video, it is important that audio and video are played synchronously so that the speed of the music does not change. This is achieved by software interrupts and repeatedly initiated by a precise timer system called jiffies. This timer will synchronize your music player. Software interrupts can also be called by special instructions to read or write data to hardware devices.
When the system needs real-time (for example, in industrial applications), software interrupts become important. You can find more information in the Linux Foundation article: an introduction to real-time Linux for embedded developers.
Abnormal
Exception exception is a type of interrupt that you may have known before. Any other running program will be interrupted when CPU executes instructions that will cause divide-by-zero or page-missing errors. In this case, you will be reminded by a pop-up window or see the * * paragraph error segmentation fault (core dumped core dumped) * * in the console output. But not all exceptions are caused by instruction errors.
Exceptions can be further divided into error Fault, trap Trap, and termination Abort.
Error: an error is an exception that the system can correct. For example, when a process tries to access a page that has been swapped out to the hard disk. When the requested address is in the process's address space and access rights are met, if the page is not in memory (RAM), an interrupt request (IRQ) will be generated and the page fault exception handler will be enabled to load the required pages into memory. If the operation is executed successfully, the program continues to run.
Traps: traps are mainly used in debugging. If you set a breakpoint in a program, you insert a special instruction that triggers the trap. Traps can trigger context switches to allow your debugger to read and display the values of local variables. The program can then continue to run. Traps are also a way to run system calls (such as killing a process)
Termination: termination is caused by hardware errors or inconsistent values in the system table. Termination does not report the location of the instruction that caused the exception. This is the most serious interrupt, and termination invokes the system's termination exception handler to end the process that caused the exception.
Hands-on practice
Interrupt requests are sorted according to the priority in the Advanced Programmable interrupt Controller (APIC) (0 is the highest priority). The first 32 interrupts (0,31) are fixed sequences specified by CPU. You can find an overview of them on the OsDev exceptions page. Subsequent interrupt requests can be allocated in different ways. The corresponding relationship between interrupt request (IRQ) and interrupt service program (ISR) is recorded in the interrupt description table interrupt descriptor table (IDT). IRQ vectors from 0 to 256 are defined in Linux.
To print out the interrupts registered in your system, open a terminal and type:
Cat / proc/interrupts
You should see a result similar to the following:
Kernel version is 5.6.6 registered interrupts (Stephan Avenwedde, CC BY-SA 4.0)
The meaning of each column from left to right is the interrupt vector number, the number of interrupts per CPU (0interrupn), the hardware source, the hardware source channel information, and the name of the device that caused the interrupt request.
At the end of the table, there are some non-numeric interrupts. They are architecture-specific interrupts, such as the interrupt request (IRQ) number of the local timer interrupt local timer interrupt (LOC) is236. Some of these are specified in the Linux IRQ vector layout in the Linux kernel source tree.
Architecture-specific interrupts (Stephan Avenwedde, CC BY-SA 4.0)
If you want to get the table in real time, run the following command:
Watch-N1 "cat / proc/interrupts" above is all the content of the article "how does the Linux kernel handle interrupts?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Server {listen 80; rewrite ^ (. *) $https://$server_name$1 permanent
© 2024 shulou.com SLNews company. All rights reserved.