Implementing TLS: step 1

Daniel Eischen eischen at vigrid.com
Fri Jun 20 13:46:07 PDT 2003


On Fri, 20 Jun 2003, Igor Sysoev wrote:
> 
> I'm wrong, this scheme does not allow to use the 1:1 model in libkse
> when kse_mailbox.km_curthread is always NULL.
> 
> We can implement such scheme on x86:
> 
> gs -> [ TP                 ] ---> [ TLS                    ]
>       [ struct kse_mailbox ]  +-> [ struct kse_thr_mailbox ]
>       [      .km_curthread ] -+
> 
> When UTS would switch to the next thread it should set thread's TLS:
> 
>      kse_mailbox.km_curthread = NULL;

FYI, The above has to be atomic.

>      gs:[0] = next_thr_tls;
>      kse_mailbox.km_curthread = next_kse_thr_mailbox;

FYI2, The above need not be atomic since upcalls are disabled
by the first line.

> kse_mailbox can be accessed via gs register. On amd64 scheme is the same
> except the use of fs register instead of gs.
> 
> 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:
> 
> TP -> [ TLS                    ]
>       [ struct kse_thr_mailbox ]
>       [                .tm_kse ] ---> [ struct kse_mailbox ]
> 
> 
> By the way how was kse_mailbox being found before gs register was used ?

We've used %gs ever since we supported multiple KSEs.
Before, it was just a port of libc_r with everything
global and only 1 KSE.

-- 
Dan Eischen



More information about the freebsd-threads mailing list