Skip to contentSkip to conversation

output minimum function trace overhead

PATCH New Jan Kiszka 1 participant 1 message Jan 8, 2007

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 2/2 output minimum function trace overhead

This patch calibrates the best-case overhead a function trace point introduces and dumps the result at the beginning of each tracer output. Should give the reader of some trace an idea what the instrumentation /at least/ costed per entry.

Jan

---
 kernel/ipipe/tracer.c |   25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
kernel/ipipe/tracer.c +23 -2
Index: linux-2.6.19-ipipe/kernel/ipipe/tracer.c
===================================================================
@@ -129,6 +129,7 @@ static int pre_trace = IPIPE_DEFAULT_PRE
 static int post_trace = IPIPE_DEFAULT_POST_TRACE;
 static int back_trace = IPIPE_DEFAULT_BACK_TRACE;
 static int verbose_trace;
+static unsigned long trace_overhead;
 
 static DEFINE_MUTEX(out_mutex);
 static struct ipipe_trace_path *print_path;
@@ -824,6 +825,9 @@ static void __ipipe_print_dbgwarning(str
 
 static void __ipipe_print_headline(struct seq_file *m)
 {
+	seq_printf(m, "Calibrated minimum trace-point overhead: %lu.%03lu "
+		   "us\n\n", trace_overhead/1000, trace_overhead%1000);
+
 	if (verbose_trace) {
 		const char *name[4] = { [0 ... 3] = "<unused>" };
 		struct list_head *pos;
@@ -917,7 +921,7 @@ static void *__ipipe_max_prtrace_start(s
 			UTS_RELEASE, IPIPE_ARCH_STRING);
 		__ipipe_print_dbgwarning(m);
 		seq_printf(m, "Begin: %lld cycles, Trace Points: %d (-%d/+%d), "
-			"Length: %lu us\n\n",
+			"Length: %lu us\n",
 			print_path->point[print_path->begin].timestamp,
 			points, print_pre_trace, print_post_trace, length_usecs);
 		__ipipe_print_headline(m);
@@ -1073,7 +1077,7 @@ static void *__ipipe_frozen_prtrace_star
 			"------\n",
 			UTS_RELEASE, IPIPE_ARCH_STRING);
 		__ipipe_print_dbgwarning(m);
-		seq_printf(m, "Freeze: %lld cycles, Trace Points: %d (+%d)\n\n",
+		seq_printf(m, "Freeze: %lld cycles, Trace Points: %d (+%d)\n",
 			print_path->point[print_path->begin].timestamp,
 			print_pre_trace+1, print_post_trace);
 		__ipipe_print_headline(m);
@@ -1200,6 +1204,8 @@ void __init __ipipe_init_tracer(void)
 {
 	struct proc_dir_entry *trace_dir;
 	struct proc_dir_entry *entry;
+	unsigned long long start, end, min = ULLONG_MAX;
+	int i;
 #ifdef CONFIG_IPIPE_TRACE_VMALLOC
 	int cpu, path;
 
@@ -1221,6 +1227,21 @@ void __init __ipipe_init_tracer(void)
 	ipipe_trace_enable = CONFIG_IPIPE_TRACE_ENABLE_VALUE;
 #endif /* CONFIG_IPIPE_TRACE_VMALLOC */
 
+	/* Calculate minimum overhead of __ipipe_trace() */
+	local_irq_disable_hw();
+	for (i = 0; i < 100; i++) {
+		ipipe_read_tsc(start);
+		__ipipe_trace(IPIPE_TRACE_FUNC, __BUILTIN_RETURN_ADDRESS0,
+			      __BUILTIN_RETURN_ADDRESS1, 0);
+		ipipe_read_tsc(end);
+
+		end -= start;
+		if (end < min)
+			min = end;
+	}
+	local_irq_enable_hw();
+	trace_overhead = ipipe_tsc2ns(min);
+
 	trace_dir = create_proc_entry("trace", S_IFDIR, ipipe_proc_root);
 
 	entry = create_proc_entry("max", 0644, trace_dir);