Linux Bottome Half Handler Mechanism Detailed Analysis

xiaoxiao2021-03-06  49

Interrupts Handling

Interrupts are used to allow the hardware to communicate with the operating system Here, a brief explanation of the principles governing the execution of an interrupt is given There are two types of interrupts in Linux:.. Fast and slow Slow interrupts are the usual kind. . Other interrupts are legal when they are being dealt with After slow interrupt has been processed, additional activities requiring regular attention are carried out by the system -.. for example, scheduler is called as and when required A typical example is the timer interrupt. Fast Interrupts Are Used for the Short, Less Complex Tasks. While They Are Handled, Other Interrupts Are Blocked. A Typical Example Is The Line Printer Interrupt [EA96B].

The Variable "INTR_COUNT" (kernel / Softirq.c of the source) is buy by the kernel to keep track of the level of the interrupt nesting.

Bottom HALF HANDLING

There are often times in a kernel when you do not want to do work at this moment. A good example of this is during interrupt processing. When the interrupt was asserted, the processor stopped what it was doing and the operating system delivered the interrupt to the appropriate device driver. Device drivers should not spend too much time handling interrupts as, during this time, nothing else in the system can run. There is often some work that could just as well be done later on. Linux's bottom half handlers were invented SO That Device Drivers And Other Parts of the Linux Kernel Could Queue Work to Be Done Later ON [EA96B].

[Image] Figure: Linux Bottom Half Handling

The Figure (fig [*]) shows the kernel data structures associated with bottom half handling. There can be to 32 different bottom half handlers up. Bh_base is a vector of pointers to each of the kernel's bottom half handling routines. Bh_active and bh_mask have their bits set according to what handlers have been installed and are active. If bit N of bh_mask is set then the Nth element of bh_base contains the address of a bottom half routine. If bit N of bh_active is set then the n'th bottom half handler routine should be called as soon as the scheduler deems reasonable These indices are statically defined;. the timer bottom half handler is the highest priority (index 0), the console bottom half handler is next in priority (index 1) and so on. Typically, the bottom half handling routines have lists of tasks associated with them. For example, the immediate bottom half handler works its way through the immediate tasks queue (tq_immediate) which contains tasks that need to be performed im mediately. Some of the kernel's bottom half handers are device specific, but others are more generic. TIMER This handler is marked as active each time the system's periodic timer interrupts and is used to drive the kernel '

s timer queue mechanisms. CONSOLE This handler is used to process console messages. TQUEUE This handler is used to process tty messages. NET This handler handles general network processing. IMMEDIATE This is a generic handler used by several device drivers to queue work to be done later. Whenever a device driver, or some other part of the kernel, needs to schedule work to be done later, it adds work to the appropriate system queue, for example the timer queue, and then signals the kernel that some bottom half handling needs to be done. It does this by setting the appropriate bit in bh_active. bit 8 is set if the driver has queued something on the immediate queue and wishes the immediate bottom half handler to run and process it. After every slow interrupt, if no further interrupt is running, the bh_active bitmask consisting of upto 32 bottom halves is scanned. If it has any bits set, the bottom half handler routines that are active are called. Bit 1 is checked first, then 2 and so on u ntil bit 31. The bit in bh_active is cleared as each bottom half handling routine is called. bh_active is transient, it only has meaning between calls to the scheduler and is a way of not calling bottom half handling routines when there is no work for them To do.the variable "intr_count" is incremented at the time of entry inttom Half processing and decrement at the end of the processing.

转载请注明原文地址:https://www.9cbs.com/read-111986.html

New Post(0)