Messages in this thread |  | | Date | Wed, 21 Apr 1999 17:41:29 -0400 | | From | Johannes Erdfelt <> | | Subject | Re: mutexs for synchronization between kernel threads? |
| |
On Thu, Apr 22, 1999, V Ganesh <ganesh@vxindia.veritas.com> wrote: > > From: Johannes Erdfelt <jerdfelt@sventech.com> > > Date: Wed, 21 Apr 1999 15:22:35 -0400 > > > > I've spent the better part of a day looking for information on mutexs in > > the kernel. I'm a bit more confused now than when I started since the > > by a strange coincidence, so have I :) so I might be wrong, take whatever > I say with a pinch of salt. > > > void interrupt_handler(...) > > { > > unsigned long flags; > > > > spin_lock_irqsave(&spinlock, flags); > > /* Stuff on structure */ > > spin_unlock_irqrestore(&spinlock, flags); > > } > > since you are already inside the interrupt handler, (and presumably there > are no other interrupt handlers accessing the same structure), all you > have to protect against are your threads. no need to save irq. so > spin_lock and spin_unlock should be adequate. > > > #define lock_struct(flags) \ > > spin_lock_irqsave(&spinlock, flags); \ > > down(&lock); > > this looks like overkill since the spinlock also provides mutual exclusion > for the thread accesses. semaphores are BLOCKING primitives which should > be used only when you might be holding the resource for a long time. since > you are accessing the structure from an interrupt handler, I assume that > your critical regions are small. otherwise you might keep your interrupt > handler spinning for a long time. > spin_lock_irqsave(&spinlock, flags) should be sufficient to ensure mutual > exclusion in the threads. you don't need the semaphore. > besides, it makes me nervous to see a down() after acquiring a spinlock. > down could block, and blocking while holding a spinlock is not allowed > because it can cause deadlocks. of course your code doesn't look likely > to deadlock, but it's better to avoid such constructs altogether.
Well, under 2.2.6 spin_lock and spin_unlock in the non SMP case are NOOPS (do { } while(0)). This is not what I want.
I understand that semaphores probably aren't the appropriate thing to use here, but there doesn't seem to be a true mutex style construct. Plus that fact they initialize semaphore's with MUTEX definately is confusing.
I guess what I want are spinlocks, but the kernel spinlock implementation seems to be created for protecting across multiple CPU's, not across multiple context's of execution (thread's)
JE
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
|  |