From f6c19f6e88428f2885ee53b892cad3f237993fba Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 10 May 2011 23:16:21 -0400 Subject: [PATCH] Add fallback wrapper for kernels without CONFIG_HAVE_TRACE_CLOCK Signed-off-by: Mathieu Desnoyers --- ltt-ring-buffer-client.h | 2 +- ltt-tracer.h | 2 +- trace-clock.h | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 trace-clock.h diff --git a/ltt-ring-buffer-client.h b/ltt-ring-buffer-client.h index c2e53f35..248cee0e 100644 --- a/ltt-ring-buffer-client.h +++ b/ltt-ring-buffer-client.h @@ -10,7 +10,7 @@ #include #include -#include +#include "trace-clock.h" #include "ltt-events.h" #include "ltt-tracer.h" diff --git a/ltt-tracer.h b/ltt-tracer.h index 2f947b7e..ef5e815b 100644 --- a/ltt-tracer.h +++ b/ltt-tracer.h @@ -16,10 +16,10 @@ #include #include #include -#include #include #include +#include "trace-clock.h" #include "ltt-tracer-core.h" #include "ltt-events.h" diff --git a/trace-clock.h b/trace-clock.h new file mode 100644 index 00000000..ca09704d --- /dev/null +++ b/trace-clock.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * Contains LTTng trace clock mapping to LTTng trace clock or mainline monotonic + * clock. This wrapper depends on CONFIG_HIGH_RES_TIMERS=y. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#ifndef _LTT_TRACE_CLOCK_H +#define _LTT_TRACE_CLOCK_H + +#ifdef CONFIG_HAVE_TRACE_CLOCK +#include +#else /* CONFIG_HAVE_TRACE_CLOCK */ + +#include +#include +#include +#include + +static inline u64 trace_clock_monotonic_wrapper(void) +{ + ktime_t ktime; + + /* + * Refuse to trace from NMIs with this wrapper, because an NMI could + * nest over the xtime write seqlock and deadlock. + */ + if (in_nmi()) + return 0; + + ktime = ktime_get(); + return (u64) ktime.tv64; +} + +static inline u32 trace_clock_read32(void) +{ + return (u32) trace_clock_monotonic_wrapper(); +} + +static inline u64 trace_clock_read64(void) +{ + return (u64) trace_clock_monotonic_wrapper(); +} + +static inline u64 trace_clock_frequency(void) +{ + return (u64)NSEC_PER_SEC; +} + +static inline u32 trace_clock_freq_scale(void) +{ + return 1; +} + +static inline int get_trace_clock(void) +{ + printk(KERN_WARNING "LTTng: Using mainline kernel monotonic clock.\n"); + printk(KERN_WARNING " * NMIs will not be traced,\n"); + printk(KERN_WARNING " * expect significant performance degradation compared to the\n"); + printk(KERN_WARNING " LTTng trace clocks.\n"); + printk(KERN_WARNING "You should consider deploying a kernel with the the LTTng kernel\n"); + printk(KERN_WARNING "patches, or, better, ask the Linux tracing maintainers to integrate\n"); + printk(KERN_WARNING "them if you care deeply about this.\n"); + return 0; +} + +static inline void put_trace_clock(void) +{ +} + +#endif /* CONFIG_HAVE_TRACE_CLOCK */ + +#endif /* _LTT_TRACE_CLOCK_H */ -- 2.34.1