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, bool preempt,
20 struct task_struct *prev, struct task_struct *next)
22 if (unlikely(!sched_ref))
25 tracing_record_cmdline(prev);
26 tracing_record_cmdline(next);
30 probe_sched_wakeup(void *ignore, struct task_struct *wakee)
32 if (unlikely(!sched_ref))
35 tracing_record_cmdline(current);
38 static int tracing_sched_register(void)
42 ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
44 pr_info("wakeup trace: Couldn't activate tracepoint"
45 " probe to kernel_sched_wakeup\n");
49 ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
51 pr_info("wakeup trace: Couldn't activate tracepoint"
52 " probe to kernel_sched_wakeup_new\n");
56 ret = register_trace_sched_switch(probe_sched_switch, NULL);
58 pr_info("sched trace: Couldn't activate tracepoint"
59 " probe to kernel_sched_switch\n");
60 goto fail_deprobe_wake_new;
64 fail_deprobe_wake_new:
65 unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
67 unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
71 static void tracing_sched_unregister(void)
73 unregister_trace_sched_switch(probe_sched_switch, NULL);
74 unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
75 unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
78 static void tracing_start_sched_switch(void)
80 mutex_lock(&sched_register_mutex);
82 tracing_sched_register();
83 mutex_unlock(&sched_register_mutex);
86 static void tracing_stop_sched_switch(void)
88 mutex_lock(&sched_register_mutex);
90 tracing_sched_unregister();
91 mutex_unlock(&sched_register_mutex);
94 void tracing_start_cmdline_record(void)
96 tracing_start_sched_switch();
99 void tracing_stop_cmdline_record(void)
101 tracing_stop_sched_switch();