From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 20 Jan 2011 08:48:44 -0800 Message-ID: From: David Leimbach To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=0016e644ce4618f6b8049a49e8bc Subject: Re: [9fans] plan9 go output faults on 9vx with rfork Topicbox-Message-UUID: 9f876580-ead6-11e9-9d60-3106f5b1d025 --0016e644ce4618f6b8049a49e8bc Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jan 19, 2011 at 10:59 PM, ron minnich wrote: > OK, Pavel sent me a nice piece of code that implements cmpswap using a > gcc trick. I did not want to use the trick for a few reasons, and > thought to use futex instead, as it seemed appropriate. Weirdly > enough, I can not find a simple implementation of cmpswap that uses > futex, though I can find several papers describing how tricky futex > is, and one Linux person who told me that futex had evolved in ways > not necessarily to our advantage. > > Every time I'm ready to throw in the towel on Plan 9 and just go with > Linux I hit something like futex and it's back into the fray ... :-) > Actually the mutex implementations I've seen with futex use cmpswap. Also my understanding of futex is that it's just an API for a portion of what needs to be done to implement a fast user space mutex. Essentially you have to examine the value in user space, see that it's what you expect and move on unblocked. If the value differs from what is expected, you must block, and wait. This is why they're "tricky" :-). I do not see anything immediately wrong with using the compiler intrinsic functions that are supported pretty well across GNU, clang, Intel C/C++ and I think even Microsoft's compilers. I do think that gcc does not implement them for i386, or if it does, it does so with a library routine instead of the compiler just generating the assembly for that architecture's version. I've run smack into this problem myself just about 8 months ago, and it was due to Boost being built with a mismatched architecture from some other code that was built with another. The result was that since these builtins get resolved sometimes at link time, and sometimes at compile time, they don't behave like normal functions, and you get a mess. You've got to pick one mess, or implement your own multi-architecture library of cmpswap and like routines :-). > > So, I have committed changes to my vx32 repo and Pavel's sieve now > works on 9vx on a 32-bit linux vmware image. It should also work if > you build on freebsd. It should also work if you build on 64-bit linux > but there are no guarantees, since all this relies on some gcc > builtins. > > You can see what I've done if you look at my repo. > > BTW, the sieve ran to 17xxx on linux and then I got some kind of > malloc failure, I'll assume it's another 32-bit gc issue. I'm up to > 57917 on osx. > If your compiler is generating code for -march=i386, you could see some funny stuff on 32bit platforms. Better to use -march=i686. Might not come up, but it's something to look for. I really need to try this version of 9vx sometime instead of just thinking about it :-) Dave > > You're going to need Pavel's mods to go, I suppose. but that's another > story ... > > ron > > --0016e644ce4618f6b8049a49e8bc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Wed, Jan 19, 2011 at 10:59 PM, ron mi= nnich <rminnich@= gmail.com> wrote:
OK, Pavel sent me a nice piece of code that implements cmpswap using a
gcc trick. I did not want to use the trick for a few reasons, and
thought to use futex instead, as it seemed appropriate. Weirdly
enough, I can not find a simple implementation of cmpswap that uses
futex, though I can find several papers describing how tricky futex
is, and one Linux person who told me that futex had evolved in ways
not necessarily to our advantage.

Every time I'm ready to throw in the towel on Plan 9 and just go with Linux I hit something like futex and it's back into the fray ... :-)

Actually the mutex implementations I'= ve seen with futex use cmpswap. =A0Also my understanding of futex is that i= t's just an API for a portion of what needs to be done to implement a f= ast user space mutex. Essentially you have to examine the value in user spa= ce, see that it's what you expect and move on unblocked. =A0If the valu= e differs from what is expected, you must block, and wait. =A0This is why t= hey're "tricky" :-).

I do not see anything immediately wrong with using the = compiler intrinsic functions that are supported pretty well across GNU, cla= ng, Intel C/C++ and I think even Microsoft's compilers. =A0I do think t= hat gcc does not implement them for i386, or if it does, it does so with a = library routine instead of the compiler just generating the assembly for th= at architecture's version.

I've run smack into this problem myself just about = 8 months ago, and it was due to Boost being built with a mismatched archite= cture from some other code that was built with another. =A0The result was t= hat since these builtins get resolved sometimes at link time, and sometimes= at compile time, they don't behave like normal functions, and you get = a mess.

You've got to pick one mess, or implement your own = multi-architecture library of cmpswap and like routines :-).
=A0<= /div>

So, I have committed changes to my vx32 repo and Pavel's sieve now
works on 9vx on a 32-bit linux vmware image. It should also work if
you build on freebsd. It should also work if you build on 64-bit linux
but there are no guarantees, since all this relies on some gcc
builtins.

You can see what I've done if you look at my repo.

BTW, the sieve ran to 17xxx on linux and then I got some kind of
malloc failure, I'll assume it's another 32-bit gc issue. I'm u= p to
57917 on osx.

If your compiler is gener= ating code for -march=3Di386, you could see some funny stuff on 32bit platf= orms. =A0Better to use -march=3Di686. =A0Might not come up, but it's so= mething to look for.

I really need to try this version of 9vx sometime inste= ad of just thinking about it :-)

Dave
= =A0

You're going to need Pavel's mods to go, I suppose. but that's = another story ...

ron


--0016e644ce4618f6b8049a49e8bc--