Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jun 2003 19:23:15 -0700
From:      Gareth Hughes <gareth@nvidia.com>
To:        'Alexander Kabaev' <kabaev@mail.ru>
Cc:        Daniel Eischen <eischen@pcnet.com>
Subject:   RE: NVIDIA and TLS
Message-ID:  <2D32959E172B8F4D9B02F68266BE421401A6D7EA@mail-sc-3.nvidia.com>

next in thread | raw e-mail | index | archive | help
On Mon, 16 Jun 2003 Alexander Kabaev wrote:
> 
> You do not understand. Whether or not it is better only time will tell.
> ELF TLS standard is defined in a way, that only a _specific_ threads
> implementation can reap full benefits, most other are penalized by the
> segment access reloads on every thread context switch.
>
> [snip]
> 
> So the choice is either to pay penalty implementing TLS through callable
> entry, or by making context switches more expensive than they have to
> be.
> 
> I am obviously not thrilled with the standard, but I guess I'll have
> live with it since I have nothing better to offer on my own anyway.

To save you the trouble, I'll copy the relevant information out
of Drepper's document (sections 3.4.2, 4.1.2, 4.2.2).

C code:

	extern __thread int x;

	&x;

Assembly code, General Dynamic access model:

	leal x@tlsgd(%ebx),%eax
	call __tls_get_addr@plt

C code:

	static __thread int x1;
	static __thread int x2;

	&x1;
	&x2;

Assembly code, Local Dynamic access model:

	leal x1@tlsldm(%ebx),%eax
	call __tls_get_addr@plt
	...
	leal x1@dtpoff(%eax),%edx
	...
	leal x2@dtpoff(%eax),%edx

I don't see any segment register use there, do you?  That's the
implementation of the dynamic TLS access models on x86
(specifically, the GNU variants, not the Sun variants).  You
implement __tls_get_addr() however you need to.  Only the static
access models require the use of %gs.  If you don't want to use
%gs, then go right ahead and only implement the dynamic access
models.  __thread variable access will be slower on FreeBSD in
some cases (those that could potentially use the static access
models), but you're free to implement whatever kind of thread
library you want, including one that does not touch nor use the
%gs segment register.

-- 
Gareth Hughes (gareth@nvidia.com)
OpenGL Developer, NVIDIA Corporation



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2D32959E172B8F4D9B02F68266BE421401A6D7EA>