From nobody Wed Nov 5 09:24:04 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