From b3c24e261f9bb37a098780aeff64b9a30dd3171f Mon Sep 17 00:00:00 2001 From: wxue1 Date: Wed, 26 Apr 2023 23:53:17 -0700 Subject: [PATCH] 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 Reviewed-by: Su, Tao --- ext/opcache/jit/zend_jit.h | 1 + ext/opcache/jit/zend_jit_trace.c | 4 ++-- ext/opcache/jit/zend_jit_vm_helpers.c | 4 ++-- ext/opcache/zend_accelerator_module.c | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ext/opcache/jit/zend_jit.h b/ext/opcache/jit/zend_jit.h index 21d1774c111b..e58c70417f98 100644 --- a/ext/opcache/jit/zend_jit.h +++ b/ext/opcache/jit/zend_jit.h @@ -116,6 +116,7 @@ typedef struct _zend_jit_globals { zend_long max_recursive_calls; /* max number of recursive inlined call unrolls */ zend_long max_recursive_returns; /* max number of recursive inlined return unrolls */ zend_long max_polymorphic_calls; /* max number of inlined polymorphic calls */ + zend_long max_trace_length; /* max length of a single trace */ zend_sym_node *symbols; /* symbols for disassembler */ diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 892902a4e03a..0a6f09f45426 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -7404,7 +7404,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const zend_jit_op_array_trace_extension *jit_extension; size_t offset; uint32_t trace_num; - zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH]; + zend_jit_trace_rec *trace_buffer = (zend_jit_trace_rec *)malloc(JIT_G(max_trace_length) * sizeof(zend_jit_trace_rec)); ZEND_ASSERT(EX(func)->type == ZEND_USER_FUNCTION); 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 zend_jit_trace_stop stop; int ret = 0; uint32_t trace_num; - zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH]; + zend_jit_trace_rec *trace_buffer = (zend_jit_trace_rec *)malloc(JIT_G(max_trace_length) * sizeof(zend_jit_trace_rec)); uint32_t is_megamorphic = 0; uint32_t polymorphism = 0; diff --git a/ext/opcache/jit/zend_jit_vm_helpers.c b/ext/opcache/jit/zend_jit_vm_helpers.c index bd65cb604340..095db3d82c6e 100644 --- a/ext/opcache/jit/zend_jit_vm_helpers.c +++ b/ext/opcache/jit/zend_jit_vm_helpers.c @@ -360,7 +360,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_trace_helper(ZEND_OPCODE_HAN trace_buffer[idx].info = _op | (_info); \ trace_buffer[idx].ptr = _ptr; \ idx++; \ - if (idx >= ZEND_JIT_TRACE_MAX_LENGTH - 2) { \ + if (idx >= JIT_G(max_trace_length) - 2) { \ stop = ZEND_JIT_TRACE_STOP_TOO_LONG; \ break; \ } @@ -372,7 +372,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_trace_helper(ZEND_OPCODE_HAN trace_buffer[idx].op3_type = _op3_type; \ trace_buffer[idx].ptr = _ptr; \ idx++; \ - if (idx >= ZEND_JIT_TRACE_MAX_LENGTH - 2) { \ + if (idx >= JIT_G(max_trace_length) - 2) { \ stop = ZEND_JIT_TRACE_STOP_TOO_LONG; \ break; \ } diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index da1696bb9208..09551093e61e 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -224,6 +224,19 @@ static ZEND_INI_MH(OnUpdateUnrollL) ZEND_JIT_TRACE_MAX_LOOPS_UNROLL); return FAILURE; } + +static ZEND_INI_MH(OnUpdateUnrollT) +{ + zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); + if (val > 3 && val <= ZEND_JIT_TRACE_MAX_LENGTH) { + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); + *p = val; + return SUCCESS; + } + zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 4 and %d", ZSTR_VAL(entry->name), + ZEND_JIT_TRACE_MAX_LENGTH); + return FAILURE; +} #endif ZEND_INI_BEGIN() @@ -302,6 +315,7 @@ ZEND_INI_BEGIN() STD_PHP_INI_ENTRY("opcache.jit_max_recursive_calls" , "2", PHP_INI_ALL, OnUpdateUnrollC, max_recursive_calls, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_max_recursive_returns" , "2", PHP_INI_ALL, OnUpdateUnrollR, max_recursive_returns, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_max_polymorphic_calls" , "2", PHP_INI_ALL, OnUpdateLong, max_polymorphic_calls, zend_jit_globals, jit_globals) + STD_PHP_INI_ENTRY("opcache.jit_max_trace_length" , "512", PHP_INI_ALL, OnUpdateUnrollT, max_trace_length, zend_jit_globals, jit_globals) #endif ZEND_INI_END() @@ -792,6 +806,7 @@ ZEND_FUNCTION(opcache_get_configuration) add_assoc_long(&directives, "opcache.jit_max_root_traces", JIT_G(max_root_traces)); add_assoc_long(&directives, "opcache.jit_max_side_traces", JIT_G(max_side_traces)); add_assoc_long(&directives, "opcache.jit_prof_threshold", JIT_G(prof_threshold)); + add_assoc_long(&directives, "opcache.jit_max_trace_length", JIT_G(max_trace_length)); #endif add_assoc_zval(return_value, "directives", &directives);