Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Jun 2003 06:36:44 +0800
From:      "David Xu" <davidxu@freebsd.org>
To:        "Igor Sysoev" <is@rambler-co.ru>, "Julian Elischer" <julian@elischer.org>
Cc:        threads@freebsd.org
Subject:   Re: Implementing TLS: step 1
Message-ID:  <002b01c3377c$6ebcb880$0701a8c0@tiger>
References:  <Pine.BSF.4.21.0306202226410.26177-100000@is>

next in thread | previous in thread | raw e-mail | index | archive | help

----- Original Message -----=20
From: "Igor Sysoev" <is@rambler-co.ru>
To: "Julian Elischer" <julian@elischer.org>
Cc: <threads@freebsd.org>
Sent: Saturday, June 21, 2003 2:27 AM
Subject: Re: Implementing TLS: step 1


> On Fri, 20 Jun 2003, Julian Elischer wrote:
>=20
> > On Fri, 20 Jun 2003, Igor Sysoev wrote:
> >=20
> > > If we could sacrifice our current thread compatibility in 5.0-5.1
> > > then we could change kse_mailbox from
> > >=20
> > >         struct kse_mailbox {
> > >            int                     km_version;     /* Mailbox =
version */
> > >            struct kse_thr_mailbox  *km_curthread;  /* Current =
thread */
> > >            ...
> > >=20
> > > to
> > >     =20
> > >         struct kse_mailbox {=20
> > >            struct kse_thr_mailbox  *km_curthread;  /* Current =
thread */
> > >            int                     km_version;     /* Mailbox =
version */
> > >            ...
> > >=20
> > > then x86's gs would still point to kse_mailbox, and gs:[0] would =
be
> > > and TP pointer.  Also we need to modify
> > >=20
> > >      struct kse_thr_mailbox {
> > > +          void              *tls;
> > >            ucontext_t        tm_context;     /* User thread =
context */
> > >            ...
> > >=20
> > > And the static TLS must be allocated before kse_thr_mailbox.
> >=20
> > Yes.
> > This is what I was thinking...
>=20
> I'm wrong, this scheme does not allow to use the 1:1 model in libkse
> when kse_mailbox.km_curthread is always NULL.
>=20
> We can implement such scheme on x86:
>=20
> gs -> [ TP                 ] ---> [ TLS                    ]
>       [ struct kse_mailbox ]  +-> [ struct kse_thr_mailbox ]
>       [      .km_curthread ] -+
>=20
> When UTS would switch to the next thread it should set thread's TLS:
>=20
>      kse_mailbox.km_curthread =3D NULL;
>      gs:[0] =3D next_thr_tls;
>      kse_mailbox.km_curthread =3D next_kse_thr_mailbox;
>=20
> kse_mailbox can be accessed via gs register. On amd64 scheme is the =
same
> except the use of fs register instead of gs.
>=20
> However on sparc64, ia64 and alpha TP is in the register but not
> in the memory so we need introduce the new field tm_kse in =
kse_thr_mailbox
> to find kse_mailbox:
>=20
> TP -> [ TLS                    ]
>       [ struct kse_thr_mailbox ]
>       [                .tm_kse ] ---> [ struct kse_mailbox ]
>=20
>=20
> By the way how was kse_mailbox being found before gs register was used =
?
>=20

In libpthread, a LDT entry is allocated and %gs is loaded as this value
when libpthread is being initialized. For newly created kse, when an
upcall is made at first time for that kse, in userland upcall handler,
the %gs will be loaded with its new value which libpthread already
allocated for it and put it in kse structure, keep in mind when=20
kernel is doing upcall, it will always push current kse pointer to
user stack and then calls userland upcall handler, so the handler
can always find its kse, and find its %gs value in kse structure.

>=20
> Igor Sysoev
> http://sysoev.ru/en/
>=20
> _______________________________________________
> freebsd-threads@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-threads
> To unsubscribe, send any mail to =
"freebsd-threads-unsubscribe@freebsd.org"
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?002b01c3377c$6ebcb880$0701a8c0>