From 928c79629089afec13dd022b5bf120e297a1d01f Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 20 May 2020 01:40:01 +0300 Subject: [PATCH] Make number of root and side traces configurable --- ext/opcache/jit/zend_jit.c | 4 ---- ext/opcache/jit/zend_jit.h | 4 ++-- ext/opcache/jit/zend_jit_trace.c | 18 +++++++++++------- ext/opcache/zend_accelerator_module.c | 4 ++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index 9a04f2dc95..43d74d36db 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -3795,10 +3795,6 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, zend_bool reattached) #endif } - if (zend_jit_trace_startup() != SUCCESS) { - return FAILURE; - } - return SUCCESS; } diff --git a/ext/opcache/jit/zend_jit.h b/ext/opcache/jit/zend_jit.h index 8c7e72c580..50f696027d 100644 --- a/ext/opcache/jit/zend_jit.h +++ b/ext/opcache/jit/zend_jit.h @@ -66,10 +66,8 @@ #define ZEND_JIT_DEBUG_PERSISTENT 0x1f0 /* profile and debbuger flags can't be changed at run-time */ -#define ZEND_JIT_TRACE_MAX_TRACES 1024 /* max number of traces */ #define ZEND_JIT_TRACE_MAX_LENGTH 1024 /* max length of single trace */ #define ZEND_JIT_TRACE_MAX_EXITS 512 /* max number of side exits per trace */ -#define ZEND_JIT_TRACE_MAX_SIDE_TRACES 128 /* max number of side traces of a root trace */ #define ZEND_JIT_TRACE_MAX_EXIT_COUNTERS 8192 /* max number of side exits for all trace */ #define ZEND_JIT_TRACE_MAX_FUNCS 30 /* max number of different functions in a single trace */ @@ -95,6 +93,8 @@ typedef struct _zend_jit_globals { zend_long debug; zend_long bisect_limit; double prof_threshold; + zend_long max_root_traces; /* max number of root traces */ + zend_long max_side_traces; /* max number of side traces (per root trace) */ zend_long hot_loop; zend_long hot_func; zend_long hot_return; diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 71f2ab642d..0da4706753 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -48,7 +48,7 @@ static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_fla static int zend_jit_trace_startup(void) { - zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * ZEND_JIT_TRACE_MAX_TRACES); + zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * JIT_G(max_root_traces)); if (!zend_jit_traces) { return FAILURE; } @@ -4217,7 +4217,7 @@ static zend_jit_trace_stop zend_jit_compile_root_trace(zend_jit_trace_rec *trace /* Checks under lock */ if ((ZEND_OP_TRACE_INFO(opline, offset)->trace_flags & ZEND_JIT_TRACE_JITED)) { ret = ZEND_JIT_TRACE_STOP_ALREADY_DONE; - } else if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) { + } else if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) { ret = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES; } else { SHM_UNPROTECT(); @@ -4639,7 +4639,7 @@ repeat: opline->lineno); } - if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) { + if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) { stop = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES; goto abort; } @@ -4780,9 +4780,9 @@ static zend_jit_trace_stop zend_jit_compile_side_trace(zend_jit_trace_rec *trace /* Checks under lock */ if (zend_jit_traces[parent_num].exit_info[exit_num].flags & (ZEND_JIT_EXIT_JITED|ZEND_JIT_EXIT_BLACKLISTED)) { ret = ZEND_JIT_TRACE_STOP_ALREADY_DONE; - } else if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) { + } else if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) { ret = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES; - } else if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= ZEND_JIT_TRACE_MAX_SIDE_TRACES) { + } else if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= JIT_G(max_side_traces)) { ret = ZEND_JIT_TRACE_STOP_TOO_MANY_CHILDREN; } else { SHM_UNPROTECT(); @@ -4905,12 +4905,12 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3 EX(opline)->lineno); } - if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) { + if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) { stop = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES; goto abort; } - if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= ZEND_JIT_TRACE_MAX_SIDE_TRACES) { + if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= JIT_G(max_side_traces)) { stop = ZEND_JIT_TRACE_STOP_TOO_MANY_CHILDREN; goto abort; } @@ -5089,6 +5089,10 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array) zend_cfg cfg; uint32_t i; + if (!zend_jit_traces && zend_jit_trace_startup() != SUCCESS) { + return FAILURE; + } + ZEND_ASSERT(zend_jit_func_trace_counter_handler != NULL); ZEND_ASSERT(zend_jit_ret_trace_counter_handler != NULL); ZEND_ASSERT(zend_jit_loop_trace_counter_handler != NULL); diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index 34251be4d2..151bc31123 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -316,6 +316,8 @@ ZEND_INI_BEGIN() STD_PHP_INI_ENTRY("opcache.jit_debug" , "0", PHP_INI_ALL, OnUpdateJitDebug, debug, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_bisect_limit" , "0", PHP_INI_ALL, OnUpdateLong, bisect_limit, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_prof_threshold" , "0.005", PHP_INI_ALL, OnUpdateReal, prof_threshold, zend_jit_globals, jit_globals) + STD_PHP_INI_ENTRY("opcache.jit_max_root_traces" , "1024", PHP_INI_SYSTEM, OnUpdateLong, max_root_traces, zend_jit_globals, jit_globals) + STD_PHP_INI_ENTRY("opcache.jit_max_side_traces" , "128", PHP_INI_SYSTEM, OnUpdateLong, max_side_traces, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_hot_loop" , "64", PHP_INI_SYSTEM, OnUpdateCounter, hot_loop, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_hot_func" , "127", PHP_INI_SYSTEM, OnUpdateCounter, hot_func, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_hot_return" , "8", PHP_INI_SYSTEM, OnUpdateCounter, hot_return, zend_jit_globals, jit_globals) @@ -807,6 +809,8 @@ ZEND_FUNCTION(opcache_get_configuration) add_assoc_long(&directives, "opcache.jit_hot_side_exit", JIT_G(hot_side_exit)); add_assoc_long(&directives, "opcache.jit_max_loops_unroll", JIT_G(max_loops_unroll)); add_assoc_long(&directives, "opcache.jit_max_recursion_unroll", JIT_G(max_recursion_unroll)); + 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)); #endif -- 2.40.0