From patchwork Thu Apr 6 02:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Fei" X-Patchwork-Id: 13202817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 722DAC7618D for ; Thu, 6 Apr 2023 02:27:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkFL1-0005KA-Sh; Wed, 05 Apr 2023 22:26:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pkFKu-0005Dz-Gv for qemu-devel@nongnu.org; Wed, 05 Apr 2023 22:26:53 -0400 Received: from mga12.intel.com ([192.55.52.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pkFKr-0007ho-Q7 for qemu-devel@nongnu.org; Wed, 05 Apr 2023 22:26:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680748010; x=1712284010; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5SZrsjIl/mB+iqg8pDGatsH/Hcyyzb65uOJ38ijiHn4=; b=Ieuzjanm0AkHOGAvdOC4Ose9mmSHopoOL0vh82rmUsUgyns0lTjZuaOr 7+dQ2HBNZy2IEBluSgII0ImPutZLq4UslzICBvH0FALbqdfpImhKUxCdT LVd14VXaHI/k59RR1cL40hk8+uALw70IZo0nHW930byYRGygDBggLf9F7 +xdWVj/bDBRvSLi7LaTErw94qC7hWuxsMma7TebdrAZrruRjtBI/DjvlS kUXyuT7shYc8wKNQu72pdDuQuvL6+x/Wfx4jPDSG4J6hYagvkUUgjuw5b TQ/CagpH9ihVlRPKZhusBOwj2gGPYuShnKs+v9uFzA8DZmfJGuSWxvi/o w==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="322269681" X-IronPort-AV: E=Sophos;i="5.98,322,1673942400"; d="scan'208";a="322269681" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 19:26:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="751487705" X-IronPort-AV: E=Sophos;i="5.98,322,1673942400"; d="scan'208";a="751487705" Received: from wufei-optiplex-7090.sh.intel.com ([10.238.200.247]) by fmsmga008.fm.intel.com with ESMTP; 05 Apr 2023 19:26:36 -0700 From: Fei Wu To: richard.henderson@linaro.org, pbonzini@redhat.com, alex.bennee@linaro.org, erdnaxe@crans.org, ma.mandourr@gmail.com, qemu-devel@nongnu.org Cc: Fei Wu Subject: [PATCH 1/2] accel/tcg/plugin: export host insn size Date: Thu, 6 Apr 2023 10:27:50 +0800 Message-Id: <20230406022751.757980-2-fei2.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230406022751.757980-1-fei2.wu@intel.com> References: <20230406022751.757980-1-fei2.wu@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.55.52.136; envelope-from=fei2.wu@intel.com; helo=mga12.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The translation ratio of host to guest instruction count is one of the key performance factor of binary translation. TCG doesn't collect host instruction count at present, it does collect host instruction size instead, although they are not the same thing as instruction size might not be fixed, instruction size is still a valid estimation. Signed-off-by: Fei Wu --- accel/tcg/plugin-gen.c | 1 + include/qemu/plugin.h | 2 ++ include/qemu/qemu-plugin.h | 8 ++++++++ plugins/api.c | 5 +++++ plugins/qemu-plugins.symbols | 1 + 5 files changed, 17 insertions(+) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 5efb8db258..4a3ca8fa2f 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -881,6 +881,7 @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, ptb->haddr2 = NULL; ptb->mem_only = mem_only; ptb->mem_helper = false; + ptb->host_insn_size = &db->tb->tc.size; plugin_gen_empty_callback(PLUGIN_GEN_FROM_TB); } diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index bc0781cab8..b38fd139e1 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -151,6 +151,8 @@ struct qemu_plugin_tb { /* if set, the TB calls helpers that might access guest memory */ bool mem_helper; + uint64_t *host_insn_size; + GArray *cbs[PLUGIN_N_CB_SUBTYPES]; }; diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 50a9957279..2397574a21 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -336,6 +336,14 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, */ size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb); +/** + * qemu_plugin_tb_n_insns() - query helper for host insns size in TB + * @tb: opaque handle to TB passed to callback + * + * Returns: address of host insns size of this block + */ +void *qemu_plugin_tb_host_insn_size(const struct qemu_plugin_tb *tb); + /** * qemu_plugin_tb_vaddr() - query helper for vaddr of TB start * @tb: opaque handle to TB passed to callback diff --git a/plugins/api.c b/plugins/api.c index 2078b16edb..0d70cb1f0f 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -188,6 +188,11 @@ size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb) return tb->n; } +void *qemu_plugin_tb_host_insn_size(const struct qemu_plugin_tb *tb) +{ + return tb->host_insn_size; +} + uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb) { return tb->vaddr; diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..3e92c3b8ba 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -39,6 +39,7 @@ qemu_plugin_start_code; qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; + qemu_plugin_tb_host_insn_size; qemu_plugin_tb_vaddr; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; From patchwork Thu Apr 6 02:27:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Fei" X-Patchwork-Id: 13202816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5F001C7618D for ; Thu, 6 Apr 2023 02:27:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkFL5-0005Tz-QX; Wed, 05 Apr 2023 22:27:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pkFKy-0005K8-Ms for qemu-devel@nongnu.org; Wed, 05 Apr 2023 22:26:57 -0400 Received: from mga12.intel.com ([192.55.52.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pkFKv-0007ho-Rx for qemu-devel@nongnu.org; Wed, 05 Apr 2023 22:26:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680748014; x=1712284014; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kDHQnfJgU6ibBWZVvy1+72aoPESwVWeS6Oj+qyGolVs=; b=L55vAleDs+ZSOZebTJrFhLtudRcfTGPxdyGiSKrnH4ahuZLuxzGkGeo9 ZywKxM2h30kyCP24bpF28mE+4ZodfOah9k2RyxokNyIloFW07FACiJgcG N9lH2MjbV7W1UGy4JJ/lzdK1KLXX4JD1W7B4M9AMy3hQWwAIrKRGlXtEc 3dPoI/ksAk1R3h4RwLeqGZjf/xVurUFnfw0gBNp0GQLUW58ZSCrsqWU4V sI+DPTjk/iEvN1Ri3oQj2eHMvQjkCC/p7bWY9HCALEt34CZwsK8sZ++gl loSdAOzwTjDqylMo2APoIqTOiZ2VQyWtsZaQOtJvHGEZeKvmDaZLzY+ww Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="322269685" X-IronPort-AV: E=Sophos;i="5.98,322,1673942400"; d="scan'208";a="322269685" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 19:26:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="751487715" X-IronPort-AV: E=Sophos;i="5.98,322,1673942400"; d="scan'208";a="751487715" Received: from wufei-optiplex-7090.sh.intel.com ([10.238.200.247]) by fmsmga008.fm.intel.com with ESMTP; 05 Apr 2023 19:26:42 -0700 From: Fei Wu To: richard.henderson@linaro.org, pbonzini@redhat.com, alex.bennee@linaro.org, erdnaxe@crans.org, ma.mandourr@gmail.com, qemu-devel@nongnu.org Cc: Fei Wu Subject: [PATCH 2/2] plugins/hotblocks: add host insn size Date: Thu, 6 Apr 2023 10:27:51 +0800 Message-Id: <20230406022751.757980-3-fei2.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230406022751.757980-1-fei2.wu@intel.com> References: <20230406022751.757980-1-fei2.wu@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.55.52.136; envelope-from=fei2.wu@intel.com; helo=mga12.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It's only valid when inline=false, otherwise it's default to 0. Signed-off-by: Fei Wu --- contrib/plugins/hotblocks.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c index 062200a7a4..c9716da7fe 100644 --- a/contrib/plugins/hotblocks.c +++ b/contrib/plugins/hotblocks.c @@ -37,6 +37,8 @@ typedef struct { uint64_t exec_count; int trans_count; unsigned long insns; + void *p_host_insn_size; + uint64_t host_insn_size; } ExecCount; static gint cmp_exec_count(gconstpointer a, gconstpointer b) @@ -59,13 +61,17 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) it = g_list_sort(counts, cmp_exec_count); if (it) { - g_string_append_printf(report, "pc, tcount, icount, ecount\n"); + g_string_append_printf(report, + "host isize is only valid when inline=false\n" + "pc, tcount, icount, ecount, host isize\n"); for (i = 0; i < limit && it->next; i++, it = it->next) { ExecCount *rec = (ExecCount *) it->data; - g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n", + g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRId64 + ", %"PRIu64"\n", rec->start_addr, rec->trans_count, - rec->insns, rec->exec_count); + rec->insns, rec->exec_count, + rec->host_insn_size); } g_list_free(it); @@ -82,14 +88,13 @@ static void plugin_init(void) static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - ExecCount *cnt; - uint64_t hash = (uint64_t) udata; + ExecCount *cnt = (ExecCount *) udata; g_mutex_lock(&lock); - cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash); - /* should always succeed */ - g_assert(cnt); cnt->exec_count++; + if (cnt->host_insn_size == 0) { + cnt->host_insn_size = *((uint64_t *)cnt->p_host_insn_size); + } g_mutex_unlock(&lock); } @@ -114,6 +119,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) cnt->start_addr = pc; cnt->trans_count = 1; cnt->insns = insns; + cnt->p_host_insn_size = qemu_plugin_tb_host_insn_size(tb); g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt); } @@ -125,7 +131,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, - (void *)hash); + (void *)cnt); } }