Tasklets in the Linux kernel

Tasklets are a means of achieving bottom-half processing in the Linux Kernel. What is bottom-half and the need for bottom half is explained in the article below.

https://www.hitchhikersguidetolearning.com/2021/05/09/bottom-half-processing-in-the-linux-kernel/

Tasklets are the preferred mechanism to defer execution in Linux. Tasklets are implemented on top of softirqs – HI_SOFTIRQ and TASKLET_SOFTIRQ. The high priority tasklets (placed in a vector tasklet_high_vec array) are handled earlier than regular tasklets (placed in tasklet_vec array). The Tasklet linked list as seen in softirq.c is below

The Tasklet structure which contain details of the tasklet is the “tasklet_struct” structure which has recently undergone a change (as in interrupt.h 5.12). 

The older Tasklet structure is provided below. 

 

The difference in the two is that the new Structure has added a new “callback API with the tasklet_struct as a parameter which is used to schedule the tasklet”. The older structure uses the “func callback to schedule the tasklet. The “data” parameter is used to send data to the tasklet. The above changes have changed the manner in which a Tasklet is setup which we will see in a later article.  

Some of the salient points of Tasklets are provided below

1

Tasklets run on the CPU that scheduled the Tasklet

2

The same Tasklet cannot be simultaneously run on two different CPUs. Different Tasklets can be executed simultaneously on different CPUs. Tasklet, being capable of running on the CPU it was scheduled and only in a serialized manner eases the manner in which a Tasklet can be implemented (Tasklet code does not need to be reentrant).  

3

Tasklet code should not contain sleep() call or any API that can sleep. Tasklets are supposed to finish atomically

In the following articles, we will see how to setup a Tasklet and how the Tasklet is scheduled and run.

Tasklet APIs

Leave a Reply

Your email address will not be published. Required fields are marked *