原文出处:http://blog.csdn.net/wq/article/details/
softirq,tasklet,workqueue
软中断和tasklet仍然运行于中断上下文,而工作队列则运行于进程上下文
实现的过程:
1.“顶半部”:是实际响应中断的例程(request_irq 注册的那个例程)。
2.“底半部”:是被顶半部调度,并在稍后更安全的时间内执行的函数
void xxx_do_tasklet(unsigned long)
{
…………
}
irqreturn_t xxx_interrupt(int irq,void *dev_id,struct pt_regs *regs)
{
…………………
tasklet_schedule(&xxx_tasklet);
………………….
}
int __init xxx_init(void)
{
……………..
result=request_irq(xxx_irq,xxx_interrupt,SA_INTERRUPT,”XX”,NULL);
………………
}
void __exit xxx_exit(void)
{
…………………
free_irq(xxx_irq,xxx_interrupt);
…………………
}
//工作队列使用模板
void xxx_do_work(unsigned long)
{
………………..
}
irqreturn_t xxx_interrupt(int irq,void *dev_id,struct pt_regs *regs)
{
…………….
schedule_work(&xxx_wq);
……………….
}
int xxx_init(void)
{
…………….
INIT_WORK(&xxx_wq,(void ()(void )) xxx_do_work,NULL);
……………..
}
void xxx_exit(void)
{
……………
free_irq(xxx_irq,xxx_interrupt);
…………….
}
软中断和tasklet仍然运行于中断上下文,而工作队列则运行于进程上下文。因此,软中断和tasklet处理函数中不能睡眠,而工作队列处理函数中允许睡眠。
local_bh_disable()和local_bh_enbale()是内核中用于禁止和使能 中断和tasklet底半部机制的函数

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/135040.html