Re: Why can't we sleep in an ISR?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Learning Linux wrote:
I have a very basic doubt here ... what makes it impossible to sleep
in an ISR? I mean, I know that the kernel preemption is disabled and
the kernel will panic, but I could not understand why?

The impossibility to sleep comes as a natural consequence of the fact that ISRs have to be fast.

An ISR has to be fast in order to allow other system tasks to happen. Otherwise it will do a lot of work (like busy waiting) and any other interrupts will fail to get handled. That would completely render the system unusable.

On the other hand, when you sleep in a given context, the scheduler is invoked. That means that the ISR routine would be replaced by a process from the scheduler's queue(s). But how would you ever know to reschedule the ISR? After all, it is asynchronous.

This is why ISRs (top halves) and tasklets/softirqs (bottom halves) are said to be running in interrupt context; processes are said to be running in process context.

Interrupt context has very strict rules like being unable to sleep or do a large amount of work (this will render the system unable and, quite likely, a panic would occur).

Hope this helps. You should be read Robert Love's excellent "Linux Kernel Development 2nd Edition". It is quite readable and has a pleasant way of showing you the basic kernel concepts. Chapter 6 is concerned with interrupts and interrupt handling routines (ISRs).

Razvan

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux