2

If a spinlock is held in the process context. What will happen if the same spinlock is required in an interrupt context?

Either the interrupt handler wait until the spinlock is released by the process, or the interrupt handler will schedule it on another processor? As mentioned in the following thread in stackoverflow.

But still the question will be the same, the interrupt handler will wait for the spinlock to be released? Isn't it?

Community
  • 1
  • 1
one.prav
  • 51
  • 5
  • I'd suggest adding any sample code that you can to this Q. Otherwise it might get closed for lack of effort/research. – slm Jun 30 '14 at 15:03
  • I don't have any sample code, I am curious if there is any example to understand this. I have gone through "LKD" but it tells that if you are sharing data between tasklet and interrupt handler, you must use the spinlock. – one.prav Jun 30 '14 at 16:30

1 Answers1

3

If a spinlock is held in the process context. What will happen if the same spinlock is required in an interrupt context?

In short, this is a bad design and will lead to deadlock. That's why there are APIs spin_lock_irq/spin_lock_irqsave that disable the interrupts before acquiring such locks and avoids such contentions.

brokenfoot
  • 11,083
  • 10
  • 59
  • 80
  • If I am not wrong then it means that we have to disable the interrupts on all the CPU. But I think that is not supposed to do. – one.prav Jun 30 '14 at 17:05
  • As I given a link in above question where "Roland" says that it is quite general and good idea to share the lock between two contexts. – one.prav Jun 30 '14 at 17:08
  • Yes, that is good but I think you couldn't correlate to what he said & what I meant. If you have such cases where the lock is shared between a process and an interrupt, you should disable the interrupts before acquiring the lock (using the APIs I mentioned above). – brokenfoot Jun 30 '14 at 17:33
  • Is that mean that interrupt must be disabled on all the processor? In that case interrupt will be lost or buffered somewhere? – one.prav Jun 30 '14 at 17:56
  • No, not all the processors, only the one on which the lock is currently held. About interrupts being lost when interrupts are disabled, read my ans here: http://stackoverflow.com/a/22281817/1755108 – brokenfoot Jun 30 '14 at 18:29
  • 1
    still one doubt remains what would happen if this interrupt is scheduled on another processor? while on the current processor lock is already hold by a process. – one.prav Jun 30 '14 at 18:45