From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQS8-0003XM-CY for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:32:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPQS7-0002rb-5W for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:32:32 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36290) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQS6-0002rP-VX for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:32:31 -0400 Received: by mail-wm0-x244.google.com with SMTP id x83so1997145wma.3 for ; Tue, 19 Jul 2016 01:32:30 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 19 Jul 2016 10:32:16 +0200 Message-Id: <1468917141-8155-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1468917141-8155-1-git-send-email-pbonzini@redhat.com> References: <1468917141-8155-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 05/10] tcg: Prepare TB invalidation for lockless TB lookup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: serge.fdrv@gmail.com, sergey.fedorov@linaro.org, alex.bennee@linaro.org When invalidating a translation block, set an invalid flag into the TranslationBlock structure first. It is also necessary to check whether the target TB is still valid after acquiring 'tb_lock' but before calling tb_add_jump() since TB lookup is to be performed out of 'tb_lock' in future. Note that we don't have to check 'last_tb'; an already invalidated TB will not be executed anyway and it is thus safe to patch it. Suggested-by: Sergey Fedorov Signed-off-by: Paolo Bonzini --- cpu-exec.c | 5 +++-- include/exec/exec-all.h | 2 ++ translate-all.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 877ff8e..cdaab1d 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -241,7 +241,8 @@ static bool tb_cmp(const void *p, const void *d) if (tb->pc == desc->pc && tb->page_addr[0] == desc->phys_page1 && tb->cs_base == desc->cs_base && - tb->flags == desc->flags) { + tb->flags == desc->flags && + !atomic_read(&tb->invalid)) { /* check next page if needed */ if (tb->page_addr[1] == -1) { return true; @@ -352,7 +353,7 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu, /* Check if translation buffer has been flushed */ if (cpu->tb_flushed) { cpu->tb_flushed = false; - } else { + } else if (!tb->invalid) { tb_add_jump(last_tb, tb_exit, tb); } } diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index acda7b6..bc0bcc5 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -213,6 +213,8 @@ struct TranslationBlock { #define CF_USE_ICOUNT 0x20000 #define CF_IGNORE_ICOUNT 0x40000 /* Do not generate icount code */ + uint16_t invalid; + void *tc_ptr; /* pointer to the translated code */ uint8_t *tc_search; /* pointer to search data */ /* original tb when cflags has CF_NOCACHE */ diff --git a/translate-all.c b/translate-all.c index 788fed1..eaa1232 100644 --- a/translate-all.c +++ b/translate-all.c @@ -773,6 +773,7 @@ static TranslationBlock *tb_alloc(target_ulong pc) tb = &tcg_ctx.tb_ctx.tbs[tcg_ctx.tb_ctx.nb_tbs++]; tb->pc = pc; tb->cflags = 0; + tb->invalid = false; return tb; } @@ -991,6 +992,8 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) uint32_t h; tb_page_addr_t phys_pc; + atomic_set(&tb->invalid, true); + /* remove the TB from the hash list */ phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); h = tb_hash_func(phys_pc, tb->pc, tb->flags); -- 2.7.4