[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/39] tcg: reorganize tb_find_physical loop
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PULL 27/39] tcg: reorganize tb_find_physical loop |
Date: |
Thu, 12 May 2016 14:13:28 -1000 |
From: Alex Bennée <address@hidden>
Put some comments and improve code structure. This should help reading
the code.
Signed-off-by: Alex Bennée <address@hidden>
[Sergey Fedorov: provide commit message; bring back resetting of
tb_invalidated_flag]
Signed-off-by: Sergey Fedorov <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
cpu-exec.c | 44 ++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index f984dc7..02a4907 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -223,10 +223,9 @@ static TranslationBlock *tb_find_physical(CPUState *cpu,
uint32_t flags)
{
CPUArchState *env = (CPUArchState *)cpu->env_ptr;
- TranslationBlock *tb, **ptb1;
+ TranslationBlock *tb, **tb_hash_head, **ptb1;
unsigned int h;
tb_page_addr_t phys_pc, phys_page1;
- target_ulong virt_page2;
tcg_ctx.tb_ctx.tb_invalidated_flag = 0;
@@ -234,37 +233,42 @@ static TranslationBlock *tb_find_physical(CPUState *cpu,
phys_pc = get_page_addr_code(env, pc);
phys_page1 = phys_pc & TARGET_PAGE_MASK;
h = tb_phys_hash_func(phys_pc);
- ptb1 = &tcg_ctx.tb_ctx.tb_phys_hash[h];
- for(;;) {
- tb = *ptb1;
- if (!tb) {
- return NULL;
- }
+
+ /* Start at head of the hash entry */
+ ptb1 = tb_hash_head = &tcg_ctx.tb_ctx.tb_phys_hash[h];
+ tb = *ptb1;
+
+ while (tb) {
if (tb->pc == pc &&
tb->page_addr[0] == phys_page1 &&
tb->cs_base == cs_base &&
tb->flags == flags) {
- /* check next page if needed */
- if (tb->page_addr[1] != -1) {
- tb_page_addr_t phys_page2;
- virt_page2 = (pc & TARGET_PAGE_MASK) +
- TARGET_PAGE_SIZE;
- phys_page2 = get_page_addr_code(env, virt_page2);
+ if (tb->page_addr[1] == -1) {
+ /* done, we have a match */
+ break;
+ } else {
+ /* check next page if needed */
+ target_ulong virt_page2 = (pc & TARGET_PAGE_MASK) +
+ TARGET_PAGE_SIZE;
+ tb_page_addr_t phys_page2 = get_page_addr_code(env,
virt_page2);
+
if (tb->page_addr[1] == phys_page2) {
break;
}
- } else {
- break;
}
}
+
ptb1 = &tb->phys_hash_next;
+ tb = *ptb1;
}
- /* Move the TB to the head of the list */
- *ptb1 = tb->phys_hash_next;
- tb->phys_hash_next = tcg_ctx.tb_ctx.tb_phys_hash[h];
- tcg_ctx.tb_ctx.tb_phys_hash[h] = tb;
+ if (tb) {
+ /* Move the TB to the head of the list */
+ *ptb1 = tb->phys_hash_next;
+ tb->phys_hash_next = *tb_hash_head;
+ *tb_hash_head = tb;
+ }
return tb;
}
--
2.5.5
- [Qemu-devel] [PULL 17/39] tcg: Use uintptr_t type for jmp_list_{next|first} fields of TB, (continued)
- [Qemu-devel] [PULL 17/39] tcg: Use uintptr_t type for jmp_list_{next|first} fields of TB, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 18/39] tcg: Rearrange tb_link_page() to avoid forward declaration, Richard Henderson, 2016/05/12
- [Qemu-devel] [PULL 19/39] tcg: Init TB's direct jumps before making it visible, Richard Henderson, 2016/05/12
- [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 <=
- [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, 2016/05/12
- [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