Pages

2010-08-27

Linux: Using Tasklet/Workqueues in Bottom Half Interrupt

In this post we will see how to use Tasklet and  Workqueue to deal with interrupts in the Linux Kernel.

First we declare our Tasklet using DECLARE_TASKLET(name, function, data):
void do_tasklet(unsigned long);
DECLARE_TASKLET(my_tasklet, do_tasklet, 0);
As you see name is the name of our Tasklet, function is the function that will called to treat the tasklet, data is what we bill passed to this function (unsigned long).

Now to schedule our Tasklet we do:
tasklet_schedule(&my_tasklet);

If we want to use Workqueue:
 #include <linux/workqueue.h>
static struct work_struct my_wq;
INIT_WORK(&my_wq, (void (*)(void *)) do_tasklet, NULL);
...
schedule_work(&my_wq);

No comments:

Post a Comment