Skip to content

Commit 9f926d6

Browse files
author
wxue1
authored
Stop JIT hot spot counting (#9343)
When max_root_trace is reached, JIT in tracing mode will not compile any new code for root trace and side trace, but counting hot code is still going on. This patch stops counting as soon as possible by replacing counter handler with original handler, which increases 1.5% performance. Signed-off-by: Wang, Xue <xue1.wang@intel.com> Signed-off-by: Wang, Xue <xue1.wang@intel.com>
1 parent 2d6a883 commit 9f926d6

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7152,6 +7152,74 @@ static zend_jit_trace_stop zend_jit_compile_root_trace(zend_jit_trace_rec *trace
71527152
return ret;
71537153
}
71547154

7155+
/* Set counting handler back to original VM handler. */
7156+
static void zend_jit_stop_hot_trace_counters(zend_op_array *op_array)
7157+
{
7158+
zend_jit_op_array_trace_extension *jit_extension;
7159+
uint32_t i;
7160+
7161+
jit_extension = (zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
7162+
zend_shared_alloc_lock();
7163+
SHM_UNPROTECT();
7164+
for (i = 0; i < op_array->last; i++) {
7165+
/* Opline with Jit-ed code handler is skipped. */
7166+
if (jit_extension->trace_info[i].trace_flags &
7167+
(ZEND_JIT_TRACE_JITED|ZEND_JIT_TRACE_BLACKLISTED)) {
7168+
continue;
7169+
}
7170+
if (jit_extension->trace_info[i].trace_flags &
7171+
(ZEND_JIT_TRACE_START_LOOP | ZEND_JIT_TRACE_START_ENTER | ZEND_JIT_TRACE_START_RETURN)) {
7172+
op_array->opcodes[i].handler = jit_extension->trace_info[i].orig_handler;
7173+
}
7174+
}
7175+
SHM_PROTECT();
7176+
zend_shared_alloc_unlock();
7177+
}
7178+
7179+
/* Get the tracing op_array. */
7180+
static void zend_jit_stop_persistent_op_array(zend_op_array *op_array) {
7181+
zend_func_info *func_info = ZEND_FUNC_INFO(op_array);
7182+
if (!func_info) {
7183+
return;
7184+
}
7185+
if (func_info->flags & ZEND_FUNC_JIT_ON_HOT_TRACE) {
7186+
zend_jit_stop_hot_trace_counters(op_array);
7187+
}
7188+
}
7189+
7190+
/* Get all op_arrays with counter handler. */
7191+
static void zend_jit_stop_persistent_script(zend_persistent_script *script) {
7192+
zend_class_entry *ce;
7193+
zend_op_array *op_array;
7194+
7195+
zend_jit_stop_persistent_op_array(&script->script.main_op_array);
7196+
7197+
ZEND_HASH_FOREACH_PTR(&script->script.function_table, op_array) {
7198+
zend_jit_stop_persistent_op_array(op_array);
7199+
} ZEND_HASH_FOREACH_END();
7200+
7201+
ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) {
7202+
ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) {
7203+
if (op_array->type == ZEND_USER_FUNCTION) {
7204+
zend_jit_stop_persistent_op_array(op_array);
7205+
}
7206+
} ZEND_HASH_FOREACH_END();
7207+
} ZEND_HASH_FOREACH_END();
7208+
}
7209+
7210+
/* Get all scripts which are accelerated by JIT */
7211+
static void zend_jit_stop_counter_handlers() {
7212+
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
7213+
zend_accel_hash_entry *cache_entry;
7214+
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
7215+
zend_persistent_script *script;
7216+
if (cache_entry->indirect) continue;
7217+
script = (zend_persistent_script *)cache_entry->data;
7218+
zend_jit_stop_persistent_script(script);
7219+
}
7220+
}
7221+
}
7222+
71557223
static void zend_jit_blacklist_root_trace(const zend_op *opline, size_t offset)
71567224
{
71577225
zend_shared_alloc_lock();
@@ -7532,6 +7600,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
75327600

75337601
if (ZEND_JIT_TRACE_NUM >= JIT_G(max_root_traces)) {
75347602
stop = ZEND_JIT_TRACE_STOP_TOO_MANY_TRACES;
7603+
zend_jit_stop_counter_handlers();
75357604
goto abort;
75367605
}
75377606

0 commit comments

Comments
 (0)