Skip to content

Commit b80bebc

Browse files
committed
Synchronize zend_jit_stop_counter_handlers()
Avoid stopping counters repeatedly from different threads/processes. Fixes GH-11609 Closes GH-11806
1 parent 3148da8 commit b80bebc

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.0beta3
44

5+
- Opcache:
6+
. Avoid resetting JIT counter handlers from multiple processes/threads.
7+
(ilutov)
58

69
03 Aug 2023, PHP 8.3.0beta2
710

ext/opcache/ZendAccelerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ typedef struct _zend_accel_shared_globals {
261261
LONGLONG restart_in;
262262
#endif
263263
bool restart_in_progress;
264+
bool jit_counters_stopped;
264265

265266
/* Preloading */
266267
zend_persistent_script *preload_script;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static int zend_jit_trace_startup(bool reattached)
6363
ZEND_JIT_EXIT_COUNTERS = 0;
6464
ZCSG(jit_traces) = zend_jit_traces;
6565
ZCSG(jit_exit_groups) = zend_jit_exit_groups;
66+
ZCSG(jit_counters_stopped) = false;
6667
} else {
6768
zend_jit_traces = ZCSG(jit_traces);
6869
if (!zend_jit_traces) {
@@ -7255,16 +7256,23 @@ static void zend_jit_stop_persistent_script(zend_persistent_script *script)
72557256
/* Get all scripts which are accelerated by JIT */
72567257
static void zend_jit_stop_counter_handlers(void)
72577258
{
7259+
if (ZCSG(jit_counters_stopped)) {
7260+
return;
7261+
}
7262+
72587263
zend_shared_alloc_lock();
72597264
/* mprotect has an extreme overhead, avoid calls to it for every function. */
72607265
SHM_UNPROTECT();
7261-
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
7262-
zend_accel_hash_entry *cache_entry;
7263-
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
7264-
zend_persistent_script *script;
7265-
if (cache_entry->indirect) continue;
7266-
script = (zend_persistent_script *)cache_entry->data;
7267-
zend_jit_stop_persistent_script(script);
7266+
if (!ZCSG(jit_counters_stopped)) {
7267+
ZCSG(jit_counters_stopped) = true;
7268+
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
7269+
zend_accel_hash_entry *cache_entry;
7270+
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
7271+
zend_persistent_script *script;
7272+
if (cache_entry->indirect) continue;
7273+
script = (zend_persistent_script *)cache_entry->data;
7274+
zend_jit_stop_persistent_script(script);
7275+
}
72687276
}
72697277
}
72707278
SHM_PROTECT();
@@ -8438,6 +8446,7 @@ static void zend_jit_trace_restart(void)
84388446
ZEND_JIT_COUNTER_NUM = 0;
84398447
ZEND_JIT_EXIT_NUM = 0;
84408448
ZEND_JIT_EXIT_COUNTERS = 0;
8449+
ZCSG(jit_counters_stopped) = false;
84418450

84428451
zend_jit_trace_init_caches();
84438452
}

0 commit comments

Comments
 (0)