Skip to content

Commit 2d9784b

Browse files
author
wxue1
committed
JIT inlined function separately if trace is too long
Duplicated JITTed code brings overhead for the instruction cache. This patch reduces duplication by JITting inlined function separately if trace is too long because the same function is JITTed in different root trace or side trace sometimes. It increases 2%~3% performance of our workload in tracing mode. Signed-off-by: Wang, Xue <[email protected]> Signed-off-by: Yang, Lin A <[email protected]> Signed-off-by: Su, Tao <[email protected]>
1 parent b698108 commit 2d9784b

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

ext/opcache/jit/zend_jit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ typedef struct _zend_jit_globals {
116116
zend_long max_recursive_calls; /* max number of recursive inlined call unrolls */
117117
zend_long max_recursive_returns; /* max number of recursive inlined return unrolls */
118118
zend_long max_polymorphic_calls; /* max number of inlined polymorphic calls */
119+
zend_long max_inline_func_length; /* max length of inlined functions in one trace */
119120

120121
zend_sym_node *symbols; /* symbols for disassembler */
121122

ext/opcache/jit/zend_jit_internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ zend_constant* ZEND_FASTCALL zend_jit_check_constant(const zval *key);
359359
_(RECURSION_EXIT, "return from recursive function") \
360360
_(BLACK_LIST, "trace blacklisted") \
361361
_(INNER_LOOP, "inner loop") /* trace it */ \
362+
_(JIT_INLINE_FUNC, "JIT inlined function and skip current trace") /* trace inlined function */ \
362363
_(COMPILED_LOOP, "compiled loop") \
363364
_(TRAMPOLINE, "trampoline call") \
364365
_(BAD_FUNC, "bad function call") \
@@ -383,8 +384,9 @@ typedef enum _zend_jit_trace_stop {
383384
#define ZEND_JIT_TRACE_STOP_DONE(ret) \
384385
(ret < ZEND_JIT_TRACE_STOP_ERROR)
385386

387+
/* restart to trace an inner loop or inlined function */
386388
#define ZEND_JIT_TRACE_STOP_REPEAT(ret) \
387-
(ret == ZEND_JIT_TRACE_STOP_INNER_LOOP)
389+
(ret == ZEND_JIT_TRACE_STOP_INNER_LOOP || ret == ZEND_JIT_TRACE_STOP_JIT_INLINE_FUNC)
388390

389391
#define ZEND_JIT_TRACE_STOP_MAY_RECOVER(ret) \
390392
(ret <= ZEND_JIT_TRACE_STOP_COMPILER_ERROR)

ext/opcache/jit/zend_jit_trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7696,7 +7696,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
76967696
zend_jit_trace_stop_description[stop]);
76977697
}
76987698
if (!ZEND_JIT_TRACE_STOP_MAY_RECOVER(stop)
7699-
|| zend_jit_trace_is_bad_root(orig_opline, stop, offset)) {
7699+
|| (stop != ZEND_JIT_TRACE_STOP_JIT_INLINE_FUNC && zend_jit_trace_is_bad_root(orig_opline, stop, offset))) {
77007700
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_BLACKLIST) {
77017701
fprintf(stderr, "---- TRACE %d blacklisted\n",
77027702
trace_num);
@@ -8039,7 +8039,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
80398039
zend_jit_trace_stop_description[stop]);
80408040
}
80418041
if (!ZEND_JIT_TRACE_STOP_MAY_RECOVER(stop)
8042-
|| zend_jit_trace_exit_is_bad(parent_num, exit_num)) {
8042+
|| (stop != ZEND_JIT_TRACE_STOP_JIT_INLINE_FUNC && zend_jit_trace_exit_is_bad(parent_num, exit_num))) {
80438043
zend_jit_blacklist_trace_exit(parent_num, exit_num);
80448044
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_BLACKLIST) {
80458045
fprintf(stderr, "---- EXIT %d/%d blacklisted\n",

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,13 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
10621062

10631063
trace_flags = ZEND_OP_TRACE_INFO(opline, offset)->trace_flags;
10641064
if (trace_flags) {
1065+
/* if inlined functions are too long, stop current tracing and restart a new one */
1066+
if (trace_buffer[idx-1].op == ZEND_JIT_TRACE_ENTER && idx > JIT_G(max_inline_func_length)) {
1067+
if (!(trace_flags & ZEND_JIT_TRACE_JITED)) {
1068+
stop = ZEND_JIT_TRACE_STOP_JIT_INLINE_FUNC;
1069+
break;
1070+
}
1071+
}
10651072
if (trace_flags & ZEND_JIT_TRACE_JITED) {
10661073
if (trace_flags & ZEND_JIT_TRACE_START_LOOP) {
10671074
if ((start & ZEND_JIT_TRACE_START_LOOP) != 0

ext/opcache/zend_accelerator_module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ ZEND_INI_BEGIN()
326326
STD_PHP_INI_ENTRY("opcache.jit_max_root_traces" , "1024", PHP_INI_SYSTEM, OnUpdateLong, max_root_traces, zend_jit_globals, jit_globals)
327327
STD_PHP_INI_ENTRY("opcache.jit_max_side_traces" , "128", PHP_INI_SYSTEM, OnUpdateLong, max_side_traces, zend_jit_globals, jit_globals)
328328
STD_PHP_INI_ENTRY("opcache.jit_max_exit_counters" , "8192", PHP_INI_SYSTEM, OnUpdateLong, max_exit_counters, zend_jit_globals, jit_globals)
329+
STD_PHP_INI_ENTRY("opcache.jit_max_inline_func_length" , "16", PHP_INI_SYSTEM, OnUpdateLong, max_inline_func_length,zend_jit_globals, jit_globals)
329330
STD_PHP_INI_ENTRY("opcache.jit_hot_loop" , "64", PHP_INI_SYSTEM, OnUpdateCounter, hot_loop, zend_jit_globals, jit_globals)
330331
STD_PHP_INI_ENTRY("opcache.jit_hot_func" , "127", PHP_INI_SYSTEM, OnUpdateCounter, hot_func, zend_jit_globals, jit_globals)
331332
STD_PHP_INI_ENTRY("opcache.jit_hot_return" , "8", PHP_INI_SYSTEM, OnUpdateCounter, hot_return, zend_jit_globals, jit_globals)
@@ -849,6 +850,7 @@ ZEND_FUNCTION(opcache_get_configuration)
849850
add_assoc_long(&directives, "opcache.jit_max_root_traces", JIT_G(max_root_traces));
850851
add_assoc_long(&directives, "opcache.jit_max_side_traces", JIT_G(max_side_traces));
851852
add_assoc_long(&directives, "opcache.jit_prof_threshold", JIT_G(prof_threshold));
853+
add_assoc_long(&directives, "opcache.jit_max_inline_func_length", JIT_G(max_inline_func_length));
852854
#endif
853855

854856
add_assoc_zval(return_value, "directives", &directives);

0 commit comments

Comments
 (0)