From patchwork Fri May 13 00:13:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 67711 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3143qge; Thu, 12 May 2016 17:28:57 -0700 (PDT) X-Received: by 10.55.15.102 with SMTP id z99mr8553508qkg.209.1463099337737; Thu, 12 May 2016 17:28:57 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 199si10314236qhk.92.2016.05.12.17.28.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 12 May 2016 17:28:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:60423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10yP-0008K2-A8 for patch@linaro.org; Thu, 12 May 2016 20:28:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10lX-0002Pi-Kc for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b10lU-00032w-BE for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:39 -0400 Received: from mail-qg0-x241.google.com ([2607:f8b0:400d:c04::241]:36467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10lU-00032R-6p for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:36 -0400 Received: by mail-qg0-x241.google.com with SMTP id f74so6835239qge.3 for ; Thu, 12 May 2016 17:15:36 -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=PKa+p3ekTa7q5hxVQs7EjKWat/dcVqrrpp6OnDXYgCg=; b=l421Bb0RIvW2uw57Pkngsr5HffHGZ8283/o0tGf/liFgQ1M0oCQfLKxSHX1nDHxJud XQOIZzpg0lI738TXDLEkSniV3zxYla7DJnLFZtCI7Qw+Es4sJ2t7N6qmGL9wI3nXODMJ dDBI0fd9q82dKHoXpDQHzaPsQ9vJi9s6XI/kZN7ZJETRD2RC8KZzOWSXSsUlMXPJah4x 1AdOtdk580KAovPqGAo8+R3JTXxjXCEPEQKKwGOiH8jS7nrxDdPNlP6JifyxARCGvTbh PlBbEEs4+ytk72c92/5YP22r1sAi3lN+RAnQ4XbfKzf024NpEqoiLl3Qi78WmP+fj5L2 yMww== 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=PKa+p3ekTa7q5hxVQs7EjKWat/dcVqrrpp6OnDXYgCg=; b=dM5/RZT6XeD2+O85swBt7qIzefBVCo82obiIYUho15EEWWZmCud2wupyFGuANy/iv3 PBshKth5NiD/GsJ+hkIDFqAXUUF6B4fD/6bvJDdYtf7XZiXGwm8KucinJJC2eaCIVyEa znXdlfTFR51R7LK9lY9TNwAm0J4Q1l5iy0EW6vIpou4TUu9997OGBk/FuYMtF80XNuXt qUg3XYOO7kXhVLTRUzMzzUwdyv3yqu6axOS2jPJ+WUrwOqrsPKNBh3JaMvPgSTDQjSET Lk2dlxB0/xdbevX33XhM3nV8Pbf7LWtGH4fJIXI+he+7zb3XPcixJVSUSfEJ9l5t6uPV 7epw== X-Gm-Message-State: AOPr4FWOjVoj5O3TYNJSIFvUgcXuezbeKNnxPYX0Rl0ukCBl872oUs8ys7BDiFcanBJ6+w== X-Received: by 10.140.29.97 with SMTP id a88mr12826065qga.45.1463098535961; Thu, 12 May 2016 17:15:35 -0700 (PDT) Received: from bigtime.com ([172.56.44.137]) by smtp.gmail.com with ESMTPSA id w16sm7171321qka.35.2016.05.12.17.15.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2016 17:15:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 12 May 2016 14:13:28 -1000 Message-Id: <1463098420-29113-28-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:c04::241 Subject: [Qemu-devel] [PULL 27/39] tcg: reorganize tb_find_physical loop 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, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Sergey Fedorov Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Put some comments and improve code structure. This should help reading the code. Signed-off-by: Alex Bennée [Sergey Fedorov: provide commit message; bring back resetting of tb_invalidated_flag] Signed-off-by: Sergey Fedorov Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- cpu-exec.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) -- 2.5.5 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; }