world leader in high performance signal processing
Trace: » tasklets


Kernel Tasklets are functions that can be added to a list of operations a kernel thread has to perform at the next “return from exception”.

They execute in the context of the Soft IRQ Thread and cannot perform any actions that may sleep.

They are very useful for performing activities that need to be triggered or scheduled at one time and have the actual execution deferred until a later time.

An interrupt action is one example where a deferred process may need to complete the data processing started by the Interupt service routiune.

Tasklet Details

To use tasklets you will need to include the header file linux/interrupt.h

The following fiunctions are available:

  • DECLARE_TASKLET(tlname, func, data);
  This will declare an enabled tasklet structure called tlname.
  struct tasklet_struct tlname = { NULL, 0, ATOMIC_INT(0), func, data }
  The function will be called with (unsigned long)data as a  parameter
  • DECLARE_TASKLET_DISABLED(tlname, function, data);
  This will declare a disabled tasklet structure called tlname.
  struct tasklet_struct tlname = { NULL, 0, ATOMIC_INT(1), func, data }
  The function will be called with (unsigned long)data as a  parameter
  • void tasklet_schedule(&tlname)
  This will cause the tasklet to be scheduled.
  If the tasklet is enabled it will be run.
  • void tasklet_disable(&tlname);
    This will disable the tasklet.
    The tasklet may still be scheduled with tasklet_schedule, but it
    will not execute until it is enabled.
  • void tasklet_enable(&tlname);
     This will enables a previously disabled taskled.
     If the tasklet had already been scheduled, it will be run after the
     return from tasklet_enable.
  • void tasklet_kill(&tlname);
    This function may be used on to remove the tasklet from any queue that
    it is on. It will wait until the tasklet executes, then removes it
    from the queue. The tasklet will not be interrupted during its
    execution. However the function may hang if the tasklet is not running
    and it may not be called from an interrupt routine.

Tasklet Examples

The keyboard driver (in the drivers/char directory) makes use of tasklets.

// from drivers/char/keyboard.c
DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh, 0);
 * This allows a newly plugged keyboard to pick the LED state.
static void kbd_refresh_leds(struct input_handle *handle)
        unsigned char leds = ledstate;
        if (leds != 0xff) {
                input_event(handle->dev, EV_LED, LED_SCROLLL, !!(leds & 0x01));
                input_event(handle->dev, EV_LED, LED_NUML,    !!(leds & 0x02));
                input_event(handle->dev, EV_LED, LED_CAPSL,   !!(leds & 0x04));
// the keyboard event handler
static void kbd_event(struct input_handle *handle, unsigned int event_type,
                      unsigned int event_code, int value)
        if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev))
        if (event_type == EV_KEY)
                kbd_keycode(event_code, value, HW_RAW(handle->dev), handle->dev->regs);
        do_poke_blanked_console = 1;