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