public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)
       [not found] <20060604050932.30946.qmail@web30506.mail.mud.yahoo.com>
@ 2006-06-04  9:09 ` FX Coudert
  2006-06-04 12:03   ` Piotr Wyderski
  2006-06-07  4:50   ` Henry Kar Ming Chan
  0 siblings, 2 replies; 4+ messages in thread
From: FX Coudert @ 2006-06-04  9:09 UTC (permalink / raw)
  To: Henry Kar Ming Chan; +Cc: GCC Development, fortran@gcc.gnu.org GFortran

[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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)
  2006-06-04  9:09 ` TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP) FX Coudert
@ 2006-06-04 12:03   ` Piotr Wyderski
  2006-06-08 21:52     ` Richard Henderson
  2006-06-07  4:50   ` Henry Kar Ming Chan
  1 sibling, 1 reply; 4+ messages in thread
From: Piotr Wyderski @ 2006-06-04 12:03 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)
  2006-06-04  9:09 ` TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP) FX Coudert
  2006-06-04 12:03   ` Piotr Wyderski
@ 2006-06-07  4:50   ` Henry Kar Ming Chan
  1 sibling, 0 replies; 4+ messages in thread
From: Henry Kar Ming Chan @ 2006-06-07  4:50 UTC (permalink / raw)
  To: FX Coudert, karminghenry; +Cc: GCC Development, fortran@gcc.gnu.org GFortran

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 <fxcoudert@gmail.com> 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 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP)
  2006-06-04 12:03   ` Piotr Wyderski
@ 2006-06-08 21:52     ` Richard Henderson
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2006-06-08 21:52 UTC (permalink / raw)
  To: Piotr Wyderski; +Cc: gcc

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~

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-06-08 21:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20060604050932.30946.qmail@web30506.mail.mud.yahoo.com>
2006-06-04  9:09 ` TLS on windows (was: Re: Gfortran on Windows (mingw32) with OpenMP) FX Coudert
2006-06-04 12:03   ` Piotr Wyderski
2006-06-08 21:52     ` Richard Henderson
2006-06-07  4:50   ` Henry Kar Ming Chan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).