debugfs: Modified default dir of debugfs for debugging UHCI.
[linux/fpc-iii.git] / kernel / trace / trace_power.c
blobfe1a00f1445aac090d101432a8d3d49dc077441b
1 /*
2 * ring buffer based C-state tracer
4 * Arjan van de Ven <arjan@linux.intel.com>
5 * Copyright (C) 2008 Intel Corporation
7 * Much is borrowed from trace_boot.c which is
8 * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
12 #include <linux/init.h>
13 #include <linux/debugfs.h>
14 #include <trace/power.h>
15 #include <linux/kallsyms.h>
16 #include <linux/module.h>
18 #include "trace.h"
19 #include "trace_output.h"
21 static struct trace_array *power_trace;
22 static int __read_mostly trace_power_enabled;
24 static void probe_power_start(struct power_trace *it, unsigned int type,
25 unsigned int level)
27 if (!trace_power_enabled)
28 return;
30 memset(it, 0, sizeof(struct power_trace));
31 it->state = level;
32 it->type = type;
33 it->stamp = ktime_get();
37 static void probe_power_end(struct power_trace *it)
39 struct ftrace_event_call *call = &event_power;
40 struct ring_buffer_event *event;
41 struct ring_buffer *buffer;
42 struct trace_power *entry;
43 struct trace_array_cpu *data;
44 struct trace_array *tr = power_trace;
46 if (!trace_power_enabled)
47 return;
49 buffer = tr->buffer;
51 preempt_disable();
52 it->end = ktime_get();
53 data = tr->data[smp_processor_id()];
55 event = trace_buffer_lock_reserve(buffer, TRACE_POWER,
56 sizeof(*entry), 0, 0);
57 if (!event)
58 goto out;
59 entry = ring_buffer_event_data(event);
60 entry->state_data = *it;
61 if (!filter_check_discard(call, entry, buffer, event))
62 trace_buffer_unlock_commit(buffer, event, 0, 0);
63 out:
64 preempt_enable();
67 static void probe_power_mark(struct power_trace *it, unsigned int type,
68 unsigned int level)
70 struct ftrace_event_call *call = &event_power;
71 struct ring_buffer_event *event;
72 struct ring_buffer *buffer;
73 struct trace_power *entry;
74 struct trace_array_cpu *data;
75 struct trace_array *tr = power_trace;
77 if (!trace_power_enabled)
78 return;
80 buffer = tr->buffer;
82 memset(it, 0, sizeof(struct power_trace));
83 it->state = level;
84 it->type = type;
85 it->stamp = ktime_get();
86 preempt_disable();
87 it->end = it->stamp;
88 data = tr->data[smp_processor_id()];
90 event = trace_buffer_lock_reserve(buffer, TRACE_POWER,
91 sizeof(*entry), 0, 0);
92 if (!event)
93 goto out;
94 entry = ring_buffer_event_data(event);
95 entry->state_data = *it;
96 if (!filter_check_discard(call, entry, buffer, event))
97 trace_buffer_unlock_commit(buffer, event, 0, 0);
98 out:
99 preempt_enable();
102 static int tracing_power_register(void)
104 int ret;
106 ret = register_trace_power_start(probe_power_start);
107 if (ret) {
108 pr_info("power trace: Couldn't activate tracepoint"
109 " probe to trace_power_start\n");
110 return ret;
112 ret = register_trace_power_end(probe_power_end);
113 if (ret) {
114 pr_info("power trace: Couldn't activate tracepoint"
115 " probe to trace_power_end\n");
116 goto fail_start;
118 ret = register_trace_power_mark(probe_power_mark);
119 if (ret) {
120 pr_info("power trace: Couldn't activate tracepoint"
121 " probe to trace_power_mark\n");
122 goto fail_end;
124 return ret;
125 fail_end:
126 unregister_trace_power_end(probe_power_end);
127 fail_start:
128 unregister_trace_power_start(probe_power_start);
129 return ret;
132 static void start_power_trace(struct trace_array *tr)
134 trace_power_enabled = 1;
137 static void stop_power_trace(struct trace_array *tr)
139 trace_power_enabled = 0;
142 static void power_trace_reset(struct trace_array *tr)
144 trace_power_enabled = 0;
145 unregister_trace_power_start(probe_power_start);
146 unregister_trace_power_end(probe_power_end);
147 unregister_trace_power_mark(probe_power_mark);
151 static int power_trace_init(struct trace_array *tr)
153 power_trace = tr;
155 trace_power_enabled = 1;
156 tracing_power_register();
158 tracing_reset_online_cpus(tr);
159 return 0;
162 static enum print_line_t power_print_line(struct trace_iterator *iter)
164 int ret = 0;
165 struct trace_entry *entry = iter->ent;
166 struct trace_power *field ;
167 struct power_trace *it;
168 struct trace_seq *s = &iter->seq;
169 struct timespec stamp;
170 struct timespec duration;
172 trace_assign_type(field, entry);
173 it = &field->state_data;
174 stamp = ktime_to_timespec(it->stamp);
175 duration = ktime_to_timespec(ktime_sub(it->end, it->stamp));
177 if (entry->type == TRACE_POWER) {
178 if (it->type == POWER_CSTATE)
179 ret = trace_seq_printf(s, "[%5ld.%09ld] CSTATE: Going to C%i on cpu %i for %ld.%09ld\n",
180 stamp.tv_sec,
181 stamp.tv_nsec,
182 it->state, iter->cpu,
183 duration.tv_sec,
184 duration.tv_nsec);
185 if (it->type == POWER_PSTATE)
186 ret = trace_seq_printf(s, "[%5ld.%09ld] PSTATE: Going to P%i on cpu %i\n",
187 stamp.tv_sec,
188 stamp.tv_nsec,
189 it->state, iter->cpu);
190 if (!ret)
191 return TRACE_TYPE_PARTIAL_LINE;
192 return TRACE_TYPE_HANDLED;
194 return TRACE_TYPE_UNHANDLED;
197 static void power_print_header(struct seq_file *s)
199 seq_puts(s, "# TIMESTAMP STATE EVENT\n");
200 seq_puts(s, "# | | |\n");
203 static struct tracer power_tracer __read_mostly =
205 .name = "power",
206 .init = power_trace_init,
207 .start = start_power_trace,
208 .stop = stop_power_trace,
209 .reset = power_trace_reset,
210 .print_line = power_print_line,
211 .print_header = power_print_header,
214 static int init_power_trace(void)
216 return register_tracer(&power_tracer);
218 device_initcall(init_power_trace);