From 16113cbd3c1351fe8b2677c468e25dab39ab858e Mon Sep 17 00:00:00 2001 From: "Emilio G. Cota" Date: Tue, 13 Mar 2018 16:22:22 -0400 Subject: [PATCH] translate-all: report correct avg host TB size 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. Backports commit f19c6cc6fc356dab7a766b471ec5eb3058f0afc1 from qemu --- qemu/accel/tcg/translate-all.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/qemu/accel/tcg/translate-all.c b/qemu/accel/tcg/translate-all.c index 39abbcc3..e6628f56 100644 --- a/qemu/accel/tcg/translate-all.c +++ b/qemu/accel/tcg/translate-all.c @@ -974,6 +974,15 @@ static void page_flush_tb(struct uc_struct *uc) } } +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 */ /* XXX: tb_flush is currently not thread safe */ void tb_flush(CPUState *cpu) @@ -983,11 +992,12 @@ void tb_flush(CPUState *cpu) if (DEBUG_TB_FLUSH_GATE) { size_t nb_tbs = g_tree_nnodes(tcg_ctx->tb_ctx.tb_tree); + size_t host_size = 0; + 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 ? - (size_t)((tcg_ctx->code_gen_ptr - tcg_ctx->code_gen_buffer) / nb_tbs : 0)); + nb_tbs > 0 ? host_size / nb_tbs : 0); } if ((unsigned long)((char*)tcg_ctx->code_gen_ptr - (char*)tcg_ctx->code_gen_buffer) > tcg_ctx->code_gen_buffer_size) {