]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - rt-patches/0026-hwlat-detector-Use-trace_clock_local-if-available.patch
Fix memguard and related syscalls
[hercules2020/nv-tegra/linux-4.4.git] / rt-patches / 0026-hwlat-detector-Use-trace_clock_local-if-available.patch
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
5
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().
11
12 Signed-off-by: Steven Rostedt <srostedt@redhat.com>
13 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
14 ---
15  drivers/misc/hwlat_detector.c | 34 +++++++++++++++++++++++++---------
16  1 file changed, 25 insertions(+), 9 deletions(-)
17
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
22 @@ -51,6 +51,7 @@
23  #include <linux/version.h>
24  #include <linux/delay.h>
25  #include <linux/slab.h>
26 +#include <linux/trace_clock.h>
27  
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)
31         return sample;
32  }
33  
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)
41 +#else
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
48 +#endif
49  /**
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)
53   */
54  static int get_sample(void *unused)
55  {
56 -       ktime_t start, t1, t2, last_t2;
57 +       time_type start, t1, t2, last_t2;
58         s64 diff, total = 0;
59         u64 sample = 0;
60         u64 outer_sample = 0;
61         int ret = 1;
62  
63 -       last_t2.tv64 = 0;
64 -       start = ktime_get(); /* start timestamp */
65 +       init_time(last_t2, 0);
66 +       start = time_get(); /* start timestamp */
67  
68         do {
69  
70 -               t1 = ktime_get();       /* we'll look for a discontinuity */
71 -               t2 = ktime_get();
72 +               t1 = time_get();        /* we'll look for a discontinuity */
73 +               t2 = time_get();
74  
75 -               if (last_t2.tv64) {
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 */
81                         if (diff < 0) {
82                                 pr_err(BANNER "time running backwards\n");
83 @@ -247,10 +263,10 @@ static int get_sample(void *unused)
84                 }
85                 last_t2 = t2;
86  
87 -               total = ktime_to_us(ktime_sub(t2, start)); /* sample width */
88 +               total = time_to_us(time_sub(t2, start)); /* sample width */
89  
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 */
93  
94                 /* This shouldn't happen */
95                 if (diff < 0) {
96 -- 
97 1.9.1
98