atomic operations in user space

Li Yang-r58472 LeoLi at freescale.com
Wed Aug 30 12:28:10 EST 2006


> -----Original Message-----
> From: Liu Dave-r63238
> Sent: Wednesday, August 30, 2006 10:17 AM
> To: Li Yang-r58472; linuxppc-embedded at ozlabs.org;
linuxppc-dev at ozlabs.org
> Subject: RE: atomic operations in user space
> 
> [snip]
> > I surely know all the theories you mentioned clearly.  But
> > please do look at the case I gave.  Correct me if I missed
> > anything.  Thanks
> >
> > All the lwarx and stwcx operate on the same address.
> >
> > > Task A		Task B
> > > lwarx
> > // Get RESERVATION
> > > 			......
> > > 			lwarx
> > > 			stwcx
> >
> > // RESERVATION cleared
> > >
> > > 			.....
> > > 			.....
> > > 			lwarx
> >
> > // Get RESERVATION again
> > > stwcx
> >
> > //Note here: RESERVATION is valid, address is the same.
> > So the result is commited, no retry for task A
> >
> > > .....
> > > 			stwcx
> > //RESERVATION is cleared, retry atomic op for task B
> >
> > Please be noted that reservation is only identified by
> > reservation bit and address operated on.  So different
> > lwarx's on the same address, may be considered as the same
> > reservation.
> 
> Is this your reason we cannot do atomic operation in user space?
> 
> How about the kernel space? You can image it.
> The context switching as above also happen in kernel space,
> Why we can do atomic operation in kernel space, not do in user space?
>

There are substantial different between kernel and user control path.
First, interrupt can't be interrupted by user process.  Second, context
switch can be explicitly controlled in kernel, but not in user space.

> You are assuming the context switching cause the reservation broken.
> but we can do atomic operation in kernel space.  The context switching
> really is the execption of processor, If we can clear the wrong
RESERVATION
> before exception return, I think we can solve this problem. We can
dummy
> stwcx. before exception return or the processor automaticly clear the
> reservation in exception.

I assume stwcx is a costing instruction, and I don't see such code
indeed.

- Leo



More information about the Linuxppc-embedded mailing list