[Question] race between spin_lock and spin_unlock

Will Deacon will.deacon at arm.com
Tue Jun 25 04:48:06 EDT 2013


On Tue, Jun 25, 2013 at 05:31:44AM +0100, Ming Lei wrote:
> On Tue, Jun 25, 2013 at 12:37 AM, Will Deacon <will.deacon at arm.com> wrote:
> > You mean, if you had two CPUs spinning on a lock held by a third CPU? In
> > this case, the third CPU would have to release the lock, then one of the
> > waiters would have to acquire it, complete its critical section and finally
> > release it before the other waiter had executed its wfe (about three
> > instructions)...
> 
> I mean the below situation:
> 
> CPU0										CPU1
> 
> spin_lock(&A)
> 	StoreExcl(lock->next)
> 											spin_unlock(&A)
> 												Store(&lock->owner)
> 												dsb_sev()
> 	interrupt comes
> 		- wfe() called in the
> 		irq handler

Is this just a vanilla wfe, or as part of a spin_lock? If it's part of a
spin_lock, then we'll do a sev when we unlock it. An opencoded wfe in an
interrupt handler sounds like a really bad idea anyway!

> 		- the sev() from CPU1
> 		is acked
> 	
> 	while(tickets.next != tickets.owner) {
> 		wfe();
> 		...
> 	}

Will



More information about the linux-arm-kernel mailing list