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 ring_buffer_event *event;
40
struct trace_power *entry;
41
struct trace_array_cpu *data;
42
struct trace_array *tr = power_trace;
44
if (!trace_power_enabled)
48
it->end = ktime_get();
49
data = tr->data[smp_processor_id()];
51
event = trace_buffer_lock_reserve(tr, TRACE_POWER,
52
sizeof(*entry), 0, 0);
55
entry = ring_buffer_event_data(event);
56
entry->state_data = *it;
57
trace_buffer_unlock_commit(tr, event, 0, 0);
62
static void probe_power_mark(struct power_trace *it, unsigned int type,
65
struct ring_buffer_event *event;
66
struct trace_power *entry;
67
struct trace_array_cpu *data;
68
struct trace_array *tr = power_trace;
70
if (!trace_power_enabled)
73
memset(it, 0, sizeof(struct power_trace));
76
it->stamp = ktime_get();
79
data = tr->data[smp_processor_id()];
81
event = trace_buffer_lock_reserve(tr, TRACE_POWER,
82
sizeof(*entry), 0, 0);
85
entry = ring_buffer_event_data(event);
86
entry->state_data = *it;
87
trace_buffer_unlock_commit(tr, event, 0, 0);
92
static int tracing_power_register(void)
96
ret = register_trace_power_start(probe_power_start);
98
pr_info("power trace: Couldn't activate tracepoint"
99
" probe to trace_power_start\n");
102
ret = register_trace_power_end(probe_power_end);
104
pr_info("power trace: Couldn't activate tracepoint"
105
" probe to trace_power_end\n");
108
ret = register_trace_power_mark(probe_power_mark);
110
pr_info("power trace: Couldn't activate tracepoint"
111
" probe to trace_power_mark\n");
116
unregister_trace_power_end(probe_power_end);
118
unregister_trace_power_start(probe_power_start);
122
static void start_power_trace(struct trace_array *tr)
124
trace_power_enabled = 1;
127
static void stop_power_trace(struct trace_array *tr)
129
trace_power_enabled = 0;
132
static void power_trace_reset(struct trace_array *tr)
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);
141
static int power_trace_init(struct trace_array *tr)
146
trace_power_enabled = 1;
147
tracing_power_register();
149
for_each_cpu(cpu, cpu_possible_mask)
150
tracing_reset(tr, cpu);
154
static enum print_line_t power_print_line(struct trace_iterator *iter)
157
struct trace_entry *entry = iter->ent;
158
struct trace_power *field ;
159
struct power_trace *it;
160
struct trace_seq *s = &iter->seq;
161
struct timespec stamp;
162
struct timespec duration;
164
trace_assign_type(field, entry);
165
it = &field->state_data;
166
stamp = ktime_to_timespec(it->stamp);
167
duration = ktime_to_timespec(ktime_sub(it->end, it->stamp));
169
if (entry->type == TRACE_POWER) {
170
if (it->type == POWER_CSTATE)
171
ret = trace_seq_printf(s, "[%5ld.%09ld] CSTATE: Going to C%i on cpu %i for %ld.%09ld\n",
174
it->state, iter->cpu,
177
if (it->type == POWER_PSTATE)
178
ret = trace_seq_printf(s, "[%5ld.%09ld] PSTATE: Going to P%i on cpu %i\n",
181
it->state, iter->cpu);
183
return TRACE_TYPE_PARTIAL_LINE;
184
return TRACE_TYPE_HANDLED;
186
return TRACE_TYPE_UNHANDLED;
189
static void power_print_header(struct seq_file *s)
191
seq_puts(s, "# TIMESTAMP STATE EVENT\n");
192
seq_puts(s, "# | | |\n");
195
static struct tracer power_tracer __read_mostly =
198
.init = power_trace_init,
199
.start = start_power_trace,
200
.stop = stop_power_trace,
201
.reset = power_trace_reset,
202
.print_line = power_print_line,
203
.print_header = power_print_header,
206
static int init_power_trace(void)
208
return register_tracer(&power_tracer);
210
device_initcall(init_power_trace);