php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50238 [PATCH] - Using #defines to improve the performance of the TSRMG macro
Submitted: 2009-11-20 10:29 UTC Modified: 2015-01-11 04:22 UTC
Votes:25
Avg. Score:4.0 ± 1.2
Reproduced:7 of 11 (63.6%)
Same Version:6 (85.7%)
Same OS:7 (100.0%)
From: yoarvi at gmail dot com Assigned:
Status: No Feedback Package: Performance problem
PHP Version: 6SVN-2009-11-20 (SVN) OS: Solaris 5.10 (SPARC)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: yoarvi at gmail dot com
New email:
PHP Version: OS:

 

 [2009-11-20 10:29 UTC] yoarvi at gmail dot com
Description:
------------
When compiled for multi-threaded (#ifdef ZTS ) operation, the various
subsystems in PHP use dynamically allocated (ts_allocate_id)
identifiers to index into the thread-local storage for each subsystem.
These dynamically allocated ids are used by macros such as CG, EG, PG,
AG.

The TSRMG macro is defined as:
#define TSRMG(id, type, element)	(((type) (*((void ***)
tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)

The PG macro is defined as:
# define PG(v) TSRMG(core_globals_id, php_core_globals *, v)

where core_globals_id is
extern PHPAPI int core_globals_id;

cc -E of
	PG(connection_status) = PHP_CONNECTION_ABORTED;
translates to:
 (((php_core_globals *) (*((void ***)
tsrm_ls))[((core_globals_id)-1)])->connection_status) = 1;

and cc -S of the same code results in:
	.loc 1 108 0
	movl	%ebx, %eax
	subl	core_globals_id, %eax
	movl	(%esi), %edx
	sall	$2, %eax
	negl	%eax
	movl	(%edx,%eax), %eax
	movw	$1, 144(%eax)

I used fixed IDs instead of dynamically allocated ones and noticed a
decent improvement in performance (few percentage points) when
running a web-based ecommerce-site workload on SPARC CMT hardware.

With my changes the PG macro is defined as:
# define PG(v) TSRMG(CORE_GLOBALS_ID, php_core_globals *, v)

#define CORE_GLOBALS_ID					10

and core_globals_id is
extern PHPAPI const ts_rsrc_id core_globals_id;

cc -E of the same line of code translates to:
 (((php_core_globals *) (*((void ***)
tsrm_ls))[((10)-1)])->connection_status) = 1;

cc -S (my version):
	.loc 1 108 0
	movl	(%eax), %eax
	movl	36(%eax), %eax
	movw	$1, 144(%eax)

The relevant discussion can be found here:
http://marc.info/?l=php-internals&m=125742200330841&w=2

Reproduce code:
---------------
The following patch implements this and incorporates the feedback received on internals: 

http://bitbucket.org/arvi/arviq/src/tip/arvi-16-ts_allocate_reserved_id

Expected result:
----------------
Improved performance when PHP is compiled with support for multi-threading.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-20 15:26 UTC] rasmus@php.net
It seems silly that this would make a difference.  I guess make the change in trunk.  Can't do it in the branches because it would break binary compatibility.
 [2014-12-28 08:18 UTC] mj@php.net
-Status: Analyzed +Status: Feedback
 [2014-12-28 08:18 UTC] mj@php.net
Recently the thread safety mode has received a bunch of updates in the course of https://wiki.php.net/rfc/native-tls. Can you please verify if your improvements are still required?
 [2015-01-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC