From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: <97d3416a6d7cadb18e8723fff3d2e2a8@hamnavoe.com> <81727c869e97f501968f868ee8794852@kw.quanstro.net> From: Venkatesh Srinivas Date: Mon, 21 Jun 2010 12:42:26 -0400 Message-ID: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=0016e6d77e5395570604898cfe27 Subject: Re: [9fans] interesting timing tests Topicbox-Message-UUID: 36132cf6-ead6-11e9-9d60-3106f5b1d025 --0016e6d77e5395570604898cfe27 Content-Type: text/plain; charset=UTF-8 On Mon, Jun 21, 2010 at 10:40 AM, erik quanstrom wrote: > void > lock(ulong *l) > { > ulong old; > ushort next, owner; > > old = _xadd(l, 1); > for(;;){ > next = old; > owner = old>>16; > old = *l; > if(next == owner) > break; > } > } > > void > unlock(ulong *l) > { > _xadd(l, 1<<16); > } Sure, that's reasonable in C; (i wasn't sure how to do it in asm for 8_a_, that was what I was asking about). Just also remember to provide xadd; the distribution 8a and 8l didn't support it last I checked. Just another observation, we can bypass the load of old in the uncontended case if we reverse old = *l and the compare/break in lock. Anyway, thoughts on this lock? -- vs --0016e6d77e5395570604898cfe27 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Mon, Jun 21, 2010 at 10:40 AM, erik quanstrom= <quanstro@qu= anstro.net> wrote:
void
lock(ulong *l)
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0ulong old;
=C2=A0 =C2=A0 =C2=A0 =C2=A0ushort next, owner;

=C2=A0 =C2=A0 =C2=A0 =C2=A0old =3D _xadd(l, 1);
=C2=A0 =C2=A0 =C2=A0 =C2=A0for(;;){
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0next =3D old;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0owner =3D old>&g= t;16;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0old =3D *l;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if(next =3D=3D owne= r)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0break;
=C2=A0 =C2=A0 =C2=A0 =C2=A0}
}

void
unlock(ulong *l)
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0_xadd(l, 1<<16);
}

Sure, that's reasonable in C; (i wasn= 't sure how to do it in asm for 8_a_, that was what I was asking about)= . Just also remember to provide xadd; the distribution 8a and 8l didn't= support it last I checked.

Just another observation, we can bypass the load of old= in the uncontended case if we reverse old =3D *l and the compare/break in = lock.=C2=A0

Anyway, thoughts on this lock?

-- vs

--0016e6d77e5395570604898cfe27--