tasklet由两类软中断代表:HI_SOFTIRQ,TASKLET_SOFTIRQ。这两者之间的唯一的区别在于前者的软中断优先于后者。
1. tasklet结构体
tasklet由tasklet_struct结构体表示。每个结构体单独代表一个tasklet,它在<linux/interrupt.h>中定义:
- /* Tasklets --- multithreaded analogue of BHs.
- Main feature differing them of generic softirqs: tasklet
- is running only on one CPU simultaneously.
- Main feature differing them of BHs: different tasklets
- may be run simultaneously on different CPUs.
- Properties:
- * If tasklet_schedule() is called, then tasklet is guaranteed
- to be executed on some cpu at least once after this.
- * If the tasklet is already scheduled, but its excecution is still not
- started, it will be executed only once.
- * If this tasklet is already running on another CPU (or schedule is called
- from tasklet itself), it is rescheduled for later.
- * Tasklet is strictly serialized wrt itself, but not
- wrt another tasklets. If client needs some intertask synchronization,
- he makes it with spinlocks.
- */
- struct tasklet_struct
- {
- struct tasklet_struct *next;//链表中的下一个tasklet
- unsigned long state;//tasklet的状态
- atomic_t count;//引用计数器
- void (*func)(unsigned long);//tasklet处理函数
- unsigned long data;//给tasklet处理函数的参数
- };
state成员函数只能在0、TASKLET_STATE_SCHED,TASKLET_STATE_RUN之间取值。count成员是tasklet的引用计数器,如果它不为0则tasklet被禁止,不允许执行;只有当它为0时,tasklet才被激活,并且在被设置为挂起状态时,该tasklet才能够执行。