Thread Local Storage

Daniel Eischen eischen at vigrid.com
Mon Mar 29 14:36:09 PST 2004


On Mon, 29 Mar 2004, Doug Rabson wrote:

> On Monday 29 March 2004 22:56, Daniel Eischen wrote:
> > On Mon, 29 Mar 2004, Doug Rabson wrote:
> > > On Monday 29 March 2004 22:26, Daniel Eischen wrote:
> > > > On Mon, 29 Mar 2004, Doug Rabson wrote:
> > > > > Surely the GNU TLS ABI is preferable? It generates much smaller
> > > > > code and needs many fewer relocations.
> > > >
> > > > No, we don't want an LDT for every thread and don't want
> > > > to force a syscall for a thread switch.
> > >
> > > But the code it generates is at least twice the size for dynamic
> > > TLS. It seems that the GNU people have done a better job defining
> > > the TLS abi for i386.
> >
> > About the only thing that uses TLS that I know is nvidia's
> > openGL.  If you design an API correctly, there's no need
> > for TLS.  I would hope that it's usage would be limited.
> 
> I'd quite like to see us use it for stuff like errno, _res and other 
> uglification currently in libc. Not until the 6.x timeframe though.

I'd like to see libc free of TLS ;-)  The _res stuff can be
avoided by modifying the implementation to use thread-safe
APIs.  The current _res stuff can _almost_ be eliminated
by passing using pthread_getspecific() once and passing
the _res around internal APIs.  That's actually a pretty
simple change.

> 
> >
> > > You don't need a syscall at thread switch if you do something like:
> > >
> > > 	_thread_switch(...)
> > > 	{
> > > 		if (tcb doesn't have LDT entry) {
> > > 			if (!free LDT entries)
> > > 				steal LDT entry from non-running thread;
> > > 			allocate LDT entry and point it at TLS goop for tcb.
> > > 		}
> > > 		load_gs(tcb's LDT sel);
> >
> > That's a system call on amd64.
> 
> I'm not quite up to speed on amd64. So in 64-bit mode it doesn't really 
> have an LDT at all, is that right?

I'm not sure, but you have to make a system call to set it
or it's equivalent (amd64_set_fsbase()).

-- 
Dan Eischen



More information about the freebsd-threads mailing list