Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was reading "Linux device drivers, 3rd edition" and don't completely understand a part describing interrupt handlers. I would like to clarify:

  • are the interrupt handlers in Linux nonpreemptible?
  • are the interrupt handlers in Linux non-reentrant?

I believe I understand the model of Top/Bottom halves quite well, and according to it the interrupts are disabled for as long as the TopHalf is being executed, thus the handler can't be re-entered, am I right?

But what about high priority interrupts? Are they supported by vanilla Linux or specific real-time extensions only? What happens if a low priority interrupt is interrupted by high priority one?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer

Nonpreemptible means that those handlers cannot be interrupted by another interrupt.

For non-preemtible handlers, reentrance is a non issue since you cannot interrupt them in the first place.

As to what the kernel does, just check wag's answer, I can't comment like he does on this topic.

share|improve this answer
    
Actually, according to makelinux.net/ldd3/chp-10-sect-2.shtml only fast interrupts (those that were requested with the SA_INTERRUPT flag) are executed with all other interrupts disabled on the current processor –  Justin Ethier Feb 9 '11 at 17:38
    
@Justin: you're right of course, I made my comment more general - my point was theoretical: it aimed to address the meaning of nonpreemtible and reentrance. –  asoundmove Feb 9 '11 at 22:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.