linux中断注册及中断线程化

linux中高优先级任务从runable到真正被调度的时间是不确定的,主要有两方面因素,
1,内核中总有些代码持有自旋锁资源(cpu一直等待),或者有些代码段会调用preempt_disable显示的禁止抢占。
2,中断上下文具有更高的优先级(包括hw_irq_handler、softirq、tasklet等)可以抢占进程上下文。

一般外设中断被分为top half和bottom half(softirq、tasklet),而bottom half的优先级也是高于进程的,所以为了进一步提高系统的响应实时性,引入了线程irq,即将外设中断处理线程化,使像内核态线程、用户态线程一样竞争cpu资源。

linux设备驱动中,申请irq的函数

int devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
unsigned long irqflags, const char *devname, void *dev_id);
以及,
int devm_request_threaded_irq(struct device *dev, unsigned int irq,
irq_handler_t handler, irq_handler_t thread_fn,
unsigned long irqflags, const char *devname,
void *dev_id);
其实devm_request_irq只是devm_request_threaded_irq的wapper,

static inline int __must_check
devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
unsigned long irqflags, const char *devname, void *dev_id)
{
return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
devname, dev_id);
}

参数thread_fn=NULL,表示非线程化irq。

前缀devm_开头的API申请的是内核“managed”资源,作用是一般不需要在出错处理和remove()接口里再显示释放。

//devres.c

/**
 *  devm_request_threaded_irq - allocate an interrupt line for a managed device
 *  @dev: device to request interrupt for
 *  @irq: Interrupt line to allocate
 *  @handler: Function to be called when the IRQ occurs
 *  @thread_fn: function to be called in a threaded interrupt context. NULL
 *          for devices which handle everything in @handler
 *  @irqflags: Interrupt type flags
 *  @devname: An ascii name for the claiming device
 *  @dev_id: A cookie passed back to the handler function
 *
 *  Except for the extr
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值