rfc:tls

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:tls [2008/08/26 14:25]
lbarnaud .
rfc:tls [2017/09/22 13:28] (current)
Line 5: Line 5:
   * Status: Under Discussion   * Status: Under Discussion
   * First Published at: http://marc.info/?l=php-internals&m=121893972814818&w=2   * First Published at: http://marc.info/?l=php-internals&m=121893972814818&w=2
-  * Initial patch: http://arnaud.lb.s3.amazonaws.com/__thread-tls.patch +  * Initial patch: http://gist.github.com/659731 
-  * Current patch: http://arnaud.lb.s3.amazonaws.com/__thread-tls-2.patch+  * Current patch: http://gist.github.com/659724
  
 Currently ZTS builds are slower than non-ZTS builds. This RFC is about avoiding some of the major overhead of ZTS builds by using native thread local storage. Currently ZTS builds are slower than non-ZTS builds. This RFC is about avoiding some of the major overhead of ZTS builds by using native thread local storage.
Line 34: Line 34:
 Unfortunately the TLS model used in these tests was the static model, which is restrictive, and in particular does not allow to use it in shared libraries which will be loaded dynamically. (c.f [[tls#tls_internals|TLS internals]] bellow). Unfortunately the TLS model used in these tests was the static model, which is restrictive, and in particular does not allow to use it in shared libraries which will be loaded dynamically. (c.f [[tls#tls_internals|TLS internals]] bellow).
  
-For the PHP module to be able to be loaded at runtime in Apache or an other server with this patch enabled, it has to be built with the static TLS model (on gcc, -ftls-model=global-dynamic), which also requires to build position independent code. While the last makes a big difference on IA-32, this is the default on x86_64 and the results on bench.php on an unpatched PHP are the same as IA-32/PIC builds.+For the PHP module to be able to be loaded at runtime in Apache or an other server with this patch enabled, it has to be built with the dynamic TLS model (on gcc, -ftls-model=global-dynamic), which also requires to build position independent code. While the last makes a big difference on IA-32, this is the default on x86_64 and the results on bench.php on an unpatched PHP are the same as IA-32/PIC builds.
  
 Native TLS can be enabled with %%--with-tsrm-__thread-tls%% or %%--with-tsrm-full__thread-tls%%. The last declares globals statically instead of making them pointers. Native TLS can be enabled with %%--with-tsrm-__thread-tls%% or %%--with-tsrm-full__thread-tls%%. The last declares globals statically instead of making them pointers.
Line 91: Line 91:
 ===== Windows ===== ===== Windows =====
  
-Dynamically loaded DLLs can use TLS starting with Windows Vista and Server 2008. But there is a restriction: TLS variables can't be exported, which means that they can't be accessed outside of the DLL. CLI and ISAPI SAPIs works with TLS enabled, but they must be built like this is done on other platforms, with all code embeded in the executable/library. The same apply for extension, they must be built statically in PHP.+Dynamically loaded DLLs can use TLS starting with Windows Vista and Server 2008. But there is a restriction: TLS variables can't be exported, which means that they can't be accessed outside of the DLL. CLI and ISAPI SAPIs works with TLS enabled, but they must be built like this is done on other platforms, with all code embeded in the executable/library (instead of a separate php5ts.dll linked by SAPIs). The same apply for extension, they must be built statically in PHP.
  
 ===== TLS internals ===== ===== TLS internals =====
Line 99: Line 99:
 ==== Static model ==== ==== Static model ====
  
-Each block is allocated at a fixed (linker-defined) offset from an address specific to each thread. As this address can be accessed very quickly, this allows very quick access to each TLS block. For instance, on Linux/IA-32, this thread-specific-address is the Thread Control Block, whose address is stored in offset 0 of the %gs segment register.+Each block is allocated at a fixed (loader-defined) offset from an address specific to each thread. As this address can be accessed very quickly, this allows very quick access to each TLS block. For instance, on Linux/IA-32, this thread-specific-address is the Thread Control Block, whose address is stored in offset 0 of the %gs segment register.
  
 The way the static model works requires that the memory needed by each TLS variable to be allocated before program startup. This means that the static model can not be used in shared libraries loaded at runtime.  The way the static model works requires that the memory needed by each TLS variable to be allocated before program startup. This means that the static model can not be used in shared libraries loaded at runtime. 
Line 165: Line 165:
 As the patch avoids passing tsrm_ls across function calls, #ifdef ZTS is not anymore relevant to check that. As the patch avoids passing tsrm_ls across function calls, #ifdef ZTS is not anymore relevant to check that.
 The new PASS_TSRMLS macro is now defined when tsrm_ls needs to be passed across function calls. For instance this is needed by ZEND_ATTRIBUTE_FORMAT and some other places. The new PASS_TSRMLS macro is now defined when tsrm_ls needs to be passed across function calls. For instance this is needed by ZEND_ATTRIBUTE_FORMAT and some other places.
- 
rfc/tls.1219760748.txt.gz · Last modified: 2017/09/22 13:28 (external edit)