From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw8si-0005UY-7r for qemu-devel@nongnu.org; Fri, 29 Apr 2016 09:55:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aw8sW-0001oq-Dm for qemu-devel@nongnu.org; Fri, 29 Apr 2016 09:54:50 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:38271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw8sV-0001it-15 for qemu-devel@nongnu.org; Fri, 29 Apr 2016 09:54:44 -0400 Received: by mail-wm0-x22f.google.com with SMTP id g17so37633399wme.1 for ; Fri, 29 Apr 2016 06:54:24 -0700 (PDT) References: <1461881459-14297-1-git-send-email-sergey.fedorov@linaro.org> <1461881459-14297-7-git-send-email-sergey.fedorov@linaro.org> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <1461881459-14297-7-git-send-email-sergey.fedorov@linaro.org> Date: Fri, 29 Apr 2016 14:54:23 +0100 Message-ID: <87d1p8ed0w.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v6 6/6] cpu-exec: Move TB chaining into tb_find_fast() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Fedorov Cc: qemu-devel@nongnu.org, Sergey Fedorov , Paolo Bonzini , Peter Crosthwaite , Richard Henderson Sergey Fedorov writes: > From: Sergey Fedorov > > 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 > Signed-off-by: Sergey Fedorov > Signed-off-by: Sergey Fedorov > --- > > Changes in v6: > * Fixed rebase conflicts > > cpu-exec.c | 35 +++++++++++++++++++---------------- > 1 file changed, 19 insertions(+), 16 deletions(-) > > diff --git a/cpu-exec.c b/cpu-exec.c > index f49a436e1a5a..5f23c0660d6e 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)) { This should be !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); -- Alex Bennée