4

Does the Linux use nested interrupts?

I mean for example when serving interrupt from any device, can be allowed further interrupts in this routine? Or it comes to top and bottom half?

EDIT:

If Linux uses nested interrupt, how is cared about their stack/s?

Nik Novák
  • 569
  • 1
  • 9
  • 24
  • 1
    Possible duplicate of [Can an interrupt handler be preempted?](http://stackoverflow.com/questions/5934402/can-an-interrupt-handler-be-preempted) – Punit Vara Dec 30 '15 at 11:07

1 Answers1

5

Yes, the Linux interrupts are reentrant. https://unix.stackexchange.com/a/7172/40346

The Linux kernel is reentrant (like all UNIX ones), which simply means that multiple processes can be executed by the CPU. He doesn't have to wait till a disk access read is handled by the deadly slow HDD controller, the CPU can process some other stuff until the disk access is finished (which itself will trigger an interrupt if so).

Generally, an interrupt can be interrupted by an other interrupt (preemption), that's called 'Nested Execution'. Depending on the architecture, there are still some critical functions which have to run without interruption (non-preemptive) by completely disabling interrupts. On x86, these are some time relevant functions (time.c, hpet.c) and some xen stuff.

There are only two priority levels concerning interrupts: 'enable all interrupts' or 'disable all interrupts', so I guess your "high priority interrupt" is the second one. This is the only behavior the Linux kernel knows concerning interrupt priorities and has nothing to do with real-time extensions.

If an interruptible interrupt (your "low priority interrupt") gets interrupted by an other interrupt ("high" or "low"), the kernel saves the old execution code of the interrupted interrupt and starts to process the new interrupt. This "nesting" can happen multiple times and thus can create multiple levels of interrupted interrupts. Afterwards, the kernel reloads the saved code from the old interrupt and tries to finish the old one.

Community
  • 1
  • 1
Benedikt Köppel
  • 4,853
  • 4
  • 32
  • 42
  • Thank you for your answer. I have question connected with nested interrupts. What happens with stack? How stack is used if system supports nested interrupt? Has every interrupt its own stack? – Nik Novák Dec 30 '15 at 11:09
  • AFAIK, as @Koppel points out above, nested interrupts _of different IRQ lines_ are allowed. NOT the same IRQ! IOW, when handling interrupt 'n', interrupt 'n' will be turned Off, i.e., it is non-reentrant. Of course, top and bottom halves can still execute concurrently.. Also, no, every interrupt does not have it;s own stack: there is (usually) a separate IRQ stack maintained by the OS – kaiwan May 23 '16 at 07:20
  • Related: [How is CR8 register used to prioritize interrupts in an x86-64 CPU?](https://stackoverflow.com/q/51490552) - It's not as bad / simplistic as interrupts on/off anymore. – Peter Cordes Apr 21 '21 at 04:26
  • But Linux might not actually use CR8 interrupt priority stuff much/at all, or at least didn't back in 2007. (https://www.realworldtech.com/forum/?threadid=79538&curpostid=79545) – Peter Cordes Apr 21 '21 at 04:40