From patchwork Tue Jul 15 11:34:58 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: 33657 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 798B2201F1 for ; Tue, 15 Jul 2014 11:34:46 +0000 (UTC) Received: by mail-oi0-f69.google.com with SMTP id h136sf657079oig.4 for ; Tue, 15 Jul 2014 04:34:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id :mime-version:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=MHTZacvrt1cyYgDhqPJkcUKHrIHZUJ80IvMTYPDvE6Q=; b=EHT8u2Ipjm3RHPzp4vZ+kjAOZJrndyoGYjY7iI5Oz8JbBs3mJGv0LumSXGYn01rVbJ COTxXwzjaWVMo2OX/QVJEafKt3MHi7V2Z1f9lX5IjNzXQpFFa1dSJ9LQfRAV5loSxDw2 1BrPkncD7qHfXDvBrnQsAfpCQWQunLQENj83ySqkzOPNIBCw6ulewcwdLcHW39H7T1K5 JQc455f9CeulYPt4M+lA1lWfQlV75nu4YN8vVyBsdkd7fKiHD9S3bc4syUA+Uv3D9LdT sn8X3vKrtTw/CdEZpbOXg9gAdNxn/DY754gkIcZijfJasemoHg/w4iTSAz9w7FlLa/+0 S+rg== X-Gm-Message-State: ALoCoQkY2fE4g+naAJOVJFOfYvtGrzk+nNncfIbBzJzCujT3XIUO9TkldXw/96fBoSH1lXfE/rJA X-Received: by 10.182.241.169 with SMTP id wj9mr10963062obc.14.1405424086051; Tue, 15 Jul 2014 04:34:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.18.194 with SMTP id 60ls64371qgf.7.gmail; Tue, 15 Jul 2014 04:34:45 -0700 (PDT) X-Received: by 10.58.143.69 with SMTP id sc5mr134539veb.64.1405424085954; Tue, 15 Jul 2014 04:34:45 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id sg10si6529300vec.88.2014.07.15.04.34.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jul 2014 04:34:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so6179577vcb.1 for ; Tue, 15 Jul 2014 04:34:45 -0700 (PDT) X-Received: by 10.220.166.9 with SMTP id k9mr21680405vcy.20.1405424085833; Tue, 15 Jul 2014 04:34:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp207053vcb; Tue, 15 Jul 2014 04:34:45 -0700 (PDT) X-Received: by 10.229.137.137 with SMTP id w9mr34619171qct.3.1405424085267; Tue, 15 Jul 2014 04:34:45 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b9si19864484qad.117.2014.07.15.04.34.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 15 Jul 2014 04:34:45 -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; Received: from localhost ([::1]:34040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X710O-0008F8-TU for patch@linaro.org; Tue, 15 Jul 2014 07:34:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X70zs-0007wn-QC for qemu-devel@nongnu.org; Tue, 15 Jul 2014 07:34:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X70zn-0006TO-V0 for qemu-devel@nongnu.org; Tue, 15 Jul 2014 07:34:12 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:59298 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X70zn-0006T5-Ot for qemu-devel@nongnu.org; Tue, 15 Jul 2014 07:34:07 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1X715m-0007rW-S0; Tue, 15 Jul 2014 13:40:19 +0200 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 15 Jul 2014 12:34:58 +0100 Message-Id: <1405424098-20703-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?= , viro@ZenIV.linux.org.uk, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 v3: - fix bracket for perf-map - find an include for the tb_enable_perfmap() declaration --- include/qemu-common.h | 2 ++ qemu-options.hx | 10 ++++++++++ translate-all.c | 26 ++++++++++++++++++++++++++ vl.c | 4 ++++ 4 files changed, 42 insertions(+) diff --git a/include/qemu-common.h b/include/qemu-common.h index 66ceceb..ffacd5a 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -259,6 +259,8 @@ typedef struct PCIHostDeviceAddress { void tcg_exec_init(unsigned long tb_size); bool tcg_enabled(void); +void tb_enable_perfmap(void); + void cpu_exec_init_all(void); /* CPU save/load. */ 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..11d3f28 100644 --- a/translate-all.c +++ b/translate-all.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "config.h" @@ -129,6 +130,24 @@ 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; + +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 +203,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 +604,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..bc840d1 100644 --- a/vl.c +++ b/vl.c @@ -117,6 +117,7 @@ int main(int argc, char **argv) #include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" #include "qom/object_interfaces.h" +#include "qemu-common.h" #define DEFAULT_RAM_SIZE 128 @@ -3387,6 +3388,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;