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