Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printk inside an interrupt handler , is it really that bad?

everybody knows that interrupt handler should be short as possible. and adding functions like printk for debugging inside an interrupt handler is something that shouldn't be done. Actually, I tried it before when I was debugging the linux kernel for an interrupt driven char device I written, and it wrecked the timing of the driver.

The question I have, is why this is happening ? printk function is buffered ! it means, as far as I understand that the data is inserted in to a queue, and it's being handled later, most probably after the interrupt handler is finished.

So why doesn't it work ?

like image 742
stdcall Avatar asked Jan 05 '12 07:01

stdcall


People also ask

Can you sleep in interrupt handler?

You can't sleep in interrupt handlers in Linux because they are not backed by a thread of execution. In other words, they aren't schedulable entities. Most systems break interrupt processing into two halves, commonly called a top half and a bottom half.

Can an interrupt handler be interrupted?

However, such kernel control paths may be arbitrarily nested; an interrupt handler may be interrupted by another interrupt handler, thus giving raise to a nested execution of kernel threads.

What is the function of interrupt handler?

The job of the interrupt handler is to service the device and stop it from interrupting. Once the handler returns, the CPU resumes what it was doing before the interrupt occurred. The Solaris 7 DDI/DKI provides a bus-architecture independent interface for registering and servicing interrupts.

Can interrupt be preempted?

If you mean, can interrupts be preempted by tasks, then the answer is quite definitely no. Task scheduling is controlled by software, and tasks run when no interrupts are executing, just like a non RTOS program can only run when no interrupts are executing.


1 Answers

The printk function is not just inserting into a queue/buffer -- assuming the log level is high enough, the output from printk will be emitted to the console immediately, as part of the call to printk. This is especially slow if the console is, say, on a serial port. But in any case, printk does introduce pretty substantial overhead and can affect timing.

If you have a timing critical place where you want to get some debug output, you can look at using the trace_printk function in modern kernels. This actually does just put input into the trace ringbuffer, and you can read it later. Take a look at this article for full details.

like image 186
Roland Avatar answered Sep 18 '22 11:09

Roland