Atomic planning

In my own kernel module, I am trying to initialize kthread in an interrupt handler function.

in global scope:

 static struct task_struct *thread1; 

irq function handler:

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

and stream function:

 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 as follows:

 request_irq(irq,func_irq_handler,IRQF_TRIGGER_HIGH | IRQF_TRIGGER_RISING ,"test_irq",(void*)&my_miscdev); 

why am I getting this error:

 BUG: scheduling while atomic: swapper 
+4
source share
1 answer

I would suggest that creating a thread requires interaction with the thread scheduler, which is unacceptable in the context of an interrupt / atom.

A better approach would be to create your kernel thread elsewhere and process the queue interrupt request.

+4
source

All Articles