Generating Tasklets

Not surprisingly, the central data structure of each tasklet is called tasklet_struct and 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 is func. It points to the address of a function whose execution is to be deferred. data is passed as a parameter when the function is executed.

next is a pointer used to build a linked list of tasklet_struct instances. This allows several tasks to be queued for execution.

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

□ tasklet_state_sched is set when the tasklet is registered in the kernel and scheduled for execution.

□ tasklet_state_run indicates 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 counter count is 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.

Continue reading here: Registering Tasklets

Was this article helpful?

0 0