From patchwork Wed Oct 25 09:35:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 117069 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp646903qgn; Wed, 25 Oct 2017 02:53:33 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RFAC4NpxIXCvjKMhBxLIAkf7DndyG+SxuwSI30L9eOhE/QWx0/2zg3lDzIKZwg9DQM+qvg X-Received: by 10.13.216.75 with SMTP id a72mr12471728ywe.303.1508925213744; Wed, 25 Oct 2017 02:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508925213; cv=none; d=google.com; s=arc-20160816; b=jVWbxuCo3u3wHA87XCB0drdQPf+TEHTIFBH3QcXdlIljrxv8mTZlyLbIxp7Thb8pO8 fZHhvAP19NKIZ1FzBfKx2cUfaZF0s+oVHe6+g6yBjz9G8DjeMCLYAKQjLrra8+yfnszq 0W1CtANRLxLcGMVXMsvuMqn+cLV9U0jrnccI2gkdZoOpJIYTFN0jammD92g9YWsQEDkF ALkg4ASdH+OBJJulnBWyk+BcQEix1WSEQr66ZEfB8Tpz8vLCpgH63vqR0gQGReKR4APr NGfF1zWDKDyp8By/mIW7VW+I4SHCOnp+kzeU6fIZ/vFvOKEcP5tO7xq5wbYmCFwbEGBz Mgjg== 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=BvvghCtn/WOaoxhDh180B1eoQ/W8x4rp54FVwKGFW2pvE/TBWmqWl0HJVyraYg6w64 qUeV/wUknG5hSP+KZzQ3BNOvJOHFwMmFl/fA2tgL2z/L4chGandadfmyRg1TzAyigg1J qw5EvMuNX+6oK2icRZ4hbvvdQ5ncz+/72vaX37mejgEYeiTtPbWHUV3xDH0dC+MbqiQ9 D3j0oljAJt71uScvdhgYQ5haYRIGwp2wHtCg6HBuEP0twywskkp7pNsXosTFQXNK3N4I X5TUCmXPp2wZodaz6ff9DNIi4Hs2n9zPMyf0PKpn6g9cW3Yke54LKxvAootPBsPDBHqb fdzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UAOrWQNJ; 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 205si193346ybl.460.2017.10.25.02.53.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 02:53:33 -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=UAOrWQNJ; 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]:47381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7INR-0006iC-7E for patch@linaro.org; Wed, 25 Oct 2017 05:53:33 -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) 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-Received: by 10.223.175.87 with SMTP id z81mr1533341wrc.12.1508924187240; Wed, 25 Oct 2017 02:36:27 -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) 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+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",