From nobody Wed Nov 5 13:30:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497472113208584.1612012841846; Wed, 14 Jun 2017 13:28:33 -0700 (PDT) Received: from localhost ([::1]:50714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEtx-0007Wr-S7 for importer@patchew.org; Wed, 14 Jun 2017 16:28:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLEt8-0007Ea-60 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:27:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLEt4-0004e9-7L for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:27:38 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:40741) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLEt4-0004dq-0j for qemu-devel@nongnu.org; Wed, 14 Jun 2017 16:27:34 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 76E0420C0D; Wed, 14 Jun 2017 16:27:33 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Wed, 14 Jun 2017 16:27:33 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 356847E6E5; Wed, 14 Jun 2017 16:27:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=egge7CPrQ0pu2mF 4GiWW4TqtEfNwLguKOVNL2WFNb9g=; b=kRj8lT3uI9D6hpRnr+L1pjW3uwVv2+w 8Fp3BXnylDqgvn38tDV5FaJpTRWWCHNPia+zP/JNB8ElVxIAPaPeH5basYVD607O 00cH3edYP7giL52yDC3qLTQHqUJ/JX5XIi8CrAG7mPmPA348qwljTopNdu2/eete PjNPOSFWIh0A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=egge7CPrQ0pu2mF4GiWW4TqtEfNwLguKOVNL2WFNb9g=; b=pf+F7t3r IBWuxZvyIipVnn2wA7bcd3irCUTJwaPiKxtBmm7OaD0NaEt+6ZRAs/9knkYEnluw pOHTLTE7kyQDo2zx5aUinw0EBc2gOilXMe8lnBHxNFbcxBZY65EocaryrqrAb3wK 3BxDUHCB2i8gdPjADlcYnF5eRo5AbAAPlLwTZj7xY7mHssHX1nts9jw8gVQMS/cW p4WOfh8GtEDsrfS6y0wWguKaH6gHvFQkvXy8GDE5b6LaBcANb++nnTBmIJ4UA0s4 6is5SGi6tc7fKl+8go2/TdewNMnXo4r9oFN+bvFGmbHKOrZYvZ8Pnf7yQzwW4Llp F184utXKjFaFWg== X-ME-Sender: X-Sasl-enc: G6hQyZqbjjW/FqlVun5jD0MKzAYwqs9BBrsPvTMrt4Jr 1497472053 Date: Wed, 14 Jun 2017 16:27:33 -0400 From: "Emilio G. Cota" To: Richard Henderson Message-ID: <20170614202733.GA8420@flamenco> References: <20170614194821.8754-1-rth@twiddle.net> <20170614194821.8754-2-rth@twiddle.net> MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20170614194821.8754-2-rth@twiddle.net> User-Agent: Mutt/1.5.24 (2015-08-30) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.28 Subject: [Qemu-devel] [PATCH] tcg-runtime: increase hit rate of lookup_tb_ptr 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: pbonzini@redhat.com, alex.bennee@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" On Wed, Jun 14, 2017 at 12:48:17 -0700, Richard Henderson wrote: > We can call tb_htable_lookup even when the tb_jmp_cache > is completely empty. Therefore, un-nest most of the code > dependent on tb !=3D NULL from the read from the cache. >=20 > Signed-off-by: Richard Henderson I just wrote this alternative patch, which does the same thing as yours. I also measured what the effect of this change has on the hit rate of lookup_tb_ptr. Feel free to reuse parts of the patch and/or the commit message! Thanks, E. Suggested-by: Alex Benn=C3=A9e Suggested-by: Richard Henderson --- 8< --- Strangely, we do not look up the tb in the global hash table when we get NULL from tb_jmp_cache. Fix it, which improves the hit rate of lookup_tb_ptr; for instance, when booting and immediately shutting down debian-arm, the hit rate improves from 93.150742% (before this patch) to 99.451323 % (after). While at it, use a variable for the tb_jmp_cache hash and get rid of the goto's. Suggested-by: Richard Henderson Suggested-by: Alex Benn=C3=A9e Signed-off-by: Emilio G. Cota --- tcg-runtime.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tcg-runtime.c b/tcg-runtime.c index 7fa90ce..09324b9 100644 --- a/tcg-runtime.c +++ b/tcg-runtime.c @@ -149,23 +149,19 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env, target= _ulong addr) CPUState *cpu =3D ENV_GET_CPU(env); TranslationBlock *tb; target_ulong cs_base, pc; + unsigned int hash =3D tb_jmp_cache_hash_func(addr); uint32_t flags; =20 - tb =3D atomic_rcu_read(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(addr)= ]); - if (likely(tb)) { - cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); - if (likely(tb->pc =3D=3D addr && tb->cs_base =3D=3D cs_base && - tb->flags =3D=3D flags)) { - goto found; - } + tb =3D atomic_rcu_read(&cpu->tb_jmp_cache[hash]); + cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); + if (unlikely(tb =3D=3D NULL || tb->pc !=3D addr || tb->cs_base !=3D cs= _base || + tb->flags !=3D flags)) { tb =3D tb_htable_lookup(cpu, addr, cs_base, flags); - if (likely(tb)) { - atomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(addr)], t= b); - goto found; + if (unlikely(tb =3D=3D NULL)) { + return tcg_ctx.code_gen_epilogue; } + atomic_set(&cpu->tb_jmp_cache[hash], tb); } - return tcg_ctx.code_gen_epilogue; - found: qemu_log_mask_and_addr(CPU_LOG_EXEC, addr, "Chain %p [%d: " TARGET_FMT_lx "] %s\n", tb->tc_ptr, cpu->cpu_index, addr, --=20 2.7.4