From nobody Tue Feb 10 06:26:01 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15089265532641006.4346731320029; Wed, 25 Oct 2017 03:15:53 -0700 (PDT) Received: from localhost ([::1]:47477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7Iii-0007ZZ-Es for importer@patchew.org; Wed, 25 Oct 2017 06:15:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7I75-0000Pd-T0 for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7I71-0000IM-MC for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:39 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:55775) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7I71-0000HP-CR for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:35 -0400 Received: by mail-wm0-x241.google.com with SMTP id u138so626623wmu.4 for ; Wed, 25 Oct 2017 02:36:35 -0700 (PDT) Received: from cloudburst.twiddle.net ([62.168.35.107]) by smtp.gmail.com with ESMTPSA id v23sm2751025wmh.8.2017.10.25.02.36.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2017 02:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vf+0CB6wiiRGtIY9wPlnvY8NTOTypDlpKaiCMODFsW0=; b=XxyZwntRlzapPWitt9aJ3KAG3uRan2f2yIfRz4c7sdC1JCDECOZNERd/vmctOKaQ+/ MxDl4JM8Ku3hcTag0Why2Gvly4yiqmAGj0oLK+04Wi0weBS6z4wqliQNyxMgSMvvbzbm kJvLI93gp47wLFQfdZ7Mmr0BF+NMaPSB1Pq4c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vf+0CB6wiiRGtIY9wPlnvY8NTOTypDlpKaiCMODFsW0=; b=TbCMFAz58W9SOJjudrMC+V9FWZ0OqmmUQA7gHA4dEJ6r/ak2MXls8Jdu+X6FpVD7n3 0Wxb71YWIQ1/14k+ANBwxvIdZP+3wjpbNdH2SsNdKIJe/G6l07erMq5hNVknSE9OCB/k aX2AUODux2WNMO5fpjsIACqTxUPSPKTDDuI585hWNUOWg8odVrDxw2vLxyl0qNTRTMSD cRP8e/BVt0SMCBmvuUMfNAUgxohNRydy+5/NE+tvU9kqWROPpeX4kos6uO3TW00y9QOn Rtz/AB/AAkI1EgemM+FwRGMXyEeo93Jkg7lerFXlTY1eIuZ5INumi0amj5YKoynPrIRj nRmA== X-Gm-Message-State: AMCzsaV3RDMW9PsLl9Ruj6a0Hcz1hGrTepMCDXhuM12YnO7i41cYme5o 1LPHbEUQYoX/KwF0Q9n0txCmsBjk6jA= X-Google-Smtp-Source: ABhQp+T1hspsy5mq8Fo4xEntrxdRZXevE6a9C99UaA3NLWM8sr25AHVlZh4IiOifJ4MvOVOArrNSZQ== X-Received: by 10.28.68.135 with SMTP id r129mr1097730wma.28.1508924194130; Wed, 25 Oct 2017 02:36:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 25 Oct 2017 11:35:29 +0200 Message-Id: <20171025093535.10175-46-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171025093535.10175-1-richard.henderson@linaro.org> References: <20171025093535.10175-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 45/51] tcg: allocate optimizer temps with tcg_malloc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" Groundwork for supporting multiple TCG contexts. While at it, also allocate temps_used directly as a bitmap of the required size, instead of using a bitmap of TCG_MAX_TEMPS via TCGTempSet. Performance-wise we lose about 1.12% in a translation-heavy workload such as booting+shutting down debian-arm: Performance counter stats for 'taskset -c 0 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=3Ddie-on-boot.qcow2,id=3Dmyblock,index=3D0,if=3Dnone \ -device virtio-blk-device,drive=3Dmyblock \ -kernel kernel.img -append console=3DttyAMA0 root=3D/dev/vda1 \ -name arm,debug-threads=3Don -smp 1' (10 runs): exec time (s) Relative slowdown wrt original (%) Suggested-by: Richard Henderson --------------------------------------------------------------- original 20.213321616 0. tcg_malloc 20.441130078 1.1270214 TCGContext 20.477846517 1.3086662 g_malloc 20.780527895 2.8061013 The other two alternatives shown in the table are: - TCGContext: embed temps[TCG_MAX_TEMPS] and TCGTempSet used_temps in TCGContext. This is simple enough but it isn't faster than using tcg_malloc; moreover, it wastes memory. - g_malloc: allocate/deallocate both temps and used_temps every time tcg_optimize is executed. Suggested-by: Richard Henderson Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- tcg/optimize.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 66daced167..438321c6cc 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -40,9 +40,6 @@ struct tcg_temp_info { tcg_target_ulong mask; }; =20 -static struct tcg_temp_info temps[TCG_MAX_TEMPS]; -static TCGTempSet temps_used; - static inline struct tcg_temp_info *ts_info(TCGTemp *ts) { return ts->state_ptr; @@ -88,31 +85,27 @@ static void reset_temp(TCGArg arg) reset_ts(arg_temp(arg)); } =20 -/* Reset all temporaries, given that there are NB_TEMPS of them. */ -static void reset_all_temps(int nb_temps) -{ - bitmap_zero(temps_used.l, nb_temps); -} - /* Initialize and activate a temporary. */ -static void init_ts_info(TCGTemp *ts) +static void init_ts_info(struct tcg_temp_info *infos, + TCGTempSet *temps_used, TCGTemp *ts) { size_t idx =3D temp_idx(ts); - if (!test_bit(idx, temps_used.l)) { - struct tcg_temp_info *ti =3D &temps[idx]; + if (!test_bit(idx, temps_used->l)) { + struct tcg_temp_info *ti =3D &infos[idx]; =20 ts->state_ptr =3D ti; ti->next_copy =3D ts; ti->prev_copy =3D ts; ti->is_const =3D false; ti->mask =3D -1; - set_bit(idx, temps_used.l); + set_bit(idx, temps_used->l); } } =20 -static void init_arg_info(TCGArg arg) +static void init_arg_info(struct tcg_temp_info *infos, + TCGTempSet *temps_used, TCGArg arg) { - init_ts_info(arg_temp(arg)); + init_ts_info(infos, temps_used, arg_temp(arg)); } =20 static int op_bits(TCGOpcode op) @@ -611,6 +604,8 @@ void tcg_optimize(TCGContext *s) { int oi, oi_next, nb_temps, nb_globals; TCGOp *prev_mb =3D NULL; + struct tcg_temp_info *infos; + TCGTempSet temps_used; =20 /* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' eleme= nt. @@ -619,7 +614,8 @@ void tcg_optimize(TCGContext *s) =20 nb_temps =3D s->nb_temps; nb_globals =3D s->nb_globals; - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); + infos =3D tcg_malloc(sizeof(struct tcg_temp_info) * nb_temps); =20 for (oi =3D s->gen_op_buf[0].next; oi !=3D 0; oi =3D oi_next) { tcg_target_ulong mask, partmask, affected; @@ -640,14 +636,14 @@ void tcg_optimize(TCGContext *s) for (i =3D 0; i < nb_oargs + nb_iargs; i++) { TCGTemp *ts =3D arg_temp(op->args[i]); if (ts) { - init_ts_info(ts); + init_ts_info(infos, &temps_used, ts); } } } else { nb_oargs =3D def->nb_oargs; nb_iargs =3D def->nb_iargs; for (i =3D 0; i < nb_oargs + nb_iargs; i++) { - init_arg_info(op->args[i]); + init_arg_info(infos, &temps_used, op->args[i]); } } =20 @@ -1208,7 +1204,7 @@ void tcg_optimize(TCGContext *s) op->args[1], op->args[2]); if (tmp !=3D 2) { if (tmp) { - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); op->opc =3D INDEX_op_br; op->args[0] =3D op->args[3]; } else { @@ -1297,7 +1293,7 @@ void tcg_optimize(TCGContext *s) if (tmp !=3D 2) { if (tmp) { do_brcond_true: - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); op->opc =3D INDEX_op_br; op->args[0] =3D op->args[5]; } else { @@ -1313,7 +1309,7 @@ void tcg_optimize(TCGContext *s) /* Simplify LT/GE comparisons vs zero to a single compare vs the high word of the input. */ do_brcond_high: - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); op->opc =3D INDEX_op_brcond_i32; op->args[0] =3D op->args[1]; op->args[1] =3D op->args[3]; @@ -1339,7 +1335,7 @@ void tcg_optimize(TCGContext *s) goto do_default; } do_brcond_low: - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); op->opc =3D INDEX_op_brcond_i32; op->args[1] =3D op->args[2]; op->args[2] =3D op->args[4]; @@ -1459,7 +1455,7 @@ void tcg_optimize(TCGContext *s) block, otherwise we only trash the output args. "mask" is the non-zero bits mask for the first output arg. */ if (def->flags & TCG_OPF_BB_END) { - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); } else { do_reset_output: for (i =3D 0; i < nb_oargs; i++) { --=20 2.13.6