Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 14: Kernel Activities


Before going into the technical details, a word of caution on the terminology used: For historical reasons,
the termbottom halfis often used to mean two different things; first, it refers to the lower half of the code
of an ISR that performs no time-critical actions. Unfortunately, the mechanisms used in earlier kernel
versions to defer the execution of actions was also referred to as the bottom half, with the result that the
term is often used ambiguously. In the meantime, bottom halves no longer exist as a kernel mechanism.
They were discarded during the development of 2.5 and replaced with tasklets, a far better substitute.

Taskletsare ‘‘small tasks‘‘that perform mini jobs that would be wasted on full processes.

14.3.1 Generating Tasklets


Not surprisingly, the central data structure of each tasklet is calledtasklet_structand is defined as
follows:

<interrupt.h>
struct tasklet_struct
{
struct tasklet_struct *next;
unsigned long state;
atomic_t count;
void (*func)(unsigned long);
unsigned long data;
};

From the perspective of a device driver, the most important element isfunc.Itpointstotheaddressofa
function whose execution is to be deferred.datais passed as a parameter when the function is executed.

nextis a pointer used to build a linked list oftasklet_structinstances. This allows several tasks to be
queued for execution.

stateindicates the current state of the task — as for a genuine task. However, only two options are
available, each represented by a separate bit instate, which is why they can be set and removed inde-
pendently of each other:

❑ TASKLET_STATE_SCHEDis set when the tasklet is registered in the kernel and scheduled for execu-
tion.
❑ TASKLET_STATE_RUNindicates that a tasklet is currently being executed.

The second state is only of relevance on SMP systems. It is used to protect tasklets against concurrent
execution on several processors.

The atomic countercountis used to disable tasklets already scheduled. If its value is not equal to 0, the
corresponding tasklet is simply ignored when all pending tasklets are next executed.

14.3.2 Registering Tasklets


tasklet_scheduleregisters a tasklet in the system:

<interrupt.h>
static inline void tasklet_schedule(struct tasklet_struct *t);
Free download pdf