申请中断request_irq()与request_threaded_irq()之间的区别?

时间:2021-09-05 04:17:27

一、申请中断函数原型

int request_threaded_irq(unsigned int irq, irq_handler_t handler, irq_handler_t thread_fn, 

                      unsigned long irqflags,const char *devname, void *dev_id)

======》

request_threaded_irq 两个完全相同的irq_handler_t类型的irq action : handler 和 thread_fn。


static inline int __must_check
request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
   const char *name, void *dev)
{
return request_threaded_irq(irq,handler,NULL, flags, name, dev);
}

=====》

request_irq是request_threaded_irq的一个wrapper,只是将其中的thread_fn置为空。


二、request_threaded_irq函数实现

int request_threaded_irq(unsigned int irq, irq_handler_t handler,
irq_handler_t thread_fn, unsigned long irqflags,
const char *devname, void *dev_id)
{
struct irqaction *action;
struct irq_desc *desc;
desc = irq_to_desc(irq);

action = kzalloc(sizeof(struct irqaction), GFP_KERNEL);
if (!action)
return -ENOMEM;

action->handler = handler;
action->thread_fn = thread_fn;
action->flags = irqflags;
action->name = devname;
action->dev_id = dev_id;
       .................
chip_bus_lock(desc);
retval =__setup_irq(irq, desc, action);
chip_bus_sync_unlock(desc);
       .................
return retval;
}


__setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
{
struct irqaction *old, **old_ptr;
unsigned long flags, thread_mask = 0;
int ret, nested, shared = 0;
cpumask_var_t mask;
       ......................................
/*
* Create a handler thread when a thread function is supplied
* and the interrupt does not nest into another interrupt
* thread.
*/
if (new->thread_fn && !nested) {
struct task_struct *t;

                // 为该irq创建一个线程:irq_thread  
t = kthread_create(irq_thread, new, "irq/%d-%s", irq,
  new->name);

if (IS_ERR(t)) {
ret = PTR_ERR(t);
goto out_mput;
}
/*
* We keep the reference to the task struct even if
* the thread dies to avoid that the interrupt code
* references an already freed task_struct.
*/
get_task_struct(t);
new->thread = t;

}


三、申请中断其它函数原型

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);


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);
}


interrupt.h

manage.c

devres.c