From nobody Mon May 6 08:15:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498768445371939.551905224255; Thu, 29 Jun 2017 13:34:05 -0700 (PDT) Received: from localhost ([::1]:41158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg8Z-00027c-14 for importer@patchew.org; Thu, 29 Jun 2017 16:34:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E7-DZ for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-0000zC-3P for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:50647) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4m-0000xN-Ql for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7E0FD20C8C; Thu, 29 Jun 2017 16:30:06 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:06 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 401AB7E070; Thu, 29 Jun 2017 16:30:06 -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=QL3 vYlNUIvXa9Wd2HzhzdCd7qyvxIat16YTIhY98l9k=; b=bcpMgJVdXPLao7lst5W rMooGT2Qvrig3M0dJeNVngzJLlOiVg7pfOyxe58C1x/1qAB/4kvzRNErKlmdl8Dr 789YiMu55t/JjNSAMyvlW0K2rylpYTZAG2QE4HSa2ldCeYkApvjcX1HcaPOCmWEG zpNTP38lWuY/zsjZ6adoKdQQ= 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=QL3vYlNUIvXa9Wd2HzhzdCd7qyvxIat16YTIhY98l 9k=; b=TuQPQLuboWWtsyTCbr17BzciMg1AkI0qxyL5GYBQ0v6EKvmpjfRKux6Xu wymJl5Rf5RKimL1E7GTItQ6VBM+SdU3FX2PmaTG9OjHPHENQingn/e0sClp4r90P QA4Uj9h8XPH9qnRqK4G9i5Ug18rKmDVKQNCJq1IvXOH4BBuonWQKnvXdxy5d/m63 Q7aZ3S41Cro+1ftVV43ebM6trm6rAmtCgV8ZTPtoPSxOJ5HDy3ThLI5ZGE5BC+7l 8kOxoKwPhte0s6o6jaVoMtPiXVxQ6EWh5TqGkq0isS4sZaHA0JL/8SepAc+mGTu1 U8gqkkHMY8yVOhRChPZQvYmO3q3EA== X-ME-Sender: X-Sasl-enc: 2RNIw0WYP+q5GslrbWKIrGLFGOBuUm3Ct3+Outx4Cw+d 1498768206 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:23 -0400 Message-Id: <1498768109-4092-2-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-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.29 Subject: [Qemu-devel] [RFC 1/7] 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" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson --- 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 724ec73..35a75f1 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -338,7 +338,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. */ @@ -349,7 +349,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 Mon May 6 08:15:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149876832063951.81046506911059; Thu, 29 Jun 2017 13:32:00 -0700 (PDT) Received: from localhost ([::1]:41152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg6X-0008IE-6a for importer@patchew.org; Thu, 29 Jun 2017 16:31:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E1-AR for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-0000zJ-44 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:43225) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4m-0000xL-Qn for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id AF20F20CA4; Thu, 29 Jun 2017 16:30:06 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:06 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 6EB3E240B0; Thu, 29 Jun 2017 16:30:06 -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=xUf COB2y1SQVSSl/f6CJIXKkDNIk276JHq+lSTqILRc=; b=ZWsGreQEnNqO4W1LuS+ FvLU0HZ80ucB3dTD5pcY+DaJdwbDPIYv4dXuj7TG2678Y2AYcvV0TeSpRKddWXmS qm8wUOd2TAs9RoRs/dTLW3L95S6uLwmKWyNi197dKCmGB6JxAVXoj1H0EPKVxz4M EscFtQOTO1eC+7BH4KzLhaG4= 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=xUfCOB2y1SQVSSl/f6CJIXKkDNIk276JHq+lSTqIL Rc=; b=OaU76kt96Yt12lbjeB25UIQ/zb7WC/nd/1NhLjAi9ai3MVZprzeE2Guz8 TaACe0X+//3iinLeWGIYvuW+fjTwS1Et8+odmMmb1vA/a6jrO2Ik3rZNXxBWsanW 4edyoMqxzkpdCNvELBuD0cphhFIMIneJck6uFuK3RAYKt5tESt8x86cNaiyTPJFG Y+/votRJdNMc/+TAiDvOZ7XZ8pnxAwDatjqNDPhAHuj07EtU2YdASBA69Gv7RYgj QZC8j5g1xgwSuTu29RNjGSvfyZLHgmI9L27ArfAkWnQ1Is7fvbbYJzPtrLv7ZsZk UYD5Rz/NsOTkWMELqfbj9UH4ee1SA== X-ME-Sender: X-Sasl-enc: 2RNc3kOaO/CwGclvbWOIrGLFGOBuUm3Ct3+Outx4Cw+d 1498768206 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:24 -0400 Message-Id: <1498768109-4092-3-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-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.29 Subject: [Qemu-devel] [RFC 2/7] translate-all: add out_size field to TranslationBlock 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 paves the way for upcoming work: we need tb->out_size for tb_find_pc to work with a binary search tree. Note that due to the cacheline padding we are using, for hosts with 64-byte cache lines this will not waste any additional memory. Using a s16 would be ideal, since that would plug an existing hole in the struct, but I see no guarantee that a TB won't overflow it. Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 1 + accel/tcg/translate-all.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 35a75f1..df12338 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -363,6 +363,7 @@ struct TranslationBlock { */ uintptr_t jmp_list_next[2]; uintptr_t jmp_list_first; + int32_t out_size; /* size of host code for this block */ }; =20 void tb_free(TranslationBlock *tb); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f6ad46b..da91482 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1260,7 +1260,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb_page_addr_t phys_pc, phys_page2; target_ulong virt_page2; tcg_insn_unit *gen_code_buf; - int gen_code_size, search_size; + int search_size; #ifdef CONFIG_PROFILER int64_t ti; #endif @@ -1327,11 +1327,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, the tcg optimization currently hidden inside tcg_gen_code. All that should be required is to flush the TBs, allocate a new TB, re-initialize it per above, and re-do the actual code generation. = */ - gen_code_size =3D tcg_gen_code(&tcg_ctx, tb); - if (unlikely(gen_code_size < 0)) { + tb->out_size =3D tcg_gen_code(&tcg_ctx, tb); + if (unlikely(tb->out_size < 0)) { goto buffer_overflow; } - search_size =3D encode_search(tb, (void *)gen_code_buf + gen_code_size= ); + search_size =3D encode_search(tb, (void *)gen_code_buf + tb->out_size); if (unlikely(search_size < 0)) { goto buffer_overflow; } @@ -1339,7 +1339,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #ifdef CONFIG_PROFILER tcg_ctx.code_time +=3D profile_getclock(); tcg_ctx.code_in_len +=3D tb->size; - tcg_ctx.code_out_len +=3D gen_code_size; + tcg_ctx.code_out_len +=3D tb->out_size; tcg_ctx.search_out_len +=3D search_size; #endif =20 @@ -1347,8 +1347,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) && qemu_log_in_addr_range(tb->pc)) { qemu_log_lock(); - qemu_log("OUT: [size=3D%d]\n", gen_code_size); - log_disas(tb->tc_ptr, gen_code_size); + qemu_log("OUT: [size=3D%d]\n", tb->out_size); + log_disas(tb->tc_ptr, tb->out_size); qemu_log("\n"); qemu_log_flush(); qemu_log_unlock(); @@ -1356,7 +1356,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #endif =20 tcg_ctx.code_gen_ptr =3D (void *) - ROUND_UP((uintptr_t)gen_code_buf + gen_code_size + search_size, + ROUND_UP((uintptr_t)gen_code_buf + tb->out_size + search_size, CODE_GEN_ALIGN); =20 /* init jump list */ --=20 2.7.4 From nobody Mon May 6 08:15:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498768447449522.7209520376587; Thu, 29 Jun 2017 13:34:07 -0700 (PDT) Received: from localhost ([::1]:41159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg8c-0002AG-3M for importer@patchew.org; Thu, 29 Jun 2017 16:34:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E3-Aa for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-0000zV-45 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:44953) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4m-0000xK-Qg for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E8A0420C8D; Thu, 29 Jun 2017 16:30:06 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:06 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 9B0E87E749; Thu, 29 Jun 2017 16:30:06 -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=xbJ dUewVOffMOCLXpIfIg6SuG7Arer/jWTSV9kldkuE=; b=2vtoC0NtsAZftr6eHQ8 QgpmnTooecrFU8x62z5tE7U8av2XrzsTGiFp5Z6mgIn3K/8ZgEoQg9I9SmVKam+N dqGWyUU861F5bJ936+LdWbFgvrWrqnYnazpLs17VnJJXGdtCeTY3qo8dzdDTxN9Z ASyf0Ps7Y1shhxVKUWfTGAT0= 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=xbJdUewVOffMOCLXpIfIg6SuG7Arer/jWTSV9kldk uE=; b=SYWfiSGrgJ25sneOSYTHbg4HCI/qPI6iWJoaiqnATpaRSoFz9lyCvcz9X Z+lPNz/jzrMAZEE3eQv0qVTup+yX7QnPU3TlWna64Hl3zJo9pp9g84AiKl7hobG2 IsaRBo7fRKxFi5uh9DKhTwt4kJ5D+3TcHh7iUykmGqCDub55R3ZL50+VxdOTYq8W STOtl6m2YG9qGJrWQWh5XW7Wsktofe0llYFBPkHB/MqQsaBa83v+0b77VU2dear6 kzjbgGOW+nZ3QD748sAhro4tDgnrMzV+9143KUAbBbBkzAP5yaN5y9U62oPF1v/q k+L3y5WL8YujYOMXDEnLIjl1yYgkw== X-ME-Sender: X-Sasl-enc: 2RNTyF2cJ+GiCMN/cGqIrGLFGOBuUm3Ct3+Outx4Cw+d 1498768206 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:25 -0400 Message-Id: <1498768109-4092-4-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-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.29 Subject: [Qemu-devel] [RFC 3/7] 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. 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: 10289.389753 task-clock (msec) # 0.952 CPUs utilized = ( +- 0.13% ) 18,238 context-switches # 0.002 M/sec = ( +- 0.73% ) 0 cpu-migrations # 0.000 K/sec 86,555 page-faults # 0.008 M/sec = ( +- 0.49% ) 45,079,926,395 cycles # 4.381 GHz = ( +- 0.14% ) stalled-cycles-frontend stalled-cycles-backend 84,582,463,603 instructions # 1.88 insns per cycl= e ( +- 0.26% ) 14,964,335,400 branches # 1454.346 M/sec = ( +- 0.29% ) 288,324,215 branch-misses # 1.93% of all branche= s ( +- 0.34% ) 10.813687279 seconds time elapsed = ( +- 0.42% ) - After: 10333.181473 task-clock (msec) # 0.944 CPUs utilized = ( +- 0.27% ) 18,167 context-switches # 0.002 M/sec = ( +- 0.20% ) 0 cpu-migrations # 0.000 K/sec 83,354 page-faults # 0.008 M/sec = ( +- 0.92% ) 45,247,697,926 cycles # 4.379 GHz = ( +- 0.23% ) stalled-cycles-frontend stalled-cycles-backend 84,537,657,945 instructions # 1.87 insns per cycl= e ( +- 0.18% ) 14,988,568,500 branches # 1450.528 M/sec = ( +- 0.21% ) 294,765,097 branch-misses # 1.97% of all branche= s ( +- 0.43% ) 10.946641611 seconds time elapsed = ( +- 0.79% ) Signed-off-by: Emilio G. Cota --- include/exec/tb-context.h | 4 +- accel/tcg/translate-all.c | 181 ++++++++++++++++++++----------------------= ---- 2 files changed, 81 insertions(+), 104 deletions(-) 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 da91482..a18fbf7 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -770,6 +770,21 @@ static inline void *alloc_code_gen_buffer(void) } #endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ =20 +/* @key is already in the tree so it's safe to use container_of on it */ +static gint tc_ptr_cmp(gconstpointer candidate, gconstpointer key) +{ + uintptr_t a =3D *(uintptr_t *)candidate; + const TranslationBlock *tb =3D container_of(key, TranslationBlock, tc_= ptr); + uintptr_t b =3D (uintptr_t)tb->tc_ptr; + + if (a >=3D b + tb->out_size) { + return 1; + } else if (a < b) { + return -1; + } + return 0; +} + static inline void code_gen_alloc(size_t tb_size) { tcg_ctx.code_gen_buffer_size =3D size_code_gen_buffer(tb_size); @@ -778,15 +793,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 @@ -827,7 +834,6 @@ bool tcg_enabled(void) static TranslationBlock *tb_alloc(target_ulong pc) { TranslationBlock *tb; - TBContext *ctx; =20 assert_tb_locked(); =20 @@ -835,12 +841,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 @@ -849,16 +849,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) @@ -906,6 +897,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, @@ -916,11 +909,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) { @@ -935,7 +929,10 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data= tb_flush_count) } } =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 @@ -1385,6 +1382,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 @@ -1653,37 +1651,14 @@ 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->out_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; - - 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, &tc_ptr); } =20 #if !defined(CONFIG_USER_ONLY) @@ -1866,63 +1841,67 @@ static void print_qht_statistics(FILE *f, fprintf_f= unction cpu_fprintf, g_free(hgram); } =20 +struct tb_tree_stats { + int target_size; + int max_target_size; + int direct_jmp_count; + int direct_jmp2_count; + int 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 count %d\n", 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); + 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); + 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 %d (%d%%)\n", tst.cross_page, + nb_tbs ? (tst.cross_page * 100) / 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); + 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 Mon May 6 08:15:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498768318768353.71907758619534; Thu, 29 Jun 2017 13:31:58 -0700 (PDT) Received: from localhost ([::1]:41151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg6W-0008Hl-CQ for importer@patchew.org; Thu, 29 Jun 2017 16:31:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E4-BE for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-0000zP-4Y for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:37085) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4m-0000xJ-Qq for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 89F2620CA7; Thu, 29 Jun 2017 16:30:07 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:07 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id D8AF224788; Thu, 29 Jun 2017 16:30:06 -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=6Xk oCzUqNFIJ9spzZ3fz3lVbNb96+o+2NyQhfGkMCIg=; b=j0gBWWyPYCnxy4Ecc9b x4ljN+cWqcVDKcZ0Og2ykEgyNv+AczKYipctLm9GNFpTH4Rrr+atdntEpwAPuVGq hXEJsyLMjPdBAdFBZ4x66gqpZ0lBYJ9jPC5bZ6EktaBHOS40bbEP7z4WtatUEvYz WOtQkNQrdZ+jbBoWo0mxrkcI= 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=6XkoCzUqNFIJ9spzZ3fz3lVbNb96+o+2NyQhfGkMC Ig=; b=H8mVQob2vz/cZFYRhl8xoVGATjLkFt1wuw7fMpMtjil8VqaCu4OvPbhXq Gtj3VkFJtd6WUozfqZC2759arc5fnpm8LwZ79S/ihvkm+c7tFpJjDSa0V93nM1UD a6i611iFhkH0BXhGzVsPfoWUqo2HTGwMyHSGZqpZMiVwYbgVAGYTTSFG+Ao5Leme zTWuUAEHwPo1EOkZjFTT4fpAEmlDpxxoVlGqyn6zNHyr0MXoY703TrCC4nSffM/C pwvDzVOhIBEMoE8B4mDrTSgnGgy+j7skNnssel9yIKA8lR1pG/TNkf7FYu/uwBwM WKYRYugxNa6vp/D/2X0ztp66kd/og== X-ME-Sender: X-Sasl-enc: 2RNDwUKANeKoBcR5ZGuIrGLFGOBuUm3Ct3+Outx4Cw+d 1498768206 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:26 -0400 Message-Id: <1498768109-4092-5-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-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.29 Subject: [Qemu-devel] [RFC 4/7] 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 a18fbf7..9714777 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -894,9 +894,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; + int *size =3D data; + + *size +=3D tb->out_size; + return false; +} + /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { + int host_size __attribute__((unused)); int nb_tbs __attribute__((unused)); =20 tb_lock(); @@ -909,12 +920,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%d\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) { @@ -1842,6 +1852,7 @@ static void print_qht_statistics(FILE *f, fprintf_fun= ction cpu_fprintf, } =20 struct tb_tree_stats { + int host_size; int target_size; int max_target_size; int direct_jmp_count; @@ -1854,6 +1865,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->out_size; tst->target_size +=3D tb->size; if (tb->size > tst->max_target_size) { tst->max_target_size =3D tb->size; @@ -1882,6 +1894,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); @@ -1889,12 +1906,9 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fp= rintf) cpu_fprintf(f, "TB avg target size %d max=3D%d 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 %d 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 %d (%d%%)\n", tst.cross_page, nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0); cpu_fprintf(f, "direct jump count %d (%d%%) (2 jumps=3D%d %d%%)\n", --=20 2.7.4 From nobody Mon May 6 08:15:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498768448457735.1401755306105; Thu, 29 Jun 2017 13:34:08 -0700 (PDT) Received: from localhost ([::1]:41160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg8d-0002Cb-2e for importer@patchew.org; Thu, 29 Jun 2017 16:34:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E6-B1 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-0000zv-DF for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:38741) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4n-0000zE-8u for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 89FC820CAA; Thu, 29 Jun 2017 16:30:07 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:07 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 1BF917E070; Thu, 29 Jun 2017 16:30:07 -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=Rjv tJkriacGvUCdZ91DxbCPxIHJ+ZaUpLw4Z+KqhBK0=; b=y/aVKaxL1Wa1HVHeaT4 4pkGtvfdqbI3RHsx/1kPPefvUfywYE33cxOk0w9llYm6fMmut5cm2QqOi3ZBir9n Lqewc3vg9CRz25L/5R0CeilNBfV5USV+scyvkU5Ea1LxqeZNeJxh/JW4y/L7+ct3 GM8Du3Res+WitopAs7xLTS9Y= 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=RjvtJkriacGvUCdZ91DxbCPxIHJ+ZaUpLw4Z+KqhB K0=; b=ojsRK2CIejBAZnGLQcM5tXM6jDLpnRLsIoXNi+kzmcYSGbnvn1J1coFwv sJniYquRj3AHBOb3a/3pFasxMrXRUHU7dhcNnnL+B+kZdNdLUFhLzMlr9V8901DX 8FxVo+ODzJpu3D2IwDdcLJCgIsavpnqRCQHHRoY3BKXe76D9vNp2gmxCLnRB8NTG yu1Pe3FboIBp7y5sQiu98RQLh1T3jXuD/6L4qjCGk3kFHDSElFAmkcRVzJQr9+Fu nBZ7paj6gsafahPBGDT1tLLmwv0Hg97EtdnraOxq3LZRVjC/qY7e109gDsWz1lnq bgyYwx9D4sck9+pC8s1+kthhWACMA== X-ME-Sender: X-Sasl-enc: 1DTYHEh8jd6st+8J28WGMvNGPazbWvzWtahOXTtH8XeZ 1498768207 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:27 -0400 Message-Id: <1498768109-4092-6-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-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.29 Subject: [Qemu-devel] [RFC 5/7] 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. Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson --- 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, 35 insertions(+), 34 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 9e37722..3b3359c 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 9714777..2869c79 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -133,6 +133,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 */ @@ -164,7 +165,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 @@ -172,13 +173,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; } } @@ -793,15 +794,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 @@ -849,7 +850,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) @@ -915,13 +916,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%d\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,17 @@ 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 +960,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 +987,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 +1007,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 +1106,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 +1135,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 +1251,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(); @@ -1392,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 @@ -1668,7 +1669,7 @@ static bool tb_invalidate_phys_page(tb_page_addr_t ad= dr, uintptr_t pc) */ static TranslationBlock *tb_find_pc(uintptr_t tc_ptr) { - return g_tree_lookup(tcg_ctx.tb_ctx.tb_tree, &tc_ptr); + return g_tree_lookup(tb_ctx.tb_tree, &tc_ptr); } =20 #if !defined(CONFIG_USER_ONLY) @@ -1890,8 +1891,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"); /* @@ -1917,15 +1918,15 @@ 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)); + atomic_read(&tb_ctx.tb_flush_count)); cpu_fprintf(f, "TB invalidate count %d\n", - tcg_ctx.tb_ctx.tb_phys_invalidate_count); + tb_ctx.tb_phys_invalidate_count); cpu_fprintf(f, "TLB flush count %d\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 Mon May 6 08:15:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498768602711252.41032337106685; Thu, 29 Jun 2017 13:36:42 -0700 (PDT) Received: from localhost ([::1]:41173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQgB7-0003qU-4F for importer@patchew.org; Thu, 29 Jun 2017 16:36:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E8-Dy for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-000105-Jy for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:55007) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4n-0000zZ-EW for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 9711320C93; Thu, 29 Jun 2017 16:30:07 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:07 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 4DA512479F; Thu, 29 Jun 2017 16:30:07 -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=YuI SimvLYGgwOIEs/P4ndvpBP0M0s9uWCKt5PYe4Apk=; b=0P0RW1IpRggHgTLjptd PuhROFqdcXwNoRsgNDyeFwlaMJsHA3X/lMK3dJj9dAe5VGIJn63fIy51GAJqioy2 LzH7G/zqcG744FEsOd269uld54A+9wy/pNopUZRpS9nIIagI1hkfdHfQ24DfB+LW JglFXvUpFSbKwv4AKAVVKTuU= 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=YuISimvLYGgwOIEs/P4ndvpBP0M0s9uWCKt5PYe4A pk=; b=X8gVV8Rqs9T/dRINu6LM0Os7icX9EZJdU0rtuSLYpzAxYairYPtdLulv9 0hmu+PmWdKUxyN6Zkc4OEP+Dm48XgfiqM7rBWjwl0icw+sKsSRvxR1PjcxGrs0T0 6JHOCfR4jVyNTntkfQWTPDHk9hclHMjszo6T93mONSENZ7s/GF8Bb7uzqvQbATUE HqHtRgEHFB8TeZmZ765lv+5dyc6LOtSZ3qcDfCxK9/50vzzn2sLm78T3/Y7Jxct/ UlAnhJkRk9G86SALZW02Z/0gUKr8THAiWg2Jtoq9BuKnH+7vCUszAsMJslVKbScX we/MEhPtcgxSkAdUuG70BSNcB/H7g== X-ME-Sender: X-Sasl-enc: 1DTeCkFygtyiv/MEyciGMvNGPazbWvzWtahOXTtH8XeZ 1498768207 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:28 -0400 Message-Id: <1498768109-4092-7-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-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.29 Subject: [Qemu-devel] [RFC 6/7] [XXX] tcg: make TCGContext thread-local 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 will allow us to generate TCG code in parallel. User-mode is kept out of this: contention due to concurrent translation is more commonly found in full-system mode (e.g. booting a many-core guest). XXX: For now, only convert arm/a64, since these are the only guests that have proper MTTCG support. XXX: arm_translate_init needs to be called from a proper place. XXX: TCG profiling info and statistics are broken by this XXX: This is calling prologue_init once per vCPU, i.e. each TCGContext gets a different prologue/epilogue (all of them with the same contents though). Far from ideal, but for an experiment it "should" work, right? XXX: Giving the same amount of code_gen_buffer to each vCPU is certainly a bad idea. A "page-like" allocation policy would be better, e.g. give chunks of 1MB to each vCPU as they need it. But for now I'm just trying to see whether this can ever work. XXX: After allowing tb_gen_code to run in parallel (see next patch), crashes due to races in TCG code are found very quickly with -smp > 1 (e.g. "tcg/tcg.c:233: tcg_out_label: Assertion `!l->has_value' failed.= ") Note that with -smp 1 it works fine; with smp > 1 I can make it fail later with "taskset -c 0", so clearly there is a race going on. Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 4 +++- target/arm/translate.h | 8 +++---- tcg/tcg.h | 10 +++++++-- accel/tcg/translate-all.c | 56 ++++++++++++++++++++++++++++++++++++++++--= ---- cpus.c | 2 ++ target/arm/cpu.c | 4 +++- target/arm/translate-a64.c | 6 ++--- target/arm/translate.c | 16 ++++++------- tcg/i386/tcg-target.inc.c | 2 +- tcg/tcg-common.c | 2 +- tcg/tcg.c | 6 ++--- 11 files changed, 85 insertions(+), 31 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index df12338..4b4c143 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_gen_init(int cpu_index); +#endif bool cpu_restore_state(CPUState *cpu, uintptr_t searched_pc); =20 void QEMU_NORETURN cpu_loop_exit_noexc(CPUState *cpu); diff --git a/target/arm/translate.h b/target/arm/translate.h index 15d383d..8f04c57 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -76,10 +76,10 @@ typedef struct DisasCompare { } DisasCompare; =20 /* Share the TCG temporaries common between 32 and 64 bit modes. */ -extern TCGv_env cpu_env; -extern TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF; -extern TCGv_i64 cpu_exclusive_addr; -extern TCGv_i64 cpu_exclusive_val; +extern TCG_THREAD TCGv_env cpu_env; +extern TCG_THREAD TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF; +extern TCG_THREAD TCGv_i64 cpu_exclusive_addr; +extern TCG_THREAD TCGv_i64 cpu_exclusive_val; =20 static inline int arm_dc_feature(DisasContext *dc, int feature) { diff --git a/tcg/tcg.h b/tcg/tcg.h index 3b3359c..01cf21f 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -727,7 +727,13 @@ struct TCGContext { target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS]; }; =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) @@ -887,7 +893,7 @@ typedef struct TCGOpDef { #endif } TCGOpDef; =20 -extern TCGOpDef tcg_op_defs[]; +extern TCG_THREAD TCGOpDef tcg_op_defs[]; extern const size_t tcg_op_defs_max; =20 typedef struct TCGTargetOpDef { diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2869c79..125b1a8 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -58,6 +58,7 @@ #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 */ @@ -132,9 +133,12 @@ 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; +#ifdef CONFIG_SOFTMMU +static TCGContext *tcg_common_ctx; +#endif =20 /* translation block context */ __thread int have_tb_lock; @@ -186,10 +190,35 @@ void tb_lock_reset(void) =20 static TranslationBlock *tb_find_pc(uintptr_t tc_ptr); =20 -void cpu_gen_init(void) +#ifdef CONFIG_SOFTMMU + +/* XXX, see below */ +void arm_translate_init(void); + +void cpu_gen_init(int cpu_index) { - tcg_context_init(&tcg_ctx);=20 + uintptr_t addr; + size_t size; + + tcg_context_init(&tcg_ctx); + size =3D tcg_common_ctx->code_gen_buffer_size / smp_cpus; + assert(!(tcg_common_ctx->code_gen_buffer_size % smp_cpus)); + addr =3D (uintptr_t)tcg_common_ctx->code_gen_buffer; + addr +=3D size * cpu_index; + tcg_ctx.code_gen_buffer =3D (void *)addr; + tcg_ctx.code_gen_buffer_size =3D size; + tcg_prologue_init(&tcg_ctx); + /* + * XXX find a proper place to init the TCG globals. This should be tri= vial + * once when the "generic translation loop" work is finished. + * + * Note that initialising the TCG globals (that are __thread variables + * in full-system mode) from a *_cpu_initfn is not a viable option, si= nce + * this function is called before the vCPU threads are created. + */ + arm_translate_init(); } +#endif =20 /* Encode VAL as a signed leb128 sequence at P. Return P incremented past the encoded value. */ @@ -561,6 +590,18 @@ static inline size_t size_code_gen_buffer(size_t tb_si= ze) if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { tb_size =3D MAX_CODE_GEN_BUFFER_SIZE; } +#ifdef CONFIG_SOFTMMU + { + size_t per_cpu =3D tb_size / smp_cpus; + + if (per_cpu < MIN_CODE_GEN_BUFFER_SIZE) { + tb_size =3D MIN_CODE_GEN_BUFFER_SIZE * smp_cpus; + per_cpu =3D MIN_CODE_GEN_BUFFER_SIZE; + } + /* make sure tb_size divides smp_cpus evenly */ + tb_size =3D per_cpu * smp_cpus; + } +#endif return tb_size; } =20 @@ -810,20 +851,21 @@ static void tb_htable_init(void) size. */ void tcg_exec_init(unsigned long tb_size) { - cpu_gen_init(); page_init(); tb_htable_init(); code_gen_alloc(tb_size); #if defined(CONFIG_SOFTMMU) - /* There's no guest base to take into account, so go ahead and - initialize the prologue now. */ - tcg_prologue_init(&tcg_ctx); + tcg_common_ctx =3D &tcg_ctx; #endif } =20 bool tcg_enabled(void) { +#ifdef CONFIG_SOFTMMU + return tcg_common_ctx->code_gen_buffer !=3D NULL; +#else return tcg_ctx.code_gen_buffer !=3D NULL; +#endif } =20 /* diff --git a/cpus.c b/cpus.c index 14bb8d5..1a5437b 100644 --- a/cpus.c +++ b/cpus.c @@ -1307,6 +1307,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) CPUState *cpu =3D arg; =20 rcu_register_thread(); + cpu_gen_init(cpu->cpu_index); =20 qemu_mutex_lock_iothread(); qemu_thread_get_self(cpu->thread); @@ -1454,6 +1455,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) g_assert(!use_icount); =20 rcu_register_thread(); + cpu_gen_init(cpu->cpu_index); =20 qemu_mutex_lock_iothread(); qemu_thread_get_self(cpu->thread); diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 28a9141..43948ef 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -469,7 +469,7 @@ static void arm_cpu_initfn(Object *obj) { CPUState *cs =3D CPU(obj); ARMCPU *cpu =3D ARM_CPU(obj); - static bool inited; + static bool inited __attribute__((unused)); =20 cs->env_ptr =3D &cpu->env; cpu->cp_regs =3D g_hash_table_new_full(g_int_hash, g_int_equal, @@ -511,10 +511,12 @@ static void arm_cpu_initfn(Object *obj) =20 if (tcg_enabled()) { cpu->psci_version =3D 2; /* TCG implements PSCI 0.2 */ +#ifndef CONFIG_SOFTMMU if (!inited) { inited =3D true; arm_translate_init(); } +#endif } } =20 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index e55547d..9450551 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -36,11 +36,11 @@ =20 #include "trace-tcg.h" =20 -static TCGv_i64 cpu_X[32]; -static TCGv_i64 cpu_pc; +static TCG_THREAD TCGv_i64 cpu_X[32]; +static TCG_THREAD TCGv_i64 cpu_pc; =20 /* Load/store exclusive handling */ -static TCGv_i64 cpu_exclusive_high; +static TCG_THREAD TCGv_i64 cpu_exclusive_high; static TCGv_i64 cpu_reg(DisasContext *s, int reg); =20 static const char *regnames[] =3D { diff --git a/target/arm/translate.c b/target/arm/translate.c index 0862f9e..9ad4bbb 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -58,17 +58,17 @@ #define IS_USER(s) (s->user) #endif =20 -TCGv_env cpu_env; +TCG_THREAD TCGv_env cpu_env; /* We reuse the same 64-bit temporaries for efficiency. */ -static TCGv_i64 cpu_V0, cpu_V1, cpu_M0; -static TCGv_i32 cpu_R[16]; -TCGv_i32 cpu_CF, cpu_NF, cpu_VF, cpu_ZF; -TCGv_i64 cpu_exclusive_addr; -TCGv_i64 cpu_exclusive_val; +static TCG_THREAD TCGv_i64 cpu_V0, cpu_V1, cpu_M0; +static TCG_THREAD TCGv_i32 cpu_R[16]; +TCG_THREAD TCGv_i32 cpu_CF, cpu_NF, cpu_VF, cpu_ZF; +TCG_THREAD TCGv_i64 cpu_exclusive_addr; +TCG_THREAD TCGv_i64 cpu_exclusive_val; =20 /* FIXME: These should be removed. */ -static TCGv_i32 cpu_F0s, cpu_F1s; -static TCGv_i64 cpu_F0d, cpu_F1d; +static TCG_THREAD TCGv_i32 cpu_F0s, cpu_F1s; +static TCG_THREAD TCGv_i64 cpu_F0d, cpu_F1d; =20 #include "exec/gen-icount.h" =20 diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index 01e3b4e..608264a 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -146,7 +146,7 @@ static bool have_lzcnt; # define have_lzcnt 0 #endif =20 -static tcg_insn_unit *tb_ret_addr; +static TCG_THREAD tcg_insn_unit *tb_ret_addr; =20 static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) diff --git a/tcg/tcg-common.c b/tcg/tcg-common.c index 2f139de..7f6edb8 100644 --- a/tcg/tcg-common.c +++ b/tcg/tcg-common.c @@ -31,7 +31,7 @@ uintptr_t tci_tb_ptr; #endif =20 -TCGOpDef tcg_op_defs[] =3D { +TCG_THREAD TCGOpDef tcg_op_defs[] =3D { #define DEF(s, oargs, iargs, cargs, flags) \ { #s, oargs, iargs, cargs, iargs + oargs + cargs, flags }, #include "tcg-opc.h" diff --git a/tcg/tcg.c b/tcg/tcg.c index 3559829..326c25a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -117,8 +117,8 @@ static bool tcg_out_tb_finalize(TCGContext *s); =20 =20 =20 -static TCGRegSet tcg_target_available_regs[2]; -static TCGRegSet tcg_target_call_clobber_regs; +static TCG_THREAD TCGRegSet tcg_target_available_regs[2]; +static TCG_THREAD TCGRegSet tcg_target_call_clobber_regs; =20 #if TCG_TARGET_INSN_UNIT_SIZE =3D=3D 1 static __attribute__((unused)) inline void tcg_out8(TCGContext *s, uint8_t= v) @@ -320,7 +320,7 @@ static const TCGHelperInfo all_helpers[] =3D { #include "exec/helper-tcg.h" }; =20 -static int indirect_reg_alloc_order[ARRAY_SIZE(tcg_target_reg_alloc_order)= ]; +static TCG_THREAD int indirect_reg_alloc_order[ARRAY_SIZE(tcg_target_reg_a= lloc_order)]; static void process_op_defs(TCGContext *s); =20 void tcg_context_init(TCGContext *s) --=20 2.7.4 From nobody Mon May 6 08:15:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498768536992968.2586038125571; Thu, 29 Jun 2017 13:35:36 -0700 (PDT) Received: from localhost ([::1]:41171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQgA3-0003Jq-QY for importer@patchew.org; Thu, 29 Jun 2017 16:35:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E2-AL for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-0000zr-Cv for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:51713) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4n-0000zH-9H for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C1F5720C9B; Thu, 29 Jun 2017 16:30:07 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:07 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 7FD537E847; Thu, 29 Jun 2017 16:30:07 -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=yvj X7ISvjeTB4z/kdarpYZzaVqE1bgJ8MBOTfXQ9IkE=; b=tySYFgI9VpDdMPXc1+e MhsYmVIXyUTxyUfQZZlzrKxDh+4Dk0SfMIMA/pgUL0fbNCziotizJp42tMwsslJ0 t9flp6qxKzFFKUuhw9tk3GHFPfotZyz2JTE20dGeYDgyOWAwoPvEUlXogLwvrx+u /s+3AOnTCK+KBJBO0rSI4SnE= 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=yvjX7ISvjeTB4z/kdarpYZzaVqE1bgJ8MBOTfXQ9I kE=; b=kDAhhXnWCyUwBwtXdWnHelyFELeWIi2yO+BuTdJ5wcCXIkbHcq81Y5BqS eRR5IjjplNHJd2SDb0i0GN1nBgr3TzuxgXCSU5Aao4UTB842CbbkhCovWwM6O3dU sIswqthjIaW1RKs0y38+Diqrc5D+okT7oA6hzY7Id8442xmueLM1bS5LMuWTxKc2 vU7VYL+i9I7ovVGqWotRvsKHMpxNnnXTZuYJ7AZIrWamzPLUOzT+C6sDWn+RkaSl qpnbT3xjEnt93ymm7t8c0NgwEKrTK866ioEs+t82buWrhxflVd4yqCtcdJpPGioi TBMcqSY0/M9QqXBPALjvhgnyEOqQw== X-ME-Sender: X-Sasl-enc: 1DTHHkBijsG0uf8Oy96GMvNGPazbWvzWtahOXTtH8XeZ 1498768207 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:29 -0400 Message-Id: <1498768109-4092-8-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-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.29 Subject: [Qemu-devel] [RFC 7/7] [XXX] translate-all: generate TCG code without holding tb_lock 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" Generate new TBs without holding tb_lock, which should increase scalability when running MTTCG for workloads that generate a lot of code (e.g. booting linux). XXX: Doesn't work :-) See the commit log from the previous patch. Signed-off-by: Emilio G. Cota --- accel/tcg/cpu-exec.c | 8 +++++++- accel/tcg/translate-all.c | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 54ecae2..47f0882 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,12 @@ 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_gen_code will acquire tb_lock. + * Just for the diff: note that have_tb_lock is local to tb_fi= nd! */ + have_tb_lock =3D true; + tb =3D tb_gen_code(cpu, pc, cs_base, flags, 0); +#endif mmap_unlock(); } =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 125b1a8..da29bcc 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -878,8 +878,6 @@ static TranslationBlock *tb_alloc(target_ulong pc) { TranslationBlock *tb; =20 - assert_tb_locked(); - tb =3D tcg_tb_alloc(&tcg_ctx); if (unlikely(tb =3D=3D NULL)) { return NULL; @@ -1314,7 +1312,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #ifdef CONFIG_PROFILER 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)) { @@ -1429,6 +1429,20 @@ 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)) { + /* this is very unlikely so just waste the TB space we just us= ed */ + 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