tasklet的实现【1】

本文深入解析了Linux内核中的Tasklet机制,介绍了tasklet_struct结构体的组成及其工作原理,阐述了Tasklet与BHs及通用softirq的区别,并强调了其在多CPU环境下并行执行的特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       tasklet由两类软中断代表:HI_SOFTIRQ,TASKLET_SOFTIRQ。这两者之间的唯一的区别在于前者的软中断优先于后者。

1. tasklet结构体

tasklet由tasklet_struct结构体表示。每个结构体单独代表一个tasklet,它在<linux/interrupt.h>中定义:

  1. /* Tasklets --- multithreaded analogue of BHs.
  2.    Main feature differing them of generic softirqs: tasklet
  3.    is running only on one CPU simultaneously.
  4.    Main feature differing them of BHs: different tasklets
  5.    may be run simultaneously on different CPUs.
  6.    Properties:
  7.    * If tasklet_schedule() is called, then tasklet is guaranteed
  8.      to be executed on some cpu at least once after this.
  9.    * If the tasklet is already scheduled, but its excecution is still not
  10.      started, it will be executed only once.
  11.    * If this tasklet is already running on another CPU (or schedule is called
  12.      from tasklet itself), it is rescheduled for later.
  13.    * Tasklet is strictly serialized wrt itself, but not
  14.      wrt another tasklets. If client needs some intertask synchronization,
  15.      he makes it with spinlocks.
  16.  */
  17. struct tasklet_struct
  18. {
  19.     struct tasklet_struct *next;//链表中的下一个tasklet
  20.     unsigned long state;//tasklet的状态
  21.     atomic_t count;//引用计数器
  22.     void (*func)(unsigned long);//tasklet处理函数
  23.     unsigned long data;//给tasklet处理函数的参数
  24. };

state成员函数只能在0、TASKLET_STATE_SCHED,TASKLET_STATE_RUN之间取值。count成员是tasklet的引用计数器,如果它不为0则tasklet被禁止,不允许执行;只有当它为0时,tasklet才被激活,并且在被设置为挂起状态时,该tasklet才能够执行。

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值