From patchwork Mon Aug 3 09:14:41 2015 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: 51854 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 1A7FD229FD for ; Mon, 3 Aug 2015 09:20:46 +0000 (UTC) Received: by lbcjf8 with SMTP id jf8sf42158740lbc.0 for ; Mon, 03 Aug 2015 02:20:45 -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:in-reply-to :references:mime-version:content-type:content-transfer-encoding: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; bh=FeRRCchCSktWB2gvObXrJd7QxNAOfoOZ9GCCuEjOlZ8=; b=Q1lwrJo7Xchnoc66CFucrM5lLrC17v+Odjrdg2eYCBTWxzzo89mNE+m3nQVynqpY4j PUfpBxvj1JG8Fil4HTqh/TVfaMOhfyWiIabzTssNbSrmC282Q6LeoNg9svl4jcW4f7Pu c5oBb9vuy0gvDbZQRrROzIrzdRExgeJz0tfXeczMwif/l6aCGXPmN7u4tn01E6doz6+x S/PMCjsFWCQmLObuX29ifuasw/Qu8ifs1qVaJkuDaWnNxoObsgwcDDTXduoykuAvI2Px ErTVIERsSPyqprizNqWe9n4TF+sv7v/98agNSqXCg4f1QxAp5hImYWGEXQcIDdl4CZaG X1DA== X-Gm-Message-State: ALoCoQmdHOemQayToXA/mnUiNHtB8JoWZ+Y4W+y5WgW0x5lg6zcXVkqGwBnW1LR9qfnkp3RjYBLU X-Received: by 10.180.160.133 with SMTP id xk5mr5538790wib.1.1438593645013; Mon, 03 Aug 2015 02:20:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.199 with SMTP id m7ls550069lam.83.gmail; Mon, 03 Aug 2015 02:20:44 -0700 (PDT) X-Received: by 10.153.6.44 with SMTP id cr12mr15579113lad.92.1438593644852; Mon, 03 Aug 2015 02:20:44 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id vk4si11425428lbb.147.2015.08.03.02.20.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2015 02:20:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by labgo9 with SMTP id go9so23389328lab.3 for ; Mon, 03 Aug 2015 02:20:44 -0700 (PDT) X-Received: by 10.112.125.34 with SMTP id mn2mr14302988lbb.76.1438593644693; Mon, 03 Aug 2015 02:20:44 -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.112.7.198 with SMTP id l6csp1755810lba; Mon, 3 Aug 2015 02:20:43 -0700 (PDT) X-Received: by 10.50.108.43 with SMTP id hh11mr20622962igb.83.1438593643079; Mon, 03 Aug 2015 02:20:43 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e11si13494181iod.74.2015.08.03.02.20.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 03 Aug 2015 02:20:43 -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]:58226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMBvF-0006gq-SG for patch@linaro.org; Mon, 03 Aug 2015 05:20:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMBpt-0005OB-Pb for qemu-devel@nongnu.org; Mon, 03 Aug 2015 05:15:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMBpo-0003AK-Nj for qemu-devel@nongnu.org; Mon, 03 Aug 2015 05:15:09 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:38544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMBpo-00038x-Fi for qemu-devel@nongnu.org; Mon, 03 Aug 2015 05:15:04 -0400 Received: by wibxm9 with SMTP id xm9so105249630wib.1 for ; Mon, 03 Aug 2015 02:15:04 -0700 (PDT) X-Received: by 10.180.20.71 with SMTP id l7mr32614450wie.32.1438593303860; Mon, 03 Aug 2015 02:15:03 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id ed10sm12549872wic.0.2015.08.03.02.15.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2015 02:15:02 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 3BC733E0456; Mon, 3 Aug 2015 10:15:00 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 3 Aug 2015 10:14:41 +0100 Message-Id: <1438593291-27109-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1438593291-27109-1-git-send-email-alex.bennee@linaro.org> References: <1438593291-27109-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.181 Cc: qemu-trivial@nongnu.org, crosthwaitepeter@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , aurelien@aurel32.net, rth@twiddle.net Subject: [Qemu-devel] [PATCH v4 01/11] 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.215.50 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 - checkpatch clean-ups --- include/qemu-common.h | 2 ++ qemu-options.hx | 9 +++++++++ translate-all.c | 26 ++++++++++++++++++++++++++ vl.c | 4 ++++ 4 files changed, 41 insertions(+) diff --git a/include/qemu-common.h b/include/qemu-common.h index fb3da6c..60b87d0 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -382,6 +382,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 77f5853..ae53346 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3572,6 +3572,15 @@ to the RNG daemon. 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 diff --git a/translate-all.c b/translate-all.c index 60a3d8b..c05e2a5 100644 --- a/translate-all.c +++ b/translate-all.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "config.h" @@ -133,6 +134,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; + +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); @@ -190,6 +209,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); @@ -669,6 +689,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 0adbbd6..1d2de4f 100644 --- a/vl.c +++ b/vl.c @@ -122,6 +122,7 @@ int main(int argc, char **argv) #include "qapi-event.h" #include "exec/semihost.h" #include "crypto/init.h" +#include "qemu-common.h" #define MAX_VIRTIO_CONSOLES 1 #define MAX_SCLP_CONSOLES 1 @@ -3348,6 +3349,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;