5
votes

When referring to Linux Kernel Interrupt handlers as I know there are two stages of interrupt executions first is Top Half and second Bottom Half.

I know Top Half will be executed immediately on occurrence of interrupt from HW but my doubt is when and how bottom half is executed ?

2
Is your bottom half implemented as a tasklet or as a workqueue?CL.
It is implemented as tasklet.Nishith Goswami

2 Answers

4
votes

¿ when and how bottom half is executed ?

When: it is executed AFTER the interrupt handler, and in fact, its execution is triggered by the interrupt handler itself. Sometimes it executes just right after the interrupt handler, sometimes not.

How: if your bottom half is implemented by a tasklet, its execution is scheduled by using the task_schedule() function, normally called from inside the interrupt handler. This function does not execute the tasklet, but informs the scheduler to queue the tasklet function for later execution.

3
votes

The bottom halves are implemented as tasklets (deferred interrupt context), workqueues (process context) and softirqs (rarely, only 9 of those in Linux kernel).

The timer interrupt handler checks which of the 9 softirqs are to be executed (scheduler, hrtimers, network rx/tx, tasklets, etc.). If there is any pending softirq, (say a list of tasklets that the top-half has notified) then those get executed. As for any tasklet, this is true for any other softirq too. Also, because tasklet is a kind of softirq it can only be executed on the same CPU core.

On the contrary, the workqueues are executed when the corresponding process subsequently context switches in. Hence, unlike tasklets, these can sleep and can be scheduled on other CPU cores too.