Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40002 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53398 invoked from network); 19 Aug 2008 04:18:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2008 04:18:11 -0000 Authentication-Results: pb1.pair.com header.from=andi@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=andi@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.163 as permitted sender) X-PHP-List-Original-Sender: andi@zend.com X-Host-Fingerprint: 212.25.124.163 il-gw1.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.163] ([212.25.124.163:43336] helo=il-gw1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/B9-25897-0894AA84 for ; Tue, 19 Aug 2008 00:18:09 -0400 Received: from us-ex1.zend.com ([192.168.16.5]) by il-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 19 Aug 2008 07:19:02 +0300 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Mon, 18 Aug 2008 21:18:51 -0700 Message-ID: <698DE66518E7CA45812BD18E807866CE01E77474@us-ex1.zend.net> In-Reply-To: <200808170419.11153.arnaud.lb@gmail.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] [PATCH] ZTS as fast as non-ZTS Thread-Index: AckAECyXkngNatNATVqB6r+Azks9vwBolCqA References: <200808170419.11153.arnaud.lb@gmail.com> To: "Arnaud Le Blanc" , "PHP Development" X-OriginalArrivalTime: 19 Aug 2008 04:19:02.0400 (UTC) FILETIME=[B5E10800:01C901B2] Subject: RE: [PHP-DEV] [PATCH] ZTS as fast as non-ZTS From: andi@zend.com ("Andi Gutmans") Hi Arnaud, I remember that at the time we looked at thread local storage and there were some real issues with it. I can't remember what as it was about 7+ years ago. I will ask Zeev if he remembers and if not search my archives (don't have years prior to 2007 indexed :'( ). Andi > -----Original Message----- > From: Arnaud Le Blanc [mailto:arnaud.lb@gmail.com] > Sent: Saturday, August 16, 2008 7:19 PM > To: PHP Development > Subject: [PHP-DEV] [PATCH] ZTS as fast as non-ZTS >=20 > Hi, >=20 > Currently the way globals work forces to pass a thread-local-storage pointer > across function calls, which involves some overhead. Also, not all functions > get the pointer as argument and need to use TSRMLS_FETCH(), which is slow. For > instance emalloc() involves a TSRMLS_FETCH(). An other overhead is accessing > globals, using multiple pointers in different locations. >=20 > The following patch caches each global address in a native TLS variable so > that accessing a global is as simple as global_name->member. This removes the > requirement of passing the tls pointer across function calls, so that the two > major overheads of ZTS builds are avoided. >=20 > Globals can optionally be declared statically, which speeds up things a bit. >=20 > Results in bench.php: > non-ZTS: 3.7s > ZTS unpatched: 5.2s > ZTS patched: 4.0s > ZTS patched and static globals: 3.8s >=20 > The patch introduces two new macros: TSRMG_D() (declare) and TSRMG_DH() > (declare, for headers) to declare globals, instead of the current "ts_rsrc_id > foo_global_id". These macros declare the global id, plus the __thread pointer > to the global storage. >=20 > ts_allocate_id now takes one more callback function as argument to bind the > global pointer to its storage. This callback is declared in TSRMG_D[H](). >=20 > As all TSRMLS_* macros now does nothing, it is needed to call ts_resource(0) > explicitly at least one time in each thread to initialize its storage. A new > TSRMLS_INIT() macro as been added for this purpose. >=20 > All this is disabled by default. --with-tsrm-__thread-tls enables the features > of the patch, and --with-tsrm-full-__thread-tls enables static declaration of > globals. >=20 > It as been tested on Linux compiled with --disable-all in CLI and a bit in > Apache2 with the worker MPM. Known issues: > - Declaring globals statically (--with-tsrm-full-__thread-tls) causes troubles > to dlopen(), actually Apache wont load the module at runtime (it works with > just --with-tsrm-__thread-tls). > - The patch assumes that all resources are ts_allocate_id()'ed before any > other thread calls ts_allocate_id or ts_resource_ex(), which is possibly not > the case. >=20 > The patch needs some tweaks and does not pretend to be included in any branch, > but I would like to have some comments on it. >=20 > The patch: http://arnaud.lb.s3.amazonaws.com/__thread-tls.patch >=20 > Regards, >=20 > Arnaud >=20 >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php