[M3devel] [M3commit] how to switch userthreads on/off

Mika Nystrom mika at async.caltech.edu
Wed Apr 29 18:22:36 CEST 2009


Jay:

I understand now.  I should do more research first.  libc_r is
a user-level threads package, and not a very good one at that.
The built-into-Modula-3 threads offer all the same facilities as
FreeBSD's libc_r, as well as much higher performance.  In view of that,
I think it's great that you've resurrected CM3's user threads.  
No reason not to use them on FreeBSD4.

Now to test on FreeBSD5.

I still don't quite understand why kernel threads should be faster
than user threads.  But since all I have at the moment is libc_r,
I can't back up my doubts with any numbers.

     Mika

Jay writes:
>--_2ce3dd88-b4b7-4b0b-8d3d-405d9122c9e1_
>Content-Type: text/plain; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>
> > But the memory allocator and garbage collector do it too=2C no?=20
>
>=20
>
>=20
>
>Right=2C the garbage collector runs a separate thread.
>
>=20
>
>
> > As for reaching the "thread locals"=2C there is one slightly crazy=20
> > idea that one could borrow from Sussman and Steele: add another=20
> > implicit argument to every Modula-3 routine. In that argument=2C=20
> > pass a pointer to the thread locals. For EXTERNAL calls (in or=20
>
>
>=20
>
>This is basically how it works already on many systems.
>
>Just not FreeBSD <5=2C where there's no kernel thread support for managing
>
>the register at thread switch time.
>
>=20
>
>Look at the assembly code for __thread on FreeBSD 5.
>
>=20
>
>Notice that they do dedicate a register to thread locals.
>
>So it is about the same as what you propose=2C but better because they use =
>a wierdo (segment) register that otherwise was unused. (Most other architec=
>tures can afford to give up a regular register. The "better" part is specif=
>ic to x86 having so few registers.)
>
>=20
>
>=20
>
>I'm hoping to lay most of the blame on FreeBSD 4.x pthread_get/setspecific.
>
>But there is still setjmp lurking in there=2C even on PM3=2C no matter user=
> or pthreads.
>
>=20
>
>=20
>
>Do you have numbers for FreeBSD 5 PM3 vs. CM3 pthreads?
>
>__thread should be faster than pthread_get/setspecific=2C but pthread_get/s=
>etspecific are probably also way better with kernel threads vs. FreeBSD 4 u=
>sermode pthreads..
>
>=20
>
>=20
>
>Olaf=2C your recall that FreeBSD userthreads were "fast"..is that based on =
>FreeBSD 4.x by chance? Maybe they don't have much advantage on any other sy=
>stem?
>
>You know...FreeBSD 4.x pthreads are also userthreads=2C not really a fair c=
>omparison maybe with other pthreads implementations and maybe give pthreads=
> a bad name?
>
>=20
>
>=20
>
> - Jay
>
>=20
>
>--_2ce3dd88-b4b7-4b0b-8d3d-405d9122c9e1_
>Content-Type: text/html; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
><html>
><head>
><style>
>.hmmessage P
>{
>margin:0px=3B
>padding:0px
>}
>body.hmmessage
>{
>font-size: 10pt=3B
>font-family:Verdana
>}
></style>
></head>
><body class=3D'hmmessage'>
>&nbsp=3B&gt=3B But the memory allocator and garbage collector do it too=2C =
>no? <BR>
>&nbsp=3B<BR>
>&nbsp=3B<BR>
>Right=2C the garbage collector runs a separate thread.<BR>
>&nbsp=3B<BR>
><BR>&nbsp=3B&gt=3B As for reaching the "thread locals"=2C there is one slig=
>htly crazy <BR>&nbsp=3B&gt=3B idea that one could borrow from Sussman and S=
>teele: add another <BR>&nbsp=3B&gt=3B implicit argument to every Modula-3 r=
>outine. In that argument=2C <BR>&nbsp=3B&gt=3B pass a pointer to the thread=
> locals. For EXTERNAL calls (in or <BR><BR>
>&nbsp=3B<BR>
>This is basically how it works already on many systems.<BR>
>Just not FreeBSD &lt=3B5=2C where there's no kernel thread support for mana=
>ging<BR>
>the register at thread switch time.<BR>
>&nbsp=3B<BR>
>Look at the assembly code for __thread on FreeBSD 5.<BR>
>&nbsp=3B<BR>
>Notice that they do dedicate a register to thread locals.<BR>
>So it is about the same as what you propose=2C but better because they&nbsp=
>=3Buse a wierdo (segment) register that otherwise was unused. (Most other a=
>rchitectures can afford to give up a regular register. The "better" part is=
> specific to x86 having so few registers.)<BR>
>&nbsp=3B<BR>
>&nbsp=3B<BR>
>I'm hoping to lay most of the blame on FreeBSD 4.x pthread_get/setspecific.=
><BR>
>But there is still setjmp lurking in there=2C even on PM3=2C no matter user=
> or pthreads.<BR>
>&nbsp=3B<BR>
>&nbsp=3B<BR>
>Do you have numbers for FreeBSD 5 PM3 vs. CM3 pthreads?<BR>
>__thread should be faster than pthread_get/setspecific=2C but pthread_get/s=
>etspecific are probably also way better with kernel threads vs.&nbsp=3BFree=
>BSD 4 usermode pthreads..<BR>
>&nbsp=3B<BR>
>&nbsp=3B<BR>
>Olaf=2C&nbsp=3Byour recall that FreeBSD userthreads were&nbsp=3B"fast"..is =
>that based on FreeBSD 4.x by chance? Maybe they don't have much advantage o=
>n any other system?<BR>
>You know...FreeBSD 4.x pthreads are also userthreads=2C not really a fair c=
>omparison maybe with other pthreads implementations and maybe give pthreads=
> a bad name?<BR>
>&nbsp=3B<BR>
>&nbsp=3B<BR>
>&nbsp=3B- Jay<BR>
>&nbsp=3B<BR></body>
></html>=
>
>--_2ce3dd88-b4b7-4b0b-8d3d-405d9122c9e1_--



More information about the M3devel mailing list