在我自己的内核模块中,我试图kthread
在一个中断处理函数中初始化一个。
在全球范围内,我有:
static struct task_struct *thread1;
irq 的函数处理程序是:
static irqreturn_t* func_irq_handler (int irq, void *dev_id)
{
printk("irq handler ... \n");
thread1 = kthread_create(thread_function,NULL,"my_thread");
if ((thread1)) {
printk(KERN_INFO "%s\n" , __FUNCTION__);
}
return IRQ_HANDLED;
}
线程函数是:
static thread_function(void)
{
unsigned long j1=jiffies+20000;
int delay = 60*HZ;
printk("%s \n",__FUNCTION__);
while (time_before(jiffies,j1)) {
schedule();
printk(KERN_INFO "after schedule\n");
}
}
request_irq
看起来像这样:
request_irq(irq,func_irq_handler,IRQF_TRIGGER_HIGH | IRQF_TRIGGER_RISING ,"test_irq",(void*)&my_miscdev);
为什么我会收到此错误:
BUG: scheduling while atomic: swapper