diff options
Diffstat (limited to 'kernel/trace/trace_power.c')
-rw-r--r-- | kernel/trace/trace_power.c | 194 |
1 files changed, 109 insertions, 85 deletions
diff --git a/kernel/trace/trace_power.c b/kernel/trace/trace_power.c index 7bda248daf55..bae791ebcc51 100644 --- a/kernel/trace/trace_power.c +++ b/kernel/trace/trace_power.c | |||
@@ -11,15 +11,113 @@ | |||
11 | 11 | ||
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/debugfs.h> | 13 | #include <linux/debugfs.h> |
14 | #include <linux/ftrace.h> | 14 | #include <trace/power.h> |
15 | #include <linux/kallsyms.h> | 15 | #include <linux/kallsyms.h> |
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | 17 | ||
18 | #include "trace.h" | 18 | #include "trace.h" |
19 | #include "trace_output.h" | ||
19 | 20 | ||
20 | static struct trace_array *power_trace; | 21 | static struct trace_array *power_trace; |
21 | static int __read_mostly trace_power_enabled; | 22 | static int __read_mostly trace_power_enabled; |
22 | 23 | ||
24 | static void probe_power_start(struct power_trace *it, unsigned int type, | ||
25 | unsigned int level) | ||
26 | { | ||
27 | if (!trace_power_enabled) | ||
28 | return; | ||
29 | |||
30 | memset(it, 0, sizeof(struct power_trace)); | ||
31 | it->state = level; | ||
32 | it->type = type; | ||
33 | it->stamp = ktime_get(); | ||
34 | } | ||
35 | |||
36 | |||
37 | static void probe_power_end(struct power_trace *it) | ||
38 | { | ||
39 | struct ring_buffer_event *event; | ||
40 | struct trace_power *entry; | ||
41 | struct trace_array_cpu *data; | ||
42 | struct trace_array *tr = power_trace; | ||
43 | |||
44 | if (!trace_power_enabled) | ||
45 | return; | ||
46 | |||
47 | preempt_disable(); | ||
48 | it->end = ktime_get(); | ||
49 | data = tr->data[smp_processor_id()]; | ||
50 | |||
51 | event = trace_buffer_lock_reserve(tr, TRACE_POWER, | ||
52 | sizeof(*entry), 0, 0); | ||
53 | if (!event) | ||
54 | goto out; | ||
55 | entry = ring_buffer_event_data(event); | ||
56 | entry->state_data = *it; | ||
57 | trace_buffer_unlock_commit(tr, event, 0, 0); | ||
58 | out: | ||
59 | preempt_enable(); | ||
60 | } | ||
61 | |||
62 | static void probe_power_mark(struct power_trace *it, unsigned int type, | ||
63 | unsigned int level) | ||
64 | { | ||
65 | struct ring_buffer_event *event; | ||
66 | struct trace_power *entry; | ||
67 | struct trace_array_cpu *data; | ||
68 | struct trace_array *tr = power_trace; | ||
69 | |||
70 | if (!trace_power_enabled) | ||
71 | return; | ||
72 | |||
73 | memset(it, 0, sizeof(struct power_trace)); | ||
74 | it->state = level; | ||
75 | it->type = type; | ||
76 | it->stamp = ktime_get(); | ||
77 | preempt_disable(); | ||
78 | it->end = it->stamp; | ||
79 | data = tr->data[smp_processor_id()]; | ||
80 | |||
81 | event = trace_buffer_lock_reserve(tr, TRACE_POWER, | ||
82 | sizeof(*entry), 0, 0); | ||
83 | if (!event) | ||
84 | goto out; | ||
85 | entry = ring_buffer_event_data(event); | ||
86 | entry->state_data = *it; | ||
87 | trace_buffer_unlock_commit(tr, event, 0, 0); | ||
88 | out: | ||
89 | preempt_enable(); | ||
90 | } | ||
91 | |||
92 | static int tracing_power_register(void) | ||
93 | { | ||
94 | int ret; | ||
95 | |||
96 | ret = register_trace_power_start(probe_power_start); | ||
97 | if (ret) { | ||
98 | pr_info("power trace: Couldn't activate tracepoint" | ||
99 | " probe to trace_power_start\n"); | ||
100 | return ret; | ||
101 | } | ||
102 | ret = register_trace_power_end(probe_power_end); | ||
103 | if (ret) { | ||
104 | pr_info("power trace: Couldn't activate tracepoint" | ||
105 | " probe to trace_power_end\n"); | ||
106 | goto fail_start; | ||
107 | } | ||
108 | ret = register_trace_power_mark(probe_power_mark); | ||
109 | if (ret) { | ||
110 | pr_info("power trace: Couldn't activate tracepoint" | ||
111 | " probe to trace_power_mark\n"); | ||
112 | goto fail_end; | ||
113 | } | ||
114 | return ret; | ||
115 | fail_end: | ||
116 | unregister_trace_power_end(probe_power_end); | ||
117 | fail_start: | ||
118 | unregister_trace_power_start(probe_power_start); | ||
119 | return ret; | ||
120 | } | ||
23 | 121 | ||
24 | static void start_power_trace(struct trace_array *tr) | 122 | static void start_power_trace(struct trace_array *tr) |
25 | { | 123 | { |
@@ -31,6 +129,14 @@ static void stop_power_trace(struct trace_array *tr) | |||
31 | trace_power_enabled = 0; | 129 | trace_power_enabled = 0; |
32 | } | 130 | } |
33 | 131 | ||
132 | static void power_trace_reset(struct trace_array *tr) | ||
133 | { | ||
134 | trace_power_enabled = 0; | ||
135 | unregister_trace_power_start(probe_power_start); | ||
136 | unregister_trace_power_end(probe_power_end); | ||
137 | unregister_trace_power_mark(probe_power_mark); | ||
138 | } | ||
139 | |||
34 | 140 | ||
35 | static int power_trace_init(struct trace_array *tr) | 141 | static int power_trace_init(struct trace_array *tr) |
36 | { | 142 | { |
@@ -38,6 +144,7 @@ static int power_trace_init(struct trace_array *tr) | |||
38 | power_trace = tr; | 144 | power_trace = tr; |
39 | 145 | ||
40 | trace_power_enabled = 1; | 146 | trace_power_enabled = 1; |
147 | tracing_power_register(); | ||
41 | 148 | ||
42 | for_each_cpu(cpu, cpu_possible_mask) | 149 | for_each_cpu(cpu, cpu_possible_mask) |
43 | tracing_reset(tr, cpu); | 150 | tracing_reset(tr, cpu); |
@@ -85,7 +192,7 @@ static struct tracer power_tracer __read_mostly = | |||
85 | .init = power_trace_init, | 192 | .init = power_trace_init, |
86 | .start = start_power_trace, | 193 | .start = start_power_trace, |
87 | .stop = stop_power_trace, | 194 | .stop = stop_power_trace, |
88 | .reset = stop_power_trace, | 195 | .reset = power_trace_reset, |
89 | .print_line = power_print_line, | 196 | .print_line = power_print_line, |
90 | }; | 197 | }; |
91 | 198 | ||
@@ -94,86 +201,3 @@ static int init_power_trace(void) | |||
94 | return register_tracer(&power_tracer); | 201 | return register_tracer(&power_tracer); |
95 | } | 202 | } |
96 | device_initcall(init_power_trace); | 203 | device_initcall(init_power_trace); |
97 | |||
98 | void trace_power_start(struct power_trace *it, unsigned int type, | ||
99 | unsigned int level) | ||
100 | { | ||
101 | if (!trace_power_enabled) | ||
102 | return; | ||
103 | |||
104 | memset(it, 0, sizeof(struct power_trace)); | ||
105 | it->state = level; | ||
106 | it->type = type; | ||
107 | it->stamp = ktime_get(); | ||
108 | } | ||
109 | EXPORT_SYMBOL_GPL(trace_power_start); | ||
110 | |||
111 | |||
112 | void trace_power_end(struct power_trace *it) | ||
113 | { | ||
114 | struct ring_buffer_event *event; | ||
115 | struct trace_power *entry; | ||
116 | struct trace_array_cpu *data; | ||
117 | unsigned long irq_flags; | ||
118 | struct trace_array *tr = power_trace; | ||
119 | |||
120 | if (!trace_power_enabled) | ||
121 | return; | ||
122 | |||
123 | preempt_disable(); | ||
124 | it->end = ktime_get(); | ||
125 | data = tr->data[smp_processor_id()]; | ||
126 | |||
127 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), | ||
128 | &irq_flags); | ||
129 | if (!event) | ||
130 | goto out; | ||
131 | entry = ring_buffer_event_data(event); | ||
132 | tracing_generic_entry_update(&entry->ent, 0, 0); | ||
133 | entry->ent.type = TRACE_POWER; | ||
134 | entry->state_data = *it; | ||
135 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); | ||
136 | |||
137 | trace_wake_up(); | ||
138 | |||
139 | out: | ||
140 | preempt_enable(); | ||
141 | } | ||
142 | EXPORT_SYMBOL_GPL(trace_power_end); | ||
143 | |||
144 | void trace_power_mark(struct power_trace *it, unsigned int type, | ||
145 | unsigned int level) | ||
146 | { | ||
147 | struct ring_buffer_event *event; | ||
148 | struct trace_power *entry; | ||
149 | struct trace_array_cpu *data; | ||
150 | unsigned long irq_flags; | ||
151 | struct trace_array *tr = power_trace; | ||
152 | |||
153 | if (!trace_power_enabled) | ||
154 | return; | ||
155 | |||
156 | memset(it, 0, sizeof(struct power_trace)); | ||
157 | it->state = level; | ||
158 | it->type = type; | ||
159 | it->stamp = ktime_get(); | ||
160 | preempt_disable(); | ||
161 | it->end = it->stamp; | ||
162 | data = tr->data[smp_processor_id()]; | ||
163 | |||
164 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), | ||
165 | &irq_flags); | ||
166 | if (!event) | ||
167 | goto out; | ||
168 | entry = ring_buffer_event_data(event); | ||
169 | tracing_generic_entry_update(&entry->ent, 0, 0); | ||
170 | entry->ent.type = TRACE_POWER; | ||
171 | entry->state_data = *it; | ||
172 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); | ||
173 | |||
174 | trace_wake_up(); | ||
175 | |||
176 | out: | ||
177 | preempt_enable(); | ||
178 | } | ||
179 | EXPORT_SYMBOL_GPL(trace_power_mark); | ||