From patchwork Mon Oct 16 17:25:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 115974 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3965081qgn; Mon, 16 Oct 2017 11:02:26 -0700 (PDT) X-Received: by 10.237.54.42 with SMTP id e39mr15641681qtb.87.1508176946583; Mon, 16 Oct 2017 11:02:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508176946; cv=none; d=google.com; s=arc-20160816; b=ehFu11+jhYDwVhj+odBqd/ks2qA9N5JjYu6Da6xWpy46Bb/MH9g/R3p7woanRf2tsY z2rCGmhMKsoPqSGKTN2B84AiFkrHEyaji7YHfPJIiyyu9E+V548B+gsUBGAPKuAYLwN3 GtgqlynBRz3Gg8cz4Eojjgw8+GHFtSbqtsvaQovpYnweXXqexYDDNFI1tT2FiJe+RtAF Gs1bsu7fYc+TFruOkHvuo1qqEyTrbJhKNcHOTyLLjduSfKXP1Q49ea8s/yhxqHj9DmiU 5qkbkLjuew3Qxdr3vvKNm2cxG1CxE5A2nMkFPq0CspfQvW9XXwx+SCJnruCeDtI0WcgC R72Q== 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=bUAYvoRE++vtOhfTfGcC3GQ+auq5Nx2oS4tsDzfqZ3k=; b=YjONcxy2qqHolq3Rra/4ZkfVnhuuh4EquI2b+DO9PmmXk69Yk6a3O7WPjW+cMbNERX VuRoG1LR26Xk+kj7drZHPSRytSEEOpXot33/xrqTHPInTqUXqZ1nqPTJhVd2wzDMpcqu CbuAfQiWidWgGX1vdsBMe0KLNUr7tOLZi+LF53eBRZJB+v7FExGynidjc+wk35feSaqH b6Bny88dA6wZEF8Qq3XALLYmKYkvhZ27E9Hy8c2LoqQ+B8XSB6h3+um9/uyN2gwIt6V4 BHbeI0Kadfc6ry4MhwSV0QEqMJ6NrhDmZfxT/gDFOYEJS93uw+leIP9SlhdbiAM9tKis kA8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CLQ5O5h/; 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 w24si1213131qta.58.2017.10.16.11.02.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 16 Oct 2017 11:02:26 -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=CLQ5O5h/; 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]:34458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49ia-0007sy-Ar for patch@linaro.org; Mon, 16 Oct 2017 14:02:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49AY-0002mO-Bf for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e49AV-0003vd-14 for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:12 -0400 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]:49899) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e49AU-0003v1-PB for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:10 -0400 Received: by mail-pg0-x22a.google.com with SMTP id g6so5925014pgn.6 for ; Mon, 16 Oct 2017 10:27:10 -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=bUAYvoRE++vtOhfTfGcC3GQ+auq5Nx2oS4tsDzfqZ3k=; b=CLQ5O5h/WNFJND+/AzeiA3mqCHqdzFzDEdjPILv3NYHeK+zq/ylJcLwRECqinYrjeS 8vmETiiVXUy8WX80irDgHwS5l0ImKJej1sxmg8FL16QyqhOe7NR0MdWqG2CAISNEq7Zt NWKIc0bTlm+dkt7vsGTvEVncSUEcmk4n95138= 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=bUAYvoRE++vtOhfTfGcC3GQ+auq5Nx2oS4tsDzfqZ3k=; b=R1k+cdfUKxE6JPOtDB6mNff1cHKNEprJHm9HzcMgBDMTpmM5RORiIrTrp+CFylhw+k 0HSRkdHrW0/eYDurBTibP3TbBBNqFQnAjbxLzwYlKw1gk15ibQ5H7uz4n5cY0I75+4l6 Zy4h1zTQGa5k01kFgs2aY2kcOWwMlEuskdqQdhcona1CwmEvhgWS2IVamCyCJScHaZG+ IF4vLrDLhf1/lGaa9Ua6BetpW1SFb+CXZK6U3xuERFZjtU3WVGxsH4ObYgqtVaoNaIMD SxyMw1y6gwgkCrJ47zHLqw8sLXGkYpsYOch5LaO/91/2F+KUHlbX1FxCkv0mu4s6XrOT Vnhw== X-Gm-Message-State: AMCzsaVbZw45yb9/9ueR0EYAlvMxKx1nPx6E5tu38DMJXndK/4iHYX9B BNT4tNIWYb87M40eJAKHhs4eZfRS8mk= X-Google-Smtp-Source: AOwi7QBQzvLdT/y2A1JXw0buMJ02cRf8Ery+RaBxoTWwQW9709nYmx0RWngYa/7glk3x32GJEC6qsQ== X-Received: by 10.99.95.201 with SMTP id t192mr7101759pgb.398.1508174829527; Mon, 16 Oct 2017 10:27:09 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 10:27:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 16 Oct 2017 10:25:59 -0700 Message-Id: <20171016172609.23422-41-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:c05::22a Subject: [Qemu-devel] [PATCH v6 40/50] 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: cota@braap.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 --- 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 76db9c775a..b21671d6f4 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -923,6 +923,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) { @@ -937,11 +946,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) { @@ -1890,6 +1900,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; @@ -1902,6 +1913,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; @@ -1930,6 +1942,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); @@ -1937,12 +1954,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",