Some information about tasklet

本文详细介绍了Linux内核中Tasklets的概念及使用方法。Tasklets是一种轻量级的任务调度机制,用于在中断上下文中安排延迟执行的任务。文章解释了Tasklets的数据结构、声明方式,并强调了在编写Tasklets处理器函数时需要注意的问题。

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

 

Tasklets

The Tasklet Structure

Tasklets are represented by the tasklet_struct structure. Each structure represents a unique tasklet. The structure is declared in <linux/interrupt.h>:

struct tasklet_struct {
        struct tasklet_struct *next;  /* next tasklet in the list */
        unsigned long state;          /* state of the tasklet */
        atomic_t count;               /* reference counter */
        void (*func)(unsigned long);  /* tasklet handler function */
        unsigned long data;           /* argument to the tasklet function */
};
Using Tasklets
Declaring Your Tasklet

You can create tasklets statically or dynamically.

What option you choose depends on whether

you have (or want) a direct or indirect reference to the tasklet.

If you are going to statically create the tasklet

(and thus have a direct reference to it),

use one of two macros in <linux/interrupt.h>:

DECLARE_TASKLET(name, func, data);//the argument "name" is up to you !not 
					//so importent! 

Writing Your Tasklet Handler

The tasklet handler must match the correct prototype:

void tasklet_handler(unsigned long data)

As with softirqs, tasklets cannot sleep. This means you cannot

use semaphores or other blocking functions in a tasklet. Tasklets

also run with all interrupts enabled, so you must take

precautions (for example, disable interrupts and obtain a lock)

if your tasklet shares data with an interrupt handler. Unlike softirqs,

however, two of the same tasklets never run concurrentlyalthough

two different tasklets can run at the same time on two different processors.

If your tasklet shares data with another tasklet or softirq, you need to use

proper locking .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值