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