[RFC PATCH 02/10] ftrace: Ensure tracing has really stopped before leaving unregister_ftrace_graph

From: Frederic Weisbecker
Date: Thu Jan 21 2010 - 20:19:09 EST


When we run under dynamic tracing, we know that after calling
unregister_ftrace_graph(), tracing has really stopped because of
the hot patching and use of stop_machine().

But in static tracing case, we only set stub callbacks. This is
not sufficient on archs that have weak memory ordering to assume
the older callbacks won't be called right after we leave
unregister_ftrace_graph().

Insert a read/write memory barrier in the end of
unregister_ftrace_graph() so that the code that follow can safely
assume tracing has really stopped. This can avoid its older tracing
callbacks to perform checks about various states like ensuring
needed buffers have been allocated, etc...

Signed-off-by: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Li Zefan <lizf@xxxxxxxxxxxxxx>
Cc: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
---
kernel/trace/ftrace.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index c050ce3..94117ec 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -3128,6 +3128,18 @@ void unregister_ftrace_graph(void)

out:
mutex_unlock(&ftrace_lock);
+
+ /*
+ * In dynamic tracing case, tracing is really stopped here.
+ * Otherwise we need to ensure ftrace_graph_return
+ * and ftrace_graph_entry are seen uptodate, so that code
+ * that follows unregister_ftrace_graph can safely assume
+ * tracing has stopped. This avoid wasteful checks of tracing
+ * states inside tracing callbacks.
+ */
+#ifndef CONFIG_DYNAMIC_FTRACE
+ smp_mb();
+#endif
}

/* Allocate a return stack for newly created task */
--
1.6.2.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/