From: Dmitry Stogov Date: Wed, 20 May 2020 22:06:50 +0000 (+0300) Subject: Allow counter settings to be "zero" to disable corresponding counter X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2dfd6cd37314f8785244d85fa86940094a4ad212;p=php Allow counter settings to be "zero" to disable corresponding counter --- diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index 9a04f2dc95..c96a1bc973 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -3266,19 +3266,23 @@ static int zend_jit_setup_hot_counters(zend_op_array *op_array) } ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension); - if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) { - while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) { - opline++; + if (JIT_G(hot_func)) { + if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) { + while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) { + opline++; + } } - } - opline->handler = (const void*)zend_jit_func_hot_counter_handler; + opline->handler = (const void*)zend_jit_func_hot_counter_handler; + } - for (i = 0; i < cfg.blocks_count; i++) { - if ((cfg.blocks[i].flags & ZEND_BB_REACHABLE) && - (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER)) { - op_array->opcodes[cfg.blocks[i].start].handler = - (const void*)zend_jit_loop_hot_counter_handler; + if (JIT_G(hot_loop)) { + for (i = 0; i < cfg.blocks_count; i++) { + if ((cfg.blocks[i].flags & ZEND_BB_REACHABLE) && + (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER)) { + op_array->opcodes[cfg.blocks[i].start].handler = + (const void*)zend_jit_loop_hot_counter_handler; + } } } diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 22f12ca78b..22b01f4d2e 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -2443,7 +2443,7 @@ static void zend_jit_trace_setup_ret_counter(const zend_op *opline, size_t offse { zend_op *next_opline = (zend_op*)(opline + 1); - if (!ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags) { + if (JIT_G(hot_return) && !ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags) { if (!ZEND_OP_TRACE_INFO(next_opline, offset)->counter) { ZEND_OP_TRACE_INFO(next_opline, offset)->counter = &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM]; @@ -5056,7 +5056,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf } return 0; } - } else if (zend_jit_trace_exit_is_hot(trace_num, exit_num)) { + } else if (JIT_G(hot_side_exit) && zend_jit_trace_exit_is_hot(trace_num, exit_num)) { return zend_jit_trace_hot_side(execute_data, trace_num, exit_num); } @@ -5086,7 +5086,6 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array) { zend_op *opline; zend_jit_op_array_trace_extension *jit_extension; - zend_cfg cfg; uint32_t i; ZEND_ASSERT(zend_jit_func_trace_counter_handler != NULL); @@ -5094,10 +5093,6 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array) ZEND_ASSERT(zend_jit_loop_trace_counter_handler != NULL); ZEND_ASSERT(sizeof(zend_op_trace_info) == sizeof(zend_op)); - if (zend_jit_build_cfg(op_array, &cfg) != SUCCESS) { - return FAILURE; - } - jit_extension = (zend_jit_op_array_trace_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_trace_extension) + (op_array->last - 1) * sizeof(zend_op_trace_info)); memset(&jit_extension->func_info, 0, sizeof(zend_func_info)); jit_extension->func_info.num_args = -1; @@ -5112,42 +5107,52 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array) } ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension); - opline = op_array->opcodes; - if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) { - while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) { - opline++; - } - } + if (JIT_G(hot_loop)) { + zend_cfg cfg; - if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) { - /* function entry */ - opline->handler = (const void*)zend_jit_func_trace_counter_handler; - ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter = - &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM]; - ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT; - ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |= - ZEND_JIT_TRACE_START_ENTER; - } + if (zend_jit_build_cfg(op_array, &cfg) != SUCCESS) { + return FAILURE; + } - for (i = 0; i < cfg.blocks_count; i++) { - if (cfg.blocks[i].flags & ZEND_BB_REACHABLE) { - if (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER) { - /* loop header */ - opline = op_array->opcodes + cfg.blocks[i].start; - if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) { - opline->handler = (const void*)zend_jit_loop_trace_counter_handler; - if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter) { - ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter = - &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM]; - ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT; + for (i = 0; i < cfg.blocks_count; i++) { + if (cfg.blocks[i].flags & ZEND_BB_REACHABLE) { + if (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER) { + /* loop header */ + opline = op_array->opcodes + cfg.blocks[i].start; + if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) { + opline->handler = (const void*)zend_jit_loop_trace_counter_handler; + if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter) { + ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter = + &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM]; + ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT; + } + ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |= + ZEND_JIT_TRACE_START_LOOP; } - ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |= - ZEND_JIT_TRACE_START_LOOP; } } } } + if (JIT_G(hot_func)) { + opline = op_array->opcodes; + if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) { + while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) { + opline++; + } + } + + if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags) { + /* function entry */ + opline->handler = (const void*)zend_jit_func_trace_counter_handler; + ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter = + &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM]; + ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT; + ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |= + ZEND_JIT_TRACE_START_ENTER; + } + } + return SUCCESS; } diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index a58c101080..f4e8d4811f 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -2246,7 +2246,7 @@ static int zend_jit_hybrid_hot_counter_stub(dasm_State **Dst, uint32_t cost) static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst) { - if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) { + if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) { return 1; } @@ -2258,7 +2258,7 @@ static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst) static int zend_jit_hybrid_loop_hot_counter_stub(dasm_State **Dst) { - if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) { + if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) { return 1; } @@ -2303,7 +2303,7 @@ static int zend_jit_hybrid_trace_counter_stub(dasm_State **Dst, uint32_t cost) static int zend_jit_hybrid_func_trace_counter_stub(dasm_State **Dst) { - if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) { + if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) { return 1; } @@ -2315,7 +2315,7 @@ static int zend_jit_hybrid_func_trace_counter_stub(dasm_State **Dst) static int zend_jit_hybrid_ret_trace_counter_stub(dasm_State **Dst) { - if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) { + if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_return)) { return 1; } @@ -2327,7 +2327,7 @@ static int zend_jit_hybrid_ret_trace_counter_stub(dasm_State **Dst) static int zend_jit_hybrid_loop_trace_counter_stub(dasm_State **Dst) { - if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) { + if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) { return 1; } diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index 4a535591c0..7ff085c059 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -218,12 +218,12 @@ static ZEND_INI_MH(OnUpdateJitDebug) static ZEND_INI_MH(OnUpdateCounter) { zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); - if (val > 0 && val < 256) { + if (val >= 0 && val < 256) { zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); *p = val; return SUCCESS; } - zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 1 and 256", ZSTR_VAL(entry->name)); + zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 0 and 256", ZSTR_VAL(entry->name)); return FAILURE; }