From patchwork Fri May 13 00:13:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9087261 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B4ECB9F1C3 for ; Fri, 13 May 2016 00:34:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EFACE201F2 for ; Fri, 13 May 2016 00:34:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 342E1201C7 for ; Fri, 13 May 2016 00:34:32 +0000 (UTC) Received: from localhost ([::1]:60476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b113n-0000GJ-DI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 20:34:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10li-0002jX-8q for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b10lg-00037V-Pj for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:50 -0400 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:36817) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10lg-00037P-GV for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:48 -0400 Received: by mail-qk0-x243.google.com with SMTP id l68so7139208qkf.3 for ; Thu, 12 May 2016 17:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uKlZH5Wd4H7dSRuXIx3kWPc9JqMtYIJ1s3TM/Qtw/+c=; b=gZHgTfKE8+OsFsesn0P90riOk1UCVcgb+PAe0p/NvoC3Y0sUo6DluqYwged7pKxCwS kUwHbv42W+J9NnlOvzdwlvS3YmlMALpR8EO0KknLM0++M/j/5ZDbBR/v7LvBLC0fPbgh JtW37tHEQsz2LEpgksifZf/uIAh8YYvJWaM5hCqVJomXKKnloimb/elfK0Qx9gcak589 TsIy6WIFZTHHyXx+9JcPOYkBM5QEoXOq/o8kTnZwqOqG720fzfh/ELu9LFuc+GsaHfsu 6V82KcLfot3kcAA06fWHE+V+3xCfbVIqiuISzyin6w3FeYHWS8wzb7ck19CksebTW2EN VEaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=uKlZH5Wd4H7dSRuXIx3kWPc9JqMtYIJ1s3TM/Qtw/+c=; b=ZpasVpH6g7MD8AZDax7rYEUMBwdM4m7W3qStR5YodK1K3oaw5XoA8Wo9ggltrm4EHR GYjonaKcsTQ9if+WAcCIuLn8e1hwUFcWau+K6rDfI85gH+apmFJcQFOfIVk7NdcaXKf/ YYqHGie3UBYS9fSv9UVwehd85ZW9X6rF+4WaXA9VfcKR7J0tMhAdnySt9xHJaX/A8+Gf XDq8B41G2sT8TbDxJKLHEIPaGgd/XHGG1yga3YXpkQrAB59jHIsfwDbtNaXlXEiQ2n8y AldulHdmRV9MNGEDJJhn3SYh9CI/6+hRS3aK6j0IBoRk2osDNkoqg+FCHDEZnf5Nzbpw e+zg== X-Gm-Message-State: AOPr4FV5o5Nai54ZY8d8xUG3ffT+9JzxUcW3QmKs9SW0S1WTmup1RPMzXSCzlG4KbnNwHQ== X-Received: by 10.55.40.38 with SMTP id o38mr11605883qkh.156.1463098548242; Thu, 12 May 2016 17:15:48 -0700 (PDT) Received: from bigtime.com ([172.56.44.137]) by smtp.gmail.com with ESMTPSA id w16sm7171321qka.35.2016.05.12.17.15.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2016 17:15:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 12 May 2016 14:13:32 -1000 Message-Id: <1463098420-29113-32-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1463098420-29113-1-git-send-email-rth@twiddle.net> References: <1463098420-29113-1-git-send-email-rth@twiddle.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c09::243 Subject: [Qemu-devel] [PULL 31/39] cpu-exec: Move TB chaining into tb_find_fast() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Sergey Fedorov , Sergey Fedorov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Richard Henderson [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);