From patchwork Fri Oct 20 23:20:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 116572 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2236112qgn; Fri, 20 Oct 2017 16:45:53 -0700 (PDT) X-Received: by 10.200.63.242 with SMTP id v47mr10416634qtk.29.1508543152963; Fri, 20 Oct 2017 16:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508543152; cv=none; d=google.com; s=arc-20160816; b=yJLbqGYrGY4U+qhEEcSkKMEs/NTwJ/GkZMGk3Z6SLxdUI9V6F+bFYF3dh9exFNt5rS iYxHtQ8SnmtdfVnMcyei3aWFQ5AGArzhI0baKgZUF2uPHQHqJqDZUhMf4LhHpe+j/4+N Drn1I915PJvwlx+0EAe5u5miJkCmXmg9wp5SVne1A3D/ZNT9AdcreYlL8mJdKeogffD5 jRC2w7LTYCx4UBEA/kcx7eHGwqqi2kpa3aHoVMstxB1+N0d2bl68Yxq5Ktcrz7zG1nYl qC4f8rbsdjbpy4R2Tuvb4MWgVkYQd4CuGpIQ3xv6R2o0ZHp94BQh4WxtrTHn7oQA8ozz Y3xA== 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=NySpqrl6neewfvZfknDFX4jeOiU6Ts0imHQfLMZHXkU=; b=Sz/Gn8RokRcUeHapjFsgMh7WGEO0WHO3LOrbQOWUzoUXl5WgngD9BrM3iXEtiEyTto 5ig4NP12RXnZYrz1PS1XD+dsI+7iRGVVp4k4Zw7baL519xPt3BL9/hGCmGy/NJSEEuwJ qy/aW1/TUL8rmxPOkGMWQMlmyMaMgT/MwMOaLSxZ6W+MLw2tl2B3LH0b1qH0JeVaGuoF 1whOR4iWlqQ4HfjABD2SZrXtV5b75NJf7zGUmspdzIfE6VNnn3HrLJ1h8LClyv7zxYEv DfzOql8HKNKEPVLNkJTYT06X+trdI1PShEb/b8xx5LeiNKTv/VmSyDTvhgLoqFtl2dpk 2/xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=et0EcA8S; 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 n26si1759678qtf.239.2017.10.20.16.45.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Oct 2017 16:45:52 -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=et0EcA8S; 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]:56085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5gz8-0003P8-NT for patch@linaro.org; Fri, 20 Oct 2017 19:45:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5gbV-0006V8-Qn for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5gbU-0007vv-MU for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:25 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:45639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5gbU-0007vZ-DV for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:24 -0400 Received: by mail-pf0-x244.google.com with SMTP id d28so13078761pfe.2 for ; Fri, 20 Oct 2017 16:21:24 -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=NySpqrl6neewfvZfknDFX4jeOiU6Ts0imHQfLMZHXkU=; b=et0EcA8Sy3G1e0XqyzeFxEL3g10S5jZi91OPZm1sv7DbEJpEIpcW4TsRFeSmgTj7b/ OVHcQ1RhLg7UzbgBBfpMumiKTek/VORM8dvZYA5rA9kbAv4TfGR0imYnUEfy9aVaSMC0 kfk3poemqj6FNUTguiU9dABchChZZCCDVz0lY= 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=NySpqrl6neewfvZfknDFX4jeOiU6Ts0imHQfLMZHXkU=; b=d9QvQqjpW2TlqOI7OqSggsyZcGHgZ9W070iEeZ7mBj3GKiTPR1JjOt+H3bFQAmn7KM 6o8xc6J99YgeBBGbVfSTonhqrSZ5BNB33be5lQunFfwo6kw8Y+tDvkm28rwHv3qOtU2v 5kMpVAazp6xUy6UXgW9idZaVsHlgFkG1Ap85Qwevo5qkcBVJkzu2szmUfAxDJ5pRG0zr ht5Df+UjQtPSMiJhCz3zND9KgYLzYg0VBvduioTaVBMEUF7oOXqY1W3R8ERRYUE/XiMA FgSCD4OBCEurz6R2j4wL5Cj2T/R9y383MsvYOk2C6bziCjmQBPtc2eKACoevyCwHhAgx Bkng== X-Gm-Message-State: AMCzsaVOCyqfjwouZE/DfsFRgs+3BSJI0x929Qktytar8/dT0erD+Lvd LNPBVuu+wezUN9HXGkjB7CMaZuGEJQs= X-Google-Smtp-Source: ABhQp+RgkPUgn62oC2YWOewF3WNkk1YiJIYjb2cKLftsCkkOoLWUjkTNQTrN1o9d5JIsPUFLxpcweA== X-Received: by 10.98.105.199 with SMTP id e190mr6364106pfc.275.1508541683203; Fri, 20 Oct 2017 16:21:23 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 16:21:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 20 Oct 2017 16:20:11 -0700 Message-Id: <20171020232023.15010-41-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 40/52] translate-all: report correct avg host TB size 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" Since commit 6e3b2bfd6 ("tcg: allocate TB structs before the corresponding translated code") we are not fully utilizing code_gen_buffer for translated code, and therefore are incorrectly reporting the amount of translated code as well as the average host TB size. Address this by: - Making the conscious choice of misreporting the total translated code; doing otherwise would mislead users into thinking "-tb-size" is not honoured. - Expanding tb_tree_stats to accurately count the bytes of translated code on the host, and using this for reporting the average tb host size, as well as the expansion ratio. In the future we might want to consider reporting the accurate numbers for the total translated code, together with a "bookkeeping/overhead" field to account for the TB structs. Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) -- 2.13.6 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index e929ccb30b..7e2c0cdb98 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -921,6 +921,15 @@ static void page_flush_tb(void) } } +static gboolean tb_host_size_iter(gpointer key, gpointer value, gpointer data) +{ + const TranslationBlock *tb = value; + size_t *size = data; + + *size += tb->tc.size; + return false; +} + /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { @@ -935,11 +944,12 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) if (DEBUG_TB_FLUSH_GATE) { size_t nb_tbs = g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); + size_t host_size = 0; - printf("qemu: flush code_size=%td nb_tbs=%zu avg_tb_size=%td\n", + g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_host_size_iter, &host_size); + printf("qemu: flush code_size=%td nb_tbs=%zu avg_tb_size=%zu\n", tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, nb_tbs, - nb_tbs > 0 ? - (tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) / nb_tbs : 0); + nb_tbs > 0 ? host_size / nb_tbs : 0); } if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) > tcg_ctx.code_gen_buffer_size) { @@ -1882,6 +1892,7 @@ static void print_qht_statistics(FILE *f, fprintf_function cpu_fprintf, } struct tb_tree_stats { + size_t host_size; size_t target_size; size_t max_target_size; size_t direct_jmp_count; @@ -1894,6 +1905,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data) const TranslationBlock *tb = value; struct tb_tree_stats *tst = data; + tst->host_size += tb->tc.size; tst->target_size += tb->size; if (tb->size > tst->max_target_size) { tst->max_target_size = tb->size; @@ -1922,6 +1934,11 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_tree_stats_iter, &tst); /* XXX: avoid using doubles ? */ cpu_fprintf(f, "Translation buffer state:\n"); + /* + * Report total code size including the padding and TB structs; + * otherwise users might think "-tb-size" is not honoured. + * For avg host size we use the precise numbers from tb_tree_stats though. + */ cpu_fprintf(f, "gen code size %td/%zd\n", tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer); @@ -1929,12 +1946,9 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) cpu_fprintf(f, "TB avg target size %zu max=%zu bytes\n", nb_tbs ? tst.target_size / nb_tbs : 0, tst.max_target_size); - cpu_fprintf(f, "TB avg host size %td bytes (expansion ratio: %0.1f)\n", - nb_tbs ? (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / nb_tbs : 0, - tst.target_size ? (double) (tcg_ctx.code_gen_ptr - - tcg_ctx.code_gen_buffer) / - tst.target_size : 0); + cpu_fprintf(f, "TB avg host size %zu bytes (expansion ratio: %0.1f)\n", + nb_tbs ? tst.host_size / nb_tbs : 0, + tst.target_size ? (double)tst.host_size / tst.target_size : 0); cpu_fprintf(f, "cross page TB count %zu (%zu%%)\n", tst.cross_page, nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0); cpu_fprintf(f, "direct jump count %zu (%zu%%) (2 jumps=%zu %zu%%)\n",