diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-05-12 15:20:46 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2008-05-23 14:42:41 -0400 |
commit | 53c37c17aafcf50f7c6fddaf01dda8f9d7e31ddf (patch) | |
tree | 69d04219218c263d43da88068342a4c91a757877 | |
parent | 750ed1a40783432d0dcb0e6c2e813a12615d7664 (diff) |
ftrace: fast, scalable, synchronized timestamps
implement globally synchronized, fast and scalable time source for tracing.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r-- | kernel/trace/trace.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index e3778ab0d3f7..9a931c7c2da3 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -42,9 +42,61 @@ ns2usecs(cycle_t nsec) | |||
42 | return nsec; | 42 | return nsec; |
43 | } | 43 | } |
44 | 44 | ||
45 | static const int time_sync_freq_max = 128; | ||
46 | static const cycle_t time_sync_thresh = 100000; | ||
47 | |||
48 | static DEFINE_PER_CPU(cycle_t, time_offset); | ||
49 | static DEFINE_PER_CPU(cycle_t, prev_cpu_time); | ||
50 | static DEFINE_PER_CPU(int, time_sync_count); | ||
51 | static DEFINE_PER_CPU(int, time_sync_freq); | ||
52 | |||
53 | /* | ||
54 | * Global lock which we take every now and then to synchronize | ||
55 | * the CPUs time. This method is not warp-safe, but it's good | ||
56 | * enough to synchronize slowly diverging time sources and thus | ||
57 | * it's good enough for tracing: | ||
58 | */ | ||
59 | static DEFINE_SPINLOCK(time_sync_lock); | ||
60 | static cycle_t prev_global_time; | ||
61 | |||
62 | static notrace cycle_t __ftrace_now_sync(cycles_t time, int cpu) | ||
63 | { | ||
64 | unsigned long flags; | ||
65 | |||
66 | spin_lock_irqsave(&time_sync_lock, flags); | ||
67 | |||
68 | /* | ||
69 | * Update the synchronization frequency: | ||
70 | */ | ||
71 | if (per_cpu(time_sync_freq, cpu) < time_sync_freq_max) | ||
72 | per_cpu(time_sync_freq, cpu) *= 2; | ||
73 | per_cpu(time_sync_count, cpu) = per_cpu(time_sync_freq, cpu); | ||
74 | |||
75 | if (time < prev_global_time) { | ||
76 | per_cpu(time_offset, cpu) += prev_global_time - time; | ||
77 | time = prev_global_time; | ||
78 | } else { | ||
79 | prev_global_time = time; | ||
80 | } | ||
81 | |||
82 | spin_unlock_irqrestore(&time_sync_lock, flags); | ||
83 | |||
84 | return time; | ||
85 | } | ||
86 | |||
45 | notrace cycle_t ftrace_now(int cpu) | 87 | notrace cycle_t ftrace_now(int cpu) |
46 | { | 88 | { |
47 | return cpu_clock(cpu); | 89 | cycle_t prev_cpu_time, time, delta_time; |
90 | |||
91 | prev_cpu_time = per_cpu(prev_cpu_time, cpu); | ||
92 | time = sched_clock() + per_cpu(time_offset, cpu); | ||
93 | delta_time = time-prev_cpu_time; | ||
94 | |||
95 | if (unlikely(delta_time > time_sync_thresh || | ||
96 | --per_cpu(time_sync_count, cpu) <= 0)) | ||
97 | time = __ftrace_now_sync(time, cpu); | ||
98 | |||
99 | return time; | ||
48 | } | 100 | } |
49 | 101 | ||
50 | static atomic_t tracer_counter; | 102 | static atomic_t tracer_counter; |