]> granicus.if.org Git - php/commitdiff
Make number of root and side traces configurable
authorDmitry Stogov <dmitry@zend.com>
Tue, 19 May 2020 22:40:01 +0000 (01:40 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 19 May 2020 22:40:01 +0000 (01:40 +0300)
ext/opcache/jit/zend_jit.c
ext/opcache/jit/zend_jit.h
ext/opcache/jit/zend_jit_trace.c
ext/opcache/zend_accelerator_module.c

index 9a04f2dc950bcbd221e56093f76133a58c07fe61..43d74d36db0b33338b247526edd3a82bb8460c4a 100644 (file)
@@ -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;
 }
 
index 8c7e72c580d5a54d321b84dc4ab6afbe9319966a..50f696027d105ab05f98708325ac7c31d6c53d92 100644 (file)
 
 #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;
index 71f2ab642d289f6f6e2ac480fc8c08c55ecbfd11..0da47067533ed747409835eee7fea21d251b9ab9 100644 (file)
@@ -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);
index 34251be4d2f38faf37f5a74d2a67af88d74cc635..151bc31123233c300663360c1318139bd9a3cd55 100644 (file)
@@ -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