diff mbox

powerpc/ftrace: add powerpc timebase as a trace clock source

Message ID 1429771504-32688-1-git-send-email-naveen.n.rao@linux.vnet.ibm.com (mailing list archive)
State Changes Requested
Delegated to: Michael Ellerman
Headers show

Commit Message

Naveen N. Rao April 23, 2015, 6:45 a.m. UTC
Add a new powerpc-specific trace clock using the timebase register,
similar to x86-tsc. This gives us
- a fast, monotonic, hardware clock source for trace entries, and
- a clock that can be used to correlate events across cpus as well as across
  hypervisor and guests.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
Changes since RFC: Updated description.
Previous discussion: http://thread.gmane.org/gmane.linux.ports.ppc.embedded/80409

Steve,
Can you please provide your ack for this?

Thanks,
Naveen


 Documentation/trace/ftrace.txt         |  5 +++++
 arch/powerpc/include/asm/Kbuild        |  1 -
 arch/powerpc/include/asm/trace_clock.h | 27 +++++++++++++++++++++++++++
 arch/powerpc/kernel/Makefile           |  1 +
 arch/powerpc/kernel/trace_clock.c      | 15 +++++++++++++++
 5 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/include/asm/trace_clock.h
 create mode 100644 arch/powerpc/kernel/trace_clock.c

Comments

Steven Rostedt April 23, 2015, 1:10 p.m. UTC | #1
On Thu, 23 Apr 2015 12:15:04 +0530
"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote:

> diff --git a/arch/powerpc/include/asm/trace_clock.h b/arch/powerpc/include/asm/trace_clock.h
> new file mode 100644
> index 0000000..0b0d094
> --- /dev/null
> +++ b/arch/powerpc/include/asm/trace_clock.h
> @@ -0,0 +1,27 @@
> +/*
> + * 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 Naveen N. Rao, IBM Corporation
> + */
> +
> +#ifndef _ASM_PPC_TRACE_CLOCK_H
> +#define _ASM_PPC_TRACE_CLOCK_H
> +
> +#include <linux/compiler.h>
> +#include <linux/types.h>
> +
> +#ifdef CONFIG_TRACE_CLOCK

You don't need this #if statement. What else is using this besides
kernel/trace/trace.c, which selects TRACE_CLOCK if it is compiled.

If you were trying to match x86, where it has:

#ifdef CONFIG_X86_TSC

where you have CONFIG_TRACE_CLOCK. We needed the #ifdef because you
can compile the x86 kernel without TSC support, and we did not want to
export a tsc tracing clock if one did not exist.

And the only place that I see that even includes this header in ppc, is
also only compiled if CONFIG_TRACE_CLOCK is selected.

I'm fine with the change, just nuke the unnecessary #ifdef.

-- Steve



> +
> +extern u64 notrace trace_clock_ppc_tb(void);
> +
> +#define ARCH_TRACE_CLOCKS { trace_clock_ppc_tb, "ppc-tb", 0 },
> +
> +#else
> +
> +#define ARCH_TRACE_CLOCKS
> +
> +#endif /* CONFIG_TRACE_CLOCK */
> +
> +#endif  /* _ASM_PPC_TRACE_CLOCK_H */
> diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
> index 502cf69..f9936f3 100644
> --- a/arch/powerpc/kernel/Makefile
> +++ b/arch/powerpc/kernel/Makefile
> @@ -118,6 +118,7 @@ obj-$(CONFIG_PPC_IO_WORKAROUNDS)	+= io-workarounds.o
>  obj-$(CONFIG_DYNAMIC_FTRACE)	+= ftrace.o
>  obj-$(CONFIG_FUNCTION_GRAPH_TRACER)	+= ftrace.o
>  obj-$(CONFIG_FTRACE_SYSCALLS)	+= ftrace.o
> +obj-$(CONFIG_TRACE_CLOCK)	+= trace_clock.o
>  
>  ifneq ($(CONFIG_PPC_INDIRECT_PIO),y)
>  obj-y				+= iomap.o
> diff --git a/arch/powerpc/kernel/trace_clock.c b/arch/powerpc/kernel/trace_clock.c
> new file mode 100644
> index 0000000..4917069
> --- /dev/null
> +++ b/arch/powerpc/kernel/trace_clock.c
> @@ -0,0 +1,15 @@
> +/*
> + * 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 Naveen N. Rao, IBM Corporation
> + */
> +
> +#include <asm/trace_clock.h>
> +#include <asm/time.h>
> +
> +u64 notrace trace_clock_ppc_tb(void)
> +{
> +	return get_tb();
> +}
Naveen N. Rao April 24, 2015, 8:07 a.m. UTC | #2
On 2015/04/23 09:10AM, Steven Rostedt wrote:
> On Thu, 23 Apr 2015 12:15:04 +0530
> "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote:
> 
> > diff --git a/arch/powerpc/include/asm/trace_clock.h b/arch/powerpc/include/asm/trace_clock.h
> > new file mode 100644
> > index 0000000..0b0d094
> > --- /dev/null
> > +++ b/arch/powerpc/include/asm/trace_clock.h
> > @@ -0,0 +1,27 @@
> > +/*
> > + * 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 Naveen N. Rao, IBM Corporation
> > + */
> > +
> > +#ifndef _ASM_PPC_TRACE_CLOCK_H
> > +#define _ASM_PPC_TRACE_CLOCK_H
> > +
> > +#include <linux/compiler.h>
> > +#include <linux/types.h>
> > +
> > +#ifdef CONFIG_TRACE_CLOCK
> 
> You don't need this #if statement. What else is using this besides
> kernel/trace/trace.c, which selects TRACE_CLOCK if it is compiled.
> 
> If you were trying to match x86, where it has:
> 
> #ifdef CONFIG_X86_TSC
> 
> where you have CONFIG_TRACE_CLOCK. We needed the #ifdef because you
> can compile the x86 kernel without TSC support, and we did not want to
> export a tsc tracing clock if one did not exist.
> 
> And the only place that I see that even includes this header in ppc, is
> also only compiled if CONFIG_TRACE_CLOCK is selected.

Ah yes, agreed. I have removed it and seeing as CONFIG_TRACE_CLOCK is 
really for the generic clocks, I have moved the dependency on 
arch/powerpc/kernel/trace_clock.o to CONFIG_TRACING since that is what 
gates kernel/trace/trace.o

> 
> I'm fine with the change, just nuke the unnecessary #ifdef.

Thanks for the review!
- Naveen
diff mbox

Patch

diff --git a/Documentation/trace/ftrace.txt b/Documentation/trace/ftrace.txt
index 572ca92..689f61a 100644
--- a/Documentation/trace/ftrace.txt
+++ b/Documentation/trace/ftrace.txt
@@ -346,6 +346,11 @@  of ftrace. Here is a list of some of the key files:
 	  x86-tsc: Architectures may define their own clocks. For
 	  	   example, x86 uses its own TSC cycle clock here.
 
+	  ppc-tb: This uses the powerpc timebase register value.
+		  This is in sync across CPUs and can also be used
+		  to correlate events across hypervisor/guest if
+		  tb_offset is known.
+
 	To set a clock, simply echo the clock name into this file.
 
 	  echo global > trace_clock
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 382b28e..5041c66 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -5,5 +5,4 @@  generic-y += mcs_spinlock.h
 generic-y += preempt.h
 generic-y += rwsem.h
 generic-y += scatterlist.h
-generic-y += trace_clock.h
 generic-y += vtime.h
diff --git a/arch/powerpc/include/asm/trace_clock.h b/arch/powerpc/include/asm/trace_clock.h
new file mode 100644
index 0000000..0b0d094
--- /dev/null
+++ b/arch/powerpc/include/asm/trace_clock.h
@@ -0,0 +1,27 @@ 
+/*
+ * 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 Naveen N. Rao, IBM Corporation
+ */
+
+#ifndef _ASM_PPC_TRACE_CLOCK_H
+#define _ASM_PPC_TRACE_CLOCK_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#ifdef CONFIG_TRACE_CLOCK
+
+extern u64 notrace trace_clock_ppc_tb(void);
+
+#define ARCH_TRACE_CLOCKS { trace_clock_ppc_tb, "ppc-tb", 0 },
+
+#else
+
+#define ARCH_TRACE_CLOCKS
+
+#endif /* CONFIG_TRACE_CLOCK */
+
+#endif  /* _ASM_PPC_TRACE_CLOCK_H */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 502cf69..f9936f3 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -118,6 +118,7 @@  obj-$(CONFIG_PPC_IO_WORKAROUNDS)	+= io-workarounds.o
 obj-$(CONFIG_DYNAMIC_FTRACE)	+= ftrace.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER)	+= ftrace.o
 obj-$(CONFIG_FTRACE_SYSCALLS)	+= ftrace.o
+obj-$(CONFIG_TRACE_CLOCK)	+= trace_clock.o
 
 ifneq ($(CONFIG_PPC_INDIRECT_PIO),y)
 obj-y				+= iomap.o
diff --git a/arch/powerpc/kernel/trace_clock.c b/arch/powerpc/kernel/trace_clock.c
new file mode 100644
index 0000000..4917069
--- /dev/null
+++ b/arch/powerpc/kernel/trace_clock.c
@@ -0,0 +1,15 @@ 
+/*
+ * 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 Naveen N. Rao, IBM Corporation
+ */
+
+#include <asm/trace_clock.h>
+#include <asm/time.h>
+
+u64 notrace trace_clock_ppc_tb(void)
+{
+	return get_tb();
+}