4

I am doing one assignment where I have to write and interrupt handler for Keyboard. So in this assignment we have to log the key stroke so it is allowed to do File I/O and we are using Work queue for that.

I know it is not allowed to sleep in Interrupt handler and so we cannot use any file i/o or printk in interrupt handler.

So in real industry how to debug and interrupt handler OR what I can do if I want to debug something ?

user2958183
  • 41
  • 2
  • 6
  • Interrupt handlers are usually very short, sometimes even as short as setting some global variable and exiting. That's why they often don't need debug (the code is too simple to be wrong!). To know if the interrupt actually gets called you can check the variable it sets from outside the handler. – Shahbaz Nov 19 '13 at 21:18
  • But what if it is long. Assume I have interrupt handler which is doing some stuff except just setting on variable so is there any way of debugging. – user2958183 Nov 19 '13 at 22:26
  • I'm sorry I don't know if it is at all possible to debug an interrupt handler. But what I _can_ tell you for sure is that a long interrupt handler is not a good idea for many reasons. That's why they divide the work an interrupt needs to do in two parts, the bigger part of which is done outside the interrupt handler. A quick search [revealed](http://www.tldp.org/LDP/tlk/dd/interrupts.html) that: _Once the reason for the interrupt has been determined, the device driver may need to do more work. If it does, the Linux kernel has mechanisms that allow it to postpone that work until later._... – Shahbaz Nov 19 '13 at 23:08
  • _... This avoids the CPU spending too much time in interrupt mode. See the Device Driver chapter (Chapter [dd-chapter](http://www.tldp.org/LDP/tlk/dd/drivers.html)) for more details._ **Note: the linked book is quite old! You may want to search for a newer version.** – Shahbaz Nov 19 '13 at 23:08

1 Answers1

1

Yes! this is correct we can not use printk inside an ISR. As i studied in RTOS(Real time operating System) during interrupt handling it creates message log and save required information in the log file which you can see later.

The similar thing is also available for latest Kernel. Using trace_printk you can debug time critical place. I haven't used this before so no sample for this. You can follow this link to know more about trace_printk.

Rocoder
  • 1,083
  • 2
  • 15
  • 26