Skip to content

Commit 86788cb

Browse files
author
wxue1
committed
Add configuration opcache.jit_max_trace_length
Max length of a single trace. A long trace generates long JITTed code, which influences the performance slightly. opcache.jit_max_trace_length range is [4,1024], the default value is 512. Signed-off-by: Wang, Xue <[email protected]> Reviewed-by: Su, Tao <[email protected]>
1 parent 945db3c commit 86788cb

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

ext/opcache/jit/zend_jit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ typedef struct _zend_jit_globals {
115115
zend_long max_recursive_calls; /* max number of recursive inlined call unrolls */
116116
zend_long max_recursive_returns; /* max number of recursive inlined return unrolls */
117117
zend_long max_polymorphic_calls; /* max number of inlined polymorphic calls */
118+
zend_long max_trace_length; /* max length of a single trace */
118119

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

ext/opcache/jit/zend_jit_trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7591,7 +7591,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
75917591
zend_jit_op_array_trace_extension *jit_extension;
75927592
size_t offset;
75937593
uint32_t trace_num;
7594-
zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH];
7594+
zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH];
75957595

75967596
ZEND_ASSERT(EX(func)->type == ZEND_USER_FUNCTION);
75977597
ZEND_ASSERT(opline >= EX(func)->op_array.opcodes &&
@@ -7926,7 +7926,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
79267926
zend_jit_trace_stop stop;
79277927
int ret = 0;
79287928
uint32_t trace_num;
7929-
zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH];
7929+
zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH];
79307930
uint32_t is_megamorphic = 0;
79317931
uint32_t polymorphism = 0;
79327932

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_trace_helper(ZEND_OPCODE_HAN
360360
trace_buffer[idx].info = _op | (_info); \
361361
trace_buffer[idx].ptr = _ptr; \
362362
idx++; \
363-
if (idx >= ZEND_JIT_TRACE_MAX_LENGTH - 2) { \
363+
if (idx >= JIT_G(max_trace_length) - 2) { \
364364
stop = ZEND_JIT_TRACE_STOP_TOO_LONG; \
365365
break; \
366366
}
@@ -372,7 +372,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_trace_helper(ZEND_OPCODE_HAN
372372
trace_buffer[idx].op3_type = _op3_type; \
373373
trace_buffer[idx].ptr = _ptr; \
374374
idx++; \
375-
if (idx >= ZEND_JIT_TRACE_MAX_LENGTH - 2) { \
375+
if (idx >= JIT_G(max_trace_length) - 2) { \
376376
stop = ZEND_JIT_TRACE_STOP_TOO_LONG; \
377377
break; \
378378
}

ext/opcache/zend_accelerator_module.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ static ZEND_INI_MH(OnUpdateUnrollL)
258258
ZEND_JIT_TRACE_MAX_LOOPS_UNROLL);
259259
return FAILURE;
260260
}
261+
262+
static ZEND_INI_MH(OnUpdateMaxTraceLength)
263+
{
264+
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
265+
if (val > 3 && val <= ZEND_JIT_TRACE_MAX_LENGTH) {
266+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
267+
*p = val;
268+
return SUCCESS;
269+
}
270+
zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 4 and %d", ZSTR_VAL(entry->name),
271+
ZEND_JIT_TRACE_MAX_LENGTH);
272+
return FAILURE;
273+
}
261274
#endif
262275

263276
ZEND_INI_BEGIN()
@@ -336,6 +349,7 @@ ZEND_INI_BEGIN()
336349
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_calls" , "2", PHP_INI_ALL, OnUpdateUnrollC, max_recursive_calls, zend_jit_globals, jit_globals)
337350
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_returns" , "2", PHP_INI_ALL, OnUpdateUnrollR, max_recursive_returns, zend_jit_globals, jit_globals)
338351
STD_PHP_INI_ENTRY("opcache.jit_max_polymorphic_calls" , "2", PHP_INI_ALL, OnUpdateLong, max_polymorphic_calls, zend_jit_globals, jit_globals)
352+
STD_PHP_INI_ENTRY("opcache.jit_max_trace_length" , "1024", PHP_INI_ALL, OnUpdateMaxTraceLength, max_trace_length, zend_jit_globals, jit_globals)
339353
#endif
340354
ZEND_INI_END()
341355

@@ -849,6 +863,7 @@ ZEND_FUNCTION(opcache_get_configuration)
849863
add_assoc_long(&directives, "opcache.jit_max_root_traces", JIT_G(max_root_traces));
850864
add_assoc_long(&directives, "opcache.jit_max_side_traces", JIT_G(max_side_traces));
851865
add_assoc_long(&directives, "opcache.jit_prof_threshold", JIT_G(prof_threshold));
866+
add_assoc_long(&directives, "opcache.jit_max_trace_length", JIT_G(max_trace_length));
852867
#endif
853868

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

0 commit comments

Comments
 (0)