tracing,x86: Add a TSC trace_clock
authorDavid Sharp <dhsharp@google.com>
Tue, 13 Nov 2012 20:18:21 +0000 (12:18 -0800)
committerSteven Rostedt <rostedt@goodmis.org>
Tue, 13 Nov 2012 20:48:27 +0000 (15:48 -0500)
In order to promote interoperability between userspace tracers and ftrace,
add a trace_clock that reports raw TSC values which will then be recorded
in the ring buffer. Userspace tracers that also record TSCs are then on
exactly the same time base as the kernel and events can be unambiguously
interlaced.

Tested: Enabled a tracepoint and the "tsc" trace_clock and saw very large
timestamp values.

v2:
Move arch-specific bits out of generic code.
v3:
Rename "x86-tsc", cleanups
v7:
Generic arch bits in Kbuild.

Google-Bug-Id: 6980623
Link: http://lkml.kernel.org/r/1352837903-32191-1-git-send-email-dhsharp@google.com
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@linux.intel.com>
Signed-off-by: David Sharp <dhsharp@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
33 files changed:
arch/alpha/include/asm/Kbuild
arch/arm/include/asm/Kbuild
arch/arm64/include/asm/Kbuild
arch/avr32/include/asm/Kbuild
arch/blackfin/include/asm/Kbuild
arch/c6x/include/asm/Kbuild
arch/cris/include/asm/Kbuild
arch/frv/include/asm/Kbuild
arch/h8300/include/asm/Kbuild
arch/hexagon/include/asm/Kbuild
arch/ia64/include/asm/Kbuild
arch/m32r/include/asm/Kbuild
arch/m68k/include/asm/Kbuild
arch/microblaze/include/asm/Kbuild
arch/mips/include/asm/Kbuild
arch/mn10300/include/asm/Kbuild
arch/openrisc/include/asm/Kbuild
arch/parisc/include/asm/Kbuild
arch/powerpc/include/asm/Kbuild
arch/s390/include/asm/Kbuild
arch/score/include/asm/Kbuild
arch/sh/include/asm/Kbuild
arch/sparc/include/asm/Kbuild
arch/tile/include/asm/Kbuild
arch/um/include/asm/Kbuild
arch/unicore32/include/asm/Kbuild
arch/x86/include/asm/trace_clock.h [new file with mode: 0644]
arch/x86/kernel/Makefile
arch/x86/kernel/trace_clock.c [new file with mode: 0644]
arch/xtensa/include/asm/Kbuild
include/asm-generic/trace_clock.h [new file with mode: 0644]
include/linux/trace_clock.h
kernel/trace/trace.c

index 64ffc9e9e5485a41b29e0836773389582dfac2fe..dcfabb9f05a07f99301849838dd9d39d6f729db2 100644 (file)
@@ -11,3 +11,4 @@ header-y += reg.h
 header-y += regdef.h
 header-y += sysinfo.h
 generic-y += exec.h
+generic-y += trace_clock.h
index f70ae175a3d6414b2edb2ef9c717b07038d0d117..514e398f1a07a8124df0d6cf59bc1ed02b4adcf5 100644 (file)
@@ -31,5 +31,6 @@ generic-y += sockios.h
 generic-y += termbits.h
 generic-y += termios.h
 generic-y += timex.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += unaligned.h
index a581a2205938db09064604a53244b756ca650d0a..6e9ca462127fc40263d26dd0fc3f3ee7c9a862f2 100644 (file)
@@ -43,6 +43,7 @@ generic-y += swab.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
index 4807ded352c581ae20ea3407884ff92888093c55..4dd4f78d3dcc80a0799a96ab7fc629fe09b728ac 100644 (file)
@@ -1,3 +1,4 @@
 
 generic-y      += clkdev.h
 generic-y      += exec.h
+generic-y      += trace_clock.h
index 5a0625aad6a0a45fa773f2bffc9994b1c4577e4a..27d70759474c4e7a16313061c1036e4f4d15fefb 100644 (file)
@@ -38,6 +38,7 @@ generic-y += statfs.h
 generic-y += termbits.h
 generic-y += termios.h
 generic-y += topology.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += ucontext.h
 generic-y += unaligned.h
index 112a496d835589b27d3685cb1bf48768688a65a9..eae7b5963e860962fef1c91f3db98f150400b67b 100644 (file)
@@ -49,6 +49,7 @@ generic-y += termbits.h
 generic-y += termios.h
 generic-y += tlbflush.h
 generic-y += topology.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += ucontext.h
 generic-y += user.h
index 6d43a951b5ec0b5b217ca8a51405cfa274be5ffb..15a122c3767cb961b44fac15107ee7403ffbc6b4 100644 (file)
@@ -11,3 +11,4 @@ header-y += sync_serial.h
 generic-y += clkdev.h
 generic-y += exec.h
 generic-y += module.h
+generic-y += trace_clock.h
index 4a159da23633dbf359c9886513958ce49e842ce7..c5d76702830603f4d2fbde47e26412c179acfde6 100644 (file)
@@ -1,3 +1,4 @@
 
 generic-y += clkdev.h
 generic-y += exec.h
+generic-y += trace_clock.h
index 50bbf387b2f880d70a6783e8d7268eac764a4992..4bc8ae73e08a931b5441cadf0bad8a60cc9fa76f 100644 (file)
@@ -3,3 +3,4 @@ include include/asm-generic/Kbuild.asm
 generic-y += clkdev.h
 generic-y += exec.h
 generic-y += module.h
+generic-y += trace_clock.h
index 3bfa9b30f448b3f464d5087ba622f6dde4523446..bdb54ceb53bc9a8c564564cb2dfd2d3e0068db64 100644 (file)
@@ -48,6 +48,7 @@ generic-y += stat.h
 generic-y += termbits.h
 generic-y += termios.h
 generic-y += topology.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += ucontext.h
 generic-y += unaligned.h
index dd02f09b6eda6e2b41f1dd643a6ff550625a15e0..05b03ecd7933cdb87af9b532f15450ea024ec73f 100644 (file)
@@ -2,3 +2,4 @@
 generic-y += clkdev.h
 generic-y += exec.h
 generic-y += kvm_para.h
+generic-y += trace_clock.h
index 50bbf387b2f880d70a6783e8d7268eac764a4992..4bc8ae73e08a931b5441cadf0bad8a60cc9fa76f 100644 (file)
@@ -3,3 +3,4 @@ include include/asm-generic/Kbuild.asm
 generic-y += clkdev.h
 generic-y += exec.h
 generic-y += module.h
+generic-y += trace_clock.h
index 88fa3ac86fae9af988331112cba87ff711eb3555..7f1949c0e089e37bae15a368cda041ade22e509c 100644 (file)
@@ -24,6 +24,7 @@ generic-y += sections.h
 generic-y += siginfo.h
 generic-y += statfs.h
 generic-y += topology.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
index 8653072d7e9f061479c5b11c5de056337cfdac7a..2957fcc71764513e6c083a1f656efef1036a9678 100644 (file)
@@ -3,3 +3,4 @@ include include/asm-generic/Kbuild.asm
 header-y  += elf.h
 generic-y += clkdev.h
 generic-y += exec.h
+generic-y += trace_clock.h
index 533053d12cede054a47d225534b1a4ec34b07986..9b54b7a403d446b59073fe39fec03e0db7a432e8 100644 (file)
@@ -1 +1,2 @@
 # MIPS headers
+generic-y += trace_clock.h
index 4a159da23633dbf359c9886513958ce49e842ce7..c5d76702830603f4d2fbde47e26412c179acfde6 100644 (file)
@@ -1,3 +1,4 @@
 
 generic-y += clkdev.h
 generic-y += exec.h
+generic-y += trace_clock.h
index 78de6805268d1b6094986d02a7c790c35cb90f17..8971026e1c63fbee30dda6c1992176a63903e115 100644 (file)
@@ -60,6 +60,7 @@ generic-y += swab.h
 generic-y += termbits.h
 generic-y += termios.h
 generic-y += topology.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += ucontext.h
 generic-y += user.h
index bac8debecffb067ca8b550e0773a3c7c204d1e0b..ff4c9faed546da39c89d4bd6f1a851376a667040 100644 (file)
@@ -3,3 +3,4 @@ generic-y += word-at-a-time.h auxvec.h user.h cputime.h emergency-restart.h \
          segment.h topology.h vga.h device.h percpu.h hw_irq.h mutex.h \
          div64.h irq_regs.h kdebug.h kvm_para.h local64.h local.h param.h \
          poll.h xor.h clkdev.h exec.h
+generic-y += trace_clock.h
index a4fe15e33c6f0e34e49446d89329d9c5cfd37a61..2d62b484b3fcd0599ca9ed1fcddcdf7c70b26a61 100644 (file)
@@ -2,3 +2,4 @@
 
 generic-y += clkdev.h
 generic-y += rwsem.h
+generic-y += trace_clock.h
index 0633dc6d254da93deff0e73019740dd46c88af33..f313f9cbcf44fa410c88e85b17642a865bf39a74 100644 (file)
@@ -1,3 +1,4 @@
 
 
 generic-y += clkdev.h
+generic-y += trace_clock.h
index ec697aeefd05436f34647fa85d61293b7aa575d9..16e41fe1a419f88a13c0605f043effde7ea98595 100644 (file)
@@ -3,3 +3,4 @@ include include/asm-generic/Kbuild.asm
 header-y +=
 
 generic-y += clkdev.h
+generic-y += trace_clock.h
index 29f83beeef7a4c463d814ee445f73e47e2ff24b8..280bea9e5e2be362a7ff32a36cdd966b5f38ffe6 100644 (file)
@@ -31,5 +31,6 @@ generic-y += socket.h
 generic-y += statfs.h
 generic-y += termbits.h
 generic-y += termios.h
+generic-y += trace_clock.h
 generic-y += ucontext.h
 generic-y += xor.h
index 645a58da0e8601cf0765db0a2fc4091199da702b..e26d430ce2fdb94b7c85281db75367acf41e2321 100644 (file)
@@ -8,4 +8,5 @@ generic-y += local64.h
 generic-y += irq_regs.h
 generic-y += local.h
 generic-y += module.h
+generic-y += trace_clock.h
 generic-y += word-at-a-time.h
index 6948015e08a2af582a8a539438460951ea3c8b45..b17b9b8e53cdcab7a9eb4f7a95e86402c27f2812 100644 (file)
@@ -34,5 +34,6 @@ generic-y += sockios.h
 generic-y += statfs.h
 generic-y += termbits.h
 generic-y += termios.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += xor.h
index 0f6e7b32826522249f9dbd170e4f5c97cfd9a414..b30f34a79882c4413e77de1495bba161ed61a9af 100644 (file)
@@ -2,3 +2,4 @@ generic-y += bug.h cputime.h device.h emergency-restart.h futex.h hardirq.h
 generic-y += hw_irq.h irq_regs.h kdebug.h percpu.h sections.h topology.h xor.h
 generic-y += ftrace.h pci.h io.h param.h delay.h mutex.h current.h exec.h
 generic-y += switch_to.h clkdev.h
+generic-y += trace_clock.h
index c910c9857e114316991b2e9c711819a3939cdad5..7be503e4569589fc318b7f7e727c27f5c5718ace 100644 (file)
@@ -54,6 +54,7 @@ generic-y += syscalls.h
 generic-y += termbits.h
 generic-y += termios.h
 generic-y += topology.h
+generic-y += trace_clock.h
 generic-y += types.h
 generic-y += ucontext.h
 generic-y += unaligned.h
diff --git a/arch/x86/include/asm/trace_clock.h b/arch/x86/include/asm/trace_clock.h
new file mode 100644 (file)
index 0000000..5c16527
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _ASM_X86_TRACE_CLOCK_H
+#define _ASM_X86_TRACE_CLOCK_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#ifdef CONFIG_X86_TSC
+
+extern u64 notrace trace_clock_x86_tsc(void);
+
+# define ARCH_TRACE_CLOCKS \
+       { trace_clock_x86_tsc,  "x86-tsc" },
+
+#else /* !CONFIG_X86_TSC */
+
+#define ARCH_TRACE_CLOCKS
+
+#endif
+
+#endif  /* _ASM_X86_TRACE_CLOCK_H */
index 9fd5eed3f8f5d30bf9256cdc88719df06f4dee5d..34e923a537628777aa4e5ac90741bef6ef575633 100644 (file)
@@ -61,6 +61,7 @@ obj-$(CONFIG_X86_REBOOTFIXUPS)        += reboot_fixups_32.o
 obj-$(CONFIG_DYNAMIC_FTRACE)   += ftrace.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
 obj-$(CONFIG_FTRACE_SYSCALLS)  += ftrace.o
+obj-$(CONFIG_X86_TSC)          += trace_clock.o
 obj-$(CONFIG_KEXEC)            += machine_kexec_$(BITS).o
 obj-$(CONFIG_KEXEC)            += relocate_kernel_$(BITS).o crash.o
 obj-$(CONFIG_CRASH_DUMP)       += crash_dump_$(BITS).o
diff --git a/arch/x86/kernel/trace_clock.c b/arch/x86/kernel/trace_clock.c
new file mode 100644 (file)
index 0000000..25b9937
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * X86 trace clocks
+ */
+#include <asm/trace_clock.h>
+#include <asm/barrier.h>
+#include <asm/msr.h>
+
+/*
+ * trace_clock_x86_tsc(): A clock that is just the cycle counter.
+ *
+ * Unlike the other clocks, this is not in nanoseconds.
+ */
+u64 notrace trace_clock_x86_tsc(void)
+{
+       u64 ret;
+
+       rdtsc_barrier();
+       rdtscll(ret);
+
+       return ret;
+}
index 6d13027899957d528a142964db0b299d36b74a13..095f0a2244f7c473eba52ebafa66968d1fd4f10f 100644 (file)
@@ -25,4 +25,5 @@ generic-y += siginfo.h
 generic-y += statfs.h
 generic-y += termios.h
 generic-y += topology.h
+generic-y += trace_clock.h
 generic-y += xor.h
diff --git a/include/asm-generic/trace_clock.h b/include/asm-generic/trace_clock.h
new file mode 100644 (file)
index 0000000..6726f1b
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _ASM_GENERIC_TRACE_CLOCK_H
+#define _ASM_GENERIC_TRACE_CLOCK_H
+/*
+ * Arch-specific trace clocks.
+ */
+
+/*
+ * Additional trace clocks added to the trace_clocks
+ * array in kernel/trace/trace.c
+ * None if the architecture has not defined it.
+ */
+#ifndef ARCH_TRACE_CLOCKS
+# define ARCH_TRACE_CLOCKS
+#endif
+
+#endif  /* _ASM_GENERIC_TRACE_CLOCK_H */
index 4eb490237d4c20c0f65cae5581e2e07e8b8f2721..d563f37e1a1dfcfb3588c05b2117737448b3da18 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
 
+#include <asm/trace_clock.h>
+
 extern u64 notrace trace_clock_local(void);
 extern u64 notrace trace_clock(void);
 extern u64 notrace trace_clock_global(void);
index c1434b5ce4d1471e1122ec3121055aa73ebd820d..0d20620c0d2710882f6b2f6bfc2ee470cbc7a908 100644 (file)
@@ -488,6 +488,7 @@ static struct {
        { trace_clock_local,    "local" },
        { trace_clock_global,   "global" },
        { trace_clock_counter,  "counter" },
+       ARCH_TRACE_CLOCKS
 };
 
 int trace_clock_id;