From patchwork Mon Oct 26 10:15:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Tomer X-Patchwork-Id: 7486791 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E1DA1BEEA4 for ; Mon, 26 Oct 2015 10:18:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E10D220693 for ; Mon, 26 Oct 2015 10:18:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8B5320692 for ; Mon, 26 Oct 2015 10:18:17 +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 1ZqepS-0007kw-3l; Mon, 26 Oct 2015 10:16:38 +0000 Received: from mail-pa0-x242.google.com ([2607:f8b0:400e:c03::242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZqepO-0007j8-Fp for linux-arm-kernel@lists.infradead.org; Mon, 26 Oct 2015 10:16:35 +0000 Received: by padfb7 with SMTP id fb7so20995118pad.0 for ; Mon, 26 Oct 2015 03:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=+GvKd/O9dh6hk0Ar7SXIhGDP5M66OcZEwptJovtLrmU=; b=0loeh7rKlzocDt8XtuRqrPAo5C42cKmjpROjgwA78j3PAnGlywWGBjZ/3yqSmUvfKY sB4WskSW4Mjf+KH1ZA/MEyBi3x3gaiOf/vBwT/skAuiMKTx6/Aw+CO4AOroM9Y1I0jMR EMV8YNaOzWvGa6SLZUQ6/5jcc2s0y12WFlGi/qzpJ8meNceHA6SSoBz9AteBOz/Bd2qb c0XuaYxRBq9XLj/hN6ZL4PhIE6SZOtnGGApAnM5PIn8b8tHc3nHIOv9Y88aH6aqBqBLd 0Q+mM0vrsBw7zrvV63KLKZOSOdak84sWxT6Qe09gAbJUUc/szEmUYTZEItF3stNU5hpX fM3Q== X-Received: by 10.66.182.131 with SMTP id ee3mr20785898pac.81.1445854573425; Mon, 26 Oct 2015 03:16:13 -0700 (PDT) Received: from amit-OptiPlex-7010.mvista.com ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id ja4sm33090608pbb.19.2015.10.26.03.16.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Oct 2015 03:16:12 -0700 (PDT) From: Amit To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v1] Ftrace: arm/arm64: Define a new arm/arm64 trace clock source based on CNTPCT/CNTPCT_EL0 register. Date: Mon, 26 Oct 2015 15:45:58 +0530 Message-Id: <1445854558-16253-1-git-send-email-amittomer25@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151026_031634_569835_A3EDA8A1 X-CRM114-Status: GOOD ( 17.57 ) X-Spam-Score: 0.9 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marc.zyngier@arm.com, andre.przywara@arm.com, rostedt@goodmis.org, Amit Singh Tomar 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=-0.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SBL_CSS, RP_MATCHES_RCVD, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no 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 From: Amit Singh Tomar Define new arm/arm64 specific trace clock using CNTPCT/CNTPCT_EL0 register, similar to x86-tsc. It can be used to correlate trace events across hosts and guest that can be useful for debugging purpose. Signed-off-by: Amit Singh Tomar --- Changes since RFC: * Replaced define with static inline * Revert few changes done in ftrace.txt * Made it common between ARM and ARM64. --- Documentation/trace/ftrace.txt | 12 ++++++++++++ arch/arm/include/asm/Kbuild | 1 - arch/arm/include/asm/trace_clock.h | 21 +++++++++++++++++++++ arch/arm/kernel/Makefile | 2 ++ arch/arm/kernel/trace_clock.c | 33 +++++++++++++++++++++++++++++++++ arch/arm64/include/asm/Kbuild | 1 - arch/arm64/include/asm/trace_clock.h | 21 +++++++++++++++++++++ arch/arm64/kernel/Makefile | 2 ++ 8 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/trace_clock.h create mode 100644 arch/arm/kernel/trace_clock.c create mode 100644 arch/arm64/include/asm/trace_clock.h diff --git a/Documentation/trace/ftrace.txt b/Documentation/trace/ftrace.txt index ef621d3..13f3737 100644 --- a/Documentation/trace/ftrace.txt +++ b/Documentation/trace/ftrace.txt @@ -351,6 +351,18 @@ of ftrace. Here is a list of some of the key files: to correlate events across hypervisor/guest if tb_offset is known. + arm-pct: This uses ARM Physical Count register value.This + is different from default "local" clock which + usese Virtual Count register.This is consistent + across processors and can be used to correlate + events across host/guest. + + arm64-pct: This uses ARM64 Physical Timer Count register + value. This is different from default "local" + clock which usese Virtual Timer Count register. + This is consistent across processors and can be + used to correlate events across host/guest. + To set a clock, simply echo the clock name into this file. echo global > trace_clock diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild index be648eb..bc3964b 100644 --- a/arch/arm/include/asm/Kbuild +++ b/arch/arm/include/asm/Kbuild @@ -34,5 +34,4 @@ generic-y += sockios.h generic-y += termbits.h generic-y += termios.h generic-y += timex.h -generic-y += trace_clock.h generic-y += unaligned.h diff --git a/arch/arm/include/asm/trace_clock.h b/arch/arm/include/asm/trace_clock.h new file mode 100644 index 0000000..dc41f75 --- /dev/null +++ b/arch/arm/include/asm/trace_clock.h @@ -0,0 +1,21 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * Copyright (C) 2015 Amit Singh Tomar, amittomer25@gmail.com +*/ + +#ifndef _ASM_ARM_TRACE_CLOCK_H +#define _ASM_ARM_TRACE_CLOCK_H + +#include +#include + +extern u64 notrace trace_clock_arm_pct(void); + +# define ARCH_TRACE_CLOCKS \ + { trace_clock_arm_pct, "arm-pct", 0}, + +#endif /* _ASM_ARM_TRACE_CLOCK_H */ + diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index af9e59b..c3abf7c 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -92,4 +92,6 @@ obj-y += psci-call.o obj-$(CONFIG_SMP) += psci_smp.o endif +obj-$(CONFIG_TRACING) += trace_clock.o + extra-y := $(head-y) vmlinux.lds diff --git a/arch/arm/kernel/trace_clock.c b/arch/arm/kernel/trace_clock.c new file mode 100644 index 0000000..3bf040d --- /dev/null +++ b/arch/arm/kernel/trace_clock.c @@ -0,0 +1,33 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * Copyright (C) 2015 Amit Singh Tomar, amittomer25@gmail.com + * + * Thanks to Steven Rostedt and Andre Przywara! +*/ + +#include +#include +#include + +static inline u64 get_cntpct(void) +{ + u64 cycles; + + isb(); + asm volatile("mrs %0, cntpct_el0" : "=r" (cycles)); + + return cycles; +} + +u64 notrace trace_clock_arm_pct(void) +{ + return arch_counter_get_cntpct(); +} + +#ifdef CONFIG_ARM64 +u64 notrace trace_clock_arm64_pct(void) +{ + return get_cntpct(); +} +#endif diff --git a/arch/arm64/include/asm/Kbuild b/arch/arm64/include/asm/Kbuild index 70fd9ff..8608f9e 100644 --- a/arch/arm64/include/asm/Kbuild +++ b/arch/arm64/include/asm/Kbuild @@ -50,7 +50,6 @@ generic-y += switch_to.h generic-y += termbits.h generic-y += termios.h generic-y += topology.h -generic-y += trace_clock.h generic-y += types.h generic-y += unaligned.h generic-y += user.h diff --git a/arch/arm64/include/asm/trace_clock.h b/arch/arm64/include/asm/trace_clock.h new file mode 100644 index 0000000..aef4ccd --- /dev/null +++ b/arch/arm64/include/asm/trace_clock.h @@ -0,0 +1,21 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * Copyright (C) 2015 Amit Singh Tomar, amittomer25@gmail.com +*/ + +#ifndef _ASM_ARM_TRACE_CLOCK_H +#define _ASM_ARM_TRACE_CLOCK_H + +#include +#include + +extern u64 notrace trace_clock_arm64_pct(void); + +# define ARCH_TRACE_CLOCKS \ + { trace_clock_arm64_pct, "arm64-pct", 0}, + +#endif /* _ASM_ARM_TRACE_CLOCK_H */ + diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 22dc9bc..b23a149 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -10,6 +10,7 @@ CFLAGS_armv8_deprecated.o := -I$(src) CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_insn.o = -pg CFLAGS_REMOVE_return_address.o = -pg +ARM=../../../arch/arm/kernel # Object file lists. arm64-obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ @@ -36,6 +37,7 @@ arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o arm64-obj-$(CONFIG_ACPI) += acpi.o +arm64-obj-$(CONFIG_TRACING) += $(ARM)/trace_clock.o obj-y += $(arm64-obj-y) vdso/ obj-m += $(arm64-obj-m)