Thread (9 messages) 9 messages, 4 authors, 2006-08-30

RE: atomic operations in user space

From: Li Yang-r58472 <hidden>
Date: 2006-08-30 02:40:00

-----Original Message-----
From: Liu Dave-r63238
Sent: Wednesday, August 30, 2006 10:27 AM
To: Liu Dave-r63238; Li Yang-r58472; linuxppc-embedded@ozlabs.org;
linuxppc-dev@ozlabs.org
Subject: RE: atomic operations in user space
=20
quoted
[snip]
quoted
I surely know all the theories you mentioned clearly.  But
please do
quoted
look at the case I gave.  Correct me if I missed anything.  Thanks

All the lwarx and stwcx operate on the same address.
quoted
Task A		Task B
lwarx
// Get RESERVATION
quoted
			......
			lwarx
			stwcx
// RESERVATION cleared
quoted
			.....
			.....
			lwarx
// Get RESERVATION again
quoted
stwcx
//Note here: RESERVATION is valid, address is the same.
So the result is commited, no retry for task A
quoted
.....
			stwcx
//RESERVATION is cleared, retry atomic op for task B

Please be noted that reservation is only identified by
reservation bit
quoted
and address operated on.  So different lwarx's on the same
address,
quoted
quoted
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?
quoted
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.

Are you missing these important things?

-DAve
=20
I got it. I noticed that all of execption return in kernel did stwcx.
to clear the wrong reserved bit. See the source code.
=20
        .globl  ret_from_except_full
ret_from_except_full:
        REST_NVGPRS(r1)
        /* fall through */
=20
        .globl  ret_from_except
ret_from_except:
           ......
=20
restore:
        lwz     r0,GPR0(r1)
        lwz     r2,GPR2(r1)
        REST_4GPRS(3, r1)
        REST_2GPRS(7, r1)
=20
        lwz     r10,_XER(r1)
        lwz     r11,_CTR(r1)
        mtspr   SPRN_XER,r10
        mtctr   r11
=20
        PPC405_ERR77(0,r1)
        stwcx.  r0,0,r1                 /* to clear the reservation */
Ya, you found the point.  There is no problem for me about this
question.

- Leo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help