Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39986 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54096 invoked from network); 17 Aug 2008 02:21:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2008 02:21:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=arnaud.lb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=arnaud.lb@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.134.190 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: arnaud.lb@gmail.com X-Host-Fingerprint: 209.85.134.190 mu-out-0910.google.com Received: from [209.85.134.190] ([209.85.134.190:65529] helo=mu-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/41-43528-22B87A84 for ; Sat, 16 Aug 2008 22:21:23 -0400 Received: by mu-out-0910.google.com with SMTP id i2so1340841mue.3 for ; Sat, 16 Aug 2008 19:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :user-agent:mime-version:content-type:content-transfer-encoding :content-disposition:message-id; bh=Ak14mVpIBz/QxtMvq8M3OCOU90+nqHecQTWBGG6otmk=; b=xec0IfFD9U/JFFIuX2Otr6SgkkoYW9zDcBpo0lLMU1JYBvoGccEQItxDqQbxmBgHqU M6lqWtVlo4w5o1S0+oF57UoNcKwmNEThkk8pUsR0d7QgfoNXjn8nLlqD3SBYq4yaneOQ RVR1gveL8qupl7VzIRsjv9nPqtP8bZn7vvwJw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; b=cUy1gnxfm9W85NKCnL8xIqQUB5MAHdm9qD36ya/sidzVfAL0burKvRvVx/Iq6cHGAk rheAWJ+FUnFSYaBKj1m+UPkapHfbtRjbxH27CvteWBhRdCi2axl5/okTa10xGVKHkSpv 8qxz2ldd9DNFQ3yFRmQhJET9CtCSDgbrPVXXw= Received: by 10.103.176.2 with SMTP id d2mr3005483mup.112.1218939679082; Sat, 16 Aug 2008 19:21:19 -0700 (PDT) Received: from 207-177-41-213.getmyip.com ( [213.41.177.207]) by mx.google.com with ESMTPS id s10sm1642315mue.15.2008.08.16.19.21.17 (version=SSLv3 cipher=RC4-MD5); Sat, 16 Aug 2008 19:21:18 -0700 (PDT) To: "PHP Development" Date: Sun, 17 Aug 2008 04:19:10 +0200 User-Agent: KMail/1.10.0 (Linux/2.6.26-noch; KDE/4.1.0; i686; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200808170419.11153.arnaud.lb@gmail.com> Subject: [PATCH] ZTS as fast as non-ZTS From: arnaud.lb@gmail.com (Arnaud Le Blanc) Hi, 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. 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. Globals can optionally be declared statically, which speeds up things a bit. Results in bench.php: non-ZTS: 3.7s ZTS unpatched: 5.2s ZTS patched: 4.0s ZTS patched and static globals: 3.8s 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. 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](). 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. 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. 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. 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. The patch: http://arnaud.lb.s3.amazonaws.com/__thread-tls.patch Regards, Arnaud