Reputation: 183
i come across a problem when i use a irq handler in linux;
i register a handler with a request_irq;
it can be called when the external hardware send a interrupt;
in the irq handler,the code is programmed as follows;
irqreturn_t irq_test_handler(int irq, void *desc)
{
wake_up_process(a_thread_handle);
mdelay(10);
printk("end the handler\n");
return IRQ_HANDLED;
}
a_thread_handle come from function : kthread_create(a_kthread....);
in a_kthread()
{
printk("in a kthread !\n");
}
so in my opinion , when irq happens;
it will print like this;
"
end the handler
in a kthread !
"
but in fact ;
it will print like this:
"
in a kthread !
end the handler
"
Can some one explain this to me ?
Upvotes: 2
Views: 844
Reputation: 628
What you are trying to do by wake_up_process()
is what request_threaded_irq()
is providing. Calling request_irq()
is the same as request_threaded_irq()
but with thread_fn=NULL
. If you provide your thread and return IRQ_WAKE_THREAD
, your thread will be waked after your handler function completed. I think that was your original intention (see here).
To try if this is a multi core effect set your system to be single core
#!/usr/bin/sudo bash
CPU_DIR="/sys/devices/system/cpu"
NEXT=$(( 1 - $( cat ${CPU_DIR}/cpu1/online ) ))
for d in /sys/devices/system/cpu/cpu*
do
CPU=${d##*/}
if [ ${CPU} == "cpuidle" ]; then continue; fi
if [ ${CPU} == "cpu0" ]; then continue; fi
echo -n $CPU $( cat $d/online )
echo "${NEXT}" >$d/online
echo " => " $( cat $d/online )
done
and try again. First call is going single core, second call back. You can also reboot using kernel parameter nosmp
or maxcpus=0
to disable SMP activation entirely (see here).
Just for documentation (see comments below): It turned out to be a multi core effect with the thread running on a different core and thus starting immediately.
Upvotes: 1