From patchwork Fri Oct 20 23:20:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 116588 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2245533qgn; Fri, 20 Oct 2017 17:01:02 -0700 (PDT) X-Received: by 10.200.40.202 with SMTP id j10mr9688247qtj.301.1508544062417; Fri, 20 Oct 2017 17:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508544062; cv=none; d=google.com; s=arc-20160816; b=Hsf0D8Jh3Fjw9oJJwALGzYhyHwSUqLoy8eBCq319sOkklvWEfIf24oL4RT7xmD1JsC f7fK19FFEFn7cDFnIP1JbdRhYRKqOgz1tPFitGM2GGguGpv4yu3zPzrXIOQosvjOiYB1 sYuiJ+gY1SK8Gmadszk2tdw4HyN+4MXpcnuB2pe4Be+IZXtC0od8SMCNJokWxFEUgCPS x23CO9wAV38iI69nYd/pLZrMuZd9+M+sQj4Ha+FJZVMt/ocAck5g5g02OztxUjek8GPs ipKYefrZwHqkJEQxC+3uimcbZRJ30tD1TOzpd5I+iBBHjovX+X/fr9YHpP2kD6pfD2bl RbjA== 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=LApZZj1h6bTQXO+YLYUVHHHRMlJMV18NbnmhVbQioU4rY0zmR1wixCv8QYmA6bfXK7 hBKwyuKKGjM33WTPzc+D14eSEf2zOzmtfSxq7cnL9zHEP8vVx8tUs1OMAoQdmfHa8+GW /RlD7sHapm3p1gnWV3Pp3TieJ56SSYYVjSiHZc1ZwNtvSP33GJ7HHWmv0q8YfE6Vvb8v 7cY6yBmYZaZdgd77TKSLuTq7Bo7DWCSHLcUzd4gq5Zaa9XLxtyNS1GU1wDvGEeFmV3Tl dtLIX+6ORlvzPSlXswS0rvOGV7ER6M1t6xuqFsfNCnbAQYJr253GchjCfMbLxq9j0jUI HPWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UNfDxss3; 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 m69si330473qki.221.2017.10.20.17.01.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Oct 2017 17:01:02 -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=UNfDxss3; 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]:56148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5hDo-0006lV-9d for patch@linaro.org; Fri, 20 Oct 2017 20:01:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5gbf-0006hE-J5 for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5gbe-00081T-2U for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:35 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:51601) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5gbd-00081D-Q5 for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:33 -0400 Received: by mail-pf0-x244.google.com with SMTP id n14so13060176pfh.8 for ; Fri, 20 Oct 2017 16:21: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=UNfDxss32yv66KzDIKMjdlMhSCjElJA3kNfdukhdEj93U7zqYDWYCd41SktSD9cZzt LDf9xmmoAIoBgHN0trRep8ZiB6d7HFWZkxZicZFnB/uH1eT0qzgPMlBa51yk4TE3eLRB LLIqIOHBcL3wykabQVL0zTyA1r1m2O/lf88uM= 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=QCLJ3tsowQKWLz/+Eh6hMqk1ZOdev4mbaySynoTi+WPvHdzzU6t1LoGNjEln+4lbzd wxGPYs5IfBaCwDrudKlqW3rj8lMa58F1/izyVztkRaRnDpUz2D+Z5f/B+zAXRbyuRuD5 9SOWodiUqXowc8FH8JNDTGytP02YNMrSHeG5gsW3a4jfd7JdZdyGf1MxvG/QFNC5BJjl ymAezyxahaSRRBrjv+kj7F7YaDuG0wh+T5U0+eRvbyNojCrEghGqe6zBsJITmtbVciD5 CXSQZT2erCBuk+3gwUx9mLGM7X432nfSfq5Uoc7DnQvvASktZs9nppWnyRPWvB/xV5zE hRrA== X-Gm-Message-State: AMCzsaWhFV7MFIrhFcN6LdUz4eVLaxqxSIRAvItA4WnlriDS4F+2apNq yUUvntefodG8d6ZN7bRmmU336+gFX6A= X-Google-Smtp-Source: ABhQp+TaGLnOAeTWtc76CUC4ehDDJE8TWsfHvOIhnowI+x5pfPmJpy6PW+gd/Zpf6b5smE2RcbE9RA== X-Received: by 10.99.119.4 with SMTP id s4mr5684063pgc.377.1508541692432; Fri, 20 Oct 2017 16:21:32 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-165-104.tukw.qwest.net. [97.113.165.104]) by smtp.gmail.com with ESMTPSA id a17sm3532594pfk.173.2017.10.20.16.21.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 16:21:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 20 Oct 2017 16:20:17 -0700 Message-Id: <20171020232023.15010-47-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020232023.15010-1-richard.henderson@linaro.org> References: <20171020232023.15010-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::244 Subject: [Qemu-devel] [PATCH v7 46/52] 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: pbonzini@redhat.com, cota@braap.org, f4bug@amsat.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 --- 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++) {