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>
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
,
27 if (!trace_power_enabled
)
30 memset(it
, 0, sizeof(struct power_trace
));
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
)
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);
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);
67 static void probe_power_mark(struct power_trace
*it
, unsigned int type
,
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
)
82 memset(it
, 0, sizeof(struct power_trace
));
85 it
->stamp
= ktime_get();
88 data
= tr
->data
[smp_processor_id()];
90 event
= trace_buffer_lock_reserve(buffer
, TRACE_POWER
,
91 sizeof(*entry
), 0, 0);
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);
102 static int tracing_power_register(void)
106 ret
= register_trace_power_start(probe_power_start
);
108 pr_info("power trace: Couldn't activate tracepoint"
109 " probe to trace_power_start\n");
112 ret
= register_trace_power_end(probe_power_end
);
114 pr_info("power trace: Couldn't activate tracepoint"
115 " probe to trace_power_end\n");
118 ret
= register_trace_power_mark(probe_power_mark
);
120 pr_info("power trace: Couldn't activate tracepoint"
121 " probe to trace_power_mark\n");
126 unregister_trace_power_end(probe_power_end
);
128 unregister_trace_power_start(probe_power_start
);
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
)
155 trace_power_enabled
= 1;
156 tracing_power_register();
158 tracing_reset_online_cpus(tr
);
162 static enum print_line_t
power_print_line(struct trace_iterator
*iter
)
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",
182 it
->state
, iter
->cpu
,
185 if (it
->type
== POWER_PSTATE
)
186 ret
= trace_seq_printf(s
, "[%5ld.%09ld] PSTATE: Going to P%i on cpu %i\n",
189 it
->state
, iter
->cpu
);
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
=
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
);