[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/62] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller
From: |
Richard Henderson |
Subject: |
[PULL 15/62] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller |
Date: |
Tue, 28 Feb 2023 16:55:56 -1000 |
From: Anton Johansson via <qemu-devel@nongnu.org>
tb-jmp-cache.h contains a few small functions that only exist to hide a
CF_PCREL check, however the caller often already performs such a check.
This patch moves CF_PCREL checks from the callee to the caller, and also
removes these functions which now only hide an access of the jmp-cache.
Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230227135202.9710-12-anjo@rev.ng>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/tb-jmp-cache.h | 36 ---------------------------
accel/tcg/cpu-exec.c | 54 +++++++++++++++++++++++++++++-----------
2 files changed, 40 insertions(+), 50 deletions(-)
diff --git a/accel/tcg/tb-jmp-cache.h b/accel/tcg/tb-jmp-cache.h
index 083939b302..bee87eb840 100644
--- a/accel/tcg/tb-jmp-cache.h
+++ b/accel/tcg/tb-jmp-cache.h
@@ -25,40 +25,4 @@ struct CPUJumpCache {
} array[TB_JMP_CACHE_SIZE];
};
-static inline TranslationBlock *
-tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t cflags, uint32_t hash)
-{
- if (cflags & CF_PCREL) {
- /* Use acquire to ensure current load of pc from jc. */
- return qatomic_load_acquire(&jc->array[hash].tb);
- } else {
- /* Use rcu_read to ensure current load of pc from *tb. */
- return qatomic_rcu_read(&jc->array[hash].tb);
- }
-}
-
-static inline target_ulong
-tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb)
-{
- if (tb_cflags(tb) & CF_PCREL) {
- return jc->array[hash].pc;
- } else {
- return tb_pc(tb);
- }
-}
-
-static inline void
-tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash,
- TranslationBlock *tb, target_ulong pc)
-{
- if (tb_cflags(tb) & CF_PCREL) {
- jc->array[hash].pc = pc;
- /* Use store_release on tb to ensure pc is written first. */
- qatomic_store_release(&jc->array[hash].tb, tb);
- } else{
- /* Use the pc value already stored in tb->pc. */
- qatomic_set(&jc->array[hash].tb, tb);
- }
-}
-
#endif /* ACCEL_TCG_TB_JMP_CACHE_H */
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 013856f103..aa14e97958 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -254,21 +254,46 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu,
target_ulong pc,
hash = tb_jmp_cache_hash_func(pc);
jc = cpu->tb_jmp_cache;
- tb = tb_jmp_cache_get_tb(jc, cflags, hash);
- if (likely(tb &&
- tb_jmp_cache_get_pc(jc, hash, tb) == pc &&
- tb->cs_base == cs_base &&
- tb->flags == flags &&
- tb->trace_vcpu_dstate == *cpu->trace_dstate &&
- tb_cflags(tb) == cflags)) {
- return tb;
+ if (cflags & CF_PCREL) {
+ /* Use acquire to ensure current load of pc from jc. */
+ tb = qatomic_load_acquire(&jc->array[hash].tb);
+
+ if (likely(tb &&
+ jc->array[hash].pc == pc &&
+ tb->cs_base == cs_base &&
+ tb->flags == flags &&
+ tb->trace_vcpu_dstate == *cpu->trace_dstate &&
+ tb_cflags(tb) == cflags)) {
+ return tb;
+ }
+ tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags);
+ if (tb == NULL) {
+ return NULL;
+ }
+ jc->array[hash].pc = pc;
+ /* Use store_release on tb to ensure pc is written first. */
+ qatomic_store_release(&jc->array[hash].tb, tb);
+ } else {
+ /* Use rcu_read to ensure current load of pc from *tb. */
+ tb = qatomic_rcu_read(&jc->array[hash].tb);
+
+ if (likely(tb &&
+ tb_pc(tb) == pc &&
+ tb->cs_base == cs_base &&
+ tb->flags == flags &&
+ tb->trace_vcpu_dstate == *cpu->trace_dstate &&
+ tb_cflags(tb) == cflags)) {
+ return tb;
+ }
+ tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags);
+ if (tb == NULL) {
+ return NULL;
+ }
+ /* Use the pc value already stored in tb->pc. */
+ qatomic_set(&jc->array[hash].tb, tb);
}
- tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags);
- if (tb == NULL) {
- return NULL;
- }
- tb_jmp_cache_set(jc, hash, tb, pc);
+
return tb;
}
@@ -957,7 +982,8 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
* for the fast lookup
*/
h = tb_jmp_cache_hash_func(pc);
- tb_jmp_cache_set(cpu->tb_jmp_cache, h, tb, pc);
+ /* Use the pc value already stored in tb->pc. */
+ qatomic_set(&cpu->tb_jmp_cache->array[h].tb, tb);
}
#ifndef CONFIG_USER_ONLY
--
2.34.1
- [PULL 13/62] target/arm: Remove `TARGET_TB_PCREL` define, (continued)
- [PULL 13/62] target/arm: Remove `TARGET_TB_PCREL` define, Richard Henderson, 2023/02/28
- [PULL 09/62] include/exec: Replace `TARGET_TB_PCREL` with `CF_PCREL`, Richard Henderson, 2023/02/28
- [PULL 14/62] target/i386: Remove `TARGET_TB_PCREL` define, Richard Henderson, 2023/02/28
- [PULL 11/62] target/i386: Replace `TARGET_TB_PCREL` with `CF_PCREL`, Richard Henderson, 2023/02/28
- [PULL 12/62] include/exec: Remove `TARGET_TB_PCREL` define, Richard Henderson, 2023/02/28
- [PULL 18/62] target/sparc: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 16/62] accel/tcg: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 20/62] target/rx: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 17/62] target/tricore: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 21/62] target/riscv: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 15/62] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller,
Richard Henderson <=
- [PULL 19/62] target/sh4: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 22/62] target/openrisc: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 23/62] target/mips: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 24/62] target/microblaze: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 28/62] target/hexagon: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 30/62] target/arm: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 32/62] tcg: Adjust TCGContext.temps_in_use check, Richard Henderson, 2023/02/28
- [PULL 25/62] target/loongarch: Replace `tb_pc()` with `tb->pc`, Richard Henderson, 2023/02/28
- [PULL 31/62] include/exec: Remove `tb_pc()`, Richard Henderson, 2023/02/28
- [PULL 33/62] accel/tcg: Pass max_insn to gen_intermediate_code by pointer, Richard Henderson, 2023/02/28