Nvidia, TLS and __thread keyword -- an observation
Igor Sysoev
is at rambler-co.ru
Tue Jun 17 06:41:14 PDT 2003
On Tue, 17 Jun 2003, Marcel Moolenaar wrote:
> There's a definite advantage to supporting the __thread keyword in
> userland and we should add the support. It really isn't that hard,
> but it requires some thought and testing. In most cases you simply
> point your thread pointer between the control structure and the
> thread local segments.
If the thread implementation uses gs register to point to thread
specific data:
gs -> [ thread specific data ]
[ tls_array ]
then this C code
__thread int a; a = 1;
can be translated to
mov tls_key, %ecx
mov $gs:tls_array, %eax
mov (%eax,%ecx,4), %eax
mov $1, (%eax)
In FreeBSD we use gs to point to KSE specific data
gs -> [ KSE specific data ]
[ current thread ] -> [ thread specfic data ]
[ tls_array ]
and then same C code can be translate to
mov tls_key, %ecx
mov $gs:current_thread, %eax
mov tls_array(%eax), %eax
mov (%eax,%ecx,4), %eax
mov $1, (%eax)
And I think we should use this scheme not only in libkse but in libthr too
to be binary compatible.
Igor Sysoev
http://sysoev.ru/en/
More information about the freebsd-threads
mailing list