0

I have a requirement to print a message to kernel log in an Irq service routine, so it's in "interrupt context". I understand that printk is not recommended for this scenario, so what would be the best alternatives here? Thanks for if any suggestions.

I heard of one option about printk_deferred, I noticed this is used in scheduler, but haven't yet found where it's used in irq isr. Can anyone explain what's the difference between printk_deferred and printk?

Bill Randerson
  • 1,028
  • 1
  • 11
  • 29
  • 2
    Possible duplicate of [printk inside an interrupt handler , is it really that bad?](https://stackoverflow.com/questions/8738951/printk-inside-an-interrupt-handler-is-it-really-that-bad) – sawdust Nov 17 '17 at 02:21
  • Let's start with what interrupt do you wish to log? What if that interrupt is generated a couple thousand times in second? Do you really want to log every single action? Well... IMHO I would create a postponed action with tasklet, softirq or workqueue as it actually recommended. Take a look at any driver which has `request_irq` routine and there should be an IRQ handler, because it doesn't call the service function directly. – 0xDen Nov 17 '17 at 09:37
  • Thanks for the comment, @0xDen The interrupt is generated every 20ms, there're certain condition checks to print out the message, let's just say the print message occurs around every 10 minute. – Bill Randerson Nov 18 '17 at 17:36

1 Answers1

1

One common idea is from interrupt handler we can update variables or info to be printed and then from kernel thread print that value to kernel log buffer. This way handler will remain intact and our objective will also be achieved.

Hercules dd
  • 215
  • 1
  • 5