Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When bottom half is called with respect to interrupt handlers

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 ?

like image 732
Nishith Goswami Avatar asked Dec 07 '13 12:12

Nishith Goswami


People also ask

What is bottom half handling?

The bottom half is a routine that is scheduled by the top half to be executed later, at a safer time. The use of the term bottom half in the 2.4 kernel can be a bit confusing, in that it can mean either the second half of an interrupt handler or one of the mechanisms used to implement this second half, or both.

Which are different types of bottom halves and where they are used?

There are three main types of bottom halves: namely tasklets, workqueues and kernel threads. Tasklets are used to queue up work to be done at a later time. Tasklets can be run in parallel, but the same tasklet cannot be run on multiple CPUs at the same time.

What are the different bottom half mechanisms in Linux?

Work queues are a very simple yet useful method of queueing work to later be performed in process context. We will get to them later. Consequently, today 2.6 has three bottom-half mechanisms in the kernel: softirqs, tasklets, and work queues.

Why are device drivers divided into a top half and bottom half?

Device drivers typically have a top and bottom half. The top half gets data and commands from the kernel, and places them into a data structure shared with the bottom half. The bottom half gets called when there is an interrupt, and places answers in the common data structure.


2 Answers

¿ 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.

like image 93
mcleod_ideafix Avatar answered Sep 21 '22 00:09

mcleod_ideafix


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.

like image 27
user31986 Avatar answered Sep 21 '22 00:09

user31986