Re: TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)

2006-06-08 Thread Richard Henderson
On Sun, Jun 04, 2006 at 02:03:05PM +0200, Piotr Wyderski wrote:
> fs:[0x14] is a per-thread 32-bit word available for applications,
> so you can store a pointer to your own TLS array there. 

I don't think we can hijack this.

> fs:[0x2c] points to a Windows-specific TLS array, so you can
> make use of it, too, but you must conform to the limitations of
> the WinAPI constraints related with TLS management.

Given that microsoft's openmp implementation is also limited
in this way, I don't think that's a real problem.

> >Now, for an idea of how much work it represents... perhaps someone  
> >here can tell us?

The biggest piece of work is in the linker, noticing the
existance of the .tls section and setting up the IMAGE_TLS_DIRECTORY
structure, and related activities.  There's a value I'll name
"tls_handle" that is created as part of this; ideally that would
use whatever name vc++ does in its object files.  There's also
arranging for tls symbol references to resolve to the offset of
the symbol in the .tls section, rather than some sort of absolute
address.

On the compiler side, you'd need to replace legitimize_tls_address
with a windows implementation.  You'd need some new patterns, since
you'll be wanting to generate something akin to

movl  %fs:0x2c, %eax// global array base
movl  tls_handle, %edx  // value from TlsAlloc
movl  (%eax, %edx, 4), %eax // local array base

addl  $variable, %eax   // compute address

movl  variable(%eax), %ecx  // when loading/storing a value


r~


Re: TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)

2006-06-06 Thread Henry Kar Ming Chan
Hi, all,

After I refer to the Intel paper titled "Threading
Methodology : Principles and Practices" versin 2.0
published in 2003, I note the following message in the
article mentioning:(from page 22, web site :
http://cache-www.intel.com/cd/00/00/21/93/219349_threadingmethodology.pdf)

_
OpenMP and thread libraries have mechanisms to create
thread-local storage. Threads can safely access this
storage without synchronization. Use the following
declarations to create thread-local storage in
different threading models:
• In OpenMP use threadprivate
• In Win32, use the TlsAlloc() function
• In Pthreads, use the pthread_key_create function
__

>From the above description, I think that "gfortran
with OpenMP" compiler can also implemented the TLS
using Win32 threads or Pthreads.

Please comment on the above implementation methods.

Thanks.

Best regards,
Henry Kar Ming Chan
 
--- FX Coudert <[EMAIL PROTECTED]> wrote:

> [First, a warning: I'm neither an expert in TLS, nor
> in Windows nor  
> in GCC guts
> 
> > can we have chance to solve the
> > problem of threadprivate by adding the TLS support
> to
> > mingw32?
> 
> The support for TLS (Thread Local Storage) would
> probably come from  
> the compiler itself. Windows has TLS (see for
> example http:// 
>
dotnet.di.unipi.it/Content/sscli/docs/doxygen/pal/localstorage_8c-
> 
> source.html and
> http://www.ddj.com/dept/cpp/184403874, or the MSDN  
> documentation at
> http://msdn.microsoft.com/library/default.asp?url=/ 
> library/en-us/dllproc/base/tlsalloc.asp), so you'd
> "only" need to  
> teach GCC how to call that.
> 
> Now, I don't have competence, time and motivation to
> do that. So, if  
> my analysis above is correct, there are three things
> you can do: ask  
> around here if someone is interested in this and is
> planning to do  
> it; do it yourself, if you have the competence; find
> someone you  
> know, that you have leverage on, to do it :)
> 
> Now, for an idea of how much work it represents...
> perhaps someone  
> here can tell us?
> 
> FX
> 


Send instant messages to your online friends http://uk.messenger.yahoo.com 


Re: TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)

2006-06-04 Thread Piotr Wyderski

FX Coudert wrote:

The support for TLS (Thread Local Storage) would probably come from  
the compiler itself. Windows has TLS (see for example http:// 
dotnet.di.unipi.it/Content/sscli/docs/doxygen/pal/localstorage_8c- 
source.html and http://www.ddj.com/dept/cpp/184403874, or the MSDN  
documentation at http://msdn.microsoft.com/library/default.asp?url=/ 
library/en-us/dllproc/base/tlsalloc.asp), so you'd "only" need to  
teach GCC how to call that.


fs:[0x14] is a per-thread 32-bit word available for applications,
so you can store a pointer to your own TLS array there. 
fs:[0x2c] points to a Windows-specific TLS array, so you can

make use of it, too, but you must conform to the limitations of
the WinAPI constraints related with TLS management. IMO the
best would be the offset 0x14 + a custom design of TLSes (BTW,
it must be extremely fast! Many applications get their TLS values
very often).

Now, for an idea of how much work it represents... perhaps someone  
here can tell us?


I don't know much about GCC internals, but I use my own
implementation based on inline assembly and the implementation
took, hm, 20 minutes?
   
   Best regards

   Piotr Wyderski



TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)

2006-06-04 Thread FX Coudert
[First, a warning: I'm neither an expert in TLS, nor in Windows nor  
in GCC guts



can we have chance to solve the
problem of threadprivate by adding the TLS support to
mingw32?


The support for TLS (Thread Local Storage) would probably come from  
the compiler itself. Windows has TLS (see for example http:// 
dotnet.di.unipi.it/Content/sscli/docs/doxygen/pal/localstorage_8c- 
source.html and http://www.ddj.com/dept/cpp/184403874, or the MSDN  
documentation at http://msdn.microsoft.com/library/default.asp?url=/ 
library/en-us/dllproc/base/tlsalloc.asp), so you'd "only" need to  
teach GCC how to call that.


Now, I don't have competence, time and motivation to do that. So, if  
my analysis above is correct, there are three things you can do: ask  
around here if someone is interested in this and is planning to do  
it; do it yourself, if you have the competence; find someone you  
know, that you have leverage on, to do it :)


Now, for an idea of how much work it represents... perhaps someone  
here can tell us?


FX