aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-05-12 21:20:46 +0200
committerThomas Gleixner <tglx@linutronix.de>2008-05-23 20:42:41 +0200
commit53c37c17aafcf50f7c6fddaf01dda8f9d7e31ddf (patch)
tree69d04219218c263d43da88068342a4c91a757877
parent750ed1a40783432d0dcb0e6c2e813a12615d7664 (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.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index e3778ab0d3f..9a931c7c2da 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -42,9 +42,61 @@ ns2usecs(cycle_t nsec)
return nsec;
}
+static const int time_sync_freq_max = 128;
+static const cycle_t time_sync_thresh = 100000;
+
+static DEFINE_PER_CPU(cycle_t, time_offset);
+static DEFINE_PER_CPU(cycle_t, prev_cpu_time);
+static DEFINE_PER_CPU(int, time_sync_count);
+static DEFINE_PER_CPU(int, time_sync_freq);
+
+/*
+ * Global lock which we take every now and then to synchronize
+ * the CPUs time. This method is not warp-safe, but it's good
+ * enough to synchronize slowly diverging time sources and thus
+ * it's good enough for tracing:
+ */
+static DEFINE_SPINLOCK(time_sync_lock);
+static cycle_t prev_global_time;
+
+static notrace cycle_t __ftrace_now_sync(cycles_t time, int cpu)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&time_sync_lock, flags);
+
+ /*
+ * Update the synchronization frequency:
+ */
+ if (per_cpu(time_sync_freq, cpu) < time_sync_freq_max)
+ per_cpu(time_sync_freq, cpu) *= 2;
+ per_cpu(time_sync_count, cpu) = per_cpu(time_sync_freq, cpu);
+
+ if (time < prev_global_time) {
+ per_cpu(time_offset, cpu) += prev_global_time - time;
+ time = prev_global_time;
+ } else {
+ prev_global_time = time;
+ }
+
+ spin_unlock_irqrestore(&time_sync_lock, flags);
+
+ return time;
+}
+
notrace cycle_t ftrace_now(int cpu)
{
- return cpu_clock(cpu);
+ cycle_t prev_cpu_time, time, delta_time;
+
+ prev_cpu_time = per_cpu(prev_cpu_time, cpu);
+ time = sched_clock() + per_cpu(time_offset, cpu);
+ delta_time = time-prev_cpu_time;
+
+ if (unlikely(delta_time > time_sync_thresh ||
+ --per_cpu(time_sync_count, cpu) <= 0))
+ time = __ftrace_now_sync(time, cpu);
+
+ return time;
}
static atomic_t tracer_counter;