From patchwork Fri Jul 11 16:43:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 369207 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 4A3131400EA for ; Sat, 12 Jul 2014 02:43:40 +1000 (EST) Received: from localhost ([::1]:45888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5dv8-0006Y0-AZ for incoming@patchwork.ozlabs.org; Fri, 11 Jul 2014 12:43:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5duo-0006Gt-7u for qemu-devel@nongnu.org; Fri, 11 Jul 2014 12:43:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X5dui-0000Pk-1y for qemu-devel@nongnu.org; Fri, 11 Jul 2014 12:43:18 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:41910 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5duh-0000Oz-Sp for qemu-devel@nongnu.org; Fri, 11 Jul 2014 12:43:12 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1X5dzl-0000fW-OV; Fri, 11 Jul 2014 18:48:25 +0200 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 11 Jul 2014 17:43:59 +0100 Message-Id: <1405097039-9524-1-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.0.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 88.198.71.155 Cc: batuzovk@ispras.ru, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Anthony Liguori , rth@twiddle.net Subject: [Qemu-devel] [PATCH] tcg: add ability to dump /tmp/perf-.map files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This allows the perf tool to map samples to each individual translation block. This could be expanded for user space but currently it gives enough information to find any hotblocks by other means. Signed-off-by: Alex Bennée --- v2: - hoist up into translate-all.c - don't use pointless glib wrappers - use proper format types for portability - mark prologue/epilog area - rebase --- qemu-options.hx | 10 ++++++++++ translate-all.c | 27 +++++++++++++++++++++++++++ vl.c | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index c2c0823..b8c81e3 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3220,6 +3220,16 @@ STEXI prepend a timestamp to each log message.(default:on) ETEXI +DEF("perfmap", 0, QEMU_OPTION_PERFMAP, \ + "-perfmap generate a /tmp/perf-${pid}.map file for perf\n", + QEMU_ARCH_ALL) +STEXI +@item -perfmap +@findex -perfmap +This will cause QEMU to generate a map file for Linux perf tools that will allow +basic profiling information to be broken down into basic blocks. +ETEXI + HXCOMM This is the last statement. Insert new options before this line! STEXI @end table diff --git a/translate-all.c b/translate-all.c index 5549a85..0c7cbbe 100644 --- a/translate-all.c +++ b/translate-all.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "config.h" @@ -129,6 +130,25 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, tb_page_addr_t phys_page2); static TranslationBlock *tb_find_pc(uintptr_t tc_ptr); +static FILE *tb_perfmap = NULL; +/* if I could put this in a header easily.... */ +void tb_enable_perfmap(void); + +void tb_enable_perfmap(void) { + gchar * map_file = g_strdup_printf("/tmp/perf-%d.map", getpid()); + tb_perfmap = fopen(map_file, "w"); + g_free(map_file); +} + +static void tb_write_perfmap(tcg_insn_unit *start, int size, target_ulong pc) +{ + if (tb_perfmap) { + fprintf(tb_perfmap, + "%"PRIxPTR" %x subject-"TARGET_FMT_lx"\n", + (uintptr_t) start, size, pc); + } +} + void cpu_gen_init(void) { tcg_context_init(&tcg_ctx); @@ -184,6 +204,7 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr s->code_out_len += gen_code_size; #endif + tb_write_perfmap(gen_code_buf, gen_code_size, tb->pc); #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) { qemu_log("OUT: [size=%d]\n", gen_code_size); @@ -584,6 +605,12 @@ static inline void code_gen_alloc(size_t tb_size) tcg_ctx.code_gen_buffer_size - 1024; tcg_ctx.code_gen_buffer_size -= 1024; + if (tb_perfmap) { + fprintf(tb_perfmap, + "%"PRIxPTR" %x tcg-prologue-buffer\n", + (uintptr_t) tcg_ctx.code_gen_prologue, 1024); + } + tcg_ctx.code_gen_buffer_max_size = tcg_ctx.code_gen_buffer_size - (TCG_MAX_OP_SIZE * OPC_BUF_SIZE); tcg_ctx.code_gen_max_blocks = tcg_ctx.code_gen_buffer_size / diff --git a/vl.c b/vl.c index d8c1572..7650ec8 100644 --- a/vl.c +++ b/vl.c @@ -118,6 +118,9 @@ int main(int argc, char **argv) #include "qapi/string-input-visitor.h" #include "qom/object_interfaces.h" +/* Not sure where the best place for this is? */ +extern void tb_enable_perfmap(void); + #define DEFAULT_RAM_SIZE 128 #define MAX_VIRTIO_CONSOLES 1 @@ -3387,6 +3390,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_D: log_file = optarg; break; + case QEMU_OPTION_PERFMAP: + tb_enable_perfmap(); + break; case QEMU_OPTION_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); break;