From patchwork Wed Oct 25 09:35:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 117099 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp666400qgn; Wed, 25 Oct 2017 03:15:38 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TrR5eGBatjgtdGs9JfS4cdSm+Aym9Dc5pEVCI02g94v8xYNup+5GeklKklHxg0ufzOdou9 X-Received: by 10.37.139.133 with SMTP id j5mr949704ybl.4.1508926537969; Wed, 25 Oct 2017 03:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508926537; cv=none; d=google.com; s=arc-20160816; b=k0rvltwMqxkrIm+/9zJrlIOL9yRfRp3Wf2iUZeWeT9JrUACAyN2l01LqpyIGNp7gEr uepHji85IQ6IKWVO1ON0wohPZgVOe3Rp/Va2BXz3mZ81plpS2WrDTnyInHeQ5zo7eREJ 7QGvzfL11OoJgYY99u077ICtmkn+FXjpOl6kL4aGL26WYhOVb4rwP23bHBvvxlwmeyLf yzvkhMD088eVD6YzYi768Ywo6OZcXggMYVZz3TZPo8sVMp9sTR3c//XNW7LmKCvbNUjX nfWXIn3hknY2tRjDpAlUU85FKeGyJJFK5oIZCSCHOzsjZhVhDnj/rlLPI3YE+bAcXMpd XgqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=vf+0CB6wiiRGtIY9wPlnvY8NTOTypDlpKaiCMODFsW0=; b=OQEdzL9OP/Sc0dMgcaXUgZ5mDMCN6/tlXMHAs/sVVRf+06WAKBSIpRzVeYenLg1/je Y1Fpb/ZLZs05RrWqcIc3i1Kn46DUoywGNiZWLp/7L+wI7vXDNVdIBt5buYQPZTYYFFbs zww3pA98rGmLm6tau5kY40t0zdpkGOBslCGvWTqJ1kYo9yy1eLo7hQ0PxzLElPMVueGr 2pBVhqYrFoAVLHl1hJcahDoClHjGKQpBq7OC1wBaxWp8svondm+oGD594GOaeEugc5Ot xB4lvXHwiCED+qzF7oAo7XUnwudzRoAKw64av9n3COUxpAeNn2VgCKVdUfOAoubdZ1HW 1nhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XxyZwntR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e140si376278ybh.419.2017.10.25.03.15.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 03:15:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XxyZwntR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7Iin-0007ZZ-Gx for patch@linaro.org; Wed, 25 Oct 2017 06:15:37 -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) 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-Received: by 10.28.68.135 with SMTP id r129mr1097730wma.28.1508924194130; Wed, 25 Oct 2017 02:36:34 -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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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=virt -nographic -smp 1 -m 4096 \ -netdev user,id=unet,hostfwd=tcp::2222-:22 \ -device virtio-net-device,netdev=unet \ -drive file=die-on-boot.qcow2,id=myblock,index=0,if=none \ -device virtio-blk-device,drive=myblock \ -kernel kernel.img -append console=ttyAMA0 root=/dev/vda1 \ -name arm,debug-threads=on -smp 1' (10 runs): exec time (s) Relative slowdown wrt original (%) --------------------------------------------------------------- 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(-) -- 2.13.6 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; }; -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)); } -/* 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 = temp_idx(ts); - if (!test_bit(idx, temps_used.l)) { - struct tcg_temp_info *ti = &temps[idx]; + if (!test_bit(idx, temps_used->l)) { + struct tcg_temp_info *ti = &infos[idx]; ts->state_ptr = ti; ti->next_copy = ts; ti->prev_copy = ts; ti->is_const = false; ti->mask = -1; - set_bit(idx, temps_used.l); + set_bit(idx, temps_used->l); } } -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)); } 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 = NULL; + struct tcg_temp_info *infos; + TCGTempSet temps_used; /* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' element. @@ -619,7 +614,8 @@ void tcg_optimize(TCGContext *s) nb_temps = s->nb_temps; nb_globals = s->nb_globals; - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); + infos = tcg_malloc(sizeof(struct tcg_temp_info) * nb_temps); for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { tcg_target_ulong mask, partmask, affected; @@ -640,14 +636,14 @@ void tcg_optimize(TCGContext *s) for (i = 0; i < nb_oargs + nb_iargs; i++) { TCGTemp *ts = arg_temp(op->args[i]); if (ts) { - init_ts_info(ts); + init_ts_info(infos, &temps_used, ts); } } } else { nb_oargs = def->nb_oargs; nb_iargs = def->nb_iargs; for (i = 0; i < nb_oargs + nb_iargs; i++) { - init_arg_info(op->args[i]); + init_arg_info(infos, &temps_used, op->args[i]); } } @@ -1208,7 +1204,7 @@ void tcg_optimize(TCGContext *s) op->args[1], op->args[2]); if (tmp != 2) { if (tmp) { - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); op->opc = INDEX_op_br; op->args[0] = op->args[3]; } else { @@ -1297,7 +1293,7 @@ void tcg_optimize(TCGContext *s) if (tmp != 2) { if (tmp) { do_brcond_true: - reset_all_temps(nb_temps); + bitmap_zero(temps_used.l, nb_temps); op->opc = INDEX_op_br; op->args[0] = 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 = INDEX_op_brcond_i32; op->args[0] = op->args[1]; op->args[1] = 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 = INDEX_op_brcond_i32; op->args[1] = op->args[2]; op->args[2] = 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 = 0; i < nb_oargs; i++) {