what is interrupt in linux
In Linux, an interrupt is a mechanism by which the hardware sends a signal to the CPU when needed, and the CPU temporarily stops its ongoing work to handle the hardware request. When the hardware is busy, the CPU is likely to do a lot of useless work (each poll is skipped and not processed); therefore, in order to improve the performance of the collaborative work between the CPU and peripheral hardware (hard disk, keyboard, mouse, etc.), introduce The interrupt mechanism.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
1. Interrupt definition
Interrupt is when the hardware sends a signal to the CPU when needed, and the CPU temporarily stops the ongoing work to process it. A mechanism for hardware requests.
Specifically:
Interrupt refers to the CPU temporarily stopping the running program due to internal or external events or events pre-arranged by the program during normal operation of the CPU, and switches to the internal or external event. Or go to the program of the pre-arranged event service, and then return to continue running the temporarily interrupted program after the service is completed.
1.1 Background (why interrupts are needed)
1. Without interrupts, collaboration between the CPU and peripheral devices The only way to work/communicate is by polling: the CPU regularly checks the hardware status and processes it when it needs to be processed, otherwise it skips it.
2. The speed of the processor is not in the same order of magnitude as the peripheral hardware devices, so a mechanism is provided for the hardware to send signals to the kernel when needed.
Disadvantages of polling/Introduction of interrupt mechanism:
When the hardware is busy, the CPU is likely to do a lot of useless work (each polling is skipped and not processed).
Therefore, in order to improve the performance of collaborative work between the CPU and peripheral hardware (hard disk, keyboard, mouse, etc.), an interrupt mechanism is introduced.
中断: 硬件/进程发,内核收 信号:内核发,进程收,或者进程发进程收
##1.3 Interrupt handling Process (refer to CSAPP books)
中断是异步发生的,是来自处理器外部的I/O设备的信号的结果 1. 硬件中断不是由任何一条专门的指令造成的,从这个意义上来说它是异步的 2. 硬件中断的异常处理程序常常被称为中断处理程序(interrupt handler)
Figure 8.5
Before the current instruction completes execution, the processor notices that the voltage on the interrupt pin has become high, reads the exception number from the system bus, and then calls the appropriate interrupt handler. When the handler returns, it returns control to the next instruction (that is, the instruction that would be after the current instruction in the control flow if no interrupt had occurred). The result is that program execution continues as if the interruption had not occurred.
剩下的异常类型(陷阱、故障和终止)是同步发生的,是执行当前指令的结果 我们把这类指令叫做故障指令(faulting instruction)
1.4 The essence of interrupt and processing mechanism/process
The essence of interrupt is a special electrical signal Interrupts are generated by hardware devices and sent directly to the input pins of the interrupt controller (simple electronic chip). The interrupt controller uses multiplexing The technology uses multiple interrupt pipelines to communicate with the processor through only one pipeline connected to the processor. Once the processor detects this signal, it interrupts its current work and processes the interrupt. When hardware devices generate interrupts, they do not consider synchronization with the processor's clock, that is, interrupts can be generated at any time, so the kernel may be interrupted at any time by new interrupts.
2. Interrupt types (categories)
Linux is usually divided into external interrupts (also called hardware interrupts) and internal interrupts (also called abnormal).2.1 Synchronous interrupt (exception/internal interrupt)
Synchronous interrupt (exception/internal interrupt): Synchronous interrupt Generated by the CPU itself, also known as internal interrupt or exception2.1.1 Synchronous interrupt example: page missing interrupt
The CPU is executing a When executing the instruction, if it is found that the page he wants to access (the page of the virtual address) is not in the physical memory, then the execution of the instruction will be stopped and a page non-existence exception will be generated. An executable file may be large and placed in On the disk, only a part of it is read into the memory at a time (cpu locality principle).
When it wants to access the remaining content, a page fault interrupt will occur. At this time, it will be swapped in from the disk.
2.2 Asynchronous interrupt (interrupt/external interrupt)
Asynchronous interrupt (interrupt/external interrupt): Asynchronous interrupt is generated by an external hardware device , also known as external interrupt or interrupt2.2.1 异步中断举例:网卡的工作原理
当网卡接受到数据包时,通知内核,触发中断,所谓的上半部就是,及时读取数据包到内存,防止因为延迟导致丢失,这是很急迫的工作。
读到内存后,对这些数据的处理不再紧迫,此时内核可以去执行中断前运行的程序,而对网络数据包的处理则交给下半部处理。
异常与中断不同,中断是由硬件引起的;
异常则发生在编程失误而导致错误指令,或者在执行期间出现特殊情况必须要靠内核来处理的时候(比如缺页)。它在产生时必须考虑与处理器时钟同步,因此异常也称同步中断。
3、中断请求实现:上下半部机制
中断处理程序运行需要快速执行(因为不可阻塞),同时要能完成尽可能多的工作,这里存在矛盾。
因此把中断处理切分为两个部分,上半部分(top half)接收到一个中断后立即执行,但是只做有严格时限的工作,例如对接收到的中断进行应答或复位硬件。能够被允许稍后完成的工作会推迟到下半部分(bottom half)去,此后在合适的时机下半部分会被中断执行,Linux提供了实现下半部分的各种机制。
优点:这种设计可以使系统处于中断屏蔽状态的时间尽可能的短,以此来提高系统的响应能力。
中断处理程序是上半部——接受中断,他就立即开始执行,但只有做严格时限的工作。
上半部简单快速,执行时禁止一些或者全部中断。
工作内容:处理紧急功能,取寄存器状态。
能够被允许稍后完成的工作会推迟到下半部去,此后,在合适的时机,下半部执行
工作内容:完成中断事件绝大多数任务。
下半部稍后执行,而且执行期间可以响应所有的中断。
下半部的实现有软中断实现, tasklet 实现和工作队列实现。
1) 如果一个任务对时间非常敏感,将其放在中断处理程序中执行; 2) 如果一个任务和硬件有关,将其放在中断处理程序中执行; 3) 如果一个任务要保证不被其他中断打断,将其放在中断处理程序中执行; 4) 其他所有任务,考虑放置在下半部执行
当网卡接受到数据包时,通知内核,触发中断,所谓的上半部就是,及时读取数据包到内存,防止因为延迟导致丢失,这是很急迫的工作。
读到内存后,对这些数据的处理不再紧迫,此时内核可以去执行中断前运行的程序,而对网络数据包的处理则交给下半部处理。
4、中断号
中断对应着一个中断号,内核通过这个中断号查找相应的中断服务程序。
每个中断都通过一个唯一的数字标志,这样操作系统才能够给不同的中断提供对应的中断处理程序。
这些中断值即中断请求线,例如IRQ 0是时钟中断、IRQ 1是键盘中断。对于连接在PCI总线上的设备而言,中断请求线是动态分配的。
5、中断上下文
中断服务程序不在进程上下文中执行,而是在一个与所有进程都无关的、专门的中断上下文中运行,以此保证中断服务程序能够在第一时间响应和处理中断请求,然后快速地退出。
处理器在任何指定时间点上的活动必然属于以下三种情况之一:
运行于用户空间,执行用户进程; 运行于内核空间,处于进程上下文,代表某个特定的进程执行; (CPU空闲时,内核执行空进程) 运行于内核空间,处于中断上下文,与任何进程无关,处理某个特定的中断;
相关推荐:《Linux视频教程》
The above is the detailed content of what is interrupt in linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

How to download BitPie Bitpie Wallet App? The steps are as follows: Search for "BitPie Bitpie Wallet" in the AppStore (Apple devices) or Google Play Store (Android devices). Click the "Get" or "Install" button to download the app. For the computer version, visit the official BitPie wallet website and download the corresponding software package.

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

Gate.io is a highly acclaimed cryptocurrency trading platform known for its extensive token selection, low transaction fees and a user-friendly interface. With its advanced security features and excellent customer service, Gate.io provides traders with a reliable and convenient cryptocurrency trading environment. If you want to join Gate.io, please click the link provided to download the official registration installation package to start your cryptocurrency trading journey.
