The difference between hard interrupt and soft interrupt!

Hard interrupt:

1. Hard interrupts are generated by hardware, such as disks, network cards, keyboards, clocks, etc. Each device or set of devices has its own IRQ (Interrupt Request). Based on the IRQ, the CPU can distribute the corresponding request to the corresponding hardware driver (Note: The hardware driver is usually a subroutine in the kernel, not an independent process).

 

2. The driver that handles the interrupt needs to run on the CPU. Therefore, when the interrupt occurs, the CPU will interrupt the currently running task to handle the interrupt. On a multi-core system, an interrupt can usually only interrupt one CPU (there is also a special case, that is, there is a hardware channel on the mainframe, which can process multiple CPUs at the same time without the support of the main CPU. an interruption.).

 

3. Hard interrupts can directly interrupt the CPU. It will cause the relevant code in the kernel to be triggered. For processes that take some time to process, the interrupt code itself can also be interrupted by other hard interrupts.

 

4. For clock interrupts, the kernel scheduling code suspends the currently running process, allowing other processes to run. It exists so that scheduling code (or scheduler) can schedule multiple tasks.

 

 

Soft interrupt:

1. Soft interrupts are handled much like hard interrupts. However, they are only spawned by currently running processes.

 

2. Usually, softirq is some request for I/O. These requests call programs in the kernel that can schedule I/O to occur. For some devices, I/O requests need to be processed immediately, while disk I/O requests can often be queued and processed later. Depending on the I/O model, the process may be suspended until the I/O completes, at which point the kernel scheduler will choose another process to run. I/O can occur between processes and the scheduling process is usually done in the same way as disk I/O.

 

3. Softirqs are only associated with the kernel. The kernel is primarily responsible for scheduling any other processes that need to run. Some kernels allow parts of the device driver to exist in user space, and the kernel also schedules this process to run when needed.

 

4. Soft interrupts do not directly interrupt the CPU. Also only the currently running code (or process) will generate a softirq. Such an interrupt is a request for the kernel to do something (usually I/O) for the running process. A special softirq is the Yield call, which asks the kernel scheduler to see if some other process can run.

 

 

 

Answers to questions:

 1. Q: For soft interrupts, is the I/O operation done by the I/O device driver in the kernel?

    A: For I/O requests, the kernel will dispatch the work to the appropriate kernel driver, which will queue the I/O so that it can be processed later (usually disk I/O), or if possible It can be executed immediately. Typically, this queue is handled by the driver when responding to hard interrupts. When an I/O request completes, the next I/O request in the queue is sent to the device.

2. Q: Is the operation process of soft interrupt less than that of hard interrupt? In other words, for soft interrupts: process -> device driver in kernel; for hard interrupt: hardware -> CPU -> device driver in kernel?

Answer: Yes, soft interrupts have one less hardware signaling step than hard interrupts. Processes that generate softirqs must be currently running processes, so they do not interrupt the CPU. But they interrupt the flow of calling code.

If the hardware needs the CPU to do something, then this hardware will cause the CPU to interrupt the currently running code. The CPU then puts the current state of the currently running process on the stack so that it can return to continue running. Such an interrupt can stop a running process; it can stop kernel code that is handling another interrupt; or it can stop an idle process.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324745980&siteId=291194637