问题
I am very confuse to get why interrupt handler can't sleep? i got 2 views for the same issue:-
Interrupt Handler is not schedulable? Because it has no task_struct.
if the handler sleeps, then the system may hang because the system clock interrupt is masked and incapable of scheduling the sleeping process.
Are interrupt handlers schedule-able,
but while the lower priority system clock interrupt
is masked by these higher priority interrupts,
they cannot be scheduled?
Please give me a good example for the same.
回答1:
when interrupt occur, the processor gets into an exception state (Interrupt context). while this happens the scheduler is disabled until the processor exit this state. if you put a task into sleep, the task get into wait queue and tell the scheduler to dequeue another task. if it happens in interrupt context, there is no scheduler until we finish this context and the processor hangs because we never finished the interrupt. what happens exactly is processor depended. one solution for that is to run the actual interrupt code in thread - this is called threaded interrupts and this is one of the configuration in the real-time patch to make linux "hard real time"
回答2:
You can't sleep in interrupt handlers in Linux because they are not backed by a thread of execution. In other words, they aren't schedulable entities.
Most systems break interrupt processing into two halves, commonly called a top half and a bottom half. The top half runs very quickly, interrupting (and in fact running as) whatever was executing when the interrupt occurred-the top half has no thread itself. Consequently, the top half is unable to sleep, as there isn't anything to schedule back into when the sleep completes.
From Robert Love on Quora
来源:https://stackoverflow.com/questions/36215399/why-interrupt-handlers-isrs-cannot-sleep