Skip to content

Commit 928c796

Browse files
committed
Make number of root and side traces configurable
1 parent e18f631 commit 928c796

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3795,10 +3795,6 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, zend_bool reattached)
37953795
#endif
37963796
}
37973797

3798-
if (zend_jit_trace_startup() != SUCCESS) {
3799-
return FAILURE;
3800-
}
3801-
38023798
return SUCCESS;
38033799
}
38043800

ext/opcache/jit/zend_jit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@
6666

6767
#define ZEND_JIT_DEBUG_PERSISTENT 0x1f0 /* profile and debbuger flags can't be changed at run-time */
6868

69-
#define ZEND_JIT_TRACE_MAX_TRACES 1024 /* max number of traces */
7069
#define ZEND_JIT_TRACE_MAX_LENGTH 1024 /* max length of single trace */
7170
#define ZEND_JIT_TRACE_MAX_EXITS 512 /* max number of side exits per trace */
72-
#define ZEND_JIT_TRACE_MAX_SIDE_TRACES 128 /* max number of side traces of a root trace */
7371
#define ZEND_JIT_TRACE_MAX_EXIT_COUNTERS 8192 /* max number of side exits for all trace */
7472

7573
#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 {
9593
zend_long debug;
9694
zend_long bisect_limit;
9795
double prof_threshold;
96+
zend_long max_root_traces; /* max number of root traces */
97+
zend_long max_side_traces; /* max number of side traces (per root trace) */
9898
zend_long hot_loop;
9999
zend_long hot_func;
100100
zend_long hot_return;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_fla
4848

4949
static int zend_jit_trace_startup(void)
5050
{
51-
zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * ZEND_JIT_TRACE_MAX_TRACES);
51+
zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * JIT_G(max_root_traces));
5252
if (!zend_jit_traces) {
5353
return FAILURE;
5454
}
@@ -4217,7 +4217,7 @@ static zend_jit_trace_stop zend_jit_compile_root_trace(zend_jit_trace_rec *trace
42174217
/* Checks under lock */
42184218
if ((ZEND_OP_TRACE_INFO(opline, offset)->trace_flags & ZEND_JIT_TRACE_JITED)) {
42194219
ret = ZEND_JIT_TRACE_STOP_ALREADY_DONE;
4220-
} else if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) {
4220+
} else if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) {
42214221
ret = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES;
42224222
} else {
42234223
SHM_UNPROTECT();
@@ -4639,7 +4639,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
46394639
opline->lineno);
46404640
}
46414641

4642-
if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) {
4642+
if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) {
46434643
stop = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES;
46444644
goto abort;
46454645
}
@@ -4780,9 +4780,9 @@ static zend_jit_trace_stop zend_jit_compile_side_trace(zend_jit_trace_rec *trace
47804780
/* Checks under lock */
47814781
if (zend_jit_traces[parent_num].exit_info[exit_num].flags & (ZEND_JIT_EXIT_JITED|ZEND_JIT_EXIT_BLACKLISTED)) {
47824782
ret = ZEND_JIT_TRACE_STOP_ALREADY_DONE;
4783-
} else if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) {
4783+
} else if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) {
47844784
ret = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES;
4785-
} else if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= ZEND_JIT_TRACE_MAX_SIDE_TRACES) {
4785+
} else if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= JIT_G(max_side_traces)) {
47864786
ret = ZEND_JIT_TRACE_STOP_TOO_MANY_CHILDREN;
47874787
} else {
47884788
SHM_UNPROTECT();
@@ -4905,12 +4905,12 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
49054905
EX(opline)->lineno);
49064906
}
49074907

4908-
if (ZEND_JIT_TRACE_NUM >= ZEND_JIT_TRACE_MAX_TRACES) {
4908+
if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) {
49094909
stop = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES;
49104910
goto abort;
49114911
}
49124912

4913-
if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= ZEND_JIT_TRACE_MAX_SIDE_TRACES) {
4913+
if (zend_jit_traces[zend_jit_traces[parent_num].root].child_count >= JIT_G(max_side_traces)) {
49144914
stop = ZEND_JIT_TRACE_STOP_TOO_MANY_CHILDREN;
49154915
goto abort;
49164916
}
@@ -5089,6 +5089,10 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
50895089
zend_cfg cfg;
50905090
uint32_t i;
50915091

5092+
if (!zend_jit_traces && zend_jit_trace_startup() != SUCCESS) {
5093+
return FAILURE;
5094+
}
5095+
50925096
ZEND_ASSERT(zend_jit_func_trace_counter_handler != NULL);
50935097
ZEND_ASSERT(zend_jit_ret_trace_counter_handler != NULL);
50945098
ZEND_ASSERT(zend_jit_loop_trace_counter_handler != NULL);

ext/opcache/zend_accelerator_module.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ ZEND_INI_BEGIN()
316316
STD_PHP_INI_ENTRY("opcache.jit_debug" , "0", PHP_INI_ALL, OnUpdateJitDebug, debug, zend_jit_globals, jit_globals)
317317
STD_PHP_INI_ENTRY("opcache.jit_bisect_limit" , "0", PHP_INI_ALL, OnUpdateLong, bisect_limit, zend_jit_globals, jit_globals)
318318
STD_PHP_INI_ENTRY("opcache.jit_prof_threshold" , "0.005", PHP_INI_ALL, OnUpdateReal, prof_threshold, zend_jit_globals, jit_globals)
319+
STD_PHP_INI_ENTRY("opcache.jit_max_root_traces" , "1024", PHP_INI_SYSTEM, OnUpdateLong, max_root_traces, zend_jit_globals, jit_globals)
320+
STD_PHP_INI_ENTRY("opcache.jit_max_side_traces" , "128", PHP_INI_SYSTEM, OnUpdateLong, max_side_traces, zend_jit_globals, jit_globals)
319321
STD_PHP_INI_ENTRY("opcache.jit_hot_loop" , "64", PHP_INI_SYSTEM, OnUpdateCounter, hot_loop, zend_jit_globals, jit_globals)
320322
STD_PHP_INI_ENTRY("opcache.jit_hot_func" , "127", PHP_INI_SYSTEM, OnUpdateCounter, hot_func, zend_jit_globals, jit_globals)
321323
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)
807809
add_assoc_long(&directives, "opcache.jit_hot_side_exit", JIT_G(hot_side_exit));
808810
add_assoc_long(&directives, "opcache.jit_max_loops_unroll", JIT_G(max_loops_unroll));
809811
add_assoc_long(&directives, "opcache.jit_max_recursion_unroll", JIT_G(max_recursion_unroll));
812+
add_assoc_long(&directives, "opcache.jit_max_root_traces", JIT_G(max_root_traces));
813+
add_assoc_long(&directives, "opcache.jit_max_side_traces", JIT_G(max_side_traces));
810814
add_assoc_long(&directives, "opcache.jit_prof_threshold", JIT_G(prof_threshold));
811815
#endif
812816

0 commit comments

Comments
 (0)