Skip to content

Commit

Permalink
tracing,x86: Add a TSC trace_clock
Browse files Browse the repository at this point in the history
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/[email protected]

Acked-by: Ingo Molnar <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Signed-off-by: David Sharp <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
David Sharp authored and rostedt committed Nov 13, 2012
1 parent 7bcfaf5 commit 8cbd9cc
Show file tree
Hide file tree
Showing 33 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/alpha/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/arm/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/arm64/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/avr32/include/asm/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

generic-y += clkdev.h
generic-y += exec.h
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/blackfin/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions arch/c6x/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions arch/cris/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/frv/include/asm/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

generic-y += clkdev.h
generic-y += exec.h
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/h8300/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/hexagon/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions arch/ia64/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
generic-y += clkdev.h
generic-y += exec.h
generic-y += kvm_para.h
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/m32r/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/m68k/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/microblaze/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/mips/include/asm/Kbuild
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# MIPS headers
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/mn10300/include/asm/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

generic-y += clkdev.h
generic-y += exec.h
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/openrisc/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions arch/parisc/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/powerpc/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

generic-y += clkdev.h
generic-y += rwsem.h
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/s390/include/asm/Kbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@


generic-y += clkdev.h
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/score/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include include/asm-generic/Kbuild.asm
header-y +=

generic-y += clkdev.h
generic-y += trace_clock.h
1 change: 1 addition & 0 deletions arch/sh/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/sparc/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/tile/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/um/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions arch/unicore32/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions arch/x86/include/asm/trace_clock.h
Original file line number Diff line number Diff line change
@@ -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 */
1 change: 1 addition & 0 deletions arch/x86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions arch/x86/kernel/trace_clock.c
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions arch/xtensa/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions include/asm-generic/trace_clock.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 2 additions & 0 deletions include/linux/trace_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8cbd9cc

Please sign in to comment.