From nobody Tue Feb 10 14:32:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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 1508925308701136.04029990968536; Wed, 25 Oct 2017 02:55:08 -0700 (PDT) Received: from localhost ([::1]:47386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7IOq-0007qs-0v for importer@patchew.org; Wed, 25 Oct 2017 05:55:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7I6v-0000GC-UX for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7I6u-0000AL-P9 for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:29 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:56390) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7I6u-00009Q-FM for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:28 -0400 Received: by mail-wr0-x244.google.com with SMTP id r79so23326274wrb.13 for ; Wed, 25 Oct 2017 02:36:28 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2017 02:36:26 -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=UAOrWQNJQpr5H8jLnOcqZICnDXku+4DPt3ZY909trYFUJECzeS+H+yrwAxjl0x1xRK zhpImEnKvDlaGiYAcHqxL5c16k+YH5KVyxi7MBX+CFCEOKnQ1e2GdsrEeSrWhbYqdAUg rqqhjkOjSnQ6ey41iENAcxCTdmBMRu0vvmtCE= 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=lyySxmiujCvJeAhdSLaH2hYsu6fSSdWwLQKFgpDfowIoymIYP4fXDw4L7hmIowvE39 OMigtTaecdxSvV2l5EtknO1yF47cc1YhVKnlnCqxQpY3nA3xfqK6bIx+mEmxs3OV2W4m u+DZOPcL4croi4d6MI1SKZuYM+N0XjcSsRS0dG673LVoiQ41ODuZlj9JyA1jY0nlmov/ komSXodiurDx8aGe7EDiN8jV31UErHt3igGc1ZrdSXCXlRSktxHQKACTuGkodwBSlP0n WEF7engBhFkjBYYOla736zho/Q59QZn3AKtcfhIclaqNlN5eDUCDVSKi5O/jTe9SNiUw s33g== X-Gm-Message-State: AMCzsaWe5VLG6PmYEyHvxgmd+JIj/gVcC/bKJKcFNEw3+zIxEFnjbjFu ylNRKT4UQDkI6YV6xOSGzOyDc1gYwn0= X-Google-Smtp-Source: ABhQp+TP6y1MRspqGVOtjSjBh/9xF9v9Sg/wZhqEo/sA4zyg28vk/T9UiKMaUPL1wiuthKbAKDaavA== X-Received: by 10.223.175.87 with SMTP id z81mr1533341wrc.12.1508924187240; Wed, 25 Oct 2017 02:36:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 25 Oct 2017 11:35:23 +0200 Message-Id: <20171025093535.10175-40-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:c0c::244 Subject: [Qemu-devel] [PULL 39/51] 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: 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_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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) } } =20 +static gboolean tb_host_size_iter(gpointer key, gpointer value, gpointer d= ata) +{ + const TranslationBlock *tb =3D value; + size_t *size =3D data; + + *size +=3D 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_dat= a tb_flush_count) =20 if (DEBUG_TB_FLUSH_GATE) { size_t nb_tbs =3D g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); + size_t host_size =3D 0; =20 - printf("qemu: flush code_size=3D%td nb_tbs=3D%zu avg_tb_size=3D%td= \n", + g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_host_size_iter, &host_si= ze); + printf("qemu: flush code_size=3D%td nb_tbs=3D%zu avg_tb_size=3D%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_fun= ction cpu_fprintf, } =20 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, gpoi= nter value, gpointer data) const TranslationBlock *tb =3D value; struct tb_tree_stats *tst =3D data; =20 + tst->host_size +=3D tb->tc.size; tst->target_size +=3D tb->size; if (tb->size > tst->max_target_size) { tst->max_target_size =3D tb->size; @@ -1922,6 +1934,11 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fp= rintf) 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 tho= ugh. + */ 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_fp= rintf) cpu_fprintf(f, "TB avg target size %zu max=3D%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=3D%zu %zu%%)\= n", --=20 2.13.6