Rewrite the descriptions about bottom half

This commit is contained in:
Jim Huang 2021-09-01 12:07:25 +08:00
parent 5b953eea75
commit 6110f8ee3c

View File

@ -1557,8 +1557,12 @@ If at all possible, it is better to declare an interrupt handler to be long.
When the CPU receives an interrupt, it stops whatever it is doing (unless it is processing a more important interrupt, in which case it will deal with this one only when the more important one is done),
saves certain parameters on the stack and calls the interrupt handler.
This means that certain things are not allowed in the interrupt handler itself, because the system is in an unknown state.
The solution to this problem is for the interrupt handler to do what needs to be done immediately, usually read something from the hardware or send something to the hardware, and then schedule the handling of the new information at a later time (this is called the "bottom half") and return.
The kernel is then guaranteed to call the bottom half as soon as possible -- and when it does, everything allowed in kernel modules will be allowed.
% TODO: add some diagrams
Linux kernel solves the problem by splitting interrupt handling into two parts.
The first part executes right away and mask the interrupt line.
Hardware interrupts must be handled quick, and that is why we need the second part to handle the heavy work deferred from a interrupt handler.
Historically, BH (Linux naming for \textit{Bottom Halves}) statistically book-keeps the deferred functions.
\textbf{Softirq} and its higher level abstraction, \textbf{Tasklet}, replace BH since Linux 2.3.
The way to implement this is to call \cpp|request_irq()| to get your interrupt handler called when the relevant IRQ is received.