From patchwork Thu Jun 29 20:28:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 782439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wzBBS49CSz9s7B for ; Fri, 30 Jun 2017 06:30:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="j0gBWWyP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="H8mVQob2"; dkim-atps=neutral Received: from localhost ([::1]:41147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg5V-0007Ek-SN for incoming@patchwork.ozlabs.org; Thu, 29 Jun 2017 16:30:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQg4q-0007E4-BE for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQg4n-0000zP-4Y for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:12 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:37085) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQg4m-0000xJ-Qq for qemu-devel@nongnu.org; Thu, 29 Jun 2017 16:30:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 89F2620CA7; Thu, 29 Jun 2017 16:30:07 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 29 Jun 2017 16:30:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=6Xk oCzUqNFIJ9spzZ3fz3lVbNb96+o+2NyQhfGkMCIg=; b=j0gBWWyPYCnxy4Ecc9b x4ljN+cWqcVDKcZ0Og2ykEgyNv+AczKYipctLm9GNFpTH4Rrr+atdntEpwAPuVGq hXEJsyLMjPdBAdFBZ4x66gqpZ0lBYJ9jPC5bZ6EktaBHOS40bbEP7z4WtatUEvYz WOtQkNQrdZ+jbBoWo0mxrkcI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=6XkoCzUqNFIJ9spzZ3fz3lVbNb96+o+2NyQhfGkMC Ig=; b=H8mVQob2vz/cZFYRhl8xoVGATjLkFt1wuw7fMpMtjil8VqaCu4OvPbhXq Gtj3VkFJtd6WUozfqZC2759arc5fnpm8LwZ79S/ihvkm+c7tFpJjDSa0V93nM1UD a6i611iFhkH0BXhGzVsPfoWUqo2HTGwMyHSGZqpZMiVwYbgVAGYTTSFG+Ao5Leme zTWuUAEHwPo1EOkZjFTT4fpAEmlDpxxoVlGqyn6zNHyr0MXoY703TrCC4nSffM/C pwvDzVOhIBEMoE8B4mDrTSgnGgy+j7skNnssel9yIKA8lR1pG/TNkf7FYu/uwBwM WKYRYugxNa6vp/D/2X0ztp66kd/og== X-ME-Sender: X-Sasl-enc: 2RNDwUKANeKoBcR5ZGuIrGLFGOBuUm3Ct3+Outx4Cw+d 1498768206 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id D8AF224788; Thu, 29 Jun 2017 16:30:06 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:28:26 -0400 Message-Id: <1498768109-4092-5-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498768109-4092-1-git-send-email-cota@braap.org> References: <1498768109-4092-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.29 Subject: [Qemu-devel] [RFC 4/7] 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: Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Emilio G. Cota --- accel/tcg/translate-all.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index a18fbf7..9714777 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -894,9 +894,20 @@ static void page_flush_tb(void) } } +static __attribute__((unused)) +gboolean tb_host_size_iter(gpointer key, gpointer value, gpointer data) +{ + const TranslationBlock *tb = value; + int *size = data; + + *size += tb->out_size; + return false; +} + /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { + int host_size __attribute__((unused)); int nb_tbs __attribute__((unused)); tb_lock(); @@ -909,12 +920,11 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) } #if defined(DEBUG_TB_FLUSH) + g_tree_foreach(tcg_ctx.tb_ctx.tb_tree, tb_host_size_iter, &host_size); nb_tbs = g_tree_nnodes(tcg_ctx.tb_ctx.tb_tree); - printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\n", + printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%d\n", (unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer), - nb_tbs, nb_tbs > 0 ? - ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer)) / - nb_tbs : 0); + nb_tbs, nb_tbs > 0 ? host_size / nb_tbs : 0); #endif if ((unsigned long)(tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) > tcg_ctx.code_gen_buffer_size) { @@ -1842,6 +1852,7 @@ static void print_qht_statistics(FILE *f, fprintf_function cpu_fprintf, } struct tb_tree_stats { + int host_size; int target_size; int max_target_size; int direct_jmp_count; @@ -1854,6 +1865,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->out_size; tst->target_size += tb->size; if (tb->size > tst->max_target_size) { tst->max_target_size = tb->size; @@ -1882,6 +1894,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); @@ -1889,12 +1906,9 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) cpu_fprintf(f, "TB avg target size %d max=%d 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 %d 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 %d (%d%%)\n", tst.cross_page, nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0); cpu_fprintf(f, "direct jump count %d (%d%%) (2 jumps=%d %d%%)\n",