Date: Wed, 24 Sep 2008 15:11:08 -0700 From: Marcel Moolenaar <xcllnt@mac.com> To: Rafal Jaworowski <raj@semihalf.com> Cc: freebsd-ppc@freebsd.org Subject: Re: 64-bit atomic ops on 32-bit CPU -- was: ZFS .. on PowerPC ? Message-ID: <2AD479FA-794C-421A-AF53-C10BBF0826DC@mac.com> In-Reply-To: <111399E3-2BC7-4724-8AFB-A40F2A47E66D@mac.com> References: <B4645B39-9D9D-49C5-8F69-55704CD2F6AA@delfi-konsult.com> <60ACBA3B-927C-4F2C-8680-A6B40B81E06C@mac.com> <48DA84D5.4010109@semihalf.com> <C725D17E-E199-4E70-BE56-07BD21783A7A@mac.com> <48DA99F8.7070904@semihalf.com> <111399E3-2BC7-4724-8AFB-A40F2A47E66D@mac.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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@mac.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2AD479FA-794C-421A-AF53-C10BBF0826DC>