64-bit atomic ops on 32-bit CPU -- was: ZFS .. on PowerPC ?
Marcel Moolenaar
xcllnt at mac.com
Wed Sep 24 22:11:10 UTC 2008
On Sep 24, 2008, at 2:07 PM, Marcel Moolenaar wrote:
> Ok. Let's assume we lose the reservation and we're
> forced to loop and try again. Step 2 then reads W2,
> which on a retry is the word written in step 4. As
> such, if we have to loop and retry X times, then
> the atomic increment would increment by X and not
> 1.
>
> I don't think an unconditional write to W2 will
> work if we don't preserve the origional value of
> W2.
What about the following algorithm:
/* Atomically read 64-bit entity. */
1:
lwarx P[0]
ldw P[1]
stwcx P[0]
b.fail 1
/* Perform operation on 64-bit entity. */
{Q[0],Q[1]} = operation({P[0],P[1]})
/*
* Pseudo-atomically write 64-bit value.
* The 64-bit entity may have been clobbered
* by this time.
*/
lwarx t[0]
ldw t[1]
cmp t[0],P[0]
b.ne 1
cmp t[1],P[1]
b.ne 1
stw Q[1]
stwcx Q[0]
b.ok 2
stw P[1]
b 1
2:
sync
ret
Interrupts should be disabled to minimize the time
the 64-bit entity is inconsistent WRT non-atomic
reads.
Thoughts?
--
Marcel Moolenaar
xcllnt at mac.com
More information about the freebsd-ppc
mailing list