From patchwork Mon Oct 16 17:26:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 115979 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3972067qgn; Mon, 16 Oct 2017 11:09:14 -0700 (PDT) X-Received: by 10.200.40.202 with SMTP id j10mr14776386qtj.301.1508177354202; Mon, 16 Oct 2017 11:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508177354; cv=none; d=google.com; s=arc-20160816; b=gxdgI1QPX3Z+CmVpCdqFo8y9kFOsvwidFOol1AwBrjUhJXXNl/Y86Q3F+lvmzr2mk5 JwaohKbU8CDtp1nB9/iyMx2cOA3VVoz2rJFA8AATQtLHtibw3+1Kmtehd8/VvXYYAPeQ G0KVMjhITcoSl9m6bR2CW1zPD6ZenRIKM18wOHjuBTNAV/npHGs9+eJCHpKoC6Q8VNTy RDs137NbgvF3XSCH9nmZ8Lvz0q9aJxVEbNx1d17aoGYlmSv/4G6FxlYFpGxAerdfvm6b PbnX9qMxSoocaGKraw3V9G+8K746Ep0USEOb1ihSCeu5eQG0+QPYhcTUop13v3rJq9/g p2Xw== 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=uJ+6idNGx8Q+mUo4Bnbv/J0eV4RGBdO4S7TS3gW8eL4=; b=rEAY2FG+z9lnLoUGbDcHWVP8W+FhCbSVApU9lkXaIfDc9UyM/pZXyfvEBm21/aBkTO vFNXSTKsd0Ur89iGGxg/Y8kR7064hVriohUrmmx6bNMfUPpWleHYlxbuhoH2MxnObZyd EQdMb4JMD90wcbaARn3WitfPUOgpfkg57rJ/96kugXas0RDUc5wV4shGk+rc8+xsOU+b zgtfJ9pQfs9WFDbvLMfvHuhX42lMNSBngKczGQsNlPY4DpkytVLyRmauWhbSHHIrWWpb AJvanev5q09WKQL7MhD2CLf9hu/8F67Qt+2Nju7+pKrrizJ2avrWq+5SYkyR9XV9qEcK iGkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YsGef0PX; 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 l76si1923976qke.71.2017.10.16.11.09.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 16 Oct 2017 11:09:14 -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=YsGef0PX; 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]:34499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49p9-0004i3-UQ for patch@linaro.org; Mon, 16 Oct 2017 14:09:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49Af-0002u3-Am for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e49Ad-000462-Ei for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:21 -0400 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]:54268) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e49Ad-00044r-7a for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:19 -0400 Received: by mail-pf0-x230.google.com with SMTP id t188so13795001pfd.10 for ; Mon, 16 Oct 2017 10:27:19 -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=uJ+6idNGx8Q+mUo4Bnbv/J0eV4RGBdO4S7TS3gW8eL4=; b=YsGef0PXwF5kbJzuJnFXeJ8rDAvpeF+bINtn4rt60nLkh05rins48uZXTkNyw2CPjw ymb00DYbpnfRII5mSu3TM1rg8f/T7Lj9sY2NeTbnC05uWNJax56JeCh8iqhLB5qUAp5b xsUfQndVDQ6fbj3b40KiGsEDv1qm/jFT0pZE0= 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=uJ+6idNGx8Q+mUo4Bnbv/J0eV4RGBdO4S7TS3gW8eL4=; b=GDX9Uk/OWOFJMSmv97jcuIzEZa3ihCgnGBSE5tJ7+AD8uQUcFM4VhgPyvEKYV+IHxZ 8Uq75+sn2H6dLCgy5a67WK5BlUm1yxJ61vBdxbKcIEYD4/UmRNHIMkCcsReRXcl8wGcl T0tnNaq4N5vO+sw+1WpXdNMDWhtMojvqv0y0wb5glLvF46y91CUTiyzrRFWQknHiaL+S JihEyHR+uvdGRW1sqIISMX728TACGsTUMmYKVNMJ1ZdvzRg+CUwXA+NDjx7Etix0kmA6 a3vcGzCl0VPsPKEyJL4m4cKaUKptH5jfTtKjEU6xtyBbw2TAvUf0YhTjqtYuYdvCu+93 CWbw== X-Gm-Message-State: AMCzsaXxoHxrktQqWtRfXQ4D52Eq0S4mI3A/q3QYAlJpHAHMd55zEheG tCT+S1hGdXQ1MAIbd6VTImFDikoRgFY= X-Google-Smtp-Source: AOwi7QCKHXe9hKzC10N6OR6P/REqUgb0k3aTJwXSx47orQzwaaCpxK750zPw/2+ZRRjlLNIIdurZZA== X-Received: by 10.84.173.4 with SMTP id o4mr9483914plb.152.1508174837914; Mon, 16 Oct 2017 10:27:17 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-104-76.tukw.qwest.net. [97.126.104.76]) by smtp.gmail.com with ESMTPSA id i187sm5594249pfc.96.2017.10.16.10.27.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 10:27:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 16 Oct 2017 10:26:05 -0700 Message-Id: <20171016172609.23422-47-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171016172609.23422-1-richard.henderson@linaro.org> References: <20171016172609.23422-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::230 Subject: [Qemu-devel] [PATCH v6 46/50] 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: cota@braap.org 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 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 ead7bb5e4f..847dfa44c9 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; @@ -93,31 +90,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) @@ -616,6 +609,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. @@ -624,7 +619,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; @@ -645,14 +641,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]); } } @@ -1213,7 +1209,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 { @@ -1302,7 +1298,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 { @@ -1318,7 +1314,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]; @@ -1344,7 +1340,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]; @@ -1464,7 +1460,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++) {