Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 1 | /* |
Ingo Molnar | e9a22d1 | 2009-03-13 11:54:40 +0100 | [diff] [blame^] | 2 | * h/w branch tracer for x86 based on BTS |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 3 | * |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 Intel Corporation. |
| 5 | * Markus Metzger <markus.t.metzger@gmail.com>, 2008-2009 |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 6 | */ |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 7 | #include <linux/spinlock.h> |
| 8 | #include <linux/kallsyms.h> |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 9 | #include <linux/debugfs.h> |
| 10 | #include <linux/ftrace.h> |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 11 | #include <linux/module.h> |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 12 | #include <linux/cpu.h> |
| 13 | #include <linux/smp.h> |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 14 | #include <linux/fs.h> |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 15 | |
| 16 | #include <asm/ds.h> |
| 17 | |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 18 | #include "trace_output.h" |
Ingo Molnar | e9a22d1 | 2009-03-13 11:54:40 +0100 | [diff] [blame^] | 19 | #include "trace.h" |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 20 | |
| 21 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 22 | #define BTS_BUFFER_SIZE (1 << 13) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 23 | |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 24 | /* |
| 25 | * The tracer lock protects the below per-cpu tracer array. |
| 26 | * It needs to be held to: |
| 27 | * - start tracing on all cpus |
| 28 | * - stop tracing on all cpus |
| 29 | * - start tracing on a single hotplug cpu |
| 30 | * - stop tracing on a single hotplug cpu |
| 31 | * - read the trace from all cpus |
| 32 | * - read the trace from a single cpu |
| 33 | */ |
| 34 | static DEFINE_SPINLOCK(bts_tracer_lock); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 35 | static DEFINE_PER_CPU(struct bts_tracer *, tracer); |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 36 | static DEFINE_PER_CPU(unsigned char[BTS_BUFFER_SIZE], buffer); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 37 | |
| 38 | #define this_tracer per_cpu(tracer, smp_processor_id()) |
| 39 | #define this_buffer per_cpu(buffer, smp_processor_id()) |
| 40 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 41 | static int trace_hw_branches_enabled __read_mostly; |
| 42 | static int trace_hw_branches_suspended __read_mostly; |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 43 | static struct trace_array *hw_branch_trace __read_mostly; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 44 | |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 45 | |
| 46 | /* |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 47 | * Initialize the tracer for the current cpu. |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 48 | * The argument is ignored. |
| 49 | * |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 50 | * pre: bts_tracer_lock must be locked. |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 51 | */ |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 52 | static void bts_trace_init_cpu(void *arg) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 53 | { |
| 54 | if (this_tracer) |
| 55 | ds_release_bts(this_tracer); |
| 56 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 57 | this_tracer = ds_request_bts(NULL, this_buffer, BTS_BUFFER_SIZE, |
| 58 | NULL, (size_t)-1, BTS_KERNEL); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 59 | if (IS_ERR(this_tracer)) { |
| 60 | this_tracer = NULL; |
| 61 | return; |
| 62 | } |
| 63 | } |
| 64 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 65 | static int bts_trace_init(struct trace_array *tr) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 66 | { |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 67 | int cpu, avail; |
| 68 | |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 69 | spin_lock(&bts_tracer_lock); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 70 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 71 | hw_branch_trace = tr; |
| 72 | |
| 73 | on_each_cpu(bts_trace_init_cpu, NULL, 1); |
| 74 | |
| 75 | /* Check on how many cpus we could enable tracing */ |
| 76 | avail = 0; |
| 77 | for_each_online_cpu(cpu) |
| 78 | if (per_cpu(tracer, cpu)) |
| 79 | avail++; |
| 80 | |
| 81 | trace_hw_branches_enabled = (avail ? 1 : 0); |
| 82 | trace_hw_branches_suspended = 0; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 83 | |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 84 | spin_unlock(&bts_tracer_lock); |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 85 | |
| 86 | |
| 87 | /* If we could not enable tracing on a single cpu, we fail. */ |
| 88 | return avail ? 0 : -EOPNOTSUPP; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 91 | /* |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 92 | * Release the tracer for the current cpu. |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 93 | * The argument is ignored. |
| 94 | * |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 95 | * pre: bts_tracer_lock must be locked. |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 96 | */ |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 97 | static void bts_trace_release_cpu(void *arg) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 98 | { |
| 99 | if (this_tracer) { |
| 100 | ds_release_bts(this_tracer); |
| 101 | this_tracer = NULL; |
| 102 | } |
| 103 | } |
| 104 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 105 | static void bts_trace_reset(struct trace_array *tr) |
| 106 | { |
| 107 | spin_lock(&bts_tracer_lock); |
| 108 | |
| 109 | on_each_cpu(bts_trace_release_cpu, NULL, 1); |
| 110 | trace_hw_branches_enabled = 0; |
| 111 | trace_hw_branches_suspended = 0; |
| 112 | |
| 113 | spin_unlock(&bts_tracer_lock); |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * Resume tracing on the current cpu. |
| 118 | * The argument is ignored. |
| 119 | * |
| 120 | * pre: bts_tracer_lock must be locked. |
| 121 | */ |
| 122 | static void bts_trace_resume_cpu(void *arg) |
| 123 | { |
| 124 | if (this_tracer) |
| 125 | ds_resume_bts(this_tracer); |
| 126 | } |
| 127 | |
| 128 | static void bts_trace_start(struct trace_array *tr) |
| 129 | { |
| 130 | spin_lock(&bts_tracer_lock); |
| 131 | |
| 132 | on_each_cpu(bts_trace_resume_cpu, NULL, 1); |
| 133 | trace_hw_branches_suspended = 0; |
| 134 | |
| 135 | spin_unlock(&bts_tracer_lock); |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Suspend tracing on the current cpu. |
| 140 | * The argument is ignored. |
| 141 | * |
| 142 | * pre: bts_tracer_lock must be locked. |
| 143 | */ |
| 144 | static void bts_trace_suspend_cpu(void *arg) |
| 145 | { |
| 146 | if (this_tracer) |
| 147 | ds_suspend_bts(this_tracer); |
| 148 | } |
| 149 | |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 150 | static void bts_trace_stop(struct trace_array *tr) |
| 151 | { |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 152 | spin_lock(&bts_tracer_lock); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 153 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 154 | on_each_cpu(bts_trace_suspend_cpu, NULL, 1); |
| 155 | trace_hw_branches_suspended = 1; |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 156 | |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 157 | spin_unlock(&bts_tracer_lock); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 160 | static int __cpuinit bts_hotcpu_handler(struct notifier_block *nfb, |
| 161 | unsigned long action, void *hcpu) |
| 162 | { |
| 163 | unsigned int cpu = (unsigned long)hcpu; |
| 164 | |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 165 | spin_lock(&bts_tracer_lock); |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 166 | |
| 167 | if (!trace_hw_branches_enabled) |
| 168 | goto out; |
| 169 | |
| 170 | switch (action) { |
| 171 | case CPU_ONLINE: |
| 172 | case CPU_DOWN_FAILED: |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 173 | smp_call_function_single(cpu, bts_trace_init_cpu, NULL, 1); |
| 174 | |
| 175 | if (trace_hw_branches_suspended) |
| 176 | smp_call_function_single(cpu, bts_trace_suspend_cpu, |
| 177 | NULL, 1); |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 178 | break; |
| 179 | case CPU_DOWN_PREPARE: |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 180 | smp_call_function_single(cpu, bts_trace_release_cpu, NULL, 1); |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 181 | break; |
| 182 | } |
| 183 | |
| 184 | out: |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 185 | spin_unlock(&bts_tracer_lock); |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 186 | return NOTIFY_DONE; |
| 187 | } |
| 188 | |
| 189 | static struct notifier_block bts_hotcpu_notifier __cpuinitdata = { |
| 190 | .notifier_call = bts_hotcpu_handler |
| 191 | }; |
| 192 | |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 193 | static void bts_trace_print_header(struct seq_file *m) |
| 194 | { |
Markus Metzger | 11edda0 | 2009-01-19 10:29:16 +0100 | [diff] [blame] | 195 | seq_puts(m, "# CPU# TO <- FROM\n"); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static enum print_line_t bts_trace_print_line(struct trace_iterator *iter) |
| 199 | { |
Ingo Molnar | e9a22d1 | 2009-03-13 11:54:40 +0100 | [diff] [blame^] | 200 | unsigned long symflags = TRACE_ITER_SYM_OFFSET; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 201 | struct trace_entry *entry = iter->ent; |
| 202 | struct trace_seq *seq = &iter->seq; |
| 203 | struct hw_branch_entry *it; |
| 204 | |
| 205 | trace_assign_type(it, entry); |
| 206 | |
| 207 | if (entry->type == TRACE_HW_BRANCHES) { |
Steven Rostedt | 1830b52 | 2009-02-07 19:38:43 -0500 | [diff] [blame] | 208 | if (trace_seq_printf(seq, "%4d ", iter->cpu) && |
Markus Metzger | 11edda0 | 2009-01-19 10:29:16 +0100 | [diff] [blame] | 209 | seq_print_ip_sym(seq, it->to, symflags) && |
| 210 | trace_seq_printf(seq, "\t <- ") && |
| 211 | seq_print_ip_sym(seq, it->from, symflags) && |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 212 | trace_seq_printf(seq, "\n")) |
| 213 | return TRACE_TYPE_HANDLED; |
| 214 | return TRACE_TYPE_PARTIAL_LINE;; |
| 215 | } |
| 216 | return TRACE_TYPE_UNHANDLED; |
| 217 | } |
| 218 | |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 219 | void trace_hw_branch(u64 from, u64 to) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 220 | { |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 221 | struct trace_array *tr = hw_branch_trace; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 222 | struct ring_buffer_event *event; |
| 223 | struct hw_branch_entry *entry; |
Arnaldo Carvalho de Melo | 0a98775 | 2009-02-05 16:12:56 -0200 | [diff] [blame] | 224 | unsigned long irq1; |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 225 | int cpu; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 226 | |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 227 | if (unlikely(!tr)) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 228 | return; |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 229 | |
| 230 | if (unlikely(!trace_hw_branches_enabled)) |
| 231 | return; |
| 232 | |
| 233 | local_irq_save(irq1); |
| 234 | cpu = raw_smp_processor_id(); |
| 235 | if (atomic_inc_return(&tr->data[cpu]->disabled) != 1) |
| 236 | goto out; |
| 237 | |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 238 | event = trace_buffer_lock_reserve(tr, TRACE_HW_BRANCHES, |
| 239 | sizeof(*entry), 0, 0); |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 240 | if (!event) |
| 241 | goto out; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 242 | entry = ring_buffer_event_data(event); |
| 243 | tracing_generic_entry_update(&entry->ent, 0, from); |
| 244 | entry->ent.type = TRACE_HW_BRANCHES; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 245 | entry->from = from; |
| 246 | entry->to = to; |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 247 | trace_buffer_unlock_commit(tr, event, 0, 0); |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 248 | |
| 249 | out: |
| 250 | atomic_dec(&tr->data[cpu]->disabled); |
| 251 | local_irq_restore(irq1); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 254 | static void trace_bts_at(const struct bts_trace *trace, void *at) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 255 | { |
| 256 | struct bts_struct bts; |
| 257 | int err = 0; |
| 258 | |
| 259 | WARN_ON_ONCE(!trace->read); |
| 260 | if (!trace->read) |
| 261 | return; |
| 262 | |
| 263 | err = trace->read(this_tracer, at, &bts); |
| 264 | if (err < 0) |
| 265 | return; |
| 266 | |
| 267 | switch (bts.qualifier) { |
| 268 | case BTS_BRANCH: |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 269 | trace_hw_branch(bts.variant.lbr.from, bts.variant.lbr.to); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 270 | break; |
| 271 | } |
| 272 | } |
| 273 | |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 274 | /* |
| 275 | * Collect the trace on the current cpu and write it into the ftrace buffer. |
| 276 | * |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 277 | * pre: bts_tracer_lock must be locked |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 278 | */ |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 279 | static void trace_bts_cpu(void *arg) |
| 280 | { |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 281 | struct trace_array *tr = (struct trace_array *)arg; |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 282 | const struct bts_trace *trace; |
| 283 | unsigned char *at; |
| 284 | |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 285 | if (unlikely(!tr)) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 286 | return; |
| 287 | |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 288 | if (unlikely(atomic_read(&tr->data[raw_smp_processor_id()]->disabled))) |
| 289 | return; |
| 290 | |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 291 | if (unlikely(!this_tracer)) |
| 292 | return; |
| 293 | |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 294 | ds_suspend_bts(this_tracer); |
| 295 | trace = ds_read_bts(this_tracer); |
| 296 | if (!trace) |
| 297 | goto out; |
| 298 | |
| 299 | for (at = trace->ds.top; (void *)at < trace->ds.end; |
| 300 | at += trace->ds.size) |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 301 | trace_bts_at(trace, at); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 302 | |
| 303 | for (at = trace->ds.begin; (void *)at < trace->ds.top; |
| 304 | at += trace->ds.size) |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 305 | trace_bts_at(trace, at); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 306 | |
| 307 | out: |
| 308 | ds_resume_bts(this_tracer); |
| 309 | } |
| 310 | |
| 311 | static void trace_bts_prepare(struct trace_iterator *iter) |
| 312 | { |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 313 | spin_lock(&bts_tracer_lock); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 314 | |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 315 | on_each_cpu(trace_bts_cpu, iter->tr, 1); |
| 316 | |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 317 | spin_unlock(&bts_tracer_lock); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Markus Metzger | e23b8ad | 2009-01-19 10:33:31 +0100 | [diff] [blame] | 320 | static void trace_bts_close(struct trace_iterator *iter) |
| 321 | { |
| 322 | tracing_reset_online_cpus(iter->tr); |
| 323 | } |
| 324 | |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 325 | void trace_hw_branch_oops(void) |
| 326 | { |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 327 | spin_lock(&bts_tracer_lock); |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 328 | |
Markus Metzger | ba9372a | 2009-03-13 10:48:52 +0100 | [diff] [blame] | 329 | if (trace_hw_branches_enabled) |
| 330 | trace_bts_cpu(hw_branch_trace); |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 331 | |
Ingo Molnar | 2d542cf | 2009-02-25 08:40:09 +0100 | [diff] [blame] | 332 | spin_unlock(&bts_tracer_lock); |
Markus Metzger | b181874 | 2009-01-19 10:31:01 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 335 | struct tracer bts_tracer __read_mostly = |
| 336 | { |
| 337 | .name = "hw-branch-tracer", |
| 338 | .init = bts_trace_init, |
Markus Metzger | 5c5317d | 2009-01-19 10:26:53 +0100 | [diff] [blame] | 339 | .reset = bts_trace_reset, |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 340 | .print_header = bts_trace_print_header, |
| 341 | .print_line = bts_trace_print_line, |
| 342 | .start = bts_trace_start, |
| 343 | .stop = bts_trace_stop, |
Markus Metzger | e23b8ad | 2009-01-19 10:33:31 +0100 | [diff] [blame] | 344 | .open = trace_bts_prepare, |
Markus Metzger | 321bb5e | 2009-03-13 10:50:27 +0100 | [diff] [blame] | 345 | .close = trace_bts_close, |
| 346 | #ifdef CONFIG_FTRACE_SELFTEST |
| 347 | .selftest = trace_selftest_startup_hw_branches, |
| 348 | #endif /* CONFIG_FTRACE_SELFTEST */ |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | __init static int init_bts_trace(void) |
| 352 | { |
Markus Metzger | 5e01cb6 | 2009-02-24 13:55:18 +0100 | [diff] [blame] | 353 | register_hotcpu_notifier(&bts_hotcpu_notifier); |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 354 | return register_tracer(&bts_tracer); |
| 355 | } |
| 356 | device_initcall(init_bts_trace); |