Synchronize zend_jit_stop_counter_handlers()

Avoid stopping counters repeatedly from different threads/processes.

Fixes GH-11609
Closes GH-11806
This commit is contained in:
Ilija Tovilo 2023-07-27 16:26:50 +02:00
parent 3148da8ee1
commit b80bebc278
No known key found for this signature in database
GPG Key ID: A4F5D403F118200A
3 changed files with 20 additions and 7 deletions

3
NEWS
View File

@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.3.0beta3
- Opcache:
. Avoid resetting JIT counter handlers from multiple processes/threads.
(ilutov)
03 Aug 2023, PHP 8.3.0beta2

View File

@ -261,6 +261,7 @@ typedef struct _zend_accel_shared_globals {
LONGLONG restart_in;
#endif
bool restart_in_progress;
bool jit_counters_stopped;
/* Preloading */
zend_persistent_script *preload_script;

View File

@ -63,6 +63,7 @@ static int zend_jit_trace_startup(bool reattached)
ZEND_JIT_EXIT_COUNTERS = 0;
ZCSG(jit_traces) = zend_jit_traces;
ZCSG(jit_exit_groups) = zend_jit_exit_groups;
ZCSG(jit_counters_stopped) = false;
} else {
zend_jit_traces = ZCSG(jit_traces);
if (!zend_jit_traces) {
@ -7255,16 +7256,23 @@ static void zend_jit_stop_persistent_script(zend_persistent_script *script)
/* Get all scripts which are accelerated by JIT */
static void zend_jit_stop_counter_handlers(void)
{
if (ZCSG(jit_counters_stopped)) {
return;
}
zend_shared_alloc_lock();
/* mprotect has an extreme overhead, avoid calls to it for every function. */
SHM_UNPROTECT();
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
zend_accel_hash_entry *cache_entry;
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
zend_persistent_script *script;
if (cache_entry->indirect) continue;
script = (zend_persistent_script *)cache_entry->data;
zend_jit_stop_persistent_script(script);
if (!ZCSG(jit_counters_stopped)) {
ZCSG(jit_counters_stopped) = true;
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
zend_accel_hash_entry *cache_entry;
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
zend_persistent_script *script;
if (cache_entry->indirect) continue;
script = (zend_persistent_script *)cache_entry->data;
zend_jit_stop_persistent_script(script);
}
}
}
SHM_PROTECT();
@ -8438,6 +8446,7 @@ static void zend_jit_trace_restart(void)
ZEND_JIT_COUNTER_NUM = 0;
ZEND_JIT_EXIT_NUM = 0;
ZEND_JIT_EXIT_COUNTERS = 0;
ZCSG(jit_counters_stopped) = false;
zend_jit_trace_init_caches();
}