From patchwork Thu Mar 27 16:37:30 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: 27229 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 88C82202FA for ; Thu, 27 Mar 2014 16:38:08 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id j17sf13729834oag.6 for ; Thu, 27 Mar 2014 09:38:08 -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=sYSH+bevZfiZPX+a42yLf5U5P0Gzbuwe+xyTRAjCNGo=; b=IhSsaeXFpQ/eZfcNOGKkklexK27PVu5aHD7pYJRQ7g3O0RJUEQX9m91Qh1wHfND0ck vkZp4SqQCWliBmOZxoCGHK2etrw6ycf9JSBWeGn1Q/fu7i1BQD4u+VnZmKF6MxamoSLr dafu8m8s5kALiFYEi+RDhzYQopT5wNaMGgppGS/FN5R6LwCaiYzXskyt4K9nrF1djE3L KHPoY5AHt11v4hJK/LGpHYvi0VWdBS3rYXH4l0T6PcnYstaI4LhRfku8f0VXJegFMRAZ K0+y+vlxzXYRgGi3vXo10m5FRgw0SGLgkjRXdZGaC3KG/4705qqBAB2Md+AoF5A6A/FY tHIg== X-Gm-Message-State: ALoCoQlWrSgiJueKR5ExlmNRuZXVQLuTpHKZfXBi2RCo5YrLPRBLsLOum8iqWOfvJ6ELRhQMc86p X-Received: by 10.50.164.198 with SMTP id ys6mr2013782igb.2.1395938288101; Thu, 27 Mar 2014 09:38:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.76 with SMTP id b70ls1098490qgd.97.gmail; Thu, 27 Mar 2014 09:38:07 -0700 (PDT) X-Received: by 10.58.161.101 with SMTP id xr5mr148391veb.36.1395938287936; Thu, 27 Mar 2014 09:38:07 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id of4si567454vcb.175.2014.03.27.09.38.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Mar 2014 09:38:07 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id oy12so4361871veb.40 for ; Thu, 27 Mar 2014 09:38:07 -0700 (PDT) X-Received: by 10.52.171.115 with SMTP id at19mr92240vdc.48.1395938287814; Thu, 27 Mar 2014 09:38:07 -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.220.78.9 with SMTP id i9csp42627vck; Thu, 27 Mar 2014 09:38:07 -0700 (PDT) X-Received: by 10.140.37.111 with SMTP id q102mr3129164qgq.77.1395938287415; Thu, 27 Mar 2014 09:38:07 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c3si1291774qan.40.2014.03.27.09.38.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 09:38:07 -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]:54881 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTDJe-0001rM-W7 for patch@linaro.org; Thu, 27 Mar 2014 12:38:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTDJA-0008KT-1r for qemu-devel@nongnu.org; Thu, 27 Mar 2014 12:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTDJ1-0002Sg-A0 for qemu-devel@nongnu.org; Thu, 27 Mar 2014 12:37:35 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:44648 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTDJ1-0002SK-41 for qemu-devel@nongnu.org; Thu, 27 Mar 2014 12:37:27 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1WTDJJ-0004ua-N8; Thu, 27 Mar 2014 17:37:45 +0100 From: alex.bennee@linaro.org To: qemu-devel@nongnu.org Date: Thu, 27 Mar 2014 16:37:30 +0000 Message-Id: <1395938253-9225-1-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 1.9.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: Yeongkyoon Lee , Alexander Graf , Kirill Batuzov , Blue Swirl , Stefan Weil , Anthony Liguori , Amit Shah , Matthew Fernandez , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [Qemu-devel] [RFC 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=neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 From: Alex Bennée 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. --- qemu-options.hx | 10 ++++++++++ tcg/tcg.c | 21 +++++++++++++++++++++ vl.c | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index c5577be..09fb1d0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2683,6 +2683,16 @@ Will dump output for any code in the 0x1000 sized block starting at 0x8000 and the 0x200 sized block starting at 0xffffffc000080000. 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 + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\n", QEMU_ARCH_ALL) diff --git a/tcg/tcg.c b/tcg/tcg.c index 57d2b82..a24f581 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -27,6 +27,8 @@ #define USE_TCG_OPTIMIZATIONS #include "config.h" +#include +#include /* Define to jump the ELF file used to communicate with GDB. */ #undef DEBUG_JIT @@ -106,6 +108,8 @@ static int tcg_target_const_match(tcg_target_long val, static void tcg_out_tb_init(TCGContext *s); static void tcg_out_tb_finalize(TCGContext *s); +static void tcg_write_perfmap(uint8_t *start, uint64_t size, uint64_t target_pc); +void qemu_tcg_enable_perfmap(void); TCGOpDef tcg_op_defs[] = { #define DEF(s, oargs, iargs, cargs, flags) { #s, oargs, iargs, cargs, iargs + oargs + cargs, flags }, @@ -2575,6 +2579,8 @@ static inline int tcg_gen_code_common(TCGContext *s, uint64_t target_pc, the_end: /* Generate TB finalization at the end of block */ tcg_out_tb_finalize(s); + + tcg_write_perfmap(gen_code_buf, s->code_ptr - gen_code_buf, target_pc); return -1; } @@ -2666,6 +2672,21 @@ void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf) } #endif +static FILE *tcg_perfmap = NULL; +void qemu_tcg_enable_perfmap(void) { + gchar * map_file = g_strdup_printf("/tmp/perf-%d.map", getpid()); + tcg_perfmap = g_fopen(map_file, "w"); + g_free(map_file); +} + +static void tcg_write_perfmap(uint8_t *start, uint64_t size, uint64_t target_pc) +{ + if (tcg_perfmap) { + g_fprintf(tcg_perfmap, "%lx %lx subject-0x%lx\n", + (uint64_t) start, size, target_pc); + } +} + #ifdef ELF_HOST_MACHINE /* In order to use this feature, the backend needs to do three things: diff --git a/vl.c b/vl.c index c036367..f1c3c3d 100644 --- a/vl.c +++ b/vl.c @@ -123,6 +123,9 @@ int main(int argc, char **argv) #define MAX_VIRTIO_CONSOLES 1 #define MAX_SCLP_CONSOLES 1 +/* seems better than pulling in all the tcg headers? */ +extern void qemu_tcg_enable_perfmap(void); + static const char *data_dir[16]; static int data_dir_idx; const char *bios_name = NULL; @@ -3345,6 +3348,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_DFILTER: qemu_set_dfilter_ranges(optarg); break; + case QEMU_OPTION_PERFMAP: + qemu_tcg_enable_perfmap(); + break; case QEMU_OPTION_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); break;