Skip to content

Commit 2dfd6cd

Browse files
committed
Allow counter settings to be "zero" to disable corresponding counter
1 parent d2446ca commit 2dfd6cd

File tree

4 files changed

+61
-52
lines changed

4 files changed

+61
-52
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,19 +3266,23 @@ static int zend_jit_setup_hot_counters(zend_op_array *op_array)
32663266
}
32673267
ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
32683268

3269-
if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
3270-
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
3271-
opline++;
3269+
if (JIT_G(hot_func)) {
3270+
if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
3271+
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
3272+
opline++;
3273+
}
32723274
}
3273-
}
32743275

3275-
opline->handler = (const void*)zend_jit_func_hot_counter_handler;
3276+
opline->handler = (const void*)zend_jit_func_hot_counter_handler;
3277+
}
32763278

3277-
for (i = 0; i < cfg.blocks_count; i++) {
3278-
if ((cfg.blocks[i].flags & ZEND_BB_REACHABLE) &&
3279-
(cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER)) {
3280-
op_array->opcodes[cfg.blocks[i].start].handler =
3281-
(const void*)zend_jit_loop_hot_counter_handler;
3279+
if (JIT_G(hot_loop)) {
3280+
for (i = 0; i < cfg.blocks_count; i++) {
3281+
if ((cfg.blocks[i].flags & ZEND_BB_REACHABLE) &&
3282+
(cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER)) {
3283+
op_array->opcodes[cfg.blocks[i].start].handler =
3284+
(const void*)zend_jit_loop_hot_counter_handler;
3285+
}
32823286
}
32833287
}
32843288

ext/opcache/jit/zend_jit_trace.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,7 @@ static void zend_jit_trace_setup_ret_counter(const zend_op *opline, size_t offse
24432443
{
24442444
zend_op *next_opline = (zend_op*)(opline + 1);
24452445

2446-
if (!ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags) {
2446+
if (JIT_G(hot_return) && !ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags) {
24472447
if (!ZEND_OP_TRACE_INFO(next_opline, offset)->counter) {
24482448
ZEND_OP_TRACE_INFO(next_opline, offset)->counter =
24492449
&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
50565056
}
50575057
return 0;
50585058
}
5059-
} else if (zend_jit_trace_exit_is_hot(trace_num, exit_num)) {
5059+
} else if (JIT_G(hot_side_exit) && zend_jit_trace_exit_is_hot(trace_num, exit_num)) {
50605060
return zend_jit_trace_hot_side(execute_data, trace_num, exit_num);
50615061
}
50625062

@@ -5086,18 +5086,13 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
50865086
{
50875087
zend_op *opline;
50885088
zend_jit_op_array_trace_extension *jit_extension;
5089-
zend_cfg cfg;
50905089
uint32_t i;
50915090

50925091
ZEND_ASSERT(zend_jit_func_trace_counter_handler != NULL);
50935092
ZEND_ASSERT(zend_jit_ret_trace_counter_handler != NULL);
50945093
ZEND_ASSERT(zend_jit_loop_trace_counter_handler != NULL);
50955094
ZEND_ASSERT(sizeof(zend_op_trace_info) == sizeof(zend_op));
50965095

5097-
if (zend_jit_build_cfg(op_array, &cfg) != SUCCESS) {
5098-
return FAILURE;
5099-
}
5100-
51015096
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));
51025097
memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
51035098
jit_extension->func_info.num_args = -1;
@@ -5112,42 +5107,52 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
51125107
}
51135108
ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
51145109

5115-
opline = op_array->opcodes;
5116-
if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
5117-
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
5118-
opline++;
5119-
}
5120-
}
5110+
if (JIT_G(hot_loop)) {
5111+
zend_cfg cfg;
51215112

5122-
if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) {
5123-
/* function entry */
5124-
opline->handler = (const void*)zend_jit_func_trace_counter_handler;
5125-
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
5126-
&zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
5127-
ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
5128-
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
5129-
ZEND_JIT_TRACE_START_ENTER;
5130-
}
5113+
if (zend_jit_build_cfg(op_array, &cfg) != SUCCESS) {
5114+
return FAILURE;
5115+
}
51315116

5132-
for (i = 0; i < cfg.blocks_count; i++) {
5133-
if (cfg.blocks[i].flags & ZEND_BB_REACHABLE) {
5134-
if (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER) {
5135-
/* loop header */
5136-
opline = op_array->opcodes + cfg.blocks[i].start;
5137-
if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) {
5138-
opline->handler = (const void*)zend_jit_loop_trace_counter_handler;
5139-
if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter) {
5140-
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
5141-
&zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
5142-
ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
5117+
for (i = 0; i < cfg.blocks_count; i++) {
5118+
if (cfg.blocks[i].flags & ZEND_BB_REACHABLE) {
5119+
if (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER) {
5120+
/* loop header */
5121+
opline = op_array->opcodes + cfg.blocks[i].start;
5122+
if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) {
5123+
opline->handler = (const void*)zend_jit_loop_trace_counter_handler;
5124+
if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter) {
5125+
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
5126+
&zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
5127+
ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
5128+
}
5129+
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
5130+
ZEND_JIT_TRACE_START_LOOP;
51435131
}
5144-
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
5145-
ZEND_JIT_TRACE_START_LOOP;
51465132
}
51475133
}
51485134
}
51495135
}
51505136

5137+
if (JIT_G(hot_func)) {
5138+
opline = op_array->opcodes;
5139+
if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
5140+
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
5141+
opline++;
5142+
}
5143+
}
5144+
5145+
if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags) {
5146+
/* function entry */
5147+
opline->handler = (const void*)zend_jit_func_trace_counter_handler;
5148+
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
5149+
&zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
5150+
ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
5151+
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
5152+
ZEND_JIT_TRACE_START_ENTER;
5153+
}
5154+
}
5155+
51515156
return SUCCESS;
51525157
}
51535158

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@ static int zend_jit_hybrid_hot_counter_stub(dasm_State **Dst, uint32_t cost)
22462246

22472247
static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst)
22482248
{
2249-
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2249+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) {
22502250
return 1;
22512251
}
22522252

@@ -2258,7 +2258,7 @@ static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst)
22582258

22592259
static int zend_jit_hybrid_loop_hot_counter_stub(dasm_State **Dst)
22602260
{
2261-
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2261+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) {
22622262
return 1;
22632263
}
22642264

@@ -2303,7 +2303,7 @@ static int zend_jit_hybrid_trace_counter_stub(dasm_State **Dst, uint32_t cost)
23032303

23042304
static int zend_jit_hybrid_func_trace_counter_stub(dasm_State **Dst)
23052305
{
2306-
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2306+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) {
23072307
return 1;
23082308
}
23092309

@@ -2315,7 +2315,7 @@ static int zend_jit_hybrid_func_trace_counter_stub(dasm_State **Dst)
23152315

23162316
static int zend_jit_hybrid_ret_trace_counter_stub(dasm_State **Dst)
23172317
{
2318-
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2318+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_return)) {
23192319
return 1;
23202320
}
23212321

@@ -2327,7 +2327,7 @@ static int zend_jit_hybrid_ret_trace_counter_stub(dasm_State **Dst)
23272327

23282328
static int zend_jit_hybrid_loop_trace_counter_stub(dasm_State **Dst)
23292329
{
2330-
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
2330+
if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) {
23312331
return 1;
23322332
}
23332333

ext/opcache/zend_accelerator_module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ static ZEND_INI_MH(OnUpdateJitDebug)
218218
static ZEND_INI_MH(OnUpdateCounter)
219219
{
220220
zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
221-
if (val > 0 && val < 256) {
221+
if (val >= 0 && val < 256) {
222222
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
223223
*p = val;
224224
return SUCCESS;
225225
}
226-
zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 1 and 256", ZSTR_VAL(entry->name));
226+
zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 0 and 256", ZSTR_VAL(entry->name));
227227
return FAILURE;
228228
}
229229

0 commit comments

Comments
 (0)