From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499586924939320.761947959566; Sun, 9 Jul 2017 00:55:24 -0700 (PDT) Received: from localhost ([::1]:35257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU73r-0007xV-CB for importer@patchew.org; Sun, 09 Jul 2017 03:55:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R5-5R for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zD-0002z1-UJ for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:40 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:42219) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zD-0002vG-Ny for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:35 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BC3402086C; Sun, 9 Jul 2017 03:50:31 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:31 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 7B80C7E70C; Sun, 9 Jul 2017 03:50:31 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=nN9 c5YFSSGysjE+mDDij2MShHfmKwX13IpXE6Tl6kFw=; b=sIyrBqB17Gq///Ap4Mm /2hxF7ha1+bNNblYC/n5OtMOdpkq0peKDo9y8wfcKxUGoxIKseEUr40xqO9MSVDG DXfdnvQloUV18+/OSTX1MGo0hm7vVMRA0UyZ8kG2VAJxLdwFsQgqOX6lXZcEVqc3 EC/1TBS5Ajc1QvsIln+zeERM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=nN9c5YFSSGysjE+mDDij2MShHfmKwX13IpXE6Tl6k Fw=; b=pVK5h7W8o40CowU5Ih0o19Y5lk6LsLDzck0XzM8kb5eODSW97vXlP7Ay7 5sF8nMtn89S/nEuYVMO0j94rgP0OB+tlrpVX0LpCfa688eWRu01VWrSk3lV3PT4d e63ie4M9FgB5CrGJ29qfmKZUGJiC5mb6/1r2xtyanicfUK4+Xb+vWlcpJjI65kuX LY5vzG2VRthudGkaFbqdO2ZSMZrHsC6v3lhlLMB7ZuqChIlb7QTNsdcEJLPzxKWA NaBS5N/wduX2A2bGKGMefEjey9wxzyOWCFpx9GQHB/4qupZpcDWjJPxs5CeV2PVo GDC6i8VDb91chY2ifqhXpYAJv3nDg== X-ME-Sender: X-Sasl-enc: 7ejrjEwLBLN7zw0l66U+hISYhQkCa7k42wHevTtKYBen 1499586631 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:49:53 -0400 Message-Id: <1499586614-20507-2-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 01/22] vl: fix breakage of -tb-size 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit e7b161d573 ("vl: add tcg_enabled() for tcg related code") adds a check to exit the program when !tcg_enabled() while parsing the -tb-size flag. It turns out that when the -tb-size flag is evaluated, tcg_enabled() can only return 0, since it is set (or not) much later by configure_accelerator= (). Fix it by unconditionally exiting if the flag is passed to a QEMU binary built with !CONFIG_TCG. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Tested-by: Alex Benn=C3=A9e --- vl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vl.c b/vl.c index d17c863..9ece570 100644 --- a/vl.c +++ b/vl.c @@ -3933,10 +3933,10 @@ int main(int argc, char **argv, char **envp) configure_rtc(opts); break; case QEMU_OPTION_tb_size: - if (!tcg_enabled()) { - error_report("TCG is disabled"); - exit(1); - } +#ifndef CONFIG_TCG + error_report("TCG is disabled"); + exit(1); +#endif if (qemu_strtoul(optarg, NULL, 0, &tcg_tb_size) < 0) { error_report("Invalid argument to -tb-size"); exit(1); --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 149958708268680.21007104939008; Sun, 9 Jul 2017 00:58:02 -0700 (PDT) Received: from localhost ([::1]:35272 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU76P-0001h8-AD for importer@patchew.org; Sun, 09 Jul 2017 03:58:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004RA-71 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zD-0002zQ-W5 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:41 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:48077) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zD-0002vI-O3 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:35 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DFEFE208A9; Sun, 9 Jul 2017 03:50:31 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:31 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id AEED4248B9; Sun, 9 Jul 2017 03:50:31 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=75J Lo4dc9KwImbl+4veFfhnV0oQ4RAG9xZmBEKM9Ed0=; b=nOmR8GwSrJ7OD6bJqrM tpG+MgNnpRPp+WJCxlgUZ+JqEDPffxFrN2ng8GjcWiXGaZVZjaYiAVseyFKJRRhO pSuUMuTnFUCdLu8NtsMy9WPlX8Ro/2to+uYUpx71J6Fc/ohLQeZhIy9ANDZRgGxs UWOa8cHi5DELhKqNNyNqQ+6Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=75JLo4dc9KwImbl+4veFfhnV0oQ4RAG9xZmBEKM9E d0=; b=fQR2HmWb+DXG3k6E1CoDtQWOhI+rEzMiYoDCmeP+oAUo4S52kZtxqQSKk YoRsf603JkGPk9kpIo8Lk2/jzNPcGEb3SfLrzvkJt43/duyaAdKPZg83p+hYN+IK mc7W5hqGu2GrYyNi51j3emuwGXFwhgUH9f8Psxw7oDVLAzptWxtYeh/QPKP6TpYr 84pBful1Np3mfjtdtQZ+sOdJ0HpdeokVOtr7F2+HNtQq54xSecWOLUCXj4QadrPK Alzmt1Xw+BnOkLQFae9KMGNMJmeQJ0oP7gpPC4M132zosJZjISQKBJjPyDAPVJNc EeuapdzYeIVbAfKwDX1NkBpcs4KBA== X-ME-Sender: X-Sasl-enc: 7ejjnVkYEqt1yA4l7L8+hISYhQkCa7k42wHevTtKYBen 1499586631 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:49:54 -0400 Message-Id: <1499586614-20507-3-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 02/22] translate-all: remove redundant !tcg_enabled check in dump_exec_info 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This check is redundant because it is already performed by the only caller of dump_exec_info -- the caller was updated by b7da97eef ("monitor: Check whether TCG is enabled before running the "info jit" code"). Checking twice wouldn't necessarily be too bad, but here the check also returns with tb_lock held. So we can either do the check before tb_lock is acquired, or just get rid of it. Given that it is redundant, I am going for the latter option. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Thomas Huth --- accel/tcg/translate-all.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index dfb9f0d..f768681 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1851,11 +1851,6 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fp= rintf) =20 tb_lock(); =20 - if (!tcg_enabled()) { - cpu_fprintf(f, "TCG not enabled\n"); - return; - } - target_code_size =3D 0; max_target_code_size =3D 0; cross_page =3D 0; --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499586932811631.5741814817007; Sun, 9 Jul 2017 00:55:32 -0700 (PDT) Received: from localhost ([::1]:35260 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU73z-00083M-FE for importer@patchew.org; Sun, 09 Jul 2017 03:55:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R9-6e for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-0002zZ-0V for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:40 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:46941) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zD-0002vF-O4 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:35 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 20BE5208C1; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:32 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id D90457E70C; Sun, 9 Jul 2017 03:50:31 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=OxC upJ9kaPIQ65jxY4EaWyWzBqgguQst3e6vw+DwxTM=; b=Mx2sNbhmWuWN/iU8NXa o+F1h0HhfGAkHykoYzJ3ohqsz+4pV+IvdYVwHub+7ZV4yRyGu7iH1n6eofDmT1NL kL2zto7LEGATzdXghqNJnzbC5HJAwc7FBrkRLvo5eEro9F71xQVI/8M3eJlokh6N 7f6oGOSHiW3Srwr+veOM8T1A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=OxCupJ9kaPIQ65jxY4EaWyWzBqgguQst3e6vw+Dwx TM=; b=cFmmewHXoejST1xlvnJtUQxHRv5vjmNCfG4ecacGXWf6R5tT/4yMv+UeS Ncze3vXJIaSgOKCyt25j0al0AmB10rFib/nRHxkgiZBNQybLHGzsJl3ei+tMoVom gGCTumBxOSTErprIRlFt4Jr7ydt8jccgcfqIT/+V4cmG6jNIFWXCK6J0pJhzwHlc PieCxRtPp05KdXNqtbjoBIfLnDnBmXJ3tI1fiWwhp+k90BVoaj7j5Oa4iYJiu9FZ cJ4vZ5v5SxscTVII3ZhnEVfOGyB07Z9nvqx69Nq/0TpCwHU7t3X1ikrmLjvJgVsM ftxn0XISHdVlSX68tchyD4vhQDrCg== X-ME-Sender: X-Sasl-enc: 7ejih04MB7R8yRco9qA+hISYhQkCa7k42wHevTtKYBen 1499586631 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:49:55 -0400 Message-Id: <1499586614-20507-4-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 03/22] cputlb: bring back tlb_flush_count under !TLB_DEBUG 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit f0aff0f124 ("cputlb: add assert_cpu_is_self checks") buried the increment of tlb_flush_count under TLB_DEBUG. This results in "info jit" always (mis)reporting 0 TLB flushes when !TLB_DEBUG. Besides, under MTTCG tlb_flush_count is updated by several threads, so in order not to lose counts we'd either have to use atomic ops or distribute the counter, which is more scalable. This patch does the latter by embedding tlb_flush_count in CPUArchState. The global count is then easily obtained by iterating over the CPU list. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- include/exec/cpu-defs.h | 1 + include/exec/cputlb.h | 3 +-- accel/tcg/cputlb.c | 17 ++++++++++++++--- accel/tcg/translate-all.c | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index bc8e7f8..e43ff83 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -137,6 +137,7 @@ typedef struct CPUIOTLBEntry { CPUTLBEntry tlb_v_table[NB_MMU_MODES][CPU_VTLB_SIZE]; \ CPUIOTLBEntry iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ CPUIOTLBEntry iotlb_v[NB_MMU_MODES][CPU_VTLB_SIZE]; \ + size_t tlb_flush_count; \ target_ulong tlb_flush_addr; \ target_ulong tlb_flush_mask; \ target_ulong vtlb_index; \ diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h index 3f94178..c91db21 100644 --- a/include/exec/cputlb.h +++ b/include/exec/cputlb.h @@ -23,7 +23,6 @@ /* cputlb.c */ void tlb_protect_code(ram_addr_t ram_addr); void tlb_unprotect_code(ram_addr_t ram_addr); -extern int tlb_flush_count; - +size_t tlb_flush_count(void); #endif #endif diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 85635ae..9377110 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -92,8 +92,18 @@ static void flush_all_helper(CPUState *src, run_on_cpu_f= unc fn, } } =20 -/* statistics */ -int tlb_flush_count; +size_t tlb_flush_count(void) +{ + CPUState *cpu; + size_t count =3D 0; + + CPU_FOREACH(cpu) { + CPUArchState *env =3D cpu->env_ptr; + + count +=3D atomic_read(&env->tlb_flush_count); + } + return count; +} =20 /* This is OK because CPU architectures generally permit an * implementation to drop entries from the TLB at any time, so @@ -112,7 +122,8 @@ static void tlb_flush_nocheck(CPUState *cpu) } =20 assert_cpu_is_self(cpu); - tlb_debug("(count: %d)\n", tlb_flush_count++); + atomic_set(&env->tlb_flush_count, env->tlb_flush_count + 1); + tlb_debug("(count: %zu)\n", tlb_flush_count()); =20 tb_lock(); =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f768681..a936a5f 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1909,7 +1909,7 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fpr= intf) atomic_read(&tcg_ctx.tb_ctx.tb_flush_count)); cpu_fprintf(f, "TB invalidate count %d\n", tcg_ctx.tb_ctx.tb_phys_invalidate_count); - cpu_fprintf(f, "TLB flush count %d\n", tlb_flush_count); + cpu_fprintf(f, "TLB flush count %zu\n", tlb_flush_count()); tcg_dump_info(f, cpu_fprintf); =20 tb_unlock(); --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499587217015126.0128599000542; Sun, 9 Jul 2017 01:00:17 -0700 (PDT) Received: from localhost ([::1]:35283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU78Z-0003Zv-QX for importer@patchew.org; Sun, 09 Jul 2017 04:00:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R8-6Q for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zD-0002zO-WC for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:41 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:48037) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zD-0002vJ-O5 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:35 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4B404208CD; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:32 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 14154248A1; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=uDH WVS/oxfXkKzY5QBFdeHKwv3yk1QCU7TAslBsJ4MA=; b=F2LqsDxk07t8CHl/Cd0 n2zr0QTBrVpX+N+Nb75Q1R654wJeoSdlnb/9eEmb8sTDYEZOQ8IUy9zZrJiJU0dm yD+AyDPOs0vKPHG5v6dcuaVAoKfQ+7wF7zwnsWe4KIUniwYVkUCaZPd7p0HsvtZ7 4veHhuNA30yhHRz++2yZxjHI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=uDHWVS/oxfXkKzY5QBFdeHKwv3yk1QCU7TAslBsJ4 MA=; b=WCXq+jfOfsThCEs5PVOD8Hmzk8+jyciLRopJr4002RCmKw/F1ZsXQLrKz Ilp8BnnL0WD98JHgfuklWTHg39SvOILqS9KMI/sJ1Qpce/M3fsSnuJuGDg+/JAgz NtZdQdcudy1aIMvfL2k1uzPulVaHlM5tidizKQrBgnLB32+W1I9aLu3MGbLlKGbh tADdJzHFASVXgCxwzsyXjKygSHJOiDLOhtPw8AFiUOedOWQg4TPqM8as3Z8vGyEa 7pguybPQIGFfA9ZHlih3kB9DtNSyB/69c4/SoDYHqwswslbsuyjJluheGBpTPi5P uaKi3xet09g5dnGZxLBiPOvq1EwYA== X-ME-Sender: X-Sasl-enc: UOkd9YtvOZ9mZIn7nW/E+ZHP7/4tip83VkDN94hCA78s 1499586632 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:49:56 -0400 Message-Id: <1499586614-20507-5-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 04/22] tcg: fix corruption of code_time profiling counter upon tb_flush 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Whenever there is an overflow in code_gen_buffer (e.g. we run out of space in it and have to flush it), the code_time profiling counter ends up with an invalid value (that is, code_time -=3D profile_getclock(), without later on getting +=3D profile_getclock() due to the goto). Fix it by using the ti variable, so that we only update code_time when there is no overflow. Note that in case there is an overflow we fail to account for the elapsed coding time, but this is quite rare so we can probably live with it. "info jit" before/after, roughly at the same time during debian-arm bootup: - before: Statistics: TB flush count 1 TB invalidate count 4665 TLB flush count 998 JIT cycles -615191529184601 (-256329.804 s at 2.4 GHz) translated TBs 302310 (aborted=3D0 0.0%) avg ops/TB 48.4 max=3D438 deleted ops/TB 8.54 avg temps/TB 32.31 max=3D38 avg host code/TB 361.5 avg search data/TB 24.5 cycles/op -42014693.0 cycles/in byte -121444900.2 cycles/out byte -5629031.1 cycles/search byte -83114481.0 gen_interm time -0.0% gen_code time 100.0% optim./code time -0.0% liveness/code time -0.0% cpu_restore count 6236 avg cycles 110.4 - after: Statistics: TB flush count 1 TB invalidate count 4665 TLB flush count 1010 JIT cycles 1996899624 (0.832 s at 2.4 GHz) translated TBs 297961 (aborted=3D0 0.0%) avg ops/TB 48.5 max=3D438 deleted ops/TB 8.56 avg temps/TB 32.31 max=3D38 avg host code/TB 361.8 avg search data/TB 24.5 cycles/op 138.2 cycles/in byte 398.4 cycles/out byte 18.5 cycles/search byte 273.1 gen_interm time 14.0% gen_code time 86.0% optim./code time 19.4% liveness/code time 10.3% cpu_restore count 6372 avg cycles 111.0 Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- accel/tcg/translate-all.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index a936a5f..72ce445 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1293,7 +1293,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #ifdef CONFIG_PROFILER tcg_ctx.tb_count++; tcg_ctx.interm_time +=3D profile_getclock() - ti; - tcg_ctx.code_time -=3D profile_getclock(); + ti =3D profile_getclock(); #endif =20 /* ??? Overflow could be handled better here. In particular, we @@ -1311,7 +1311,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } =20 #ifdef CONFIG_PROFILER - tcg_ctx.code_time +=3D profile_getclock(); + tcg_ctx.code_time +=3D profile_getclock() - ti; tcg_ctx.code_in_len +=3D tb->size; tcg_ctx.code_out_len +=3D gen_code_size; tcg_ctx.search_out_len +=3D search_size; --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499587488464209.59789718434513; Sun, 9 Jul 2017 01:04:48 -0700 (PDT) Received: from localhost ([::1]:35310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7Cw-00077i-AO for importer@patchew.org; Sun, 09 Jul 2017 04:04:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zK-0004RC-I8 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030e-OB for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:42 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:44859) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002z7-9L for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7A6D0208CF; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:32 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 3DB837E70C; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=1EK LKz/XI2G9helWzXQ3sjJNeqZebWH7gJw7dR4EZLI=; b=1tw46nRaayORMdOt4WE vJzAaX+LiWGAqqs44JGFsiM/lkFUocHDQB3QnKHjCd+knl5r90yp3+s0KY8zxa3u zFW8PhWARr+49IuNSVE+kRzmIkbPW1H2ZNg1n53VjD7CvEOiufTraIcG+6vnSoMO +MTXs6zWAIrk+mfU3EYmcJok= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=1EKLKz/XI2G9helWzXQ3sjJNeqZebWH7gJw7dR4EZ LI=; b=RhsxIwcS7apc2fzFZHNufS2obhcJzZtH25pbFrxynzgJnSEgNHGuA+Dox ueulF73lqI6SLfPp4Ick19WXwd3Tps8S230jmI9Rn64zl01bAiDobYHApMcWLTPF 2NsWkT6kYFkxL4aXTZns5KgPNkEKK7ot05VjbXxEGQZQnjyR+a6z8QoF8liP90uJ SygE+JT76ERqyD75yG8MTpc5yTC9I2pM/XqehDa1xB8opgh/We305FMdn4L9/uCL T43F4Oa1j6EeYY4mJ2EZYhnBeNhTLrgl5zMuDij9r05Y18Tl8+0rejvHYhSV9GRz TtDIoC+CjOS3Vg2jvbAYMsNkSAI/A== X-ME-Sender: X-Sasl-enc: UOkI4Yl4NoR3d5PylmbE+ZHP7/4tip83VkDN94hCA78s 1499586632 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:49:57 -0400 Message-Id: <1499586614-20507-6-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 05/22] exec-all: fix typos in TranslationBlock's documentation 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e --- include/exec/exec-all.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 8096d64..8326e7d 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -341,7 +341,7 @@ struct TranslationBlock { /* The following data are used to directly call another TB from * the code of this one. This can be done either by emitting direct or * indirect native jump instructions. These jumps are reset so that th= e TB - * just continue its execution. The TB can be linked to another one by + * just continues its execution. The TB can be linked to another one by * setting one of the jump targets (or patching the jump instruction).= Only * two of such jumps are supported. */ @@ -352,7 +352,7 @@ struct TranslationBlock { #else uintptr_t jmp_target_addr[2]; /* target address for indirect jump */ #endif - /* Each TB has an assosiated circular list of TBs jumping to this one. + /* Each TB has an associated circular list of TBs jumping to this one. * jmp_list_first points to the first TB jumping to this one. * jmp_list_next is used to point to the next TB in a list. * Since each TB can have two jumps, it can participate in two lists. --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499586762588487.06805730338965; Sun, 9 Jul 2017 00:52:42 -0700 (PDT) Received: from localhost ([::1]:35249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU71E-0005e5-Cx for importer@patchew.org; Sun, 09 Jul 2017 03:52:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R2-4K for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030C-LC for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:40 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49909) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002yr-3B for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A0322208D1; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:32 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 6C5AE24254; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=06o b8tw3JxTRd5bht8VJfuI/OOuKl9m+VoTcmWvyDII=; b=AzFoqqfpsGKDP/NZylG SCLet1QRYM3uqer6XOMC/vOyKnvcnYyTd5WEi1FeBKUvPbi3dv23tAY20siwBRys GLZSpl67TRtTJJs8KmCNo/A5i2HWyDT2khCT4s5xvGhjRD0hP7fvhZUfLsCQZnIb h/E5ba4if0ZM3bXDeOAVeqSs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=06ob8tw3JxTRd5bht8VJfuI/OOuKl9m+VoTcmWvyD II=; b=HoJQUb7Ajj3iHlmTQmaaCN+fDrvkViCVOj7bEhW1qX9IQES4tBOIhgdLB YY0nF78BbtvfB2Ph8mWxC6p635iPK695G7B7+fo9tVrlkIWk3vVT6/g8+6TzlKcZ PeHTfefREc0jmQ+oMHunRv2IgKKX+bygBNGjQUVnii4vcm76UpTE4DtmLkwZPik8 TVIeq10mW7muGY46Bd05z/KIveiTXAMFboZprfM8jRV1V2xB5ma4XQVnLSmTb3ST MHSWJsj+i7uy8DzRD6ADmyeAdbXs+CrKqKv4XlY/9G613Q1+C7HNjGF/MMkPFQag UR5UdOmB2NXkhm/TlSONZ1vDNG0sA== X-ME-Sender: X-Sasl-enc: UOkY4I5yPpxnfYz6mGfE+ZHP7/4tip83VkDN94hCA78s 1499586632 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:49:58 -0400 Message-Id: <1499586614-20507-7-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 06/22] translate-all: make have_tb_lock static 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is only used by this object, and it's not exported to any other. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 72ce445..2fa9f65 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -133,7 +133,7 @@ TCGContext tcg_ctx; bool parallel_cpus; =20 /* translation block context */ -__thread int have_tb_lock; +static __thread int have_tb_lock; =20 static void page_table_config_init(void) { --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499586763390120.64180239010932; Sun, 9 Jul 2017 00:52:43 -0700 (PDT) Received: from localhost ([::1]:35250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU71E-0005ey-Uq for importer@patchew.org; Sun, 09 Jul 2017 03:52:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R3-5K for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030N-LT for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:41 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:42129) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002yx-5H for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C2807208D6; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:32 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 9995D7E70C; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=6sO GdflgG8dxAcB/eoi19BFmylj12av7QzXrkdPf6Xk=; b=LBxbS5j44P3t4tj4/no zg3nCcNJfe0lu4z98nSOoKLQjoBsg1enBqFguOj1wJnmf13BNYIOYPoUpA314i6F nH8iyBmvOOzYLePmtYRz0JaSvtDnSyLhZDTinsxZ4oe6RrTYtYEbXH7VrbL0D+TN 9icw1rAg+HJcqRB9PlRdYHvA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=6sOGdflgG8dxAcB/eoi19BFmylj12av7QzXrkdPf6 Xk=; b=cYxYO1UJb0fZ31BbvuDmVXrJ1VVXLxW6o8vDhrxMo/llwdtDn1jujaGcc 4WWxwyc510evtI7g3Ywl7sSzTeMWNJxRtaZX+U3D3z07ookF3JwU5RvX6zLpNwJi jp2ehGGgAx8EXXE8KI9DfVojo36bdidaLAhSSiFaMrdjT8kgtMv6GcIxfi1hXJ3/ WeROgen8RnzB8qmc9hEfkxgHFPc7jUmE9zlb+pYdHyN9pfCrxH1IJam+f4umxDQu 19qdKNpEgOqe/VYlh4zIKRVgR33mSXJBNNGxZbBM5J63HcB0IWtRXRHhY7tcxe3d qHrvFWSfj6OaJhzZ6Z+bpZfsrxWjg== X-ME-Sender: X-Sasl-enc: UOkM+4BkJIJrfoj8n2fE+ZHP7/4tip83VkDN94hCA78s 1499586632 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:49:59 -0400 Message-Id: <1499586614-20507-8-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 07/22] tcg/i386: constify tcg_target_callee_save_regs 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- tcg/i386/tcg-target.inc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index 01e3b4e..06df01a 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -2514,7 +2514,7 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode op) return NULL; } =20 -static int tcg_target_callee_save_regs[] =3D { +static const int tcg_target_callee_save_regs[] =3D { #if TCG_TARGET_REG_BITS =3D=3D 64 TCG_REG_RBP, TCG_REG_RBX, --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499586925765919.64654937698; Sun, 9 Jul 2017 00:55:25 -0700 (PDT) Received: from localhost ([::1]:35258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU73s-0007yE-Kb for importer@patchew.org; Sun, 09 Jul 2017 03:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R7-5a for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030S-Lx for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:41 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:45501) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002yw-45 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 0DF1D208E9; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:33 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id C496B24254; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=4i7 CEvw+RwJUdXLxRJGyejEfUOXOASJ2LPq7Oc9aOVU=; b=lSxofXP1O9k8Qq7HewD XQmGl0Ny8yTy+4kbAXNXJBo2ce7UR5/Cal+82E86rRb44OGQ4a3IbECV4PMckNbA USrm7mGmRJ78BemvSv2nSLKyAGFoSZrfvWMPHzd+GPsSdh2YJWLMwjeWUIViPLqg NFI+jRjQKJzdCxNlx+lVnOJs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=4i7CEvw+RwJUdXLxRJGyejEfUOXOASJ2LPq7Oc9aO VU=; b=qJxJkOURWXDI2vXlmSSeR9xWkibjkiGUsn6hMvZycpoh9ZcNa103FKWej G2W/H5tIc3XKIbVqfaWtkxrEfM7p0FbHJWtmtr+AGSyXOoEqaHsSrZ1GSbmN/u6e LcTqjyX2c/tsK0NqzZ43RuGCGTRUW3KzfD1nAOBVcpzzESqcjMZ/qFvAirecHlGz 3uWyM4ulRMxjaZbzYHnuKy1rHNGvmXL9itwc/zq6Qzpwbb1R5ShpqxoGFBSoyHo/ KMFzq/w+ZtYDabop1mt/A58+Vig4K5Fg2Ir+l2yIRKRKb+zEjCX5vLv+VTcw4U0J EigRFISNWQqLw0ehQZer2o9+qM/mw== X-ME-Sender: X-Sasl-enc: UOkI5op4JIJ/dZTomWvE+ZHP7/4tip83VkDN94hCA78s 1499586632 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:00 -0400 Message-Id: <1499586614-20507-9-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 08/22] tcg/mips: constify tcg_target_callee_save_regs 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- tcg/mips/tcg-target.inc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/mips/tcg-target.inc.c b/tcg/mips/tcg-target.inc.c index 8cff9a6..790b4fc 100644 --- a/tcg/mips/tcg-target.inc.c +++ b/tcg/mips/tcg-target.inc.c @@ -2323,7 +2323,7 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode op) return NULL; } =20 -static int tcg_target_callee_save_regs[] =3D { +static const int tcg_target_callee_save_regs[] =3D { TCG_REG_S0, /* used for the global env (TCG_AREG0) */ TCG_REG_S1, TCG_REG_S2, --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499587448598827.0700669931722; Sun, 9 Jul 2017 01:04:08 -0700 (PDT) Received: from localhost ([::1]:35309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7CJ-0006iO-Bv for importer@patchew.org; Sun, 09 Jul 2017 04:04:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zL-0004RG-5h for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030n-PF for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:43989) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002z5-5C for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 341B5208D9; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:33 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id EE33A7E70C; Sun, 9 Jul 2017 03:50:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=khi Krm6R9RYFKJfVzxXn6Rgqt5kb0p2LJNo2COELqkM=; b=Jk1vEjTjRMzFtmYFvzq gEs3tG7aPuCSA+hdtxWAONQWKMtaShnHoZiyp5EVL/m7j3tiPVvcKlQy7TJB8eK2 9dSDfm/Or/t1S7XacYM1hP0K+5Ue14Chh1ZyA/nrs6gaCB8PgLlV08ta+o0dhBh3 miSeca2okGiwu68rrqZiNfcM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=khiKrm6R9RYFKJfVzxXn6Rgqt5kb0p2LJNo2COELq kM=; b=R4KlGbN0UTRTZVV7SIpjfjVdxmOGHozPjfJ+VnEe4ZghZniyIaWHoD691 81wZEWuwj4OjpMHA3TYtxCx/Cqk8DAX8EAaEYXoJrR0460udSy3cDiLFjYK88GxS pYx8v59ASCmTsAOTYiMuxnGf78gLFmKiOUKS/5qC4U2n3fB2KIgBxJoBzWHkRCHH SmiXR/2+1w/WNOg01uzYni5EYTA+p159UtjnrvCmEEbh6SMOOZIUyaX7wF1Ltm39 8/D60Doi8Q0JPTKPmfBqs9I6sSoewfshYS2Fhoqh2o1u6RjlhNaZCmZOwWwWoMkU tiCyNZeYah1lrwDYFiOysFWXBWtlg== X-ME-Sender: X-Sasl-enc: UOkJ/IpxMothd4rhhnXE+ZHP7/4tip83VkDN94hCA78s 1499586632 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:01 -0400 Message-Id: <1499586614-20507-10-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 09/22] exec-all: shrink tb->invalid to uint8_t 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To avoid wasting a byte. I don't have any use in mind for this byte, but I think it's good to leave this byte explicitly free for future use. See this discussion for how the u16 came to be: https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg04564.html We could use a bool but in some systems that would take > 1 byte. Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 8326e7d..a388756 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -327,7 +327,7 @@ struct TranslationBlock { #define CF_USE_ICOUNT 0x20000 #define CF_IGNORE_ICOUNT 0x40000 /* Do not generate icount code */ =20 - uint16_t invalid; + uint8_t invalid; =20 void *tc_ptr; /* pointer to the translated code */ uint8_t *tc_search; /* pointer to search data */ --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499587341788537.097050017437; Sun, 9 Jul 2017 01:02:21 -0700 (PDT) Received: from localhost ([::1]:35305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7AZ-0005Pm-MQ for importer@patchew.org; Sun, 09 Jul 2017 04:02:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zK-0004RB-H0 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030g-Nm for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:42 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:42939) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002zM-AB for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 68420208C3; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:33 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 29CEC24254; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=PDL Hlx/SpR/9nOEFa5iCy6ycPGXf+9bh3Zm9B+3XW1g=; b=fBle4ghPQyDon32emlw 0d/hlQOaq1TYghH8U4QZ3sc+Ens9A+pr+dVts3MqvqclbCRckGlzGjZJnTITNn0N Vk3MNiScIwv2pM8CuNpvA2ti0+dqFmQ+nMINO8yHkAGMMyjBf5WIWIZ+qLGhMLgM XGgscw9pjOPlk438I5bSSPnU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=PDLHlx/SpR/9nOEFa5iCy6ycPGXf+9bh3Zm9B+3XW 1g=; b=RG3shl5umekNRG1CjHJYUaOKm5DTxmXcwqw2bgSM4evg+gXRxBAet576m aGwf4IttREVBFyaPrICCXwQWPqLh63LR6H0aq6btjvrDyvBPigSCZr5Y9blx6Azr Qj8SaFXaNAph7i6pL8zQlu5h7xO5IUAoPTFLiDWR7Nf2sPj7rrsha8bUTI4wXYQ9 s78mGM+Nk5TYKHy4//WP3E2aMldw4yeNPfewH7xpEmx93F6wk7PE7g+685txKcow 72DHPmFYOen7zTd3tvw28FHZDheO+ydZMnEv+F3mNJ/V+ZaBvO/Cq+YuThJ/bWRh iO8DNnTG+PB7khPOek8ne041ugFyQ== X-ME-Sender: X-Sasl-enc: UBHVtUCZZyWfR1q4ACHvQ84DZxJZjLIOl1qu6FTY3Tj0 1499586633 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:02 -0400 Message-Id: <1499586614-20507-11-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 10/22] exec-all: move tb->invalid to the end of the struct 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This opens up a 4-byte hole to be used by upcoming work. Note that moving this field to the 2nd cache line of the struct does not affect performance: tb->page_addr is in the 2nd cache line as well, and both are accessed during code lookup. Besides, the tb->invalid check is easily predicted. Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index a388756..fd20bca 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -327,8 +327,6 @@ struct TranslationBlock { #define CF_USE_ICOUNT 0x20000 #define CF_IGNORE_ICOUNT 0x40000 /* Do not generate icount code */ =20 - uint8_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 */ @@ -366,6 +364,7 @@ struct TranslationBlock { */ uintptr_t jmp_list_next[2]; uintptr_t jmp_list_first; + uint8_t invalid; }; =20 void tb_free(TranslationBlock *tb); --=20 2.7.4 From nobody Wed Nov 5 06:43:55 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.zohomail.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 1499587654627790.8544525435103; Sun, 9 Jul 2017 01:07:34 -0700 (PDT) Received: from localhost ([::1]:35322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7Fd-0000ST-15 for importer@patchew.org; Sun, 09 Jul 2017 04:07:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R4-4o for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030Y-LF for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:41 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:57221) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002z8-5v for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 95437208E8; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:33 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 565867E70C; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=ZgD M8sK3HH/Z70GC3kiD+3sqHYwiC47f2Ond5ddScn0=; b=l3L++UaC/jGJKpFFCiA J2TrOeTHXjBuqd9km+1+jsCgImogQhK4nWIq1838R8/tRTGWtlOmZlVZG5j+Mg9J 0vG1W/4hw4bioXov6bKMmt+xqoD0boe2a5BRH9SpxptChvjLhHzEVbFji0cl4mzr 98K0q36hkGyCjkgUn6+hxt0I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=ZgDM8sK3HH/Z70GC3kiD+3sqHYwiC47f2Ond5ddSc n0=; b=CNZAIZX98BFBjZ1HhRK8q4MB3robvTwQ9Kg6tif9AIuANjnRs1BhSOM6V n8O2mB9okQrYeJWYB22wdhvuKplJnzJBSv5H7b2d60LKeGjglfN0vL+uovLoKe+m nW91sHIxX4EOMymLvgSRPhO2uUaggC5h48v/ZcwG7SrstlIZycgHFbVrD2LVe08l fO7DyNV4bJv/IBia5h2uA084QfUMb+J6tMToash/vvP5CwQo1llWaom4s7YwTahF BR/M1X/0QB/qMbH2R1exRqLJ3lHJ1fWxl8PXhvMv412YPmXT0UPlGkqiwYwkV0KO 9eqlsG7X97COQag+ThopZqRE428Ng== X-ME-Sender: X-Sasl-enc: UBHYs0WIYimYUk6sAzPvQ84DZxJZjLIOl1qu6FTY3Tj0 1499586633 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:03 -0400 Message-Id: <1499586614-20507-12-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 11/22] translate-all: use a binary search tree to track TBs in TBContext 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is a prerequisite for having threads generate code on separate buffers, which will help scalability when booting multiple cores under MTTCG. For this we need a new field (.tc_size) in TranslationBlock to keep track of the size of the translated code. This field is added into a 4-byte hole that the previous commit created. In order to use glib's binary search tree we embed a helper struct in TranslationBlock to allow us to compare tb's based on their tc_ptr as well as their tc_size fields. We use an anonymous struct in TranslationBlock to minimize churn; the alternatives I can see are to (a) just add a comment and cross our fingers, (b) use -fms-extensions, and (c) embed the struct and update all calling code. I think using an anonymous struct is superior, but I can be persuaded otherwise. The comparison function we use is optimized for the common case: insertions. Profiling shows that upon booting debian-arm, 98% of comparisons are between existing tb's (i.e. a->size and b->size are both !0), which happens during insertions (and removals, but those are rare). The remaining cases are lookups. From reading the glib sources we see that the first key is always the lookup key. However, the code does not assume this to always be the case because this behaviour is not guaranteed in the glib docs. However, we embed this knowledge in the code as a branch hint for the compiler. Note that tb_free does not free space in the code_gen_buffer anymore, since we cannot easily know whether the tb is the last one inserted in code_gen_buffer. Performance-wise, lookups in tb_find_pc are the same as before: O(log n). However, insertions are O(log n) instead of O(1), which results in a small slowdown when booting debian-arm: Performance counter stats for 'build/arm-softmmu/qemu-system-arm \ -machine type=3Dvirt -nographic -smp 1 -m 4096 \ -netdev user,id=3Dunet,hostfwd=3Dtcp::2222-:22 \ -device virtio-net-device,netdev=3Dunet \ -drive file=3Dimg/arm/jessie-arm32.qcow2,id=3Dmyblock,index=3D0,if=3Dnone \ -device virtio-blk-device,drive=3Dmyblock \ -kernel img/arm/aarch32-current-linux-kernel-only.img \ -append console=3DttyAMA0 root=3D/dev/vda1 \ -name arm,debug-threads=3Don -smp 1' (10 runs): - Before: 8048.598422 task-clock (msec) # 0.931 CPUs utilized = ( +- 0.28% ) 16,974 context-switches # 0.002 M/sec = ( +- 0.12% ) 0 cpu-migrations # 0.000 K/sec 10,125 page-faults # 0.001 M/sec = ( +- 1.23% ) 35,144,901,879 cycles # 4.367 GHz = ( +- 0.14% ) stalled-cycles-frontend stalled-cycles-backend 65,758,252,643 instructions # 1.87 insns per cycl= e ( +- 0.33% ) 10,871,298,668 branches # 1350.707 M/sec = ( +- 0.41% ) 192,322,212 branch-misses # 1.77% of all branche= s ( +- 0.32% ) 8.640869419 seconds time elapsed = ( +- 0.57% ) - After: 8146.242027 task-clock (msec) # 0.923 CPUs utilized = ( +- 1.23% ) 17,016 context-switches # 0.002 M/sec = ( +- 0.40% ) 0 cpu-migrations # 0.000 K/sec 18,769 page-faults # 0.002 M/sec = ( +- 0.45% ) 35,660,956,120 cycles # 4.378 GHz = ( +- 1.22% ) stalled-cycles-frontend stalled-cycles-backend 65,095,366,607 instructions # 1.83 insns per cycl= e ( +- 1.73% ) 10,803,480,261 branches # 1326.192 M/sec = ( +- 1.95% ) 195,601,289 branch-misses # 1.81% of all branche= s ( +- 0.39% ) 8.828660235 seconds time elapsed = ( +- 0.38% ) Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 17 +++- include/exec/tb-context.h | 4 +- accel/tcg/translate-all.c | 212 ++++++++++++++++++++++++------------------= ---- 3 files changed, 125 insertions(+), 108 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index fd20bca..673b26d 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -320,14 +320,25 @@ struct TranslationBlock { uint16_t size; /* size of target code for this block (1 <=3D size <=3D TARGET_PAGE_SIZE) */ uint16_t icount; - uint32_t cflags; /* compile flags */ + /* + * @tc_size must be kept right after @tc_ptr to facilitate TB lookups = in a + * binary search tree -- see struct ptr_size. + * We use an anonymous struct here to avoid updating all calling code, + * which would be quite a lot of churn. + * The only reason to bring @cflags into the anonymous struct is to + * avoid inducing a hole in TranslationBlock. + */ + struct { + void *tc_ptr; /* pointer to the translated code */ + uint32_t tc_size; /* size of translated code for this block */ + + uint32_t cflags; /* compile flags */ #define CF_COUNT_MASK 0x7fff #define CF_LAST_IO 0x8000 /* Last insn may be an IO access. */ #define CF_NOCACHE 0x10000 /* To be freed after execution */ #define CF_USE_ICOUNT 0x20000 #define CF_IGNORE_ICOUNT 0x40000 /* Do not generate icount code */ - - void *tc_ptr; /* pointer to the translated code */ + }; uint8_t *tc_search; /* pointer to search data */ /* original tb when cflags has CF_NOCACHE */ struct TranslationBlock *orig_tb; diff --git a/include/exec/tb-context.h b/include/exec/tb-context.h index 25c2afe..1fa8dcc 100644 --- a/include/exec/tb-context.h +++ b/include/exec/tb-context.h @@ -31,10 +31,8 @@ typedef struct TBContext TBContext; =20 struct TBContext { =20 - TranslationBlock **tbs; + GTree *tb_tree; struct qht htable; - size_t tbs_size; - int nb_tbs; /* any access to the tbs or the page table must use this lock */ QemuMutex tb_lock; =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2fa9f65..aa3a08b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -752,6 +752,47 @@ static inline void *alloc_code_gen_buffer(void) } #endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ =20 +struct ptr_size { + void *ptr; + uint32_t size; +}; + +/* compare a single @ptr and a ptr_size @s */ +static int ptr_size_cmp(const void *ptr, const struct ptr_size *s) +{ + if (ptr >=3D s->ptr + s->size) { + return 1; + } else if (ptr < s->ptr) { + return -1; + } + return 0; +} + +static gint tc_ptr_cmp(gconstpointer ap, gconstpointer bp) +{ + const struct ptr_size *a =3D ap; + const struct ptr_size *b =3D bp; + + /* + * When both sizes are set, we know this isn't a lookup and therefore + * the two buffers are non-overlapping: a pointer comparison will do. + * This is the most likely case: every TB must be inserted; lookups + * are a lot less frequent. + */ + if (likely(a->size && b->size)) { + return a->ptr - b->ptr; + } + /* + * All lookups have either .size field set to 0. + * From the glib sources we see that @ap is always the lookup key. How= ever + * the docs provide no guarantee, so we just mark this case as likely. + */ + if (likely(a->size =3D=3D 0)) { + return ptr_size_cmp(a->ptr, b); + } + return ptr_size_cmp(b->ptr, a); +} + static inline void code_gen_alloc(size_t tb_size) { tcg_ctx.code_gen_buffer_size =3D size_code_gen_buffer(tb_size); @@ -760,15 +801,7 @@ static inline void code_gen_alloc(size_t tb_size) fprintf(stderr, "Could not allocate dynamic translator buffer\n"); exit(1); } - - /* size this conservatively -- realloc later if needed */ - tcg_ctx.tb_ctx.tbs_size =3D - tcg_ctx.code_gen_buffer_size / CODE_GEN_AVG_BLOCK_SIZE / 8; - if (unlikely(!tcg_ctx.tb_ctx.tbs_size)) { - tcg_ctx.tb_ctx.tbs_size =3D 64 * 1024; - } - tcg_ctx.tb_ctx.tbs =3D g_new(TranslationBlock *, tcg_ctx.tb_ctx.tbs_si= ze); - + tcg_ctx.tb_ctx.tb_tree =3D g_tree_new(tc_ptr_cmp); qemu_mutex_init(&tcg_ctx.tb_ctx.tb_lock); } =20 @@ -805,7 +838,6 @@ void tcg_exec_init(unsigned long tb_size) static TranslationBlock *tb_alloc(target_ulong pc) { TranslationBlock *tb; - TBContext *ctx; =20 assert_tb_locked(); =20 @@ -813,12 +845,6 @@ static TranslationBlock *tb_alloc(target_ulong pc) if (unlikely(tb =3D=3D NULL)) { return NULL; } - ctx =3D &tcg_ctx.tb_ctx; - if (unlikely(ctx->nb_tbs =3D=3D ctx->tbs_size)) { - ctx->tbs_size *=3D 2; - ctx->tbs =3D g_renew(TranslationBlock *, ctx->tbs, ctx->tbs_size); - } - ctx->tbs[ctx->nb_tbs++] =3D tb; return tb; } =20 @@ -827,16 +853,7 @@ void tb_free(TranslationBlock *tb) { assert_tb_locked(); =20 - /* In practice this is mostly used for single use temporary TB - Ignore the hard cases and just back up if this TB happens to - be the last one generated. */ - if (tcg_ctx.tb_ctx.nb_tbs > 0 && - tb =3D=3D tcg_ctx.tb_ctx.tbs[tcg_ctx.tb_ctx.nb_tbs - 1]) { - size_t struct_size =3D ROUND_UP(sizeof(*tb), qemu_icache_linesize); - - tcg_ctx.code_gen_ptr =3D tb->tc_ptr - struct_size; - tcg_ctx.tb_ctx.nb_tbs--; - } + g_tree_remove(tcg_ctx.tb_ctx.tb_tree, &tb->tc_ptr); } =20 static inline void invalidate_page_bitmap(PageDesc *p) @@ -884,6 +901,8 @@ static void page_flush_tb(void) /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { + int nb_tbs __attribute__((unused)); + tb_lock(); =20 /* If it is already been done on request of another CPU, @@ -894,11 +913,12 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_dat= a tb_flush_count) } =20 #if defined(DEBUG_TB_FLUSH) + nb_tbs =3D g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); printf("qemu: flush code_size=3D%ld nb_tbs=3D%d avg_tb_size=3D%ld\n", (unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer), - tcg_ctx.tb_ctx.nb_tbs, tcg_ctx.tb_ctx.nb_tbs > 0 ? + nb_tbs, nb_tbs > 0 ? ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer= )) / - tcg_ctx.tb_ctx.nb_tbs : 0); + nb_tbs : 0); #endif if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) > tcg_ctx.code_gen_buffer_size) { @@ -909,7 +929,10 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data= tb_flush_count) cpu_tb_jmp_cache_clear(cpu); } =20 - tcg_ctx.tb_ctx.nb_tbs =3D 0; + /* Increment the refcount first so that destroy acts as a reset */ + g_tree_ref(tcg_ctx.tb_ctx.tb_tree); + g_tree_destroy(tcg_ctx.tb_ctx.tb_tree); + qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); =20 @@ -1309,6 +1332,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if (unlikely(search_size < 0)) { goto buffer_overflow; } + tb->tc_size =3D gen_code_size; =20 #ifdef CONFIG_PROFILER tcg_ctx.code_time +=3D profile_getclock() - ti; @@ -1359,6 +1383,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, * through the physical hash table and physical page list. */ tb_link_page(tb, phys_pc, phys_page2); + g_tree_insert(tcg_ctx.tb_ctx.tb_tree, &tb->tc_ptr, tb); return tb; } =20 @@ -1627,37 +1652,16 @@ static bool tb_invalidate_phys_page(tb_page_addr_t = addr, uintptr_t pc) } #endif =20 -/* find the TB 'tb' such that tb[0].tc_ptr <=3D tc_ptr < - tb[1].tc_ptr. Return NULL if not found */ +/* + * Find the TB 'tb' such that + * tb->tc_ptr <=3D tc_ptr < tb->tc_ptr + tb->tc_size + * Return NULL if not found. + */ static TranslationBlock *tb_find_pc(uintptr_t tc_ptr) { - int m_min, m_max, m; - uintptr_t v; - TranslationBlock *tb; + struct ptr_size s =3D { .ptr =3D (void *)tc_ptr }; =20 - if (tcg_ctx.tb_ctx.nb_tbs <=3D 0) { - return NULL; - } - if (tc_ptr < (uintptr_t)tcg_ctx.code_gen_buffer || - tc_ptr >=3D (uintptr_t)tcg_ctx.code_gen_ptr) { - return NULL; - } - /* binary search (cf Knuth) */ - m_min =3D 0; - m_max =3D tcg_ctx.tb_ctx.nb_tbs - 1; - while (m_min <=3D m_max) { - m =3D (m_min + m_max) >> 1; - tb =3D tcg_ctx.tb_ctx.tbs[m]; - v =3D (uintptr_t)tb->tc_ptr; - if (v =3D=3D tc_ptr) { - return tb; - } else if (tc_ptr < v) { - m_max =3D m - 1; - } else { - m_min =3D m + 1; - } - } - return tcg_ctx.tb_ctx.tbs[m_max]; + return g_tree_lookup(tcg_ctx.tb_ctx.tb_tree, &s); } =20 #if !defined(CONFIG_USER_ONLY) @@ -1842,63 +1846,67 @@ static void print_qht_statistics(FILE *f, fprintf_f= unction cpu_fprintf, g_free(hgram); } =20 +struct tb_tree_stats { + size_t target_size; + size_t max_target_size; + size_t direct_jmp_count; + size_t direct_jmp2_count; + size_t cross_page; +}; + +static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer = data) +{ + const TranslationBlock *tb =3D value; + struct tb_tree_stats *tst =3D data; + + tst->target_size +=3D tb->size; + if (tb->size > tst->max_target_size) { + tst->max_target_size =3D tb->size; + } + if (tb->page_addr[1] !=3D -1) { + tst->cross_page++; + } + if (tb->jmp_reset_offset[0] !=3D TB_JMP_RESET_OFFSET_INVALID) { + tst->direct_jmp_count++; + if (tb->jmp_reset_offset[1] !=3D TB_JMP_RESET_OFFSET_INVALID) { + tst->direct_jmp2_count++; + } + } + return false; +} + void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) { - int i, target_code_size, max_target_code_size; - int direct_jmp_count, direct_jmp2_count, cross_page; - TranslationBlock *tb; + struct tb_tree_stats tst =3D {}; struct qht_stats hst; + int nb_tbs; =20 tb_lock(); =20 - target_code_size =3D 0; - max_target_code_size =3D 0; - cross_page =3D 0; - direct_jmp_count =3D 0; - direct_jmp2_count =3D 0; - for (i =3D 0; i < tcg_ctx.tb_ctx.nb_tbs; i++) { - tb =3D tcg_ctx.tb_ctx.tbs[i]; - target_code_size +=3D tb->size; - if (tb->size > max_target_code_size) { - max_target_code_size =3D tb->size; - } - if (tb->page_addr[1] !=3D -1) { - cross_page++; - } - if (tb->jmp_reset_offset[0] !=3D TB_JMP_RESET_OFFSET_INVALID) { - direct_jmp_count++; - if (tb->jmp_reset_offset[1] !=3D TB_JMP_RESET_OFFSET_INVALID) { - direct_jmp2_count++; - } - } - } + nb_tbs =3D g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); + g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_tree_stats_iter, &tst); /* XXX: avoid using doubles ? */ cpu_fprintf(f, "Translation buffer state:\n"); cpu_fprintf(f, "gen code size %td/%zd\n", tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer); - cpu_fprintf(f, "TB count %d\n", tcg_ctx.tb_ctx.nb_tbs); - cpu_fprintf(f, "TB avg target size %d max=3D%d bytes\n", - tcg_ctx.tb_ctx.nb_tbs ? target_code_size / - tcg_ctx.tb_ctx.nb_tbs : 0, - max_target_code_size); + cpu_fprintf(f, "TB count %d\n", nb_tbs); + cpu_fprintf(f, "TB avg target size %zu max=3D%zu bytes\n", + nb_tbs ? tst.target_size / nb_tbs : 0, + tst.max_target_size); cpu_fprintf(f, "TB avg host size %td bytes (expansion ratio: %0.1f)= \n", - tcg_ctx.tb_ctx.nb_tbs ? (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / - tcg_ctx.tb_ctx.nb_tbs : 0, - target_code_size ? (double) (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / - target_code_size : 0); - cpu_fprintf(f, "cross page TB count %d (%d%%)\n", cross_page, - tcg_ctx.tb_ctx.nb_tbs ? (cross_page * 100) / - tcg_ctx.tb_ctx.nb_tbs : 0); - cpu_fprintf(f, "direct jump count %d (%d%%) (2 jumps=3D%d %d%%)\n", - direct_jmp_count, - tcg_ctx.tb_ctx.nb_tbs ? (direct_jmp_count * 100) / - tcg_ctx.tb_ctx.nb_tbs : 0, - direct_jmp2_count, - tcg_ctx.tb_ctx.nb_tbs ? (direct_jmp2_count * 100) / - tcg_ctx.tb_ctx.nb_tbs : 0); + nb_tbs ? (tcg_ctx.code_gen_ptr - + tcg_ctx.code_gen_buffer) / nb_tbs : 0, + tst.target_size ? (double) (tcg_ctx.code_gen_ptr - + tcg_ctx.code_gen_buffer) / + tst.target_size : 0); + cpu_fprintf(f, "cross page TB count %zu (%zu%%)\n", tst.cross_page, + nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0); + cpu_fprintf(f, "direct jump count %zu (%zu%%) (2 jumps=3D%zu %zu%%)\= n", + tst.direct_jmp_count, + nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0, + tst.direct_jmp2_count, + nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0); =20 qht_statistics_init(&tcg_ctx.tb_ctx.htable, &hst); print_qht_statistics(f, cpu_fprintf, hst); --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 14995867669957.436725931391379; Sun, 9 Jul 2017 00:52:46 -0700 (PDT) Received: from localhost ([::1]:35251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU71J-0005in-Az for importer@patchew.org; Sun, 09 Jul 2017 03:52:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zK-0004RE-Pw for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030p-OF for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:42 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:60363) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002zB-7h for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C9E2C208F0; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:33 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 8797224254; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=y4o pQTR9YHqy5nw2xRdXsi8djJJe+iG2cMk8YPWnXuo=; b=sgHBye5WaoyyU6EHr6w p8Kz2ekv3igPL4ZpkLscRQt3XPUC0ENSjlGRh6GjmJnz4iJLurzqrmNprbSHsIG/ V6xXAV8voLR6gxqvrfa6mIzF+/xNWaiRk4THOnHbtwu5JYvFBrl62WO57csAJToP KxQnk8SuHQZ7PJxVrF+/Rqcs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=y4opQTR9YHqy5nw2xRdXsi8djJJe+iG2cMk8YPWnX uo=; b=Eak9wZAu0Dfueum5S6+inReDlRK52FhIpR82G6a0WokmFK1QdteYUQy3g DjwhGEG3FcbDjc/TtZIMy/qEezedLloVuglOMU8qi4MWSA8GOkO94M5zi1SDa7x7 0XbupeixtEz1e1ThQEF4aelFsFiEF+EOr8bbyT7A2dR6H34hTQ4tzGGEsa6rFeMS O6eWBprztiIFr555fq8lR3MGbHXAHTu3jlJS7grrwXlftU0gWf1VeTfCnFWp6X2c O6NsJDmT343gp0Rxiuuj89w4ziyGo2vWvlg2nDu4vuSq1JuQKz0FN6KxBQRou2XL oqa/wproyo4QpYMMficWWSRTyavcA== X-ME-Sender: X-Sasl-enc: UBHEr02DaDCBRlqwDSLvQ84DZxJZjLIOl1qu6FTY3Tj0 1499586633 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:04 -0400 Message-Id: <1499586614-20507-13-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 12/22] translate-all: report correct avg host TB size 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since commit 6e3b2bfd6 ("tcg: allocate TB structs before the corresponding translated code") we are not fully utilizing code_gen_buffer for translated code, and therefore are incorrectly reporting the amount of translated code as well as the average host TB size. Address this by: - Making the conscious choice of misreporting the total translated code; doing otherwise would mislead users into thinking "-tb-size" is not honoured. - Expanding tb_tree_stats to accurately count the bytes of translated code = on the host, and using this for reporting the average tb host size, as well as the expansion ratio. In the future we might want to consider reporting the accurate numbers for the total translated code, together with a "bookkeeping/overhead" field to account for the TB structs. Signed-off-by: Emilio G. Cota --- accel/tcg/translate-all.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index aa3a08b..aa71292 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -898,9 +898,20 @@ static void page_flush_tb(void) } } =20 +static __attribute__((unused)) +gboolean tb_host_size_iter(gpointer key, gpointer value, gpointer data) +{ + const TranslationBlock *tb =3D value; + size_t *size =3D data; + + *size +=3D tb->tc_size; + return false; +} + /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { + size_t host_size __attribute__((unused)) =3D 0; int nb_tbs __attribute__((unused)); =20 tb_lock(); @@ -913,12 +924,11 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_dat= a tb_flush_count) } =20 #if defined(DEBUG_TB_FLUSH) + g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_host_size_iter, &host_size); nb_tbs =3D g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); - printf("qemu: flush code_size=3D%ld nb_tbs=3D%d avg_tb_size=3D%ld\n", + printf("qemu: flush code_size=3D%ld nb_tbs=3D%d avg_tb_size=3D%zu\n", (unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer), - nb_tbs, nb_tbs > 0 ? - ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer= )) / - nb_tbs : 0); + nb_tbs, nb_tbs > 0 ? host_size / nb_tbs : 0); #endif if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) > tcg_ctx.code_gen_buffer_size) { @@ -1847,6 +1857,7 @@ static void print_qht_statistics(FILE *f, fprintf_fun= ction cpu_fprintf, } =20 struct tb_tree_stats { + size_t host_size; size_t target_size; size_t max_target_size; size_t direct_jmp_count; @@ -1859,6 +1870,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpoi= nter value, gpointer data) const TranslationBlock *tb =3D value; struct tb_tree_stats *tst =3D data; =20 + tst->host_size +=3D tb->tc_size; tst->target_size +=3D tb->size; if (tb->size > tst->max_target_size) { tst->max_target_size =3D tb->size; @@ -1887,6 +1899,11 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fp= rintf) g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_tree_stats_iter, &tst); /* XXX: avoid using doubles ? */ cpu_fprintf(f, "Translation buffer state:\n"); + /* + * Report total code size including the padding and TB structs; + * otherwise users might think "-tb-size" is not honoured. + * For avg host size we use the precise numbers from tb_tree_stats tho= ugh. + */ cpu_fprintf(f, "gen code size %td/%zd\n", tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer); @@ -1894,12 +1911,9 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fp= rintf) cpu_fprintf(f, "TB avg target size %zu max=3D%zu bytes\n", nb_tbs ? tst.target_size / nb_tbs : 0, tst.max_target_size); - cpu_fprintf(f, "TB avg host size %td bytes (expansion ratio: %0.1f)= \n", - nb_tbs ? (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / nb_tbs : 0, - tst.target_size ? (double) (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / - tst.target_size : 0); + cpu_fprintf(f, "TB avg host size %zu bytes (expansion ratio: %0.1f)= \n", + nb_tbs ? tst.host_size / nb_tbs : 0, + tst.target_size ? (double)tst.host_size / tst.target_size = : 0); cpu_fprintf(f, "cross page TB count %zu (%zu%%)\n", tst.cross_page, nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0); cpu_fprintf(f, "direct jump count %zu (%zu%%) (2 jumps=3D%zu %zu%%)\= n", --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499587226936377.44046957411945; Sun, 9 Jul 2017 01:00:26 -0700 (PDT) Received: from localhost ([::1]:35289 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU78j-0003pw-M9 for importer@patchew.org; Sun, 09 Jul 2017 04:00:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zM-0004SH-R8 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-00030x-Ot for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:48999) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002zD-5X for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 0264B20905; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:34 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id BA3E77E70C; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=bUm 3B55VCAIdC8H2p9Ik811S0pksqgzNIsawzHDxTv0=; b=MiiRCpCwQ6FcWREgsZb dj0f6bPEDikqeqYCKP5LjHOJehQ+F4Bbmrjb4O6zPyyJUr7nfDCYVm/i4TNwZxyV ZGRA7wCSDIGVZg8oVQgU6ltVbcVmuhKV9MS00XXzx58IGOJ5JHg97wX9lCiBBnVu YNxS8x02aPRvNGVhBB5SAt1Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=bUm3B55VCAIdC8H2p9Ik811S0pksqgzNIsawzHDxT v0=; b=aK1SC7a/ceuw6F2ctZWDDzGc0j6IMb9Kj3cR0J+lbNj+rEEIqeVXwsotS JB4niEAaQX7UCSShPvnUDreruquooHDHMOp5jeW8l+Tkq7ycBin2ZubshaVO9PnP BWIev61elJfwKX8hUOWNr6LvR986gNqqeVU/2wRBSAf7poD4HL9mwNUGvAQt4yrl n7IT+kR//8Lz3VvWj78afGh900RFCXhHAaBVGE+30Fbm52jFRac0k93ltJoM3b67 juzj5zU8uFzfD1EjkF4Es4XV3pLYfcEZ19DTcj4j/UdvKQUOlWjhzUUcoxYahhuc c0WZ3oQEKCPYFxi/1EsaTKlDYPCrg== X-ME-Sender: X-Sasl-enc: UBHLtFGUbimJXlamEjzvQ84DZxJZjLIOl1qu6FTY3Tj0 1499586633 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:05 -0400 Message-Id: <1499586614-20507-14-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 13/22] tcg: take tb_ctx out of TCGContext 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before TCGContext is made thread-local. Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e --- include/exec/tb-context.h | 2 ++ tcg/tcg.h | 2 -- accel/tcg/cpu-exec.c | 2 +- accel/tcg/translate-all.c | 57 +++++++++++++++++++++++--------------------= ---- linux-user/main.c | 6 ++--- 5 files changed, 34 insertions(+), 35 deletions(-) diff --git a/include/exec/tb-context.h b/include/exec/tb-context.h index 1fa8dcc..1d41202 100644 --- a/include/exec/tb-context.h +++ b/include/exec/tb-context.h @@ -41,4 +41,6 @@ struct TBContext { int tb_phys_invalidate_count; }; =20 +extern TBContext tb_ctx; + #endif diff --git a/tcg/tcg.h b/tcg/tcg.h index da78721..ad2d959 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -706,8 +706,6 @@ struct TCGContext { /* Threshold to flush the translated code buffer. */ void *code_gen_highwater; =20 - TBContext tb_ctx; - /* Track which vCPU triggers events */ CPUState *cpu; /* *_trans */ TCGv_env tcg_env; /* *_exec */ diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 3581618..54ecae2 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -323,7 +323,7 @@ TranslationBlock *tb_htable_lookup(CPUState *cpu, targe= t_ulong pc, phys_pc =3D get_page_addr_code(desc.env, pc); desc.phys_page1 =3D phys_pc & TARGET_PAGE_MASK; h =3D tb_hash_func(phys_pc, pc, flags); - return qht_lookup(&tcg_ctx.tb_ctx.htable, tb_cmp, &desc, h); + return qht_lookup(&tb_ctx.htable, tb_cmp, &desc, h); } =20 static inline TranslationBlock *tb_find(CPUState *cpu, diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index aa71292..84e19d9 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -130,6 +130,7 @@ static void *l1_map[V_L1_MAX_SIZE]; =20 /* code generation context */ TCGContext tcg_ctx; +TBContext tb_ctx; bool parallel_cpus; =20 /* translation block context */ @@ -161,7 +162,7 @@ static void page_table_config_init(void) void tb_lock(void) { assert_tb_unlocked(); - qemu_mutex_lock(&tcg_ctx.tb_ctx.tb_lock); + qemu_mutex_lock(&tb_ctx.tb_lock); have_tb_lock++; } =20 @@ -169,13 +170,13 @@ void tb_unlock(void) { assert_tb_locked(); have_tb_lock--; - qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); + qemu_mutex_unlock(&tb_ctx.tb_lock); } =20 void tb_lock_reset(void) { if (have_tb_lock) { - qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); + qemu_mutex_unlock(&tb_ctx.tb_lock); have_tb_lock =3D 0; } } @@ -801,15 +802,15 @@ static inline void code_gen_alloc(size_t tb_size) fprintf(stderr, "Could not allocate dynamic translator buffer\n"); exit(1); } - tcg_ctx.tb_ctx.tb_tree =3D g_tree_new(tc_ptr_cmp); - qemu_mutex_init(&tcg_ctx.tb_ctx.tb_lock); + tb_ctx.tb_tree =3D g_tree_new(tc_ptr_cmp); + qemu_mutex_init(&tb_ctx.tb_lock); } =20 static void tb_htable_init(void) { unsigned int mode =3D QHT_MODE_AUTO_RESIZE; =20 - qht_init(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE, mode); + qht_init(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE, mode); } =20 /* Must be called before using the QEMU cpus. 'tb_size' is the size @@ -853,7 +854,7 @@ void tb_free(TranslationBlock *tb) { assert_tb_locked(); =20 - g_tree_remove(tcg_ctx.tb_ctx.tb_tree, &tb->tc_ptr); + g_tree_remove(tb_ctx.tb_tree, &tb->tc_ptr); } =20 static inline void invalidate_page_bitmap(PageDesc *p) @@ -919,13 +920,13 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_dat= a tb_flush_count) /* If it is already been done on request of another CPU, * just retry. */ - if (tcg_ctx.tb_ctx.tb_flush_count !=3D tb_flush_count.host_int) { + if (tb_ctx.tb_flush_count !=3D tb_flush_count.host_int) { goto done; } =20 #if defined(DEBUG_TB_FLUSH) - g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_host_size_iter, &host_size); - nb_tbs =3D g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); + g_tree_foreach(tb_ctx.tb_tree, tb_host_size_iter, &host_size); + nb_tbs =3D g_tree_nnodes(tb_ctx.tb_tree); printf("qemu: flush code_size=3D%ld nb_tbs=3D%d avg_tb_size=3D%zu\n", (unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer), nb_tbs, nb_tbs > 0 ? host_size / nb_tbs : 0); @@ -940,17 +941,16 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_dat= a tb_flush_count) } =20 /* Increment the refcount first so that destroy acts as a reset */ - g_tree_ref(tcg_ctx.tb_ctx.tb_tree); - g_tree_destroy(tcg_ctx.tb_ctx.tb_tree); + g_tree_ref(tb_ctx.tb_tree); + g_tree_destroy(tb_ctx.tb_tree); =20 - qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE); + qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); =20 tcg_ctx.code_gen_ptr =3D tcg_ctx.code_gen_buffer; /* XXX: flush processor icache at this point if cache flush is expensive */ - atomic_mb_set(&tcg_ctx.tb_ctx.tb_flush_count, - tcg_ctx.tb_ctx.tb_flush_count + 1); + atomic_mb_set(&tb_ctx.tb_flush_count, tb_ctx.tb_flush_count + 1); =20 done: tb_unlock(); @@ -959,7 +959,7 @@ done: void tb_flush(CPUState *cpu) { if (tcg_enabled()) { - unsigned tb_flush_count =3D atomic_mb_read(&tcg_ctx.tb_ctx.tb_flus= h_count); + unsigned tb_flush_count =3D atomic_mb_read(&tb_ctx.tb_flush_count); async_safe_run_on_cpu(cpu, do_tb_flush, RUN_ON_CPU_HOST_INT(tb_flush_count)); } @@ -986,7 +986,7 @@ do_tb_invalidate_check(struct qht *ht, void *p, uint32_= t hash, void *userp) static void tb_invalidate_check(target_ulong address) { address &=3D TARGET_PAGE_MASK; - qht_iter(&tcg_ctx.tb_ctx.htable, do_tb_invalidate_check, &address); + qht_iter(&tb_ctx.htable, do_tb_invalidate_check, &address); } =20 static void @@ -1006,7 +1006,7 @@ do_tb_page_check(struct qht *ht, void *p, uint32_t ha= sh, void *userp) /* verify that all the pages have correct rights for code */ static void tb_page_check(void) { - qht_iter(&tcg_ctx.tb_ctx.htable, do_tb_page_check, NULL); + qht_iter(&tb_ctx.htable, do_tb_page_check, NULL); } =20 #endif @@ -1105,7 +1105,7 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page= _addr_t page_addr) /* remove the TB from the hash list */ phys_pc =3D tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); h =3D tb_hash_func(phys_pc, tb->pc, tb->flags); - qht_remove(&tcg_ctx.tb_ctx.htable, tb, h); + qht_remove(&tb_ctx.htable, tb, h); =20 /* remove the TB from the page list */ if (tb->page_addr[0] !=3D page_addr) { @@ -1134,7 +1134,7 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page= _addr_t page_addr) /* suppress any remaining jumps to this TB */ tb_jmp_unlink(tb); =20 - tcg_ctx.tb_ctx.tb_phys_invalidate_count++; + tb_ctx.tb_phys_invalidate_count++; } =20 #ifdef CONFIG_SOFTMMU @@ -1250,7 +1250,7 @@ static void tb_link_page(TranslationBlock *tb, tb_pag= e_addr_t phys_pc, =20 /* add in the hash table */ h =3D tb_hash_func(phys_pc, tb->pc, tb->flags); - qht_insert(&tcg_ctx.tb_ctx.htable, tb, h); + qht_insert(&tb_ctx.htable, tb, h); =20 #ifdef DEBUG_TB_CHECK tb_page_check(); @@ -1393,7 +1393,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, * through the physical hash table and physical page list. */ tb_link_page(tb, phys_pc, phys_page2); - g_tree_insert(tcg_ctx.tb_ctx.tb_tree, &tb->tc_ptr, tb); + g_tree_insert(tb_ctx.tb_tree, &tb->tc_ptr, tb); return tb; } =20 @@ -1671,7 +1671,7 @@ static TranslationBlock *tb_find_pc(uintptr_t tc_ptr) { struct ptr_size s =3D { .ptr =3D (void *)tc_ptr }; =20 - return g_tree_lookup(tcg_ctx.tb_ctx.tb_tree, &s); + return g_tree_lookup(tb_ctx.tb_tree, &s); } =20 #if !defined(CONFIG_USER_ONLY) @@ -1895,8 +1895,8 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fpr= intf) =20 tb_lock(); =20 - nb_tbs =3D g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); - g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_tree_stats_iter, &tst); + nb_tbs =3D g_tree_nnodes(tb_ctx.tb_tree); + g_tree_foreach(tb_ctx.tb_tree, tb_tree_stats_iter, &tst); /* XXX: avoid using doubles ? */ cpu_fprintf(f, "Translation buffer state:\n"); /* @@ -1922,15 +1922,14 @@ void dump_exec_info(FILE *f, fprintf_function cpu_f= printf) tst.direct_jmp2_count, nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0); =20 - qht_statistics_init(&tcg_ctx.tb_ctx.htable, &hst); + qht_statistics_init(&tb_ctx.htable, &hst); print_qht_statistics(f, cpu_fprintf, hst); qht_statistics_destroy(&hst); =20 cpu_fprintf(f, "\nStatistics:\n"); cpu_fprintf(f, "TB flush count %u\n", - atomic_read(&tcg_ctx.tb_ctx.tb_flush_count)); - cpu_fprintf(f, "TB invalidate count %d\n", - tcg_ctx.tb_ctx.tb_phys_invalidate_count); + atomic_read(&tb_ctx.tb_flush_count)); + cpu_fprintf(f, "TB invalidate count %d\n", tb_ctx.tb_phys_invalidate_c= ount); cpu_fprintf(f, "TLB flush count %zu\n", tlb_flush_count()); tcg_dump_info(f, cpu_fprintf); =20 diff --git a/linux-user/main.c b/linux-user/main.c index ad03c9e..630c73d 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -114,7 +114,7 @@ int cpu_get_pic_interrupt(CPUX86State *env) void fork_start(void) { cpu_list_lock(); - qemu_mutex_lock(&tcg_ctx.tb_ctx.tb_lock); + qemu_mutex_lock(&tb_ctx.tb_lock); mmap_fork_start(); } =20 @@ -130,11 +130,11 @@ void fork_end(int child) QTAILQ_REMOVE(&cpus, cpu, node); } } - qemu_mutex_init(&tcg_ctx.tb_ctx.tb_lock); + qemu_mutex_init(&tb_ctx.tb_lock); qemu_init_cpu_list(); gdbserver_fork(thread_cpu); } else { - qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); + qemu_mutex_unlock(&tb_ctx.tb_lock); cpu_list_unlock(); } } --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499587218837781.3607938925896; Sun, 9 Jul 2017 01:00:18 -0700 (PDT) Received: from localhost ([::1]:35285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU78b-0003aj-I0 for importer@patchew.org; Sun, 09 Jul 2017 04:00:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zJ-0004R6-5U for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zE-0002zw-G5 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:41 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:53541) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002zH-5C for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 2CB2320911; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:34 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id EA6B524254; Sun, 9 Jul 2017 03:50:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=MBw CryoarOodoGlSXewqYblfwB6sB5V64KMvf3BIgqg=; b=P3PTMIs/ErIzoU1M7HC dPD1LvegdWTqeV3EKW7C/MLlytXQkCSRdcieJpOGL18Ih73MjAYj+0aiRGcfK68d 9w5FRlb7TtIOEQYHa1eKcn+4eznhc1AHvFib2YNkxQUqNhoUuEWLOnB2jqwfczso A05vlJcWyQf1fKE/tUl7uoys= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=MBwCryoarOodoGlSXewqYblfwB6sB5V64KMvf3BIg qg=; b=QejWjmwvYfWCotXowr9FKdpzNQQyJvIjUiokDthQDXCreEMTJDntmLnGs 8dVC3MQ0/NbB9EYfuhhOD5uf7X5C6546GsrEOrpX2c9zx3dU70wgL6iPYOKO1uK8 6OYdpL0p6iABHInqmAyIYXCyar4nId0o4GHxAj0rZJla3MQXn/XtXtN75Z297nQw qqhIIgV1bNJJ9Iu9WD4lIrIyyQ2fv7apsZmwbgEXOOSew4fcDfMv2BdYNCdtqFvl piwMOmQlIrgeg0/pXvHH4FiCaNUp2qBYadVkwZ3L6z/SMCEGkwuciJXA3levzxuF 4OsMhTSeJ0kJVuSXxdXogrMu9riUQ== X-ME-Sender: X-Sasl-enc: UBHdqEOcYC6QTk6pBTbvQ84DZxJZjLIOl1qu6FTY3Tj0 1499586633 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:06 -0400 Message-Id: <1499586614-20507-15-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 14/22] tcg: take .helpers out of TCGContext 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before TCGContext is made thread-local. The hash table becomes read-only after it is filled in, so we can save space by keeping just a global pointer to it. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- tcg/tcg.h | 2 -- tcg/tcg.c | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tcg/tcg.h b/tcg/tcg.h index ad2d959..4f57878 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -663,8 +663,6 @@ struct TCGContext { =20 tcg_insn_unit *code_ptr; =20 - GHashTable *helpers; - #ifdef CONFIG_PROFILER /* profiling info */ int64_t tb_count1; diff --git a/tcg/tcg.c b/tcg/tcg.c index 3559829..d9b083a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -319,6 +319,7 @@ typedef struct TCGHelperInfo { static const TCGHelperInfo all_helpers[] =3D { #include "exec/helper-tcg.h" }; +static GHashTable *helper_table; =20 static int indirect_reg_alloc_order[ARRAY_SIZE(tcg_target_reg_alloc_order)= ]; static void process_op_defs(TCGContext *s); @@ -329,7 +330,6 @@ void tcg_context_init(TCGContext *s) TCGOpDef *def; TCGArgConstraint *args_ct; int *sorted_args; - GHashTable *helper_table; =20 memset(s, 0, sizeof(*s)); s->nb_globals =3D 0; @@ -357,7 +357,7 @@ void tcg_context_init(TCGContext *s) =20 /* Register helpers. */ /* Use g_direct_hash/equal for direct pointer comparisons on func. */ - s->helpers =3D helper_table =3D g_hash_table_new(NULL, NULL); + helper_table =3D g_hash_table_new(NULL, NULL); =20 for (i =3D 0; i < ARRAY_SIZE(all_helpers); ++i) { g_hash_table_insert(helper_table, (gpointer)all_helpers[i].func, @@ -761,7 +761,7 @@ void tcg_gen_callN(TCGContext *s, void *func, TCGArg re= t, unsigned sizemask, flags; TCGHelperInfo *info; =20 - info =3D g_hash_table_lookup(s->helpers, (gpointer)func); + info =3D g_hash_table_lookup(helper_table, (gpointer)func); flags =3D info->flags; sizemask =3D info->sizemask; =20 @@ -990,8 +990,8 @@ static char *tcg_get_arg_str_idx(TCGContext *s, char *b= uf, static inline const char *tcg_find_helper(TCGContext *s, uintptr_t val) { const char *ret =3D NULL; - if (s->helpers) { - TCGHelperInfo *info =3D g_hash_table_lookup(s->helpers, (gpointer)= val); + if (helper_table) { + TCGHelperInfo *info =3D g_hash_table_lookup(helper_table, (gpointe= r)val); if (info) { ret =3D info->name; } --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 149958693476896.72157212932859; Sun, 9 Jul 2017 00:55:34 -0700 (PDT) Received: from localhost ([::1]:35266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU741-00086U-Fo for importer@patchew.org; Sun, 09 Jul 2017 03:55:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zL-0004RF-5d for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-00031t-C4 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:41119) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002zn-QP for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:37 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5779620920; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:34 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 1F6387E70C; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=Sux ttA29D1fuUr/Z2FyFFd7Lh+ais3HCztrfPS7k0bc=; b=K2mD9yRnk9C2n5JS0dL AuUQpY1ccuiB2XOmKNxc7y2Iwr6G2C7rzmyYPq6avtNvuf1EfEnxMOoCk0llb/5A MZAOSwXF7KPX8niDmeXDIXOMVIWlb5vrqPrutuWP4WORcoit0aaTkdw4PR5+/kKP x5k0iDKJW1zeuc6TGkUS71wQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=SuxttA29D1fuUr/Z2FyFFd7Lh+ais3HCztrfPS7k0 bc=; b=nREa3W3U4O2uNSEOmg+z3nMDnhODFJHhOvMDld0w1l/XV2zRusGUKcAib eeQ0aHfqgbbUCQtQqhoUCuOASOuxZqHcZKjYbmj/cOAhSmA28Zwrr/9fKWMxHYzR V+QF2g1vK9g/cAZ9/LeBdUJkngOGBL51auo1CBviLMXC/Ugv+A+CK6dGyO0OyxV7 mzEeAElkRL47OLNp+3kuI8x8z+O1KbjrL/eBa6bzayJxnCgM+j1o6V0bQI6uKn8c fZdm557PG8/3qep2k0rMt7y3poqXKrvCHsIu7ml+QIsUnlp91R+YtaJ0ihQ8SNDV xDeOk1O8bh+4PElu8iBegvKd+jvqQ== X-ME-Sender: X-Sasl-enc: Ei7VFsMrBKG2H7YuYnj3MoNFTMmBOqqC58cvc28t4cI0 1499586634 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:07 -0400 Message-Id: <1499586614-20507-16-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 15/22] gen-icount: fold exitreq_label into TCGContext 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before we make TCGContext thread-local. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- include/exec/gen-icount.h | 7 +++---- tcg/tcg.h | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index 9b3cb14..489aff7 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -6,13 +6,12 @@ /* Helpers for instruction counting code generation. */ =20 static int icount_start_insn_idx; -static TCGLabel *exitreq_label; =20 static inline void gen_tb_start(TranslationBlock *tb) { TCGv_i32 count, imm; =20 - exitreq_label =3D gen_new_label(); + tcg_ctx.exitreq_label =3D gen_new_label(); if (tb->cflags & CF_USE_ICOUNT) { count =3D tcg_temp_local_new_i32(); } else { @@ -34,7 +33,7 @@ static inline void gen_tb_start(TranslationBlock *tb) tcg_temp_free_i32(imm); } =20 - tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, exitreq_label); + tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx.exitreq_label); =20 if (tb->cflags & CF_USE_ICOUNT) { tcg_gen_st16_i32(count, tcg_ctx.tcg_env, @@ -52,7 +51,7 @@ static inline void gen_tb_end(TranslationBlock *tb, int n= um_insns) tcg_set_insn_param(icount_start_insn_idx, 1, num_insns); } =20 - gen_set_label(exitreq_label); + gen_set_label(tcg_ctx.exitreq_label); tcg_gen_exit_tb((uintptr_t)tb + TB_EXIT_REQUESTED); =20 /* Terminate the linked list. */ diff --git a/tcg/tcg.h b/tcg/tcg.h index 4f57878..534ead5 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -711,6 +711,8 @@ struct TCGContext { /* The TCGBackendData structure is private to tcg-target.inc.c. */ struct TCGBackendData *be; =20 + TCGLabel *exitreq_label; + TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ =20 --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499587591278514.0875460221826; Sun, 9 Jul 2017 01:06:31 -0700 (PDT) Received: from localhost ([::1]:35319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7Eb-0008G9-3E for importer@patchew.org; Sun, 09 Jul 2017 04:06:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zL-0004RI-8K for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-00031K-8j for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:42783) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002zo-Qw for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 832D12093A; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:34 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 4D00B24254; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=pfU q+tssllgtE68No2AfNZEF5BYYAP01XiQkLf8FdvY=; b=HTaFCGvp519NJHW3bXB PGOojbrEaIKt87mQzA2Fb8yl4P0ff6789QZuLgQ15CbFK8to16E4Fj7CHDdov36f bu0uUctpayF7JddROFRBduiK8j3PU6LrwBIZJtdreGguNDqMBg+KuH51sxSSOm83 pUP94RGPXRpmFxnfzegt0JPE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=pfUq+tssllgtE68No2AfNZEF5BYYAP01XiQkLf8Fd vY=; b=Jh9p5LY3tKuTMnJ0gEvdZTDJC6Pvn1KVrlY9FNSKMNQaF28EdRg+rdaKw xjtm0AbbrItzTOnbD8EqiEjdxZ8aXxAGonOIBwDQqZNiMaP87A079MYlB60iQcVq 0puZG6eudGkYYxQXU7bgjamt7kKv39czxaVA4ZnTqhrBkwo0peHg7eBTgic6AQJa 53hCLCr5vyBZTNL9CMVApEMrrbgd1NCXJo+g0/mcMRjWELP9WP0Nla3cdWmKZOF3 GgIR13ikUGa09bByGbQFh6paZrxGXqCekaIsLShoTNey73SeQFbGAawlQ1jPGr4o RfmYgGjBj3w3+e5XGFmtQrSdYhxPg== X-ME-Sender: X-Sasl-enc: Ei7fBtctCKO0B70+aXP3MoNFTMmBOqqC58cvc28t4cI0 1499586634 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:08 -0400 Message-Id: <1499586614-20507-17-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 16/22] tcg: keep a list of TCGContext's 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before we make TCGContext thread-local. Once that is done, iterating over all TCG contexts will be quite useful; for instance we will need it to gather profiling info from each TCGContext. A possible alternative would be to keep an array of TCGContext pointers. However this option however is not that trivial, because vCPUs are spawned = in parallel. So let's just keep it simple and use a list protected by a lock. Note that this lock will soon be used for other purposes, hence the generic "tcg_lock" name. Signed-off-by: Emilio G. Cota --- tcg/tcg.h | 3 +++ tcg/tcg.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tcg/tcg.h b/tcg/tcg.h index 534ead5..8e1cd45 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -725,6 +725,8 @@ struct TCGContext { =20 uint16_t gen_insn_end_off[TCG_MAX_INSNS]; target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS]; + + QSIMPLEQ_ENTRY(TCGContext) entry; }; =20 extern TCGContext tcg_ctx; @@ -773,6 +775,7 @@ static inline void *tcg_malloc(int size) =20 void tcg_context_init(TCGContext *s); void tcg_prologue_init(TCGContext *s); +void tcg_register_thread(void); void tcg_func_start(TCGContext *s); =20 int tcg_gen_code(TCGContext *s, TranslationBlock *tb); diff --git a/tcg/tcg.c b/tcg/tcg.c index d9b083a..0da7c61 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -115,7 +115,16 @@ static int tcg_target_const_match(tcg_target_long val,= TCGType type, static void tcg_out_tb_init(TCGContext *s); static bool tcg_out_tb_finalize(TCGContext *s); =20 +static QemuMutex tcg_lock; =20 +/* + * List of TCGContext's in the system. Protected by tcg_lock. + * Once vcpu threads have been inited, there will be no further modificati= ons + * to the list (vcpu threads never return) so we can safely traverse the l= ist + * without synchronization. + */ +static QSIMPLEQ_HEAD(, TCGContext) ctx_list =3D + QSIMPLEQ_HEAD_INITIALIZER(ctx_list); =20 static TCGRegSet tcg_target_available_regs[2]; static TCGRegSet tcg_target_call_clobber_regs; @@ -324,6 +333,17 @@ static GHashTable *helper_table; static int indirect_reg_alloc_order[ARRAY_SIZE(tcg_target_reg_alloc_order)= ]; static void process_op_defs(TCGContext *s); =20 +/* + * Child TCG threads, i.e. the ones that do not call tcg_context_init, mus= t call + * this function before initiating translation. + */ +void tcg_register_thread(void) +{ + qemu_mutex_lock(&tcg_lock); + QSIMPLEQ_INSERT_TAIL(&ctx_list, &tcg_ctx, entry); + qemu_mutex_unlock(&tcg_lock); +} + void tcg_context_init(TCGContext *s) { int op, total_args, n, i; @@ -381,6 +401,9 @@ void tcg_context_init(TCGContext *s) for (; i < ARRAY_SIZE(tcg_target_reg_alloc_order); ++i) { indirect_reg_alloc_order[i] =3D tcg_target_reg_alloc_order[i]; } + + qemu_mutex_init(&tcg_lock); + tcg_register_thread(); } =20 /* --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499586771925988.8985354111824; Sun, 9 Jul 2017 00:52:51 -0700 (PDT) Received: from localhost ([::1]:35252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU71O-0005k0-Jm for importer@patchew.org; Sun, 09 Jul 2017 03:52:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zM-0004S5-Ma for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-00031Q-9W for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49909) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-0002zq-Q2 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id B126720929; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:34 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 76D157E70C; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=igM hOXoqSUTi5lFHmxZibheWjE29MO/RlZxoAfTPbyc=; b=Fb7+vgOKPsBJm4+ZiZI H/MCpVIP1V2clboy1UuQdDeMcPZN12NIyeu8uaAkAIKltjU9oLkDCotR75IN3P5T j2RBhM3Z+RNpuyZ1w9Jiz3BFw28WX6L6REmJaktAIe0k5owVhAvpOXFaECvJNsSF KEoZs09XX8fijen55Y9UjEUM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=igMhOXoqSUTi5lFHmxZibheWjE29MO/RlZxoAfTPb yc=; b=bYyBH5jr3KR6t5P+9WaNfGKtjAxZarr7tg7cpG0NzWYulp7UtpVzjCUIk rcBpZFJ1lmV4w6EVeiV5/UxUAEANHaAKLTpmp4FniAOVm/Q04MW8bEhfRDgmscvG m/0tjXDisb5NIx/tnpPtp+Ws6uCiQJkt/9uLI4EZG+1Buz4IpBFulMI8/FsU0nCg y/vMzBi+C8vE8voD2DCOCUmrSuWrJJCuR48EVqTIMT4xywS61Y7N5Np40KQ+AAcU wXhd5MHXgJFIMtJzqS94/v608pfp9h/H4uyIBiovoOKfQqNc+AEPemLBy0oODxN5 YwJ6H93BpR6gvSEeEn4yBnVfh/OZw== X-ME-Sender: X-Sasl-enc: Ei7fAtIvErWnGa4tbGr3MoNFTMmBOqqC58cvc28t4cI0 1499586634 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:09 -0400 Message-Id: <1499586614-20507-18-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 17/22] tcg: distribute profiling counters across TCGContext's 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" TCGContext is about to be made thread-local. To avoid scalability issues when profiling info is enabled, this patch makes the profiling info counters distributed via the following changes: 1) Consolidate profile info into its own struct, TCGProfile, which TCGContext also includes. Note that tcg_table_op_count is brought into TCGProfile after dropping the tcg_ prefix. 2) Iterate over the TCG contexts in the system to obtain the total counts. Note that this change also requires updating the accessors to TCGProfile fields to use atomic_read/set whenever there may be concurrent accesses to them. Signed-off-by: Emilio G. Cota --- tcg/tcg.h | 38 ++++++++-------- accel/tcg/translate-all.c | 23 +++++----- tcg/tcg.c | 108 ++++++++++++++++++++++++++++++++++++++----= ---- 3 files changed, 124 insertions(+), 45 deletions(-) diff --git a/tcg/tcg.h b/tcg/tcg.h index 8e1cd45..2a64ee2 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -641,6 +641,26 @@ QEMU_BUILD_BUG_ON(OPPARAM_BUF_SIZE > (1 << 14)); /* Make sure that we don't overflow 64 bits without noticing. */ QEMU_BUILD_BUG_ON(sizeof(TCGOp) > 8); =20 +typedef struct TCGProfile { + int64_t tb_count1; + int64_t tb_count; + int64_t op_count; /* total insn count */ + int op_count_max; /* max insn per TB */ + int64_t temp_count; + int temp_count_max; + int64_t del_op_count; + int64_t code_in_len; + int64_t code_out_len; + int64_t search_out_len; + int64_t interm_time; + int64_t code_time; + int64_t la_time; + int64_t opt_time; + int64_t restore_count; + int64_t restore_time; + int64_t table_op_count[NB_OPS]; +} TCGProfile; + struct TCGContext { uint8_t *pool_cur, *pool_end; TCGPool *pool_first, *pool_current, *pool_first_large; @@ -664,23 +684,7 @@ struct TCGContext { tcg_insn_unit *code_ptr; =20 #ifdef CONFIG_PROFILER - /* profiling info */ - int64_t tb_count1; - int64_t tb_count; - int64_t op_count; /* total insn count */ - int op_count_max; /* max insn per TB */ - int64_t temp_count; - int temp_count_max; - int64_t del_op_count; - int64_t code_in_len; - int64_t code_out_len; - int64_t search_out_len; - int64_t interm_time; - int64_t code_time; - int64_t la_time; - int64_t opt_time; - int64_t restore_count; - int64_t restore_time; + TCGProfile prof; #endif =20 #ifdef CONFIG_DEBUG_TCG diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 84e19d9..31a9d42 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -287,6 +287,7 @@ static int cpu_restore_state_from_tb(CPUState *cpu, Tra= nslationBlock *tb, uint8_t *p =3D tb->tc_search; int i, j, num_insns =3D tb->icount; #ifdef CONFIG_PROFILER + TCGProfile *prof =3D &tcg_ctx.prof; int64_t ti =3D profile_getclock(); #endif =20 @@ -321,8 +322,9 @@ static int cpu_restore_state_from_tb(CPUState *cpu, Tra= nslationBlock *tb, restore_state_to_opc(env, tb, data); =20 #ifdef CONFIG_PROFILER - tcg_ctx.restore_time +=3D profile_getclock() - ti; - tcg_ctx.restore_count++; + atomic_set(&prof->restore_time, + prof->restore_time + profile_getclock() - ti); + atomic_set(&prof->restore_count, prof->restore_count + 1); #endif return 0; } @@ -1269,6 +1271,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_insn_unit *gen_code_buf; int gen_code_size, search_size; #ifdef CONFIG_PROFILER + TCGProfile *prof =3D &tcg_ctx.prof; int64_t ti; #endif assert_memory_lock(); @@ -1298,8 +1301,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->invalid =3D false; =20 #ifdef CONFIG_PROFILER - tcg_ctx.tb_count1++; /* includes aborted translations because of - exceptions */ + /* includes aborted translations because of exceptions */ + atomic_set(&prof->tb_count1, prof->tb_count1 + 1); ti =3D profile_getclock(); #endif =20 @@ -1324,8 +1327,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #endif =20 #ifdef CONFIG_PROFILER - tcg_ctx.tb_count++; - tcg_ctx.interm_time +=3D profile_getclock() - ti; + atomic_set(&prof->tb_count, prof->tb_count + 1); + atomic_set(&prof->interm_time, prof->interm_time + profile_getclock() = - ti); ti =3D profile_getclock(); #endif =20 @@ -1345,10 +1348,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->tc_size =3D gen_code_size; =20 #ifdef CONFIG_PROFILER - tcg_ctx.code_time +=3D profile_getclock() - ti; - tcg_ctx.code_in_len +=3D tb->size; - tcg_ctx.code_out_len +=3D gen_code_size; - tcg_ctx.search_out_len +=3D search_size; + atomic_set(&prof->code_time, prof->code_time + profile_getclock() - ti= ); + atomic_set(&prof->code_in_len, prof->code_in_len + tb->size); + atomic_set(&prof->code_out_len, prof->code_out_len + gen_code_size); + atomic_set(&prof->search_out_len, prof->search_out_len + search_size); #endif =20 #ifdef DEBUG_DISAS diff --git a/tcg/tcg.c b/tcg/tcg.c index 0da7c61..c19c473 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1362,7 +1362,7 @@ void tcg_op_remove(TCGContext *s, TCGOp *op) memset(op, 0, sizeof(*op)); =20 #ifdef CONFIG_PROFILER - s->del_op_count++; + atomic_set(&s->prof.del_op_count, s->prof.del_op_count + 1); #endif } =20 @@ -2533,15 +2533,77 @@ static void tcg_reg_alloc_call(TCGContext *s, int n= b_oargs, int nb_iargs, =20 #ifdef CONFIG_PROFILER =20 -static int64_t tcg_table_op_count[NB_OPS]; +/* avoid copy/paste errors */ +#define PROF_ADD(to, from, field) \ + (to)->field +=3D atomic_read(&((from)->field)) + +#define PROF_ADD_MAX(to, from, field) \ + do { \ + typeof((from)->field) val__ =3D atomic_read(&((from)->field)); \ + if (val__ > (to)->field) { \ + (to)->field =3D val__; \ + } \ + } while (0) + +/* Pass in a zero'ed @prof */ +static inline +void tcg_profile_snapshot(TCGProfile *prof, bool counters, bool table) +{ + const TCGContext *s; + + QSIMPLEQ_FOREACH(s, &ctx_list, entry) { + const TCGProfile *orig =3D &s->prof; + + if (counters) { + PROF_ADD(prof, orig, tb_count1); + PROF_ADD(prof, orig, tb_count); + PROF_ADD(prof, orig, op_count); + PROF_ADD_MAX(prof, orig, op_count_max); + PROF_ADD(prof, orig, temp_count); + PROF_ADD_MAX(prof, orig, temp_count_max); + PROF_ADD(prof, orig, del_op_count); + PROF_ADD(prof, orig, code_in_len); + PROF_ADD(prof, orig, code_out_len); + PROF_ADD(prof, orig, search_out_len); + PROF_ADD(prof, orig, interm_time); + PROF_ADD(prof, orig, code_time); + PROF_ADD(prof, orig, la_time); + PROF_ADD(prof, orig, opt_time); + PROF_ADD(prof, orig, restore_count); + PROF_ADD(prof, orig, restore_time); + } + if (table) { + int i; + + for (i =3D 0; i < NB_OPS; i++) { + PROF_ADD(prof, orig, table_op_count[i]); + } + } + } +} + +#undef PROF_ADD +#undef PROF_ADD_MAX + +static void tcg_profile_snapshot_counters(TCGProfile *prof) +{ + tcg_profile_snapshot(prof, true, false); +} + +static void tcg_profile_snapshot_table(TCGProfile *prof) +{ + tcg_profile_snapshot(prof, false, true); +} =20 void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf) { + TCGProfile prof =3D {}; int i; =20 + tcg_profile_snapshot_table(&prof); for (i =3D 0; i < NB_OPS; i++) { cpu_fprintf(f, "%s %" PRId64 "\n", tcg_op_defs[i].name, - tcg_table_op_count[i]); + prof.table_op_count[i]); } } #else @@ -2554,6 +2616,9 @@ void tcg_dump_op_count(FILE *f, fprintf_function cpu_= fprintf) =20 int tcg_gen_code(TCGContext *s, TranslationBlock *tb) { +#ifdef CONFIG_PROFILER + TCGProfile *prof =3D &s->prof; +#endif int i, oi, oi_next, num_insns; =20 #ifdef CONFIG_PROFILER @@ -2561,15 +2626,15 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *t= b) int n; =20 n =3D s->gen_op_buf[0].prev + 1; - s->op_count +=3D n; - if (n > s->op_count_max) { - s->op_count_max =3D n; + atomic_set(&prof->op_count, prof->op_count + n); + if (n > prof->op_count_max) { + atomic_set(&prof->op_count_max, n); } =20 n =3D s->nb_temps; - s->temp_count +=3D n; - if (n > s->temp_count_max) { - s->temp_count_max =3D n; + atomic_set(&prof->temp_count, prof->temp_count + n); + if (n > prof->temp_count_max) { + atomic_set(&prof->temp_count_max, n); } } #endif @@ -2586,7 +2651,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #endif =20 #ifdef CONFIG_PROFILER - s->opt_time -=3D profile_getclock(); + atomic_set(&prof->opt_time, prof->opt_time - profile_getclock()); #endif =20 #ifdef USE_TCG_OPTIMIZATIONS @@ -2594,8 +2659,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #endif =20 #ifdef CONFIG_PROFILER - s->opt_time +=3D profile_getclock(); - s->la_time -=3D profile_getclock(); + atomic_set(&prof->opt_time, prof->opt_time + profile_getclock()); + atomic_set(&prof->la_time, prof->la_time - profile_getclock()); #endif =20 { @@ -2623,7 +2688,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } =20 #ifdef CONFIG_PROFILER - s->la_time +=3D profile_getclock(); + atomic_set(&prof->la_time, prof->la_time + profile_getclock()); #endif =20 #ifdef DEBUG_DISAS @@ -2654,7 +2719,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) =20 oi_next =3D op->next; #ifdef CONFIG_PROFILER - tcg_table_op_count[opc]++; + atomic_set(&prof->table_op_count[opc], prof->table_op_count[opc] += 1); #endif =20 switch (opc) { @@ -2730,10 +2795,17 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *t= b) #ifdef CONFIG_PROFILER void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf) { - TCGContext *s =3D &tcg_ctx; - int64_t tb_count =3D s->tb_count; - int64_t tb_div_count =3D tb_count ? tb_count : 1; - int64_t tot =3D s->interm_time + s->code_time; + TCGProfile prof =3D {}; + const TCGProfile *s; + int64_t tb_count; + int64_t tb_div_count; + int64_t tot; + + tcg_profile_snapshot_counters(&prof); + s =3D &prof; + tb_count =3D s->tb_count; + tb_div_count =3D tb_count ? tb_count : 1; + tot =3D s->interm_time + s->code_time; =20 cpu_fprintf(f, "JIT cycles %" PRId64 " (%0.3f s at 2.4 GHz)\n= ", tot, tot / 2.4e9); --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499587387282767.1694447151375; Sun, 9 Jul 2017 01:03:07 -0700 (PDT) Received: from localhost ([::1]:35306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7BI-0005q2-9t for importer@patchew.org; Sun, 09 Jul 2017 04:03:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zK-0004RD-Mz for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-00031X-B9 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:42 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:35749) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-000300-P1 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D70852093D; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:34 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id A2C5D24254; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=rjp B9TTNVB3M3sZYIisOMccsMLWcGtsK5Ik1bwanluU=; b=Nt5bDXaIkX9ajOqdNE7 wvxaIX5nHmfFjjcywbVs0q0+AaMTNaJIfTwVY5ct0w3+86p73PsHbBGXE3u5/R7Z 0ShEjKwdnDDNhLJ3IMseG1rwIFVPqociNVo42jUQM83+8/+/nKbiWsdgnLBwoKAm hfaDY6QhtXVJOwrWR3cDbPEQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=rjpB9TTNVB3M3sZYIisOMccsMLWcGtsK5Ik1bwanl uU=; b=MBSzTi01WNVTbgSMZ6HsPU/VlzDtp9JgpNDba82Th3A3Mvw08BGTduQNQ fUa6iToUJ7pHrLsvCT13XIEo96ugqYDKZcdqfz8guPYz0iMWWy9fdvsXkWeBz7q4 6RA5f0LTBbHFvlNqGhYmuMpYQZKAQVFEFP85c03g50hhmX7BZgaxTTEzMlrXZ6/o kXiSh3WBM/EWRVh8dOMQ05LZ2W7S4CZ4yhop+LwVnQwlwZxOuinfu73emxIFh0Hs ICcWLi7xZa964hNeg0zuWUNi4t9bCEeOwUTHMEPpO/xP31RBzHQDYqvP3VYvWBrN 0yQUl27lQ1/DcRKcPH8voAcjRMRGA== X-ME-Sender: X-Sasl-enc: Ei7YHNIrA7KrDr01ZHz3MoNFTMmBOqqC58cvc28t4cI0 1499586634 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:10 -0400 Message-Id: <1499586614-20507-19-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 18/22] tcg: define TCG_HIGHWATER 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Will come in handy very soon. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- tcg/tcg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index c19c473..2f003a0 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -115,6 +115,8 @@ static int tcg_target_const_match(tcg_target_long val, = TCGType type, static void tcg_out_tb_init(TCGContext *s); static bool tcg_out_tb_finalize(TCGContext *s); =20 +#define TCG_HIGHWATER 1024 + static QemuMutex tcg_lock; =20 /* @@ -453,7 +455,7 @@ void tcg_prologue_init(TCGContext *s) /* Compute a high-water mark, at which we voluntarily flush the buffer and start over. The size here is arbitrary, significantly larger than we expect the code generation for any one opcode to require. = */ - s->code_gen_highwater =3D s->code_gen_buffer + (total_size - 1024); + s->code_gen_highwater =3D s->code_gen_buffer + (total_size - TCG_HIGHW= ATER); =20 tcg_register_jit(s->code_gen_buffer, total_size); =20 --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499587550251236.43493401147782; Sun, 9 Jul 2017 01:05:50 -0700 (PDT) Received: from localhost ([::1]:35318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7Dw-0007ph-Tt for importer@patchew.org; Sun, 09 Jul 2017 04:05:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zL-0004RH-7s for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-00031h-CE for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:43 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:53043) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-000301-Q3 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 0E08B20913; Sun, 9 Jul 2017 03:50:35 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:35 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id CBCCC7E70C; Sun, 9 Jul 2017 03:50:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=pHD pNGHV/1gs0s5Swyo6UHJtms5yBA3noLN382UZZAI=; b=HAW5Q9ckjZBdYHj4t3Q ve3xnwfOX1G7HBZUn6Cx/bCFOC7wex6RSQaSR8UgESBkETVqRiiNgnW849rZRXy7 RvUqQ5x4UbZWKiWnfZoD5o5iYuPS3fd8C/5QveKz/yKLZ07DdewDaX9f8hm6/upU DXKTGQX8vUtxhBwd75fj3Xrw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=pHDpNGHV/1gs0s5Swyo6UHJtms5yBA3noLN382UZZ AI=; b=GRTHR4eEst6gsoosUW1afdrnv3hJuejfFP+E6yjxF8HfsRcnHfTqgh6GK Ty7G01xxDf1rkhrnyTjwLH5LyhhpPALT44vLHQvzt+L3Uv69veF5196qan7FHr8f FTnOmyUuP5sgDmR+Unujvx9wzO2n6O7UBgeKTtWBj4RmH6rKQnortKHe68tXW3bO AHE5/5NAykdTBhzvjqh7CmUQ8LNWgWP1S59p1FuokMoz7xeihWT24k3W2nQpKZ07 /8b0FmxV1yxs3hqj/hCxkvO9+E1wnW6NRB07yYwn0osVYXPZFLys5kuvbCljafAI 0p4KEIux8kWJ81zj6GorCkr6z9KIQ== X-ME-Sender: X-Sasl-enc: Ei7MHNg7Dq2wC6khbm/3MoNFTMmBOqqC58cvc28t4cI0 1499586634 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:11 -0400 Message-Id: <1499586614-20507-20-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 19/22] tcg: introduce tcg_context_clone 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before we make TCGContext thread-local. Signed-off-by: Emilio G. Cota --- tcg/tcg.h | 1 + tcg/tcg.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/tcg/tcg.h b/tcg/tcg.h index 2a64ee2..be5f3fd 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -778,6 +778,7 @@ static inline void *tcg_malloc(int size) } =20 void tcg_context_init(TCGContext *s); +void tcg_context_clone(TCGContext *s); void tcg_prologue_init(TCGContext *s); void tcg_register_thread(void); void tcg_func_start(TCGContext *s); diff --git a/tcg/tcg.c b/tcg/tcg.c index 2f003a0..8febf53 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -117,6 +117,7 @@ static bool tcg_out_tb_finalize(TCGContext *s); =20 #define TCG_HIGHWATER 1024 =20 +static const TCGContext *tcg_init_ctx; static QemuMutex tcg_lock; =20 /* @@ -353,6 +354,7 @@ void tcg_context_init(TCGContext *s) TCGArgConstraint *args_ct; int *sorted_args; =20 + tcg_init_ctx =3D s; memset(s, 0, sizeof(*s)); s->nb_globals =3D 0; =20 @@ -409,6 +411,18 @@ void tcg_context_init(TCGContext *s) } =20 /* + * Clone the initial TCGContext. Used by TCG threads to copy the TCGContext + * set up by their parent thread via tcg_context_init(). + */ +void tcg_context_clone(TCGContext *s) +{ + if (unlikely(tcg_init_ctx =3D=3D NULL || tcg_init_ctx =3D=3D s)) { + tcg_abort(); + } + memcpy(s, tcg_init_ctx, sizeof(*s)); +} + +/* * Allocate TBs right before their corresponding translated code, making * sure that TBs and code are on different cache lines. */ --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 14995876944747.226359610975919; Sun, 9 Jul 2017 01:08:14 -0700 (PDT) Received: from localhost ([::1]:35323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU7GG-0000se-Ew for importer@patchew.org; Sun, 09 Jul 2017 04:08:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zN-0004Sn-8a for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-000320-Cl for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:45 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:46671) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-000308-Te for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:37 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 44FA720909; Sun, 9 Jul 2017 03:50:35 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:35 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 0444D24254; Sun, 9 Jul 2017 03:50:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=yy1 7R76bDWI7Fe2WTODXRQXUFMXLAWQiZ1XH7LOU2S8=; b=yKiHv9YzoXFGN3X2XeW NQq94BwhkVw6+y96V+Tci9ZAXS1Ryzqe9hRWv3rLom2pSYK00qjdweXJG7p1ga4Q t61Ilv8/cD61NZFcKb3v00ZAwye1fZwT1VbGga4cT39vN66ev9zF/WjbF7k143sj w09dv+YvukNC4EFO2Fv5MJKU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=yy17R76bDWI7Fe2WTODXRQXUFMXLAWQiZ1XH7LOU2 S8=; b=jeUl8joMcKVFyXsf8PBMx0l46hr0vfZxdm2vAvTa/6fU3gp3N5UFAulKT JCiwO1PAfnpDPa+gh1jw6Q5fcbz4bunKM6iEcBjNF4acULAfznOUFZ2Uft07bSHS aR6/WVw1LXx3zE/O9kB1WIdrBHXwBWfa5lx/sAUdSgA8ll4i5ZoZm2gCLLrf23/Y w4iWxCjmhLPHNB83AU9xaavqB5InFMq3ikLv1YrQatjlMW003jzSpTbk8xUjJLE5 L5TDSxKMbyfXLUrxiJwOYl+hMxqBT7Gbi3hh+u23PBy9xgr3jK2yfSss3MigNII+ dxvML5JwM1KCMxo0EGnShkitDIuDw== X-ME-Sender: X-Sasl-enc: G6Kyp9AMJ7o6/ZTZR6TyEf//IWpQtk7ZoSJFVDtvr5vJ 1499586635 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:12 -0400 Message-Id: <1499586614-20507-21-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 20/22] tcg: dynamically allocate from code_gen_buffer using equally-sized regions 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In preparation for having multiple TCG threads. The naive solution here is to split code_gen_buffer statically among the TCG threads; this however results in poor utilization if translation needs are different across TCG threads. What we do here is to add an extra layer of indirection, assigning regions that act just like pages do in virtual memory allocation. (BTW if you are wondering about the chosen naming, I did not want to use blocks or pages because those are already heavily used in QEMU). The effectiveness of this approach is clear after seeing some numbers. I used the bootup+shutdown of debian-arm with '-tb-size 80' as a benchmark. Note that I'm evaluating this after enabling per-thread TCG (which is done by a subsequent commit). * -smp 1, 1 region (entire buffer): qemu: flush code_size=3D83885014 nb_tbs=3D154739 avg_tb_size=3D357 qemu: flush code_size=3D83884902 nb_tbs=3D153136 avg_tb_size=3D363 qemu: flush code_size=3D83885014 nb_tbs=3D152777 avg_tb_size=3D364 qemu: flush code_size=3D83884950 nb_tbs=3D150057 avg_tb_size=3D373 qemu: flush code_size=3D83884998 nb_tbs=3D150234 avg_tb_size=3D373 qemu: flush code_size=3D83885014 nb_tbs=3D154009 avg_tb_size=3D360 qemu: flush code_size=3D83885014 nb_tbs=3D151007 avg_tb_size=3D370 qemu: flush code_size=3D83885014 nb_tbs=3D151816 avg_tb_size=3D367 That is, 8 flushes. * -smp 8, 32 regions (80/32 MB per region) [i.e. this patch]: qemu: flush code_size=3D76328008 nb_tbs=3D141040 avg_tb_size=3D356 qemu: flush code_size=3D75366534 nb_tbs=3D138000 avg_tb_size=3D361 qemu: flush code_size=3D76864546 nb_tbs=3D140653 avg_tb_size=3D361 qemu: flush code_size=3D76309084 nb_tbs=3D135945 avg_tb_size=3D375 qemu: flush code_size=3D74581856 nb_tbs=3D132909 avg_tb_size=3D375 qemu: flush code_size=3D73927256 nb_tbs=3D135616 avg_tb_size=3D360 qemu: flush code_size=3D78629426 nb_tbs=3D142896 avg_tb_size=3D365 qemu: flush code_size=3D76667052 nb_tbs=3D138508 avg_tb_size=3D368 Again, 8 flushes. Note how buffer utilization is not 100%, but it is close. Smaller region sizes would yield higher utilization, but we want region allocation to be rare (it acquires a lock), so we do not want to go too small. * -smp 8, static partitioning of 8 regions (10 MB per region): qemu: flush code_size=3D21936504 nb_tbs=3D40570 avg_tb_size=3D354 qemu: flush code_size=3D11472174 nb_tbs=3D20633 avg_tb_size=3D370 qemu: flush code_size=3D11603976 nb_tbs=3D21059 avg_tb_size=3D365 qemu: flush code_size=3D23254872 nb_tbs=3D41243 avg_tb_size=3D377 qemu: flush code_size=3D28289496 nb_tbs=3D52057 avg_tb_size=3D358 qemu: flush code_size=3D43605160 nb_tbs=3D78896 avg_tb_size=3D367 qemu: flush code_size=3D45166552 nb_tbs=3D82158 avg_tb_size=3D364 qemu: flush code_size=3D63289640 nb_tbs=3D116494 avg_tb_size=3D358 qemu: flush code_size=3D51389960 nb_tbs=3D93937 avg_tb_size=3D362 qemu: flush code_size=3D59665928 nb_tbs=3D107063 avg_tb_size=3D372 qemu: flush code_size=3D38380824 nb_tbs=3D68597 avg_tb_size=3D374 qemu: flush code_size=3D44884568 nb_tbs=3D79901 avg_tb_size=3D376 qemu: flush code_size=3D50782632 nb_tbs=3D90681 avg_tb_size=3D374 qemu: flush code_size=3D39848888 nb_tbs=3D71433 avg_tb_size=3D372 qemu: flush code_size=3D64708840 nb_tbs=3D119052 avg_tb_size=3D359 qemu: flush code_size=3D49830008 nb_tbs=3D90992 avg_tb_size=3D362 qemu: flush code_size=3D68372408 nb_tbs=3D123442 avg_tb_size=3D368 qemu: flush code_size=3D33555560 nb_tbs=3D59514 avg_tb_size=3D378 qemu: flush code_size=3D44748344 nb_tbs=3D80974 avg_tb_size=3D367 qemu: flush code_size=3D37104248 nb_tbs=3D67609 avg_tb_size=3D364 That is, 20 flushes. Note how a static partitioning approach uses the code buffer poorly, leading to many unnecessary flushes. Signed-off-by: Emilio G. Cota --- tcg/tcg.h | 8 +++ accel/tcg/translate-all.c | 61 ++++++++++++---- bsd-user/main.c | 1 + linux-user/main.c | 1 + tcg/tcg.c | 175 ++++++++++++++++++++++++++++++++++++++++++= +++- 5 files changed, 230 insertions(+), 16 deletions(-) diff --git a/tcg/tcg.h b/tcg/tcg.h index be5f3fd..a767a33 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -761,6 +761,14 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); =20 +void tcg_region_init(TCGContext *s); +bool tcg_region_alloc(TCGContext *s); +void tcg_region_set_size(size_t size); +void tcg_region_reset_all(void); + +size_t tcg_code_size(void); +size_t tcg_code_capacity(void); + /* Called with tb_lock held. */ static inline void *tcg_malloc(int size) { diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 31a9d42..ce9d746 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -53,11 +53,13 @@ #include "exec/cputlb.h" #include "exec/tb-hash.h" #include "translate-all.h" +#include "qemu/error-report.h" #include "qemu/bitmap.h" #include "qemu/timer.h" #include "qemu/main-loop.h" #include "exec/log.h" #include "sysemu/cpus.h" +#include "sysemu/sysemu.h" =20 /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */ @@ -808,6 +810,41 @@ static inline void code_gen_alloc(size_t tb_size) qemu_mutex_init(&tb_ctx.tb_lock); } =20 +#ifdef CONFIG_SOFTMMU +/* + * It is likely that some vCPUs will translate more code than others, so we + * first try to set more regions than smp_cpus, with those regions being + * larger than the minimum code_gen_buffer size. If that's not possible we + * make do by evenly dividing the code_gen_buffer among the vCPUs. + */ +static void code_gen_set_region_size(TCGContext *s) +{ + size_t per_cpu =3D s->code_gen_buffer_size / smp_cpus; + size_t div; + + assert(per_cpu); + /* + * Use a single region if all we have is one vCPU. + * We could also use a single region with !mttcg, but at this time we = have + * not yet processed the thread=3Dsingle|multi flag. + */ + if (smp_cpus =3D=3D 1) { + tcg_region_set_size(0); + return; + } + + for (div =3D 8; div > 0; div--) { + size_t region_size =3D per_cpu / div; + + if (region_size >=3D 2 * MIN_CODE_GEN_BUFFER_SIZE) { + tcg_region_set_size(region_size); + return; + } + } + tcg_region_set_size(per_cpu); +} +#endif + static void tb_htable_init(void) { unsigned int mode =3D QHT_MODE_AUTO_RESIZE; @@ -829,6 +866,8 @@ void tcg_exec_init(unsigned long tb_size) /* There's no guest base to take into account, so go ahead and initialize the prologue now. */ tcg_prologue_init(&tcg_ctx); + code_gen_set_region_size(&tcg_ctx); + tcg_region_init(&tcg_ctx); #endif } =20 @@ -929,14 +968,9 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data= tb_flush_count) #if defined(DEBUG_TB_FLUSH) g_tree_foreach(tb_ctx.tb_tree, tb_host_size_iter, &host_size); nb_tbs =3D g_tree_nnodes(tb_ctx.tb_tree); - printf("qemu: flush code_size=3D%ld nb_tbs=3D%d avg_tb_size=3D%zu\n", - (unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer), - nb_tbs, nb_tbs > 0 ? host_size / nb_tbs : 0); + fprintf(stderr, "qemu: flush code_size=3D%zu nb_tbs=3D%d avg_tb_size= =3D%zu\n", + tcg_code_size(), nb_tbs, nb_tbs > 0 ? host_size / nb_tbs : 0); #endif - if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) - > tcg_ctx.code_gen_buffer_size) { - cpu_abort(cpu, "Internal error: code buffer overflow\n"); - } =20 CPU_FOREACH(cpu) { cpu_tb_jmp_cache_clear(cpu); @@ -949,7 +983,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data = tb_flush_count) qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); =20 - tcg_ctx.code_gen_ptr =3D tcg_ctx.code_gen_buffer; + tcg_region_reset_all(); /* XXX: flush processor icache at this point if cache flush is expensive */ atomic_mb_set(&tb_ctx.tb_flush_count, tb_ctx.tb_flush_count + 1); @@ -1281,9 +1315,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, cflags |=3D CF_USE_ICOUNT; } =20 + buffer_overflow: tb =3D tb_alloc(pc); if (unlikely(!tb)) { - buffer_overflow: /* flush must be done */ tb_flush(cpu); mmap_unlock(); @@ -1366,9 +1400,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } #endif =20 - tcg_ctx.code_gen_ptr =3D (void *) + atomic_set(&tcg_ctx.code_gen_ptr, (void *) ROUND_UP((uintptr_t)gen_code_buf + gen_code_size + search_size, - CODE_GEN_ALIGN); + CODE_GEN_ALIGN)); =20 /* init jump list */ assert(((uintptr_t)tb & 3) =3D=3D 0); @@ -1907,9 +1941,8 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fpr= intf) * otherwise users might think "-tb-size" is not honoured. * For avg host size we use the precise numbers from tb_tree_stats tho= ugh. */ - cpu_fprintf(f, "gen code size %td/%zd\n", - tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, - tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer); + cpu_fprintf(f, "gen code size %zu/%zd\n", + tcg_code_size(), tcg_code_capacity()); cpu_fprintf(f, "TB count %d\n", nb_tbs); cpu_fprintf(f, "TB avg target size %zu max=3D%zu bytes\n", nb_tbs ? tst.target_size / nb_tbs : 0, diff --git a/bsd-user/main.c b/bsd-user/main.c index fa9c012..1a16052 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -979,6 +979,7 @@ int main(int argc, char **argv) generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init(&tcg_ctx); + tcg_region_init(&tcg_ctx); =20 /* build Task State */ memset(ts, 0, sizeof(TaskState)); diff --git a/linux-user/main.c b/linux-user/main.c index 630c73d..b73759c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -4457,6 +4457,7 @@ int main(int argc, char **argv, char **envp) generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init(&tcg_ctx); + tcg_region_init(&tcg_ctx); =20 #if defined(TARGET_I386) env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; diff --git a/tcg/tcg.c b/tcg/tcg.c index 8febf53..03ebc8c 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -129,6 +129,23 @@ static QemuMutex tcg_lock; static QSIMPLEQ_HEAD(, TCGContext) ctx_list =3D QSIMPLEQ_HEAD_INITIALIZER(ctx_list); =20 +/* + * We divide code_gen_buffer into equally-sized "regions" that TCG threads + * dynamically allocate from as demand dictates. Given appropriate region + * sizing, this minimizes flushes even when some TCG threads generate a lot + * more code than others. + */ +struct tcg_region_state { + void *buf; + size_t n; + size_t current; + size_t n_full; + size_t size; /* size of one region */ +}; + +/* protected by tcg_lock */ +static struct tcg_region_state region; + static TCGRegSet tcg_target_available_regs[2]; static TCGRegSet tcg_target_call_clobber_regs; =20 @@ -410,6 +427,156 @@ void tcg_context_init(TCGContext *s) tcg_register_thread(); } =20 +static void tcg_region_set_size__locked(size_t size) +{ + if (!size) { + region.size =3D tcg_init_ctx->code_gen_buffer_size; + region.n =3D 1; + } else { + region.size =3D size; + region.n =3D tcg_init_ctx->code_gen_buffer_size / size; + } + if (unlikely(region.size < TCG_HIGHWATER)) { + tcg_abort(); + } +} + +/* + * Call this function at init time (i.e. only once). Calling this function= is + * optional: if no region size is set, a single region will be used. + * + * Note: calling this function *after* calling tcg_region_init() is a bug. + */ +void tcg_region_set_size(size_t size) +{ + tcg_debug_assert(!region.size); + + qemu_mutex_lock(&tcg_lock); + tcg_region_set_size__locked(size); + qemu_mutex_unlock(&tcg_lock); +} + +static void tcg_region_assign__locked(TCGContext *s) +{ + void *buf =3D region.buf + region.size * region.current; + + s->code_gen_buffer =3D buf; + s->code_gen_ptr =3D buf; + s->code_gen_buffer_size =3D region.size; + s->code_gen_highwater =3D buf + region.size - TCG_HIGHWATER; +} + +static bool tcg_region_alloc__locked(TCGContext *s) +{ + if (region.current =3D=3D region.n) { + return false; + } + tcg_region_assign__locked(s); + region.current++; + return true; +} + +/* + * Request a new region once the one in use has filled up. + * Note: upon initializing a TCG thread, allocate a new region with + * tcg_region_init() instead. + * Returns true on success. + * */ +bool tcg_region_alloc(TCGContext *s) +{ + bool success; + + qemu_mutex_lock(&tcg_lock); + success =3D tcg_region_alloc__locked(s); + if (success) { + region.n_full++; + } + qemu_mutex_unlock(&tcg_lock); + return success; +} + +/* + * Allocate an initial region. + * All TCG threads must have called this function before any of them initi= ates + * translation. + * + * The region size might have previously been set by tcg_region_set_size(); + * otherwise a single region will be used on the entire code_gen_buffer. + * + * Note: allocate subsequent regions with tcg_region_alloc(). + */ +void tcg_region_init(TCGContext *s) +{ + qemu_mutex_lock(&tcg_lock); + if (region.buf =3D=3D NULL) { + region.buf =3D tcg_init_ctx->code_gen_buffer; + } + if (!region.size) { + tcg_region_set_size__locked(0); + } + /* if we cannot allocate on init, then we did something wrong */ + if (!tcg_region_alloc__locked(s)) { + tcg_abort(); + } + qemu_mutex_unlock(&tcg_lock); + +} + +/* Call from a safe-work context */ +void tcg_region_reset_all(void) +{ + TCGContext *s; + + qemu_mutex_lock(&tcg_lock); + region.current =3D 0; + region.n_full =3D 0; + + QSIMPLEQ_FOREACH(s, &ctx_list, entry) { + if (unlikely(!tcg_region_alloc__locked(s))) { + tcg_abort(); + } + } + qemu_mutex_unlock(&tcg_lock); +} + +/* + * Returns the size (in bytes) of all translated code (i.e. from all regio= ns) + * currently in the cache. + * See also: tcg_code_capacity() + * Do not confuse with tcg_current_code_size(); that one applies to a sing= le + * TCG context. + */ +size_t tcg_code_size(void) +{ + const TCGContext *s; + size_t total; + + qemu_mutex_lock(&tcg_lock); + total =3D region.n_full * (region.size - TCG_HIGHWATER); + QSIMPLEQ_FOREACH(s, &ctx_list, entry) { + size_t size; + + size =3D atomic_read(&s->code_gen_ptr) - s->code_gen_buffer; + if (unlikely(size > s->code_gen_buffer_size)) { + tcg_abort(); + } + total +=3D size; + } + qemu_mutex_unlock(&tcg_lock); + return total; +} + +/* + * Returns the code capacity (in bytes) of the entire cache, i.e. includin= g all + * regions. + * See also: tcg_code_size() + */ +size_t tcg_code_capacity(void) +{ + /* no need for synchronization; these variables are set at init time */ + return region.n * (region.size - TCG_HIGHWATER); +} + /* * Clone the initial TCGContext. Used by TCG threads to copy the TCGContext * set up by their parent thread via tcg_context_init(). @@ -432,13 +599,17 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s) TranslationBlock *tb; void *next; =20 + retry: tb =3D (void *)ROUND_UP((uintptr_t)s->code_gen_ptr, align); next =3D (void *)ROUND_UP((uintptr_t)(tb + 1), align); =20 if (unlikely(next > s->code_gen_highwater)) { - return NULL; + if (!tcg_region_alloc(s)) { + return NULL; + } + goto retry; } - s->code_gen_ptr =3D next; + atomic_set(&s->code_gen_ptr, next); return tb; } =20 --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499587091373635.5887350437803; Sun, 9 Jul 2017 00:58:11 -0700 (PDT) Received: from localhost ([::1]:35274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU76Y-0001nd-4f for importer@patchew.org; Sun, 09 Jul 2017 03:58:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zM-0004S4-Kd for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-00031f-Bs for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:51035) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-000302-Pi for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6B703208D2; Sun, 9 Jul 2017 03:50:35 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:35 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 31AB37E70C; Sun, 9 Jul 2017 03:50:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=c6m 9agnHBPPv2W7XvhakGphSdz6S0zINpBDYpZXo/7g=; b=GsgozrZY5C6kt0z2YAK RGWjvu0KCZiUkAdBW/+yhCn+i7/cmtmcRf8tftEdCvD7/yVoEWHxIDCBMOVI+JhD vG2HUk6n2O0dGVefpf7VMYhgaEPOtQqTIDE96VCGuI5Au5IRZHZPQu+SQ0k6dixw aBCfiwUgzlEotNH52VWIf+Uk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=c6m9agnHBPPv2W7XvhakGphSdz6S0zINpBDYpZXo/ 7g=; b=VI5r6DKWKqhtibQM2uJb4/HsKePi69Ey/ykTOBHCVu3JNNbRblA4nWtsk hiRwCqB18/SPgj6PTV5dlXIDH/i2wRJf2dskcNFVXoy/hcj/BWA9wie1eJ21BsmD ylLG8ReDBTVkSyGSjXrY/vKc7r+8JUCyFjNSSTBSdVidFXWTnSCZPCHCw33Jy/cU q48VV1a0vO5TJnldCzhLvgn72xFl+8zfz56qWU8V1LtwNtBi240GilhG/Wfxp5uE 80uv0HYa66ykXt8TvbsZlXi1JfvobpPXgH560E3qULmYpX46MfaSnJ8MuNEEv2aS zRkEFh87gfAugH8h9F4WH038C1SAA== X-ME-Sender: X-Sasl-enc: G6K0pdkBPLA845nZXr7yEf//IWpQtk7ZoSJFVDtvr5vJ 1499586635 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:13 -0400 Message-Id: <1499586614-20507-22-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 21/22] tcg: enable per-thread TCG for softmmu 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This allows us to generate TCG code in parallel. MTTCG already uses it, although the next commit pushes down a lock to actually perform parallel generation. User-mode is kept out of this: contention due to concurrent translation is more commonly found in full-system mode. This patch is fairly small due to the preparation work done in previous patches. Note that targets do not need any conversion: the TCGContext set up during initialization (i.e. where globals are set) is then cloned by the vCPU threads, which also double as TCG threads. I searched for globals under tcg/ that might have to be converted to thread-local. I converted the ones that I saw, and I wrote down the ones that I found are non-const globals that are only set at init-time: Only written by tcg_context_init: - indirect_reg_alloc_order - tcg_op_defs Only written by tcg_target_init (called from tcg_context_init): - tcg_target_available_regs - tcg_target_call_clobber_regs - arm: arm_arch, use_idiv_instructions - i386: have_cmov, have_bmi1, have_bmi2, have_lzcnt, have_movbe, have_popcnt - mips: use_movnz_instructions, use_mips32_instructions, use_mips32r2_instructions, got_sigill (tcg_target_detect_isa) - ppc: have_isa_2_06, have_isa_3_00, tb_ret_addr - s390: tb_ret_addr, s390_facilities - sparc: qemu_ld_trampoline, qemu_st_trampoline (build_trampolines), use_vis3_instructions Only written by tcg_prologue_init: - 'struct jit_code_entry one_entry' - aarch64: tb_ret_addr - arm: tb_ret_addr - i386: tb_ret_addr, guest_base_flags - ia64: tb_ret_addr - mips: tb_ret_addr, bswap32_addr, bswap32u_addr, bswap64_addr I was not sure about tci_regs. From code inspection it seems that they have to be per-thread, so I converted them, but I do not think anyone has ever tried to get MTTCG working with TCI. Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 4 +++- tcg/tcg.h | 12 +++++++++--- accel/tcg/translate-all.c | 20 +++++++++++++------- cpus.c | 3 +++ tcg/optimize.c | 4 ++-- tcg/tcg.c | 10 ++++++++++ tcg/tci.c | 2 +- 7 files changed, 41 insertions(+), 14 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 673b26d..5334b7a 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -47,7 +47,9 @@ void gen_intermediate_code(CPUArchState *env, struct Tran= slationBlock *tb); void restore_state_to_opc(CPUArchState *env, struct TranslationBlock *tb, target_ulong *data); =20 -void cpu_gen_init(void); +#ifdef CONFIG_SOFTMMU +void cpu_thread_tcg_init(void); +#endif bool cpu_restore_state(CPUState *cpu, uintptr_t searched_pc); =20 void QEMU_NORETURN cpu_loop_exit_noexc(CPUState *cpu); diff --git a/tcg/tcg.h b/tcg/tcg.h index a767a33..0cc2cab 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -733,7 +733,13 @@ struct TCGContext { QSIMPLEQ_ENTRY(TCGContext) entry; }; =20 -extern TCGContext tcg_ctx; +#ifdef CONFIG_SOFTMMU +#define TCG_THREAD __thread +#else +#define TCG_THREAD +#endif + +extern TCG_THREAD TCGContext tcg_ctx; extern bool parallel_cpus; =20 static inline void tcg_set_insn_param(int op_idx, int arg, TCGArg v) @@ -756,7 +762,7 @@ static inline bool tcg_op_buf_full(void) =20 /* pool based memory allocation */ =20 -/* tb_lock must be held for tcg_malloc_internal. */ +/* user-mode: tb_lock must be held for tcg_malloc_internal. */ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); @@ -769,7 +775,7 @@ void tcg_region_reset_all(void); size_t tcg_code_size(void); size_t tcg_code_capacity(void); =20 -/* Called with tb_lock held. */ +/* user-mode: Called with tb_lock held. */ static inline void *tcg_malloc(int size) { TCGContext *s =3D &tcg_ctx; diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index ce9d746..17b18a9 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -131,7 +131,7 @@ static int v_l2_levels; static void *l1_map[V_L1_MAX_SIZE]; =20 /* code generation context */ -TCGContext tcg_ctx; +TCG_THREAD TCGContext tcg_ctx; TBContext tb_ctx; bool parallel_cpus; =20 @@ -185,10 +185,6 @@ void tb_lock_reset(void) =20 static TranslationBlock *tb_find_pc(uintptr_t tc_ptr); =20 -void cpu_gen_init(void) -{ - tcg_context_init(&tcg_ctx);=20 -} =20 /* Encode VAL as a signed leb128 sequence at P. Return P incremented past the encoded value. */ @@ -812,6 +808,17 @@ static inline void code_gen_alloc(size_t tb_size) =20 #ifdef CONFIG_SOFTMMU /* + * Threads calling this function must be the TCG threads, i.e. they + * have their own tcg_ctx. + */ +void cpu_thread_tcg_init(void) +{ + tcg_context_clone(&tcg_ctx); + tcg_register_thread(); + tcg_region_init(&tcg_ctx); +} + +/* * It is likely that some vCPUs will translate more code than others, so we * first try to set more regions than smp_cpus, with those regions being * larger than the minimum code_gen_buffer size. If that's not possible we @@ -858,7 +865,7 @@ static void tb_htable_init(void) void tcg_exec_init(unsigned long tb_size) { tcg_allowed =3D true; - cpu_gen_init(); + tcg_context_init(&tcg_ctx); page_init(); tb_htable_init(); code_gen_alloc(tb_size); @@ -867,7 +874,6 @@ void tcg_exec_init(unsigned long tb_size) initialize the prologue now. */ tcg_prologue_init(&tcg_ctx); code_gen_set_region_size(&tcg_ctx); - tcg_region_init(&tcg_ctx); #endif } =20 diff --git a/cpus.c b/cpus.c index 14bb8d5..58efc95 100644 --- a/cpus.c +++ b/cpus.c @@ -1307,6 +1307,8 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) CPUState *cpu =3D arg; =20 rcu_register_thread(); + /* For single-threaded TCG we just need to initialize one tcg_ctx */ + cpu_thread_tcg_init(); =20 qemu_mutex_lock_iothread(); qemu_thread_get_self(cpu->thread); @@ -1454,6 +1456,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) g_assert(!use_icount); =20 rcu_register_thread(); + cpu_thread_tcg_init(); =20 qemu_mutex_lock_iothread(); qemu_thread_get_self(cpu->thread); diff --git a/tcg/optimize.c b/tcg/optimize.c index adfc56c..71af19b 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -40,8 +40,8 @@ struct tcg_temp_info { tcg_target_ulong mask; }; =20 -static struct tcg_temp_info temps[TCG_MAX_TEMPS]; -static TCGTempSet temps_used; +static TCG_THREAD struct tcg_temp_info temps[TCG_MAX_TEMPS]; +static TCG_THREAD TCGTempSet temps_used; =20 static inline bool temp_is_const(TCGArg arg) { diff --git a/tcg/tcg.c b/tcg/tcg.c index 03ebc8c..0ba61ea 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -532,6 +532,11 @@ void tcg_region_reset_all(void) region.n_full =3D 0; =20 QSIMPLEQ_FOREACH(s, &ctx_list, entry) { +#ifdef CONFIG_SOFTMMU + if (s =3D=3D tcg_init_ctx) { + continue; + } +#endif if (unlikely(!tcg_region_alloc__locked(s))) { tcg_abort(); } @@ -556,6 +561,11 @@ size_t tcg_code_size(void) QSIMPLEQ_FOREACH(s, &ctx_list, entry) { size_t size; =20 +#ifdef CONFIG_SOFTMMU + if (s =3D=3D tcg_init_ctx) { + continue; + } +#endif size =3D atomic_read(&s->code_gen_ptr) - s->code_gen_buffer; if (unlikely(size > s->code_gen_buffer_size)) { tcg_abort(); diff --git a/tcg/tci.c b/tcg/tci.c index 4bdc645..d374ddc 100644 --- a/tcg/tci.c +++ b/tcg/tci.c @@ -55,7 +55,7 @@ typedef uint64_t (*helper_function)(tcg_target_ulong, tcg= _target_ulong, tcg_target_ulong); #endif =20 -static tcg_target_ulong tci_reg[TCG_TARGET_NB_REGS]; +static TCG_THREAD tcg_target_ulong tci_reg[TCG_TARGET_NB_REGS]; =20 static tcg_target_ulong tci_read_reg(TCGReg index) { --=20 2.7.4 From nobody Wed Nov 5 06:43:56 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.zohomail.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 1499587091522460.32084071399504; Sun, 9 Jul 2017 00:58:11 -0700 (PDT) Received: from localhost ([::1]:35275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU76Y-0001o9-A0 for importer@patchew.org; Sun, 09 Jul 2017 03:58:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dU6zN-0004Sg-71 for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dU6zF-00031i-Bi for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:45 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:43205) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dU6zE-000305-QO for qemu-devel@nongnu.org; Sun, 09 Jul 2017 03:50:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A2F932094B; Sun, 9 Jul 2017 03:50:35 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 09 Jul 2017 03:50:35 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 629A124254; Sun, 9 Jul 2017 03:50:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=2Zx byJ5W+HwugsqNaevhopLgSr82Vqhnk5HXaWoUq84=; b=IXjxVYAVDUIP+rOKyxb l5Q/1G25vjh5MRPYkl3QpDeCv8wmoLo6hCUslCpuPYZQDdPRDjSnvBc8s6II3R81 8h7OspFPo8ZDLQ3PG/VJAOxEPIgLlGkQ6K1hnxXirNly7dyBcKprzdru/cJNKws0 7WeOjAfcJAZ6AizJ41BSIqao= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=2ZxbyJ5W+HwugsqNaevhopLgSr82Vqhnk5HXaWoUq 84=; b=LzZflk/MgwwTRsjM3XNw6yaUB/GDG9q80epGQ9YaRpbaLgHRy/GS36kxq L/BgUYFSo6tEzIAmqMwIsN7hE4yS1jdOMvU49z6IP9gbx8leLevTv9Kje0Vd1vgl SxKHpzbSZ5Ub2k2Cuv8YFRXYfz7ANvs5Tk6PP3fWnMrzagOCk/BdaUtNCVM1woHD Dri5X55R/TClKwAEkoAep4OVRM5wKlTZN7SrXaXYoF6snlIZD5Z0vm1WIrjBffz5 qELHu7mFbIhlwt9+neUdIkaXgfzf2XM9m+bW7+MDXVpLM2S5ePdTF3ZDWSF08UKo Y6pjiy3saI3iGoNrD7YwqYdPm1mag== X-ME-Sender: X-Sasl-enc: G6K/rtYAPLkr44HXWLDyEf//IWpQtk7ZoSJFVDtvr5vJ 1499586635 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 03:50:14 -0400 Message-Id: <1499586614-20507-23-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499586614-20507-1-git-send-email-cota@braap.org> References: <1499586614-20507-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 22/22] translate-all: do not hold tb_lock during code generation in softmmu 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: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Each vCPU can now generate code with TCG in parallel. Thus, drop tb_lock around code generation in softmmu. Note that we still have to take tb_lock after code translation, since there is global state that we have to update. Nonetheless holding tb_lock for less time provides significant performance improvements to workloads that are translation-heavy. A good example of this is booting Linux; in my measurements, bootup+shutdown time of debian-arm is reduced by 20% before/after this entire patchset, when using -smp 8 and MTTCG on a machine with >=3D 8 real cores: Host: Intel(R) Xeon(R) CPU E5-2690 @ 2.90GHz Performance counter stats for 'qemu/build/arm-softmmu/qemu-system-arm \ -machine type=3Dvirt -nographic -smp 1 -m 4096 \ -netdev user,id=3Dunet,hostfwd=3Dtcp::2222-:22 \ -device virtio-net-device,netdev=3Dunet \ -drive file=3Dfoobar.qcow2,id=3Dmyblock,index=3D0,if=3Dnone \ -device virtio-blk-device,drive=3Dmyblock \ -kernel /foobar.img -append console=3DttyAMA0 root=3D/dev/vda1 \ -name arm,debug-threads=3Don -smp 8' (3 runs): Before: 28764.018852 task-clock # 1.663 CPUs utilized = ( +- 0.30% ) 727,490 context-switches # 0.025 M/sec = ( +- 0.68% ) 2,429 CPU-migrations # 0.000 M/sec = ( +- 11.36% ) 14,042 page-faults # 0.000 M/sec = ( +- 1.00% ) 70,644,349,920 cycles # 2.456 GHz = ( +- 0.96% ) [83.42%] 37,129,806,098 stalled-cycles-frontend # 52.56% frontend cycles idl= e ( +- 1.27% ) [83.20%] 26,620,190,524 stalled-cycles-backend # 37.68% backend cycles idl= e ( +- 1.29% ) [66.50%] 85,528,287,892 instructions # 1.21 insns per cycle # 0.43 stalled cycles per = insn ( +- 0.62% ) [83.40%] 14,417,482,689 branches # 501.233 M/sec = ( +- 0.49% ) [83.36%] 321,182,192 branch-misses # 2.23% of all branches = ( +- 1.17% ) [83.53%] 17.297750583 seconds time elapsed = ( +- 1.08% ) After: 28690.888633 task-clock # 2.069 CPUs utilized = ( +- 1.54% ) 473,947 context-switches # 0.017 M/sec = ( +- 1.32% ) 2,793 CPU-migrations # 0.000 M/sec = ( +- 18.74% ) 22,634 page-faults # 0.001 M/sec = ( +- 1.20% ) 69,314,663,510 cycles # 2.416 GHz = ( +- 1.08% ) [83.50%] 36,114,710,208 stalled-cycles-frontend # 52.10% frontend cycles idl= e ( +- 1.64% ) [83.26%] 25,519,842,658 stalled-cycles-backend # 36.82% backend cycles idl= e ( +- 1.70% ) [66.77%] 84,588,443,638 instructions # 1.22 insns per cycle # 0.43 stalled cycles per = insn ( +- 0.78% ) [83.44%] 14,258,100,183 branches # 496.956 M/sec = ( +- 0.87% ) [83.32%] 324,984,804 branch-misses # 2.28% of all branches = ( +- 0.51% ) [83.17%] 13.870347754 seconds time elapsed = ( +- 1.65% ) That is, a speedup of 17.29/13.87=3D1.24X. Similar numbers on a slower machine: Host: AMD Opteron(tm) Processor 6376: Before: 74765.850569 task-clock (msec) # 1.956 CPUs utilized = ( +- 1.42% ) 841,430 context-switches # 0.011 M/sec = ( +- 2.50% ) 18,228 cpu-migrations # 0.244 K/sec = ( +- 2.87% ) 26,565 page-faults # 0.355 K/sec = ( +- 9.19% ) 98,775,815,944 cycles # 1.321 GHz = ( +- 1.40% ) (83.44%) 26,325,365,757 stalled-cycles-frontend # 26.65% frontend cycle= s idle ( +- 1.96% ) (83.26%) 17,270,620,447 stalled-cycles-backend # 17.48% backend cycle= s idle ( +- 3.45% ) (33.32%) 82,998,905,540 instructions # 0.84 insns per cycle # 0.32 stalled cycles= per insn ( +- 0.71% ) (50.06%) 14,209,593,402 branches # 190.055 M/sec = ( +- 1.01% ) (66.74%) 571,258,648 branch-misses # 4.02% of all branche= s ( +- 0.20% ) (83.40%) 38.220740889 seconds time elapsed = ( +- 0.72% ) After: 73281.226761 task-clock (msec) # 2.415 CPUs utilized = ( +- 0.29% ) 571,984 context-switches # 0.008 M/sec = ( +- 1.11% ) 14,301 cpu-migrations # 0.195 K/sec = ( +- 2.90% ) 42,635 page-faults # 0.582 K/sec = ( +- 7.76% ) 98,478,185,775 cycles # 1.344 GHz = ( +- 0.32% ) (83.39%) 25,555,945,935 stalled-cycles-frontend # 25.95% frontend cycle= s idle ( +- 0.47% ) (83.37%) 15,174,223,390 stalled-cycles-backend # 15.41% backend cycle= s idle ( +- 0.83% ) (33.26%) 81,939,511,983 instructions # 0.83 insns per cycle # 0.31 stalled cycles= per insn ( +- 0.12% ) (49.95%) 13,992,075,918 branches # 190.937 M/sec = ( +- 0.16% ) (66.65%) 580,790,655 branch-misses # 4.15% of all branche= s ( +- 0.20% ) (83.26%) 30.340574988 seconds time elapsed = ( +- 0.39% ) That is, a speedup of 1.25X. Signed-off-by: Emilio G. Cota --- accel/tcg/cpu-exec.c | 7 ++++++- accel/tcg/translate-all.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 54ecae2..2b34d58 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -351,6 +351,7 @@ static inline TranslationBlock *tb_find(CPUState *cpu, * single threaded the locks are NOPs. */ mmap_lock(); +#ifdef CONFIG_USER_ONLY tb_lock(); have_tb_lock =3D true; =20 @@ -362,7 +363,11 @@ static inline TranslationBlock *tb_find(CPUState *cpu, /* if no translated code available, then translate it now = */ tb =3D tb_gen_code(cpu, pc, cs_base, flags, 0); } - +#else + tb =3D tb_gen_code(cpu, pc, cs_base, flags, 0); + /* tb_gen_code returns with tb_lock acquired */ + have_tb_lock =3D true; +#endif mmap_unlock(); } =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 17b18a9..6cab609 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -887,7 +887,9 @@ static TranslationBlock *tb_alloc(target_ulong pc) { TranslationBlock *tb; =20 +#ifdef CONFIG_USER_ONLY assert_tb_locked(); +#endif =20 tb =3D tcg_tb_alloc(&tcg_ctx); if (unlikely(tb =3D=3D NULL)) { @@ -1314,7 +1316,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGProfile *prof =3D &tcg_ctx.prof; int64_t ti; #endif +#ifdef CONFIG_USER_ONLY assert_memory_lock(); +#endif =20 phys_pc =3D get_page_addr_code(env, pc); if (use_icount && !(cflags & CF_IGNORE_ICOUNT)) { @@ -1430,6 +1434,24 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if ((pc & TARGET_PAGE_MASK) !=3D virt_page2) { phys_page2 =3D get_page_addr_code(env, virt_page2); } + if (!have_tb_lock) { + TranslationBlock *t; + + tb_lock(); + /* + * There's a chance that our desired tb has been translated while + * we were translating it. + */ + t =3D tb_htable_lookup(cpu, pc, cs_base, flags); + if (unlikely(t)) { + /* discard what we just translated */ + uintptr_t orig_aligned =3D (uintptr_t)gen_code_buf; + + orig_aligned -=3D ROUND_UP(sizeof(*tb), qemu_icache_linesize); + atomic_set(&tcg_ctx.code_gen_ptr, orig_aligned); + return t; + } + } /* As long as consistency of the TB stuff is provided by tb_lock in us= er * mode and is implicit in single-threaded softmmu emulation, no expli= cit * memory barrier is required before tb_link_page() makes the TB visib= le --=20 2.7.4