From patchwork Fri Jun 27 14:57:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 4435791 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8DCF6BEECB for ; Fri, 27 Jun 2014 15:00:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CF6320377 for ; Fri, 27 Jun 2014 15:00:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CBB682026F for ; Fri, 27 Jun 2014 15:00:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X0Xbu-0004u1-0K; Fri, 27 Jun 2014 14:58:42 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X0Xbf-0004iN-Uj for linux-arm-kernel@lists.infradead.org; Fri, 27 Jun 2014 14:58:28 +0000 Received: by mail-wi0-f177.google.com with SMTP id r20so2913520wiv.16 for ; Fri, 27 Jun 2014 07:58:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IZgBsz6hy6WGWNEfms+q/wyUURR2jlMWejdzGMVT9lc=; b=Oz3gQjCweGRf68Vl+ukB3v/Wf68GxICQA6Yy8EbgCHP4KoXZ9V04X3B7Ja0EWEE4df CvhqVPqfio3+MUqunSbiCqRX4PODKdWRKMbfQDv6ORZECFZrBgP3XVNA0E8W1TnSduO7 +S0MI+m0wzsU/Ds5ffoiZKFBr2Fs5WYidUjsnALmKgIJpHebU1PW9hK4mtdKqHbU9kiu DgL8I/Qn4+fJtr1UYl0PXDSii9Bdu1dw/bW4UbFfiGVBqxqECUd9EDKiVx6nfy4QXIga o33nh8to6+3sePKbi5y1AHrIvuIVR3Q7b8KhQcfwIY/3s+zwhZVt8MiCLtnf7++VKMLo l0Bg== X-Gm-Message-State: ALoCoQle41ZGofXSaeaSWWSfqpKyyVSL2fbd+czPo3qtAjKzeLp67zCRAh8qCZtyndWPaDBDrDlX X-Received: by 10.194.63.228 with SMTP id j4mr25726116wjs.7.1403881089314; Fri, 27 Jun 2014 07:58:09 -0700 (PDT) Received: from localhost.localdomain (216.193-240-81.adsl-dyn.isp.belgacom.be. [81.240.193.216]) by mx.google.com with ESMTPSA id 19sm21920749wjz.3.2014.06.27.07.58.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Jun 2014 07:58:08 -0700 (PDT) From: Jean Pihet To: Will Deacon , linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, Sneha Priya , linux-kernel@vger.kernel.org, Jiri Olsa , Arnaldo Carvalho de Melo Subject: [PATCH 3/3] ARM: perf: allow tracing with kernel tracepoints events Date: Fri, 27 Jun 2014 16:57:47 +0200 Message-Id: <1403881067-22690-4-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1403881067-22690-1-git-send-email-jean.pihet@linaro.org> References: <1403881067-22690-1-git-send-email-jean.pihet@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140627_075828_139354_C92F3A00 X-CRM114-Status: GOOD ( 12.97 ) X-Spam-Score: -0.7 (/) Cc: Jean Pihet X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When tracing with tracepoints events the IP and CPSR are set to 0, preventing the perf code to resolve the symbols: ./perf record -e kmem:kmalloc cal [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.007 MB perf.data (~321 samples) ] ./perf report Overhead Command Shared Object Symbol ........ ....... ............. ........... 40.78% cal [unknown] [.]00000000 31.6% cal [unknown] [.]00000000 The examination of the gathered samples (perf report -D) shows the IP is set to 0 and that the samples are considered as user space samples, while the IP should be set from the registers and the samples should be considered as kernel samples. The fix is to implement perf_arch_fetch_caller_regs for ARM, which fills the necessary registers used for the callchain unwinding and to determine the user/kernel space property of the samples: ip, sp, fp and cpsr. Tested with perf record and tracepoints triggering (-e ), with unwinding using fp (--call-graph fp) and dwarf info (--call-graph dwarf). Reported by Sneha Priya on linaro-dev, cf. http://lists.linaro.org/pipermail/linaro-dev/2014-May/017151.html Signed-off-by: Jean Pihet Cc: Will Deacon Reported-by: Sneha Priya --- arch/arm/include/asm/perf_event.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/arm/include/asm/perf_event.h b/arch/arm/include/asm/perf_event.h index 7558775..b02b5d3 100644 --- a/arch/arm/include/asm/perf_event.h +++ b/arch/arm/include/asm/perf_event.h @@ -26,6 +26,25 @@ struct pt_regs; extern unsigned long perf_instruction_pointer(struct pt_regs *regs); extern unsigned long perf_misc_flags(struct pt_regs *regs); #define perf_misc_flags(regs) perf_misc_flags(regs) + +/* + * Take a snapshot of the regs. + * We only need a few of the regs: + * - ip for PERF_SAMPLE_IP, + * - sp & fp for fp & dwarf based callchain unwinding, + * - cpsr for user_mode() tests. + */ +#define perf_arch_fetch_caller_regs(regs, __ip) { \ + instruction_pointer(regs)= (__ip); \ + __asm__ ( \ + "str sp, %[_ARM_sp] \n\t" \ + "str fp, %[_ARM_fp] \n\t" \ + "mrs %[_ARM_cpsr], cpsr \n\t" \ + : [_ARM_sp] "=m" (regs->ARM_sp), \ + [_ARM_fp] "=m" (regs->ARM_fp), \ + [_ARM_cpsr] "=r" (regs->ARM_cpsr) \ + ); \ +} #endif #endif /* __ARM_PERF_EVENT_H__ */