Skip to content

Commit 84f1561

Browse files
committed
accel/tcg: Add CF_NO_GOTO_TB and CF_NO_GOTO_PTR
Move the -d nochain check to bits on tb->cflags. These will be used for more than -d nochain shortly. Set bits during curr_cflags, test them in translator_use_goto_tb, assert we're not doing anything odd in tcg_gen_goto_tb. The test in tcg_gen_exit_tb is redundant with the assert for goto_tb_issue_mask. Tested-by: Mark Cave-Ayland <[email protected]> Signed-off-by: Richard Henderson <[email protected]> Reviewed-by: Alex Bennée <[email protected]> Reviewed-by: Peter Maydell <[email protected]> Message-Id: <[email protected]>
1 parent 288a5fe commit 84f1561

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

accel/tcg/cpu-exec.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ static void init_delay_params(SyncClocks *sc, const CPUState *cpu)
147147

148148
uint32_t curr_cflags(CPUState *cpu)
149149
{
150-
return cpu->tcg_cflags;
150+
uint32_t cflags = cpu->tcg_cflags;
151+
152+
if (qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
153+
cflags |= CF_NO_GOTO_TB | CF_NO_GOTO_PTR;
154+
}
155+
156+
return cflags;
151157
}
152158

153159
/* Might cause an exception, so have a longjmp destination ready */

accel/tcg/translator.c

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ void translator_loop_temp_check(DisasContextBase *db)
3333

3434
bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest)
3535
{
36+
/* Suppress goto_tb if requested. */
37+
if (tb_cflags(db->tb) & CF_NO_GOTO_TB) {
38+
return false;
39+
}
40+
3641
/* Suppress goto_tb in the case of single-steping. */
3742
if (db->singlestep_enabled || singlestep) {
3843
return false;

include/exec/exec-all.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,15 @@ struct TranslationBlock {
494494
uint32_t cflags; /* compile flags */
495495

496496
/* Note that TCG_MAX_INSNS is 512; we validate this match elsewhere. */
497-
#define CF_COUNT_MASK 0x000001ff
498-
#define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */
499-
#define CF_MEMI_ONLY 0x00010000 /* Only instrument memory ops */
500-
#define CF_USE_ICOUNT 0x00020000
501-
#define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */
502-
#define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */
503-
#define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */
497+
#define CF_COUNT_MASK 0x000001ff
498+
#define CF_NO_GOTO_TB 0x00000200 /* Do not chain with goto_tb */
499+
#define CF_NO_GOTO_PTR 0x00000400 /* Do not chain with goto_ptr */
500+
#define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */
501+
#define CF_MEMI_ONLY 0x00010000 /* Only instrument memory ops */
502+
#define CF_USE_ICOUNT 0x00020000
503+
#define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */
504+
#define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */
505+
#define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */
504506
#define CF_CLUSTER_SHIFT 24
505507

506508
/* Per-vCPU dynamic tracing state used to generate this TB */

tcg/tcg-op.c

+12-16
Original file line numberDiff line numberDiff line change
@@ -2723,10 +2723,6 @@ void tcg_gen_exit_tb(const TranslationBlock *tb, unsigned idx)
27232723
seen this numbered exit before, via tcg_gen_goto_tb. */
27242724
tcg_debug_assert(tcg_ctx->goto_tb_issue_mask & (1 << idx));
27252725
#endif
2726-
/* When not chaining, exit without indicating a link. */
2727-
if (qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
2728-
val = 0;
2729-
}
27302726
} else {
27312727
/* This is an exit via the exitreq label. */
27322728
tcg_debug_assert(idx == TB_EXIT_REQUESTED);
@@ -2738,6 +2734,8 @@ void tcg_gen_exit_tb(const TranslationBlock *tb, unsigned idx)
27382734

27392735
void tcg_gen_goto_tb(unsigned idx)
27402736
{
2737+
/* We tested CF_NO_GOTO_TB in translator_use_goto_tb. */
2738+
tcg_debug_assert(!(tcg_ctx->tb_cflags & CF_NO_GOTO_TB));
27412739
/* We only support two chained exits. */
27422740
tcg_debug_assert(idx <= TB_EXIT_IDXMAX);
27432741
#ifdef CONFIG_DEBUG_TCG
@@ -2746,25 +2744,23 @@ void tcg_gen_goto_tb(unsigned idx)
27462744
tcg_ctx->goto_tb_issue_mask |= 1 << idx;
27472745
#endif
27482746
plugin_gen_disable_mem_helpers();
2749-
/* When not chaining, we simply fall through to the "fallback" exit. */
2750-
if (!qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
2751-
tcg_gen_op1i(INDEX_op_goto_tb, idx);
2752-
}
2747+
tcg_gen_op1i(INDEX_op_goto_tb, idx);
27532748
}
27542749

27552750
void tcg_gen_lookup_and_goto_ptr(void)
27562751
{
2757-
if (!qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
2758-
TCGv_ptr ptr;
2752+
TCGv_ptr ptr;
27592753

2760-
plugin_gen_disable_mem_helpers();
2761-
ptr = tcg_temp_new_ptr();
2762-
gen_helper_lookup_tb_ptr(ptr, cpu_env);
2763-
tcg_gen_op1i(INDEX_op_goto_ptr, tcgv_ptr_arg(ptr));
2764-
tcg_temp_free_ptr(ptr);
2765-
} else {
2754+
if (tcg_ctx->tb_cflags & CF_NO_GOTO_PTR) {
27662755
tcg_gen_exit_tb(NULL, 0);
2756+
return;
27672757
}
2758+
2759+
plugin_gen_disable_mem_helpers();
2760+
ptr = tcg_temp_new_ptr();
2761+
gen_helper_lookup_tb_ptr(ptr, cpu_env);
2762+
tcg_gen_op1i(INDEX_op_goto_ptr, tcgv_ptr_arg(ptr));
2763+
tcg_temp_free_ptr(ptr);
27682764
}
27692765

27702766
static inline MemOp tcg_canonicalize_memop(MemOp op, bool is64, bool st)

0 commit comments

Comments
 (0)