summaryrefslogtreecommitdiffstats
path: root/samples/trace_events/trace-events-sample.c
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2015-02-09 16:32:19 -0500
committerSteven Rostedt <rostedt@goodmis.org>2015-02-09 18:05:39 -0500
commit6adc13f8c096736957444ffa2aa11421b5671aef (patch)
tree705f6ba74c25d29405f80e339a6562c81d145018 /samples/trace_events/trace-events-sample.c
parentc4c7eb29382c456b9be9858c357a490ae0ccd0f6 (diff)
downloadtalos-obmc-linux-6adc13f8c096736957444ffa2aa11421b5671aef.tar.gz
talos-obmc-linux-6adc13f8c096736957444ffa2aa11421b5671aef.zip
tracing: Add TRACE_EVENT_FN example
If a function should be called before a tracepoint is enabled and/or after it is disabled, the TRACE_EVENT_FN() serves this purpose. But it is not well documented. Having it as a sample would help developers to know how to use it. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'samples/trace_events/trace-events-sample.c')
-rw-r--r--samples/trace_events/trace-events-sample.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c
index c396a49b5d78..39d4484aef53 100644
--- a/samples/trace_events/trace-events-sample.c
+++ b/samples/trace_events/trace-events-sample.c
@@ -49,6 +49,52 @@ static int simple_thread(void *arg)
}
static struct task_struct *simple_tsk;
+static struct task_struct *simple_tsk_fn;
+
+static void simple_thread_func_fn(int cnt)
+{
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout(HZ);
+
+ /* More silly tracepoints */
+ trace_foo_bar_with_fn("Look at me", cnt);
+}
+
+static int simple_thread_fn(void *arg)
+{
+ int cnt = 0;
+
+ while (!kthread_should_stop())
+ simple_thread_func_fn(cnt++);
+
+ return 0;
+}
+
+static DEFINE_MUTEX(thread_mutex);
+
+void foo_bar_reg(void)
+{
+ pr_info("Starting thread for foo_bar_fn\n");
+ /*
+ * We shouldn't be able to start a trace when the module is
+ * unloading (there's other locks to prevent that). But
+ * for consistency sake, we still take the thread_mutex.
+ */
+ mutex_lock(&thread_mutex);
+ simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn");
+ mutex_unlock(&thread_mutex);
+}
+
+void foo_bar_unreg(void)
+{
+ pr_info("Killing thread for foo_bar_fn\n");
+ /* protect against module unloading */
+ mutex_lock(&thread_mutex);
+ if (simple_tsk_fn)
+ kthread_stop(simple_tsk_fn);
+ simple_tsk_fn = NULL;
+ mutex_unlock(&thread_mutex);
+}
static int __init trace_event_init(void)
{
@@ -62,6 +108,11 @@ static int __init trace_event_init(void)
static void __exit trace_event_exit(void)
{
kthread_stop(simple_tsk);
+ mutex_lock(&thread_mutex);
+ if (simple_tsk_fn)
+ kthread_stop(simple_tsk_fn);
+ simple_tsk_fn = NULL;
+ mutex_unlock(&thread_mutex);
}
module_init(trace_event_init);
OpenPOWER on IntegriCloud