1 From 5a4e0bc5e940b628a8c7e5146dd3ec1a8ed7c1bf Mon Sep 17 00:00:00 2001
2 From: Steven Rostedt <rostedt@goodmis.org>
3 Date: Mon, 19 Aug 2013 17:33:26 -0400
4 Subject: [PATCH 026/366] hwlat-detector: Use trace_clock_local if available
6 As ktime_get() calls into the timing code which does a read_seq(), it
7 may be affected by other CPUS that touch that lock. To remove this
8 dependency, use the trace_clock_local() which is already exported
9 for module use. If CONFIG_TRACING is enabled, use that as the clock,
10 otherwise use ktime_get().
12 Signed-off-by: Steven Rostedt <srostedt@redhat.com>
13 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
15 drivers/misc/hwlat_detector.c | 34 +++++++++++++++++++++++++---------
16 1 file changed, 25 insertions(+), 9 deletions(-)
18 diff --git a/drivers/misc/hwlat_detector.c b/drivers/misc/hwlat_detector.c
19 index c07e859..0fcc0e3 100644
20 --- a/drivers/misc/hwlat_detector.c
21 +++ b/drivers/misc/hwlat_detector.c
23 #include <linux/version.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 +#include <linux/trace_clock.h>
28 #define BUF_SIZE_DEFAULT 262144UL /* 8K*(sizeof(entry)) */
29 #define BUF_FLAGS (RB_FL_OVERWRITE) /* no block on full */
30 @@ -211,6 +212,21 @@ static struct sample *buffer_get_sample(struct sample *sample)
34 +#ifndef CONFIG_TRACING
35 +#define time_type ktime_t
36 +#define time_get() ktime_get()
37 +#define time_to_us(x) ktime_to_us(x)
38 +#define time_sub(a, b) ktime_sub(a, b)
39 +#define init_time(a, b) (a).tv64 = b
40 +#define time_u64(a) ((a).tv64)
42 +#define time_type u64
43 +#define time_get() trace_clock_local()
44 +#define time_to_us(x) div_u64(x, 1000)
45 +#define time_sub(a, b) ((a) - (b))
46 +#define init_time(a, b) (a = b)
47 +#define time_u64(a) a
50 * get_sample - sample the CPU TSC and look for likely hardware latencies
51 * @unused: This is not used but is a part of the stop_machine API
52 @@ -220,23 +236,23 @@ static struct sample *buffer_get_sample(struct sample *sample)
54 static int get_sample(void *unused)
56 - ktime_t start, t1, t2, last_t2;
57 + time_type start, t1, t2, last_t2;
64 - start = ktime_get(); /* start timestamp */
65 + init_time(last_t2, 0);
66 + start = time_get(); /* start timestamp */
70 - t1 = ktime_get(); /* we'll look for a discontinuity */
72 + t1 = time_get(); /* we'll look for a discontinuity */
76 + if (time_u64(last_t2)) {
77 /* Check the delta from outer loop (t2 to next t1) */
78 - diff = ktime_to_us(ktime_sub(t1, last_t2));
79 + diff = time_to_us(time_sub(t1, last_t2));
80 /* This shouldn't happen */
82 pr_err(BANNER "time running backwards\n");
83 @@ -247,10 +263,10 @@ static int get_sample(void *unused)
87 - total = ktime_to_us(ktime_sub(t2, start)); /* sample width */
88 + total = time_to_us(time_sub(t2, start)); /* sample width */
90 /* This checks the inner loop (t1 to t2) */
91 - diff = ktime_to_us(ktime_sub(t2, t1)); /* current diff */
92 + diff = time_to_us(time_sub(t2, t1)); /* current diff */
94 /* This shouldn't happen */