In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Linux kernel interrupt example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
Interruption means that during the normal operation of CPU, due to internal and external events or events prearranged by the program, CPU temporarily stops the running program and turns to serve the internal or external event or prearranged event, and then returns to run the temporarily interrupted program after the service is completed.
Define
The interrupt request (IRQ) is initiated by the programmable interrupt controller (PIC) to interrupt the CPU and execute the interrupt service program (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 you will see a segment error segmentation fault (core has been 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 terminated by the way system calls are run (such as killing a process): 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"
Thank you for reading this article carefully. I hope the article "sample Analysis of Linux Kernel interrupts" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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
© 2024 shulou.com SLNews company. All rights reserved.