4. Upper half and lower part
1 Why should be divided into the lower half of
Game of speed and function. As mentioned above, interrupt handlers are interrupted by other people's operations, so run as fast as you can. But I want to try to do a great function. This is one of two conflicting goals. The solution is to divide the interrupt handler into the following two parts
2)
Top half: There are strict time constraints, do some work that must be done immediately, such as the response to interrupts and hardware reset
Lower half: Allow to finish later, do some less urgent work, such as data processing
In this way, the interrupt handler handles the upper half, and the lower part is then performed at a later idle time to achieve a balance between speed and function.
3) Example: Interrupt handling of network card
The network card has data arrives, sends an interrupt to the kernel
The kernel call interrupt handler handles the following tasks: notifying hardware, copying data to memory. These tasks are urgent, that the network card is usually relatively small cache, if not in time to copy out, the cache will cause loss of packets. And you must have the NIC reset and ready to receive new data immediately.
The lower half of the work: in-memory data processing, and sent to the corresponding process. This is less urgent work that can be done later.