4

I have a scenario where my driver needs to listen to two different interrupts from two different IRQ lines. Is it possible to register two different IRQs and install two different handlers for the single driver? What's the best way to achieve this?

P.S: This is Linux device driver and the both IRQs are not shared.

  • Could those who vote for off-topic please describe why they think it's off-topic? It's a perfectly valid Linux kernel question. – dirkt May 17 '17 at 11:07
  • I haven't voted, but kernel programming questions might be better moved to the programming site StackOverflow (which is what both closers so far have voted to do). U.S.E. leans more towards admins/users, even if this sometimes involves debugging the kernel code or trying to guess at the intention of its authors. – sourcejedi May 17 '17 at 11:50
  • "If your question is a programming question, requiring knowledge of programming languages other than unix shell scripting languages, ask on Stack Overflow." https://unix.stackexchange.com/help/on-topic – sourcejedi May 17 '17 at 11:53
  • @sourcejedi: But it's not a programming question. It doesn't involve a particular programming language, it's not a question about how to write something in a particular programming language, it's a question about how the Linux kernel works. That the Linux kernel happens to be written in C is not important for this question. – dirkt May 17 '17 at 14:45
  • @dirkt "What's the best way to achieve this?" = code. – sourcejedi May 17 '17 at 14:54
  • @sourcejedi: Funnily enough, your answer has no code. Should I now downvote it? :-) – dirkt May 17 '17 at 14:58
  • @dirkt the OP didn't know whether it could be answered without describing code or not. And I'd say my answer does describe code. I describe details of how you "synchronize" with interrupt handlers. I would have formatted "spinlock irqsave" as code if I'd bothered to look up the exact spelling, which is the least important part, and would be required knowledge regardless of how many interrupt handlers you installed. I only have this knowledge from studying Linux kernel programming. If I only read LWN.net without having studied any kernel programming, I would not have this confidence. – sourcejedi May 17 '17 at 15:14

2 Answers2

1

register two different IRQs and install two different handlers for the single driver

"It's just that easy". The answer to "is it possible" is "Yes".


Device interrupt rountines will not interrupt each other on the same CPU.

According to LDD3 (this is quite old now), a single interrupt routine could be assured that it did not run on multiple CPUs simultaneously. I'm not sure what was meant by this - I can't imagine it applies to timer interrupts.

In your driver, I would expect it to be possible for the different interrupt routines to run at the same time, on different CPUs.

However the typical "spin lock irqsave" to achieve mutual exclusion where necessary, should still work fine in this case.

You might want to double-check you have the NMI watchdog, and lockdep enabled on your test system :). The NMI watchdog will trigger if a cpu gets stuck spinning inside an interrupt routine.

https://static.lwn.net/images/pdf/LDD3/ch10.pdf

sourcejedi
  • 50,249
1

This is totally possible. When registering an interrupt handler, the driver gives the kernel the address of a function to call when the interrupt triggers. A driver can set up as many interrupts as it wants, and all can point to the same service routine or they can all point to their own (or some other combination of things).

See this answer for a bit more detail on how interrupts are actually handled.

Steve
  • 171