[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 31/39] cpu-exec: Move TB chaining into tb_find_fast()
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PULL 31/39] cpu-exec: Move TB chaining into tb_find_fast() |
Date: |
Thu, 12 May 2016 14:13:32 -1000 |
From: Sergey Fedorov <address@hidden>
Move tb_add_jump() call and surrounding code from cpu_exec() into
tb_find_fast(). That simplifies cpu_exec() a little by hiding the direct
chaining optimization details into tb_find_fast(). It also allows to
move tb_lock()/tb_unlock() pair into tb_find_fast(), putting it closer
to tb_find_slow() which also manipulates the lock.
Suggested-by: Alex Bennée <address@hidden>
Signed-off-by: Sergey Fedorov <address@hidden>
Signed-off-by: Sergey Fedorov <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
[rth: Fixed rebase typo in nochain test.]
---
cpu-exec.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index f49a436..7380b1e 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -320,7 +320,9 @@ found:
return tb;
}
-static inline TranslationBlock *tb_find_fast(CPUState *cpu)
+static inline TranslationBlock *tb_find_fast(CPUState *cpu,
+ TranslationBlock **last_tb,
+ int tb_exit)
{
CPUArchState *env = (CPUArchState *)cpu->env_ptr;
TranslationBlock *tb;
@@ -331,11 +333,24 @@ static inline TranslationBlock *tb_find_fast(CPUState
*cpu)
always be the same before a given translated block
is executed. */
cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);
+ tb_lock();
tb = cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
if (unlikely(!tb || tb->pc != pc || tb->cs_base != cs_base ||
tb->flags != flags)) {
tb = tb_find_slow(cpu, pc, cs_base, flags);
}
+ if (cpu->tb_flushed) {
+ /* Ensure that no TB jump will be modified as the
+ * translation buffer has been flushed.
+ */
+ *last_tb = NULL;
+ cpu->tb_flushed = false;
+ }
+ /* See if we can patch the calling TB. */
+ if (*last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
+ tb_add_jump(*last_tb, tb_exit, tb);
+ }
+ tb_unlock();
return tb;
}
@@ -441,7 +456,8 @@ int cpu_exec(CPUState *cpu)
} else if (replay_has_exception()
&& cpu->icount_decr.u16.low + cpu->icount_extra == 0) {
/* try to cause an exception pending in the log */
- cpu_exec_nocache(cpu, 1, tb_find_fast(cpu), true);
+ last_tb = NULL; /* Avoid chaining TBs */
+ cpu_exec_nocache(cpu, 1, tb_find_fast(cpu, &last_tb, 0), true);
ret = -1;
break;
#endif
@@ -511,20 +527,7 @@ int cpu_exec(CPUState *cpu)
cpu->exception_index = EXCP_INTERRUPT;
cpu_loop_exit(cpu);
}
- tb_lock();
- tb = tb_find_fast(cpu);
- if (cpu->tb_flushed) {
- /* Ensure that no TB jump will be modified as the
- * translation buffer has been flushed.
- */
- last_tb = NULL;
- cpu->tb_flushed = false;
- }
- /* See if we can patch the calling TB. */
- if (last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
- tb_add_jump(last_tb, tb_exit, tb);
- }
- tb_unlock();
+ tb = tb_find_fast(cpu, &last_tb, tb_exit);
if (likely(!cpu->exit_request)) {
uintptr_t ret;
trace_exec_tb(tb, tb->pc);
--
2.5.5
- [Qemu-devel] [PULL 21/39] tcg: Rename tb_jmp_remove() to tb_remove_from_jmp_list(), (continued)
- [Qemu-devel] [PULL 21/39] tcg: Rename tb_jmp_remove() to tb_remove_from_jmp_list(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 20/39] tcg: Clarify thread safety check in tb_add_jump(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 23/39] tcg: Clean up tb_jmp_unlink(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 22/39] tcg: Extract removing of jumps to TB from tb_phys_invalidate(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 24/39] tcg: Clean up direct block chaining safety checks, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 26/39] tcg: code_bitmap and code_write_count are not used by user-mode emulation, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 25/39] tcg: Allow goto_tb to any target PC in user mode, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 27/39] tcg: reorganize tb_find_physical loop, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 28/39] cpu-exec: elide more icount code if CONFIG_USER_ONLY, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 29/39] tcg: Clean up from 'next_tb', Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 31/39] cpu-exec: Move TB chaining into tb_find_fast(),
Richard Henderson <=
- [Qemu-devel] [PULL 30/39] tcg: Rework tb_invalidated_flag, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 33/39] cpu-exec: Remove relic orphaned comment, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 32/39] tcg: Remove needless CPUState::current_tb, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 35/39] cpu-exec: Move exception handling out of cpu_exec(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 34/39] cpu-exec: Move halt handling out of cpu_exec(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 38/39] cpu-exec: Remove unused 'x86_cpu' and 'env' from cpu_exec(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 36/39] cpu-exec: Move interrupt handling out of cpu_exec(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 37/39] cpu-exec: Move TB execution stuff out of cpu_exec(), Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 39/39] cpu-exec: Clean up 'interrupt_request' reloading in cpu_handle_interrupt(), Richard Henderson, 2016/05/12
- Re: [Qemu-devel] [PULL 00/39] tcg-next patch queue, Peter Maydell, 2016/05/13