From patchwork Mon Jul 7 13:45:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 4494891 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 83E519F392 for ; Mon, 7 Jul 2014 13:48:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B27252022A for ; Mon, 7 Jul 2014 13:48:03 +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 E274020221 for ; Mon, 7 Jul 2014 13:48:02 +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 1X49FD-0003uM-Gz; Mon, 07 Jul 2014 13:46:11 +0000 Received: from mail-we0-f175.google.com ([74.125.82.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X49Ex-0003ae-Pv for linux-arm-kernel@lists.infradead.org; Mon, 07 Jul 2014 13:45:56 +0000 Received: by mail-we0-f175.google.com with SMTP id k48so4382978wev.6 for ; Mon, 07 Jul 2014 06:45:33 -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=5kY2DlYH8UYzk3tIVqBMMITsG1Y2ZREbuhEGhXP3o2I=; b=WLkwZXIX8AnhGzUF17VESLNhcSxl77iIPAzXO2d1T49Z2c/WMxOx+osvrcW2HDcI+x cU3LcKrwkq+6vGbthmq/UOAuR/BUL2cZde8AhLT8U4+kyYVCWhLmlntWSRzS7kd7wFAo 7XTkAdvW4CzOKPDR0WhGt13oihY4te8lcKL8FOrlUA5QSeWMFu+0LJdwmNttN8QdUmID 1HI4HyrC7mxMTS2MRroS31+mZIpsHdC7WYQUPZnuRgNVAvhv6s27X1M0e9sdIRhpqIta gDkZOlgqasW/pyI1BqIxwLo5ZOSWmwqKezLJ2Hc4rMYRFPFAUaSMB/pp8om0ZjqUsXhV hFJA== X-Gm-Message-State: ALoCoQmEAzpJq5tACBvsUyLE7rO6krjDOCj9gmKhDr4w01q0+oCSmi1kykteNSLeQnro9v+lHj7v X-Received: by 10.194.82.198 with SMTP id k6mr32906889wjy.10.1404740733411; Mon, 07 Jul 2014 06:45:33 -0700 (PDT) Received: from rachael.linaro.local ([213.122.173.130]) by mx.google.com with ESMTPSA id e18sm26653901wic.0.2014.07.07.06.45.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jul 2014 06:45:32 -0700 (PDT) From: Jean Pihet To: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Will Deacon Subject: [PATCH 3/3] ARM: perf: allow tracing with kernel tracepoints events Date: Mon, 7 Jul 2014 15:45:10 +0200 Message-Id: <1404740710-14691-4-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1404740710-14691-1-git-send-email-jean.pihet@linaro.org> References: <1404740710-14691-1-git-send-email-jean.pihet@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140707_064556_060586_B9E1F3DD X-CRM114-Status: GOOD ( 13.66 ) X-Spam-Score: -0.7 (/) Cc: Arnaldo Carvalho de Melo , steve.capper@linaro.org, Jean Pihet , Jiri Olsa , Ingo Molnar 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=-2.6 required=5.0 tests=BAYES_00,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: - program counter for PERF_SAMPLE_IP, as used by dwarf unwinding, - sp & fp for fp based callchain unwinding, - cpsr for user_mode() tests. 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 Cc: Steve Capper 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: + * - program counter for PERF_SAMPLE_IP, as used by dwarf unwinding, + * - sp & fp for fp 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__ */