What is the difference between these two functions in Linux. I know that irqs_disabled() will return whether irqs are disabled or not and in_interrupt() will return whether you are in interrupt context or not. By default if you are in the interrupt context doesn't that mean irqs are disabled?
What are the scenarios where we use these functions specifically?
Consider these two cases:
1) There are platform that support nested interrupts, where one interrupt can occur when another hasn't returned yet. The priorities are configured in the interrupt controller registers.
2) Multi core CPU can process two interrupts at the same time, on at each core.
There are many reasons to check if a function is running in interrupt context, i.e: functions that uses thread locking, shall not be executed in interrupt context otherwise a deadlock will occur. These functions might want to check if it is interrupt context and abort with an error.
Also, there are many reasons to disable interrupts, i.e.: when you are writing to a memory structure that will be consumed by an interrupt handler, you might fill up the data in atomic mode (irqs disabled).
One place where both functions are used is in the spinlock function family because spinlocks are good to be used in interrupt context.
I got the answer.
#define in_irq() (hardirq_count())
#define in_softirq() (softirq_count())
#define in_interrupt() (irq_count())
The function in_interrupt() checks both the (hard)irq and softirq counters. Either you executing an interrupt handler or a softirq handler, this function returns a true.
But irqs_disabled() checks only for (hard)irqs disabled or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With