Skip to content

Commit b3c24e2

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 964f494 commit b3c24e2

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
@@ -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_trace_length; /* max length of a single trace */
119120

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

ext/opcache/jit/zend_jit_trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7404,7 +7404,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
74047404
zend_jit_op_array_trace_extension *jit_extension;
74057405
size_t offset;
74067406
uint32_t trace_num;
7407-
zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH];
7407+
zend_jit_trace_rec *trace_buffer = (zend_jit_trace_rec *)malloc(JIT_G(max_trace_length) * sizeof(zend_jit_trace_rec));
74087408

74097409
ZEND_ASSERT(EX(func)->type == ZEND_USER_FUNCTION);
74107410
ZEND_ASSERT(opline >= EX(func)->op_array.opcodes &&
@@ -7720,7 +7720,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
77207720
zend_jit_trace_stop stop;
77217721
int ret = 0;
77227722
uint32_t trace_num;
7723-
zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH];
7723+
zend_jit_trace_rec *trace_buffer = (zend_jit_trace_rec *)malloc(JIT_G(max_trace_length) * sizeof(zend_jit_trace_rec));
77247724
uint32_t is_megamorphic = 0;
77257725
uint32_t polymorphism = 0;
77267726

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
@@ -224,6 +224,19 @@ static ZEND_INI_MH(OnUpdateUnrollL)
224224
ZEND_JIT_TRACE_MAX_LOOPS_UNROLL);
225225
return FAILURE;
226226
}
227+
228+
static ZEND_INI_MH(OnUpdateUnrollT)
229+
{
230+
zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
231+
if (val > 3 && val <= ZEND_JIT_TRACE_MAX_LENGTH) {
232+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
233+
*p = val;
234+
return SUCCESS;
235+
}
236+
zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 4 and %d", ZSTR_VAL(entry->name),
237+
ZEND_JIT_TRACE_MAX_LENGTH);
238+
return FAILURE;
239+
}
227240
#endif
228241

229242
ZEND_INI_BEGIN()
@@ -302,6 +315,7 @@ ZEND_INI_BEGIN()
302315
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_calls" , "2", PHP_INI_ALL, OnUpdateUnrollC, max_recursive_calls, zend_jit_globals, jit_globals)
303316
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_returns" , "2", PHP_INI_ALL, OnUpdateUnrollR, max_recursive_returns, zend_jit_globals, jit_globals)
304317
STD_PHP_INI_ENTRY("opcache.jit_max_polymorphic_calls" , "2", PHP_INI_ALL, OnUpdateLong, max_polymorphic_calls, zend_jit_globals, jit_globals)
318+
STD_PHP_INI_ENTRY("opcache.jit_max_trace_length" , "512", PHP_INI_ALL, OnUpdateUnrollT, max_trace_length, zend_jit_globals, jit_globals)
305319
#endif
306320
ZEND_INI_END()
307321

@@ -792,6 +806,7 @@ ZEND_FUNCTION(opcache_get_configuration)
792806
add_assoc_long(&directives, "opcache.jit_max_root_traces", JIT_G(max_root_traces));
793807
add_assoc_long(&directives, "opcache.jit_max_side_traces", JIT_G(max_side_traces));
794808
add_assoc_long(&directives, "opcache.jit_prof_threshold", JIT_G(prof_threshold));
809+
add_assoc_long(&directives, "opcache.jit_max_trace_length", JIT_G(max_trace_length));
795810
#endif
796811

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

0 commit comments

Comments
 (0)