[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 02/57] accel/tcg: Add cpu_in_serial_context
From: |
Richard Henderson |
Subject: |
[PATCH v3 02/57] accel/tcg: Add cpu_in_serial_context |
Date: |
Tue, 25 Apr 2023 20:30:51 +0100 |
Like cpu_in_exclusive_context, but also true if
there is no other cpu against which we could race.
Use it in tb_flush as a direct replacement.
Use it in cpu_loop_exit_atomic to ensure that there
is no loop against cpu_exec_step_atomic.
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/internal.h | 5 +++++
accel/tcg/cpu-exec-common.c | 3 +++
accel/tcg/tb-maint.c | 2 +-
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h
index 96f198b28b..8250ecbf74 100644
--- a/accel/tcg/internal.h
+++ b/accel/tcg/internal.h
@@ -64,6 +64,11 @@ static inline target_ulong log_pc(CPUState *cpu, const
TranslationBlock *tb)
}
}
+static inline bool cpu_in_serial_context(CPUState *cs)
+{
+ return !(cs->tcg_cflags & CF_PARALLEL) || cpu_in_exclusive_context(cs);
+}
+
extern int64_t max_delay;
extern int64_t max_advance;
diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c
index e7962c9348..9a5fabf625 100644
--- a/accel/tcg/cpu-exec-common.c
+++ b/accel/tcg/cpu-exec-common.c
@@ -22,6 +22,7 @@
#include "sysemu/tcg.h"
#include "exec/exec-all.h"
#include "qemu/plugin.h"
+#include "internal.h"
bool tcg_allowed;
@@ -81,6 +82,8 @@ void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)
void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc)
{
+ /* Prevent looping if already executing in a serial context. */
+ g_assert(!cpu_in_serial_context(cpu));
cpu->exception_index = EXCP_ATOMIC;
cpu_loop_exit_restore(cpu, pc);
}
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index cb1f806f00..7d613d36d2 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -760,7 +760,7 @@ void tb_flush(CPUState *cpu)
if (tcg_enabled()) {
unsigned tb_flush_count = qatomic_mb_read(&tb_ctx.tb_flush_count);
- if (cpu_in_exclusive_context(cpu)) {
+ if (cpu_in_serial_context(cpu)) {
do_tb_flush(cpu, RUN_ON_CPU_HOST_INT(tb_flush_count));
} else {
async_safe_run_on_cpu(cpu, do_tb_flush,
--
2.34.1
- [PATCH v3 00/57] tcg: Improve atomicity support, Richard Henderson, 2023/04/25
- [PATCH v3 01/57] include/exec/memop: Add bits describing atomicity, Richard Henderson, 2023/04/25
- [PATCH v3 03/57] accel/tcg: Introduce tlb_read_idx, Richard Henderson, 2023/04/25
- [PATCH v3 02/57] accel/tcg: Add cpu_in_serial_context,
Richard Henderson <=
- [PATCH v3 04/57] accel/tcg: Reorg system mode load helpers, Richard Henderson, 2023/04/25
- [PATCH v3 05/57] accel/tcg: Reorg system mode store helpers, Richard Henderson, 2023/04/25
- [PATCH v3 06/57] accel/tcg: Honor atomicity of loads, Richard Henderson, 2023/04/25
- [PATCH v3 07/57] accel/tcg: Honor atomicity of stores, Richard Henderson, 2023/04/25
- [PATCH v3 08/57] target/loongarch: Do not include tcg-ldst.h, Richard Henderson, 2023/04/25
- [PATCH v3 09/57] tcg: Unify helper_{be,le}_{ld,st}*, Richard Henderson, 2023/04/25
- [PATCH v3 10/57] accel/tcg: Implement helper_{ld, st}*_mmu for user-only, Richard Henderson, 2023/04/25
- [PATCH v3 11/57] tcg/tci: Use helper_{ld,st}*_mmu for user-only, Richard Henderson, 2023/04/25
- [PATCH v3 12/57] tcg: Add 128-bit guest memory primitives, Richard Henderson, 2023/04/25