[lttng-dev] [PATCH] Exporting the Trace Clock to Userspace for ARM architecture

Adeel Arshad adeel_arshad at mentor.com
Wed Feb 15 08:49:54 EST 2012


From: Adeel Arshad <adeel_arshad at mentor.com>
Date: Fri, 03 Feb 2012 21:16:16 +0500
Subject: [PATCH] Exporting the Trace Clock to Userspace for ARM architecture

Description: To synchronise the Time Stamps of Kernel Space and User Space traces generated by Lttng we need to use the same clock source. So by Adding a new Posix Clock mapped to Trace Clock we are making this Trace Clock available to User Space as well.

Signed-off-by: Adeel Arshad <adeel_arshad at mentor.com>
---
 kernel/Makefile                       |    2 +
 kernel/trace-clock.c                  |   56 ++++++++++++++++++++++++++++++++++
 mach-omap2/include/mach/trace-clock.h |   16 +++++++++
 plat-omap/include/plat/trace-clock.h  |   16 +++++++++
 4 files changed, 90 insertions(+)

diff -uprN -X modified/Documentation/dontdiff orig/arch/arm/kernel/Makefile modified/arch/arm/kernel/Makefile
--- orig/arch/arm/kernel/Makefile	2012-02-01 18:52:11.541452077 +0500
+++ modified/arch/arm/kernel/Makefile	2012-02-01 18:25:55.281859440 +0500
@@ -39,6 +39,8 @@ obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_ARM_UNWIND)	+= unwind.o
 obj-$(CONFIG_HAVE_TCM)		+= tcm.o
 
+obj-$(CONFIG_HAVE_TRACE_CLOCK)	+= trace-clock.o
+
 obj-$(CONFIG_CRUNCH)		+= crunch.o crunch-bits.o
 AFLAGS_crunch-bits.o		:= -Wa,-mcpu=ep9312
 
diff -uprN -X modified/Documentation/dontdiff orig/arch/arm/kernel/trace-clock.c modified/arch/arm/kernel/trace-clock.c
--- orig/arch/arm/kernel/trace-clock.c	1970-01-01 05:00:00.000000000 +0500
+++ modified/arch/arm/kernel/trace-clock.c	2012-02-03 16:31:22.739631674 +0500
@@ -0,0 +1,56 @@
+/*
+* arch/arm/kernel/trace-clock.c
+*
+* Exporting Trace clock to Userspace for ARM Architecture.
+*
+* Adeel Arshad <adeel_arshad at mentor.com>, January 2012
+*/
+
+#include <linux/module.h>
+#include <linux/trace-clock.h>
+#include <linux/timer.h>
+#include <linux/posix-timers.h>
+
+static int posix_get_trace(clockid_t which_clock, struct timespec *tp)
+{
+	union lttng_timespec *lts = (union lttng_timespec *) tp;
+
+	lts->lttng_ts = trace_clock_read64();
+	return 0;
+}
+
+static int posix_get_trace_freq(clockid_t which_clock, struct timespec *tp)
+{
+	union lttng_timespec *lts = (union lttng_timespec *) tp;
+
+	lts->lttng_ts = trace_clock_frequency();
+	return 0;
+}
+
+static int posix_get_trace_res(const clockid_t which_clock, struct timespec *tp)
+{
+	union lttng_timespec *lts = (union lttng_timespec *) tp;
+
+	lts->lttng_ts = TRACE_CLOCK_RES;
+	return 0;
+}
+
+static __init int init_trace_clock(void)
+{
+
+	struct k_clock clock_trace = {
+		.clock_getres = posix_get_trace_res,
+		.clock_get = posix_get_trace,
+	};
+	struct k_clock clock_trace_freq = {
+		.clock_getres = posix_get_trace_res,
+		.clock_get = posix_get_trace_freq,
+	};
+
+	register_posix_clock(CLOCK_TRACE, &clock_trace);
+	register_posix_clock(CLOCK_TRACE_FREQ, &clock_trace_freq);
+
+	return 0;
+}
+
+early_initcall(init_trace_clock);
diff -uprN -X modified/Documentation/dontdiff orig/arch/arm/mach-omap2/include/mach/trace-clock.h modified/arch/arm/mach-omap2/include/mach/trace-clock.h
--- orig/arch/arm/mach-omap2/include/mach/trace-clock.h	2012-02-01 18:52:11.414609282 +0500
+++ modified/arch/arm/mach-omap2/include/mach/trace-clock.h	2012-02-03 16:20:25.320061803 +0500
@@ -11,6 +11,22 @@
 #include <linux/timer.h>
 #include <plat/clock.h>
 
+#define TRACE_CLOCK_MIN_PROBE_DURATION 200
+#define TRACE_CLOCK_RES TRACE_CLOCK_MIN_PROBE_DURATION
+
+#ifndef CLOCK_TRACE_FREQ
+#define CLOCK_TRACE_FREQ	14
+#endif
+
+#ifndef CLOCK_TRACE
+#define CLOCK_TRACE	15
+#endif
+
+union lttng_timespec {
+	struct timespec ts;
+	u64 lttng_ts;
+};
+
 /*
  * Number of hardware clock bits. The higher order bits are expected to be 0.
  * If the hardware clock source has more than 32 bits, the bits higher than the
diff -uprN -X modified/Documentation/dontdiff orig/arch/arm/plat-omap/include/plat/trace-clock.h modified/arch/arm/plat-omap/include/plat/trace-clock.h
--- orig/arch/arm/plat-omap/include/plat/trace-clock.h	2012-02-01 18:52:11.429012673 +0500
+++ modified/arch/arm/plat-omap/include/plat/trace-clock.h	2012-02-03 16:24:00.458865642 +0500
@@ -11,6 +11,22 @@
 #include <linux/timer.h>
 #include <plat/clock.h>
 
+#define TRACE_CLOCK_MIN_PROBE_DURATION	200
+#define TRACE_CLOCK_RES	TRACE_CLOCK_MIN_PROBE_DURATION
+
+#ifndef CLOCK_TRACE_FREQ
+#define CLOCK_TRACE_FREQ	14
+#endif
+
+#ifndef CLOCK_TRACE
+#define CLOCK_TRACE	15
+#endif
+
+union lttng_timespec {
+	struct timespec ts;
+	u64 lttng_ts;
+};
+
 /*
  * Number of hardware clock bits. The higher order bits are expected to be 0.
  * If the hardware clock source has more than 32 bits, the bits higher than the





More information about the lttng-dev mailing list