linux-user: Split out begin_parallel_context

Move the test/flush/set block to a new function.
Use tb_flush__exclusive_or_serial while we're at it.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2025-09-23 13:14:09 -07:00
parent 7330741b3e
commit 430014bee7
3 changed files with 19 additions and 17 deletions

View file

@ -22,8 +22,6 @@
#include "exec/log.h"
#include "exec/page-protection.h"
#include "exec/mmap-lock.h"
#include "exec/tb-flush.h"
#include "exec/translation-block.h"
#include "qemu.h"
#include "user/page-protection.h"
#include "user-internals.h"
@ -1007,11 +1005,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
* be atomic with respect to an external process.
*/
if (ret != -1 && (flags & MAP_TYPE) != MAP_PRIVATE) {
CPUState *cpu = thread_cpu;
if (!tcg_cflags_has(cpu, CF_PARALLEL)) {
tcg_cflags_set(cpu, CF_PARALLEL);
tb_flush(cpu);
}
begin_parallel_context(thread_cpu);
}
return ret;
@ -1448,10 +1442,7 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid,
* supported by the host -- anything that requires EXCP_ATOMIC will not
* be atomic with respect to an external process.
*/
if (!tcg_cflags_has(cpu, CF_PARALLEL)) {
tcg_cflags_set(cpu, CF_PARALLEL);
tb_flush(cpu);
}
begin_parallel_context(cpu);
if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
FILE *f = qemu_log_trylock();

View file

@ -27,8 +27,6 @@
#include "target_mman.h"
#include "exec/page-protection.h"
#include "exec/mmap-lock.h"
#include "exec/tb-flush.h"
#include "exec/translation-block.h"
#include <elf.h>
#include <endian.h>
#include <grp.h>
@ -6667,10 +6665,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
* generate code for parallel execution and flush old translations.
* Do this now so that the copy gets CF_PARALLEL too.
*/
if (!tcg_cflags_has(cpu, CF_PARALLEL)) {
tcg_cflags_set(cpu, CF_PARALLEL);
tb_flush(cpu);
}
begin_parallel_context(cpu);
/* we create a new CPU instance. */
new_env = cpu_copy(env);

View file

@ -20,6 +20,8 @@
#include "user/thunk.h"
#include "qemu/log.h"
#include "exec/tb-flush.h"
#include "exec/translation-block.h"
extern char *exec_path;
void init_task_state(TaskState *ts);
@ -172,6 +174,20 @@ static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 0; }
*/
void preexit_cleanup(CPUArchState *env, int code);
/**
* begin_parallel_context
* @cs: the CPU context
*
* Called when starting the second vcpu, or joining shared memory.
*/
static inline void begin_parallel_context(CPUState *cs)
{
if (!tcg_cflags_has(cs, CF_PARALLEL)) {
tb_flush__exclusive_or_serial();
tcg_cflags_set(cs, CF_PARALLEL);
}
}
/*
* Include target-specific struct and function definitions;
* they may need access to the target-independent structures