Skip to contentSkip to conversation

newbie questions about while (1) in kernel mode and spinlocks

DISCUSSION Robert Hancock 1 participant 1 message Dec 21, 2006 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 11 lines · Sorin Manolache

The Linux Device Drivers book says that a spin_lock should not be shared between a process and an interrupt handler. The explanation is that the process may hold the lock, an interrupt occurs, the interrupt handler spins on the lock held by the process and the system freezes. Why should it freeze? Isn't it possible for the interrupt handler to re-enable interrupts as its first thing, then to spin at the lock, the timer interrupt to preempt the interrupt handler and to relinquish control to the process which in turn will finish its critical section and release the lock, making way for the interrupt handler to continue.

When the timer interrupt finishes, it's not going to return control to the process, it's going to return control to what it interrupted which is the interrupt handler in your code which will just continue spinning. Interrupt handlers are not preemptible by anything other than other interrupt handlers (and then only in some cases) so it will sit spinning on that lock forever.

Signature · 3 lines
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/