4 * Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com>
7 #include <linux/module.h>
8 #include <linux/kallsyms.h>
9 #include <linux/uaccess.h>
10 #include <linux/ftrace.h>
11 #include <trace/events/sched.h>
16 static DEFINE_MUTEX(sched_register_mutex
);
19 probe_sched_switch(void *ignore
, struct task_struct
*prev
, struct task_struct
*next
)
21 if (unlikely(!sched_ref
))
24 tracing_record_cmdline(prev
);
25 tracing_record_cmdline(next
);
29 probe_sched_wakeup(void *ignore
, struct task_struct
*wakee
, int success
)
31 if (unlikely(!sched_ref
))
34 tracing_record_cmdline(current
);
37 static int tracing_sched_register(void)
41 ret
= register_trace_sched_wakeup(probe_sched_wakeup
, NULL
);
43 pr_info("wakeup trace: Couldn't activate tracepoint"
44 " probe to kernel_sched_wakeup\n");
48 ret
= register_trace_sched_wakeup_new(probe_sched_wakeup
, NULL
);
50 pr_info("wakeup trace: Couldn't activate tracepoint"
51 " probe to kernel_sched_wakeup_new\n");
55 ret
= register_trace_sched_switch(probe_sched_switch
, NULL
);
57 pr_info("sched trace: Couldn't activate tracepoint"
58 " probe to kernel_sched_switch\n");
59 goto fail_deprobe_wake_new
;
63 fail_deprobe_wake_new
:
64 unregister_trace_sched_wakeup_new(probe_sched_wakeup
, NULL
);
66 unregister_trace_sched_wakeup(probe_sched_wakeup
, NULL
);
70 static void tracing_sched_unregister(void)
72 unregister_trace_sched_switch(probe_sched_switch
, NULL
);
73 unregister_trace_sched_wakeup_new(probe_sched_wakeup
, NULL
);
74 unregister_trace_sched_wakeup(probe_sched_wakeup
, NULL
);
77 static void tracing_start_sched_switch(void)
79 mutex_lock(&sched_register_mutex
);
81 tracing_sched_register();
82 mutex_unlock(&sched_register_mutex
);
85 static void tracing_stop_sched_switch(void)
87 mutex_lock(&sched_register_mutex
);
89 tracing_sched_unregister();
90 mutex_unlock(&sched_register_mutex
);
93 void tracing_start_cmdline_record(void)
95 tracing_start_sched_switch();
98 void tracing_stop_cmdline_record(void)
100 tracing_stop_sched_switch();