Skip to content

Commit 0e5ac62

Browse files
author
Sara
authored
Add configuration opcache.jit_max_trace_length (#11173)
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 1024. Reviewed-by: Su, Tao <[email protected]> Signed-off-by: Wang, Xue <[email protected]>
1 parent e2f477c commit 0e5ac62

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
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_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)