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>
15 #define RECORD_CMDLINE 1
18 static int sched_cmdline_ref;
19 static int sched_tgid_ref;
20 static DEFINE_MUTEX(sched_register_mutex);
23 probe_sched_switch(void *ignore, bool preempt,
24 struct task_struct *prev, struct task_struct *next)
28 flags = (RECORD_TGID * !!sched_tgid_ref) +
29 (RECORD_CMDLINE * !!sched_cmdline_ref);
33 tracing_record_taskinfo_sched_switch(prev, next, flags);
37 probe_sched_wakeup(void *ignore, struct task_struct *wakee)
41 flags = (RECORD_TGID * !!sched_tgid_ref) +
42 (RECORD_CMDLINE * !!sched_cmdline_ref);
46 tracing_record_taskinfo(current, flags);
49 static int tracing_sched_register(void)
53 ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
55 pr_info("wakeup trace: Couldn't activate tracepoint"
56 " probe to kernel_sched_wakeup\n");
60 ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
62 pr_info("wakeup trace: Couldn't activate tracepoint"
63 " probe to kernel_sched_wakeup_new\n");
67 ret = register_trace_sched_switch(probe_sched_switch, NULL);
69 pr_info("sched trace: Couldn't activate tracepoint"
70 " probe to kernel_sched_switch\n");
71 goto fail_deprobe_wake_new;
75 fail_deprobe_wake_new:
76 unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
78 unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
82 static void tracing_sched_unregister(void)
84 unregister_trace_sched_switch(probe_sched_switch, NULL);
85 unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
86 unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
89 static void tracing_start_sched_switch(int ops)
91 bool sched_register = (!sched_cmdline_ref && !sched_tgid_ref);
92 mutex_lock(&sched_register_mutex);
104 if (sched_register && (sched_cmdline_ref || sched_tgid_ref))
105 tracing_sched_register();
106 mutex_unlock(&sched_register_mutex);
109 static void tracing_stop_sched_switch(int ops)
111 mutex_lock(&sched_register_mutex);
123 if (!sched_cmdline_ref && !sched_tgid_ref)
124 tracing_sched_unregister();
125 mutex_unlock(&sched_register_mutex);
128 void tracing_start_cmdline_record(void)
130 tracing_start_sched_switch(RECORD_CMDLINE);
133 void tracing_stop_cmdline_record(void)
135 tracing_stop_sched_switch(RECORD_CMDLINE);
138 void tracing_start_tgid_record(void)
140 tracing_start_sched_switch(RECORD_TGID);
143 void tracing_stop_tgid_record(void)
145 tracing_stop_sched_switch(RECORD_TGID);