Commit | Line | Data |
---|---|---|
35e8e302 SR |
1 | /* |
2 | * trace context switch | |
3 | * | |
4 | * Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com> | |
5 | * | |
6 | */ | |
7 | #include <linux/module.h> | |
8 | #include <linux/fs.h> | |
9 | #include <linux/debugfs.h> | |
10 | #include <linux/kallsyms.h> | |
11 | #include <linux/uaccess.h> | |
35e8e302 | 12 | #include <linux/ftrace.h> |
ad8d75ff | 13 | #include <trace/events/sched.h> |
35e8e302 SR |
14 | |
15 | #include "trace.h" | |
16 | ||
efade6e7 FW |
17 | static int sched_ref; |
18 | static DEFINE_MUTEX(sched_register_mutex); | |
82e04af4 | 19 | |
e309b41d | 20 | static void |
38516ab5 | 21 | probe_sched_switch(void *ignore, struct task_struct *prev, struct task_struct *next) |
35e8e302 | 22 | { |
dcef788e | 23 | if (unlikely(!sched_ref)) |
b07c3f19 MD |
24 | return; |
25 | ||
41bc8144 SR |
26 | tracing_record_cmdline(prev); |
27 | tracing_record_cmdline(next); | |
35e8e302 SR |
28 | } |
29 | ||
4e655519 | 30 | static void |
38516ab5 | 31 | probe_sched_wakeup(void *ignore, struct task_struct *wakee, int success) |
57422797 | 32 | { |
dcef788e | 33 | if (unlikely(!sched_ref)) |
57422797 IM |
34 | return; |
35 | ||
b07c3f19 | 36 | tracing_record_cmdline(current); |
57422797 IM |
37 | } |
38 | ||
5b82a1b0 MD |
39 | static int tracing_sched_register(void) |
40 | { | |
41 | int ret; | |
42 | ||
38516ab5 | 43 | ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL); |
5b82a1b0 | 44 | if (ret) { |
b07c3f19 | 45 | pr_info("wakeup trace: Couldn't activate tracepoint" |
5b82a1b0 MD |
46 | " probe to kernel_sched_wakeup\n"); |
47 | return ret; | |
48 | } | |
49 | ||
38516ab5 | 50 | ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
5b82a1b0 | 51 | if (ret) { |
b07c3f19 | 52 | pr_info("wakeup trace: Couldn't activate tracepoint" |
5b82a1b0 MD |
53 | " probe to kernel_sched_wakeup_new\n"); |
54 | goto fail_deprobe; | |
55 | } | |
56 | ||
38516ab5 | 57 | ret = register_trace_sched_switch(probe_sched_switch, NULL); |
5b82a1b0 | 58 | if (ret) { |
b07c3f19 | 59 | pr_info("sched trace: Couldn't activate tracepoint" |
73d8b8bc | 60 | " probe to kernel_sched_switch\n"); |
5b82a1b0 MD |
61 | goto fail_deprobe_wake_new; |
62 | } | |
63 | ||
64 | return ret; | |
65 | fail_deprobe_wake_new: | |
38516ab5 | 66 | unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
5b82a1b0 | 67 | fail_deprobe: |
38516ab5 | 68 | unregister_trace_sched_wakeup(probe_sched_wakeup, NULL); |
5b82a1b0 MD |
69 | return ret; |
70 | } | |
71 | ||
72 | static void tracing_sched_unregister(void) | |
73 | { | |
38516ab5 SR |
74 | unregister_trace_sched_switch(probe_sched_switch, NULL); |
75 | unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL); | |
76 | unregister_trace_sched_wakeup(probe_sched_wakeup, NULL); | |
5b82a1b0 MD |
77 | } |
78 | ||
f2252935 | 79 | static void tracing_start_sched_switch(void) |
5b82a1b0 | 80 | { |
efade6e7 | 81 | mutex_lock(&sched_register_mutex); |
e168e051 | 82 | if (!(sched_ref++)) |
5b82a1b0 | 83 | tracing_sched_register(); |
efade6e7 | 84 | mutex_unlock(&sched_register_mutex); |
5b82a1b0 MD |
85 | } |
86 | ||
f2252935 | 87 | static void tracing_stop_sched_switch(void) |
5b82a1b0 | 88 | { |
efade6e7 | 89 | mutex_lock(&sched_register_mutex); |
e168e051 | 90 | if (!(--sched_ref)) |
5b82a1b0 | 91 | tracing_sched_unregister(); |
efade6e7 | 92 | mutex_unlock(&sched_register_mutex); |
5b82a1b0 MD |
93 | } |
94 | ||
41bc8144 SR |
95 | void tracing_start_cmdline_record(void) |
96 | { | |
97 | tracing_start_sched_switch(); | |
98 | } | |
99 | ||
100 | void tracing_stop_cmdline_record(void) | |
101 | { | |
102 | tracing_stop_sched_switch(); | |
103 | } |