Paolo Ciarrocchi | d441373 | 2008-02-19 23:51:27 +0100 | [diff] [blame] | 1 | /* |
Robert Richter | 6852fd9 | 2008-07-22 21:09:08 +0200 | [diff] [blame] | 2 | * @file op_model_amd.c |
Barry Kasindorf | bd87f1f | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 3 | * athlon / K7 / K8 / Family 10h model-specific MSR operations |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Robert Richter | ae735e9 | 2008-12-25 17:26:07 +0100 | [diff] [blame] | 5 | * @remark Copyright 2002-2009 OProfile authors |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * @remark Read the file COPYING |
| 7 | * |
| 8 | * @author John Levon |
| 9 | * @author Philippe Elie |
| 10 | * @author Graydon Hoare |
Robert Richter | adf5ec0 | 2008-07-22 21:08:48 +0200 | [diff] [blame] | 11 | * @author Robert Richter <robert.richter@amd.com> |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 12 | * @author Barry Kasindorf <barry.kasindorf@amd.com> |
| 13 | * @author Jason Yeh <jason.yeh@amd.com> |
| 14 | * @author Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> |
Robert Richter | ae735e9 | 2008-12-25 17:26:07 +0100 | [diff] [blame] | 15 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <linux/oprofile.h> |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 18 | #include <linux/device.h> |
| 19 | #include <linux/pci.h> |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 20 | #include <linux/percpu.h> |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/ptrace.h> |
| 23 | #include <asm/msr.h> |
Don Zickus | 3e4ff11 | 2006-06-26 13:57:01 +0200 | [diff] [blame] | 24 | #include <asm/nmi.h> |
Robert Richter | 013cfc5 | 2010-01-28 18:05:26 +0100 | [diff] [blame] | 25 | #include <asm/apic.h> |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 26 | #include <asm/processor.h> |
| 27 | #include <asm/cpufeature.h> |
Paolo Ciarrocchi | d441373 | 2008-02-19 23:51:27 +0100 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "op_x86_model.h" |
| 30 | #include "op_counter.h" |
| 31 | |
Robert Richter | 4c168ea | 2008-09-24 11:08:52 +0200 | [diff] [blame] | 32 | #define NUM_COUNTERS 4 |
| 33 | #define NUM_CONTROLS 4 |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 34 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
| 35 | #define NUM_VIRT_COUNTERS 32 |
| 36 | #define NUM_VIRT_CONTROLS 32 |
| 37 | #else |
| 38 | #define NUM_VIRT_COUNTERS NUM_COUNTERS |
| 39 | #define NUM_VIRT_CONTROLS NUM_CONTROLS |
| 40 | #endif |
| 41 | |
Robert Richter | 3370d35 | 2009-05-25 15:10:32 +0200 | [diff] [blame] | 42 | #define OP_EVENT_MASK 0x0FFF |
Robert Richter | 42399ad | 2009-05-25 17:59:06 +0200 | [diff] [blame] | 43 | #define OP_CTR_OVERFLOW (1ULL<<31) |
Robert Richter | 3370d35 | 2009-05-25 15:10:32 +0200 | [diff] [blame] | 44 | |
| 45 | #define MSR_AMD_EVENTSEL_RESERVED ((0xFFFFFCF0ULL<<32)|(1ULL<<21)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 47 | static unsigned long reset_value[NUM_VIRT_COUNTERS]; |
Robert Richter | 852402c | 2008-07-22 21:09:06 +0200 | [diff] [blame] | 48 | |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 49 | #define IBS_FETCH_SIZE 6 |
| 50 | #define IBS_OP_SIZE 12 |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 51 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 52 | static u32 ibs_caps; |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 53 | |
| 54 | struct op_ibs_config { |
| 55 | unsigned long op_enabled; |
| 56 | unsigned long fetch_enabled; |
| 57 | unsigned long max_cnt_fetch; |
| 58 | unsigned long max_cnt_op; |
| 59 | unsigned long rand_en; |
| 60 | unsigned long dispatched_ops; |
| 61 | }; |
| 62 | |
| 63 | static struct op_ibs_config ibs_config; |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 64 | static u64 ibs_op_ctl; |
Paolo Ciarrocchi | d441373 | 2008-02-19 23:51:27 +0100 | [diff] [blame] | 65 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 66 | /* |
| 67 | * IBS cpuid feature detection |
| 68 | */ |
| 69 | |
| 70 | #define IBS_CPUID_FEATURES 0x8000001b |
| 71 | |
| 72 | /* |
| 73 | * Same bit mask as for IBS cpuid feature flags (Fn8000_001B_EAX), but |
| 74 | * bit 0 is used to indicate the existence of IBS. |
| 75 | */ |
| 76 | #define IBS_CAPS_AVAIL (1LL<<0) |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 77 | #define IBS_CAPS_RDWROPCNT (1LL<<3) |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 78 | #define IBS_CAPS_OPCNT (1LL<<4) |
| 79 | |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 80 | /* |
| 81 | * IBS randomization macros |
| 82 | */ |
| 83 | #define IBS_RANDOM_BITS 12 |
| 84 | #define IBS_RANDOM_MASK ((1ULL << IBS_RANDOM_BITS) - 1) |
| 85 | #define IBS_RANDOM_MAXCNT_OFFSET (1ULL << (IBS_RANDOM_BITS - 5)) |
| 86 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 87 | static u32 get_ibs_caps(void) |
| 88 | { |
| 89 | u32 ibs_caps; |
| 90 | unsigned int max_level; |
| 91 | |
| 92 | if (!boot_cpu_has(X86_FEATURE_IBS)) |
| 93 | return 0; |
| 94 | |
| 95 | /* check IBS cpuid feature flags */ |
| 96 | max_level = cpuid_eax(0x80000000); |
| 97 | if (max_level < IBS_CPUID_FEATURES) |
| 98 | return IBS_CAPS_AVAIL; |
| 99 | |
| 100 | ibs_caps = cpuid_eax(IBS_CPUID_FEATURES); |
| 101 | if (!(ibs_caps & IBS_CAPS_AVAIL)) |
| 102 | /* cpuid flags not valid */ |
| 103 | return IBS_CAPS_AVAIL; |
| 104 | |
| 105 | return ibs_caps; |
| 106 | } |
| 107 | |
Robert Richter | 7e7478c | 2009-07-16 13:09:53 +0200 | [diff] [blame] | 108 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
| 109 | |
Robert Richter | 7e7478c | 2009-07-16 13:09:53 +0200 | [diff] [blame] | 110 | static void op_mux_switch_ctrl(struct op_x86_model_spec const *model, |
| 111 | struct op_msrs const * const msrs) |
| 112 | { |
| 113 | u64 val; |
| 114 | int i; |
| 115 | |
| 116 | /* enable active counters */ |
| 117 | for (i = 0; i < NUM_COUNTERS; ++i) { |
| 118 | int virt = op_x86_phys_to_virt(i); |
Robert Richter | cfc9c0b | 2010-02-26 13:45:24 +0100 | [diff] [blame] | 119 | if (!reset_value[virt]) |
Robert Richter | 7e7478c | 2009-07-16 13:09:53 +0200 | [diff] [blame] | 120 | continue; |
| 121 | rdmsrl(msrs->controls[i].addr, val); |
| 122 | val &= model->reserved; |
| 123 | val |= op_x86_get_ctrl(model, &counter_config[virt]); |
| 124 | wrmsrl(msrs->controls[i].addr, val); |
| 125 | } |
| 126 | } |
| 127 | |
Robert Richter | 7e7478c | 2009-07-16 13:09:53 +0200 | [diff] [blame] | 128 | #endif |
| 129 | |
Robert Richter | 6657fe4 | 2008-07-22 21:08:50 +0200 | [diff] [blame] | 130 | /* functions for op_amd_spec */ |
Robert Richter | dfa1542 | 2008-07-22 21:08:49 +0200 | [diff] [blame] | 131 | |
Robert Richter | 6657fe4 | 2008-07-22 21:08:50 +0200 | [diff] [blame] | 132 | static void op_amd_fill_in_addresses(struct op_msrs * const msrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 134 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Paolo Ciarrocchi | d441373 | 2008-02-19 23:51:27 +0100 | [diff] [blame] | 136 | for (i = 0; i < NUM_COUNTERS; i++) { |
Robert Richter | 4c168ea | 2008-09-24 11:08:52 +0200 | [diff] [blame] | 137 | if (reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i)) |
| 138 | msrs->counters[i].addr = MSR_K7_PERFCTR0 + i; |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Paolo Ciarrocchi | d441373 | 2008-02-19 23:51:27 +0100 | [diff] [blame] | 141 | for (i = 0; i < NUM_CONTROLS; i++) { |
Robert Richter | 4c168ea | 2008-09-24 11:08:52 +0200 | [diff] [blame] | 142 | if (reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i)) |
| 143 | msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i; |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Robert Richter | ef8828d | 2009-05-25 19:31:44 +0200 | [diff] [blame] | 147 | static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, |
| 148 | struct op_msrs const * const msrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
Robert Richter | 3370d35 | 2009-05-25 15:10:32 +0200 | [diff] [blame] | 150 | u64 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | int i; |
Paolo Ciarrocchi | d441373 | 2008-02-19 23:51:27 +0100 | [diff] [blame] | 152 | |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 153 | /* setup reset_value */ |
| 154 | for (i = 0; i < NUM_VIRT_COUNTERS; ++i) { |
Robert Richter | cfc9c0b | 2010-02-26 13:45:24 +0100 | [diff] [blame] | 155 | if (counter_config[i].enabled |
| 156 | && msrs->counters[op_x86_virt_to_phys(i)].addr) |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 157 | reset_value[i] = counter_config[i].count; |
Robert Richter | c550091 | 2009-07-16 13:11:16 +0200 | [diff] [blame] | 158 | else |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 159 | reset_value[i] = 0; |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* clear all counters */ |
Robert Richter | 6e63ea4 | 2009-07-07 19:25:39 +0200 | [diff] [blame] | 163 | for (i = 0; i < NUM_CONTROLS; ++i) { |
Robert Richter | 98a2e73 | 2010-02-23 18:14:58 +0100 | [diff] [blame] | 164 | if (unlikely(!msrs->controls[i].addr)) { |
| 165 | if (counter_config[i].enabled && !smp_processor_id()) |
| 166 | /* |
| 167 | * counter is reserved, this is on all |
| 168 | * cpus, so report only for cpu #0 |
| 169 | */ |
| 170 | op_x86_warn_reserved(i); |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 171 | continue; |
Robert Richter | 98a2e73 | 2010-02-23 18:14:58 +0100 | [diff] [blame] | 172 | } |
Robert Richter | 3370d35 | 2009-05-25 15:10:32 +0200 | [diff] [blame] | 173 | rdmsrl(msrs->controls[i].addr, val); |
Robert Richter | 98a2e73 | 2010-02-23 18:14:58 +0100 | [diff] [blame] | 174 | if (val & ARCH_PERFMON_EVENTSEL0_ENABLE) |
| 175 | op_x86_warn_in_use(i); |
Robert Richter | 3370d35 | 2009-05-25 15:10:32 +0200 | [diff] [blame] | 176 | val &= model->reserved; |
| 177 | wrmsrl(msrs->controls[i].addr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /* avoid a false detection of ctr overflows in NMI handler */ |
Robert Richter | 4c168ea | 2008-09-24 11:08:52 +0200 | [diff] [blame] | 181 | for (i = 0; i < NUM_COUNTERS; ++i) { |
Robert Richter | 217d3cf | 2009-06-04 02:36:44 +0200 | [diff] [blame] | 182 | if (unlikely(!msrs->counters[i].addr)) |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 183 | continue; |
Robert Richter | bbc5986 | 2009-05-25 17:38:19 +0200 | [diff] [blame] | 184 | wrmsrl(msrs->counters[i].addr, -1LL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* enable active counters */ |
Robert Richter | 4c168ea | 2008-09-24 11:08:52 +0200 | [diff] [blame] | 188 | for (i = 0; i < NUM_COUNTERS; ++i) { |
Robert Richter | d8471ad | 2009-07-16 13:04:43 +0200 | [diff] [blame] | 189 | int virt = op_x86_phys_to_virt(i); |
Robert Richter | cfc9c0b | 2010-02-26 13:45:24 +0100 | [diff] [blame] | 190 | if (!reset_value[virt]) |
Robert Richter | d8471ad | 2009-07-16 13:04:43 +0200 | [diff] [blame] | 191 | continue; |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 192 | |
Robert Richter | d8471ad | 2009-07-16 13:04:43 +0200 | [diff] [blame] | 193 | /* setup counter registers */ |
| 194 | wrmsrl(msrs->counters[i].addr, -(u64)reset_value[virt]); |
| 195 | |
| 196 | /* setup control registers */ |
| 197 | rdmsrl(msrs->controls[i].addr, val); |
| 198 | val &= model->reserved; |
| 199 | val |= op_x86_get_ctrl(model, &counter_config[virt]); |
| 200 | wrmsrl(msrs->controls[i].addr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Suravee Suthikulpanit | f125be1 | 2010-01-18 11:25:45 -0600 | [diff] [blame] | 204 | /* |
| 205 | * 16-bit Linear Feedback Shift Register (LFSR) |
| 206 | * |
| 207 | * 16 14 13 11 |
| 208 | * Feedback polynomial = X + X + X + X + 1 |
| 209 | */ |
| 210 | static unsigned int lfsr_random(void) |
| 211 | { |
| 212 | static unsigned int lfsr_value = 0xF00D; |
| 213 | unsigned int bit; |
| 214 | |
| 215 | /* Compute next bit to shift in */ |
| 216 | bit = ((lfsr_value >> 0) ^ |
| 217 | (lfsr_value >> 2) ^ |
| 218 | (lfsr_value >> 3) ^ |
| 219 | (lfsr_value >> 5)) & 0x0001; |
| 220 | |
| 221 | /* Advance to next register value */ |
| 222 | lfsr_value = (lfsr_value >> 1) | (bit << 15); |
| 223 | |
| 224 | return lfsr_value; |
| 225 | } |
| 226 | |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 227 | /* |
| 228 | * IBS software randomization |
| 229 | * |
| 230 | * The IBS periodic op counter is randomized in software. The lower 12 |
| 231 | * bits of the 20 bit counter are randomized. IbsOpCurCnt is |
| 232 | * initialized with a 12 bit random value. |
| 233 | */ |
| 234 | static inline u64 op_amd_randomize_ibs_op(u64 val) |
| 235 | { |
| 236 | unsigned int random = lfsr_random(); |
| 237 | |
| 238 | if (!(ibs_caps & IBS_CAPS_RDWROPCNT)) |
| 239 | /* |
| 240 | * Work around if the hw can not write to IbsOpCurCnt |
| 241 | * |
| 242 | * Randomize the lower 8 bits of the 16 bit |
| 243 | * IbsOpMaxCnt [15:0] value in the range of -128 to |
| 244 | * +127 by adding/subtracting an offset to the |
| 245 | * maximum count (IbsOpMaxCnt). |
| 246 | * |
| 247 | * To avoid over or underflows and protect upper bits |
| 248 | * starting at bit 16, the initial value for |
| 249 | * IbsOpMaxCnt must fit in the range from 0x0081 to |
| 250 | * 0xff80. |
| 251 | */ |
| 252 | val += (s8)(random >> 4); |
| 253 | else |
| 254 | val |= (u64)(random & IBS_RANDOM_MASK) << 32; |
| 255 | |
| 256 | return val; |
| 257 | } |
| 258 | |
Andrew Morton | 4680e64 | 2009-06-23 12:36:08 -0700 | [diff] [blame] | 259 | static inline void |
Robert Richter | 7939d2b | 2008-07-22 21:08:56 +0200 | [diff] [blame] | 260 | op_amd_handle_ibs(struct pt_regs * const regs, |
| 261 | struct op_msrs const * const msrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 263 | u64 val, ctl; |
Robert Richter | 1acda87 | 2009-01-05 10:35:31 +0100 | [diff] [blame] | 264 | struct op_entry entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 266 | if (!ibs_caps) |
Andrew Morton | 4680e64 | 2009-06-23 12:36:08 -0700 | [diff] [blame] | 267 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Robert Richter | 7939d2b | 2008-07-22 21:08:56 +0200 | [diff] [blame] | 269 | if (ibs_config.fetch_enabled) { |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 270 | rdmsrl(MSR_AMD64_IBSFETCHCTL, ctl); |
| 271 | if (ctl & IBS_FETCH_VAL) { |
| 272 | rdmsrl(MSR_AMD64_IBSFETCHLINAD, val); |
| 273 | oprofile_write_reserve(&entry, regs, val, |
Robert Richter | 14f0ca8 | 2009-01-07 21:50:22 +0100 | [diff] [blame] | 274 | IBS_FETCH_CODE, IBS_FETCH_SIZE); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 275 | oprofile_add_data64(&entry, val); |
| 276 | oprofile_add_data64(&entry, ctl); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 277 | rdmsrl(MSR_AMD64_IBSFETCHPHYSAD, val); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 278 | oprofile_add_data64(&entry, val); |
Robert Richter | 14f0ca8 | 2009-01-07 21:50:22 +0100 | [diff] [blame] | 279 | oprofile_write_commit(&entry); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 280 | |
Robert Richter | fd13f6c | 2008-10-19 21:00:09 +0200 | [diff] [blame] | 281 | /* reenable the IRQ */ |
Robert Richter | a163b10 | 2010-02-25 19:43:07 +0100 | [diff] [blame^] | 282 | ctl &= ~(IBS_FETCH_VAL | IBS_FETCH_CNT); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 283 | ctl |= IBS_FETCH_ENABLE; |
| 284 | wrmsrl(MSR_AMD64_IBSFETCHCTL, ctl); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Robert Richter | 7939d2b | 2008-07-22 21:08:56 +0200 | [diff] [blame] | 288 | if (ibs_config.op_enabled) { |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 289 | rdmsrl(MSR_AMD64_IBSOPCTL, ctl); |
| 290 | if (ctl & IBS_OP_VAL) { |
| 291 | rdmsrl(MSR_AMD64_IBSOPRIP, val); |
| 292 | oprofile_write_reserve(&entry, regs, val, |
Robert Richter | 14f0ca8 | 2009-01-07 21:50:22 +0100 | [diff] [blame] | 293 | IBS_OP_CODE, IBS_OP_SIZE); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 294 | oprofile_add_data64(&entry, val); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 295 | rdmsrl(MSR_AMD64_IBSOPDATA, val); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 296 | oprofile_add_data64(&entry, val); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 297 | rdmsrl(MSR_AMD64_IBSOPDATA2, val); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 298 | oprofile_add_data64(&entry, val); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 299 | rdmsrl(MSR_AMD64_IBSOPDATA3, val); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 300 | oprofile_add_data64(&entry, val); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 301 | rdmsrl(MSR_AMD64_IBSDCLINAD, val); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 302 | oprofile_add_data64(&entry, val); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 303 | rdmsrl(MSR_AMD64_IBSDCPHYSAD, val); |
Robert Richter | 51563a0 | 2009-06-03 20:54:56 +0200 | [diff] [blame] | 304 | oprofile_add_data64(&entry, val); |
Robert Richter | 14f0ca8 | 2009-01-07 21:50:22 +0100 | [diff] [blame] | 305 | oprofile_write_commit(&entry); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 306 | |
| 307 | /* reenable the IRQ */ |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 308 | ctl = op_amd_randomize_ibs_op(ibs_op_ctl); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 309 | wrmsrl(MSR_AMD64_IBSOPCTL, ctl); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 310 | } |
| 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 314 | static inline void op_amd_start_ibs(void) |
| 315 | { |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 316 | u64 val; |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 317 | |
| 318 | if (!ibs_caps) |
| 319 | return; |
| 320 | |
| 321 | if (ibs_config.fetch_enabled) { |
Robert Richter | a163b10 | 2010-02-25 19:43:07 +0100 | [diff] [blame^] | 322 | val = (ibs_config.max_cnt_fetch >> 4) & IBS_FETCH_MAX_CNT; |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 323 | val |= ibs_config.rand_en ? IBS_FETCH_RAND_EN : 0; |
| 324 | val |= IBS_FETCH_ENABLE; |
| 325 | wrmsrl(MSR_AMD64_IBSFETCHCTL, val); |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 328 | if (ibs_config.op_enabled) { |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 329 | ibs_op_ctl = ibs_config.max_cnt_op >> 4; |
| 330 | if (!(ibs_caps & IBS_CAPS_RDWROPCNT)) { |
| 331 | /* |
| 332 | * IbsOpCurCnt not supported. See |
| 333 | * op_amd_randomize_ibs_op() for details. |
| 334 | */ |
| 335 | ibs_op_ctl = clamp(ibs_op_ctl, 0x0081ULL, 0xFF80ULL); |
| 336 | } else { |
| 337 | /* |
| 338 | * The start value is randomized with a |
| 339 | * positive offset, we need to compensate it |
| 340 | * with the half of the randomized range. Also |
| 341 | * avoid underflows. |
| 342 | */ |
| 343 | ibs_op_ctl = min(ibs_op_ctl + IBS_RANDOM_MAXCNT_OFFSET, |
Robert Richter | a163b10 | 2010-02-25 19:43:07 +0100 | [diff] [blame^] | 344 | IBS_OP_MAX_CNT); |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 345 | } |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 346 | if (ibs_caps & IBS_CAPS_OPCNT && ibs_config.dispatched_ops) |
Robert Richter | ba52078 | 2010-02-23 15:46:49 +0100 | [diff] [blame] | 347 | ibs_op_ctl |= IBS_OP_CNT_CTL; |
| 348 | ibs_op_ctl |= IBS_OP_ENABLE; |
| 349 | val = op_amd_randomize_ibs_op(ibs_op_ctl); |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 350 | wrmsrl(MSR_AMD64_IBSOPCTL, val); |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | static void op_amd_stop_ibs(void) |
| 355 | { |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 356 | if (!ibs_caps) |
| 357 | return; |
| 358 | |
| 359 | if (ibs_config.fetch_enabled) |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 360 | /* clear max count and enable */ |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 361 | wrmsrl(MSR_AMD64_IBSFETCHCTL, 0); |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 362 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 363 | if (ibs_config.op_enabled) |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 364 | /* clear max count and enable */ |
Robert Richter | c572ae4 | 2009-06-03 20:10:39 +0200 | [diff] [blame] | 365 | wrmsrl(MSR_AMD64_IBSOPCTL, 0); |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 366 | } |
| 367 | |
Robert Richter | 7939d2b | 2008-07-22 21:08:56 +0200 | [diff] [blame] | 368 | static int op_amd_check_ctrs(struct pt_regs * const regs, |
| 369 | struct op_msrs const * const msrs) |
| 370 | { |
Robert Richter | 42399ad | 2009-05-25 17:59:06 +0200 | [diff] [blame] | 371 | u64 val; |
Robert Richter | 7939d2b | 2008-07-22 21:08:56 +0200 | [diff] [blame] | 372 | int i; |
| 373 | |
Robert Richter | 6e63ea4 | 2009-07-07 19:25:39 +0200 | [diff] [blame] | 374 | for (i = 0; i < NUM_COUNTERS; ++i) { |
Robert Richter | d8471ad | 2009-07-16 13:04:43 +0200 | [diff] [blame] | 375 | int virt = op_x86_phys_to_virt(i); |
| 376 | if (!reset_value[virt]) |
Robert Richter | 7939d2b | 2008-07-22 21:08:56 +0200 | [diff] [blame] | 377 | continue; |
Robert Richter | 42399ad | 2009-05-25 17:59:06 +0200 | [diff] [blame] | 378 | rdmsrl(msrs->counters[i].addr, val); |
| 379 | /* bit is clear if overflowed: */ |
| 380 | if (val & OP_CTR_OVERFLOW) |
| 381 | continue; |
Robert Richter | d8471ad | 2009-07-16 13:04:43 +0200 | [diff] [blame] | 382 | oprofile_add_sample(regs, virt); |
| 383 | wrmsrl(msrs->counters[i].addr, -(u64)reset_value[virt]); |
Robert Richter | 7939d2b | 2008-07-22 21:08:56 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | op_amd_handle_ibs(regs, msrs); |
| 387 | |
| 388 | /* See op_model_ppro.c */ |
| 389 | return 1; |
| 390 | } |
Paolo Ciarrocchi | d441373 | 2008-02-19 23:51:27 +0100 | [diff] [blame] | 391 | |
Robert Richter | 6657fe4 | 2008-07-22 21:08:50 +0200 | [diff] [blame] | 392 | static void op_amd_start(struct op_msrs const * const msrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
Robert Richter | dea3766 | 2009-05-25 18:11:52 +0200 | [diff] [blame] | 394 | u64 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | int i; |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 396 | |
Robert Richter | 6e63ea4 | 2009-07-07 19:25:39 +0200 | [diff] [blame] | 397 | for (i = 0; i < NUM_COUNTERS; ++i) { |
Robert Richter | d8471ad | 2009-07-16 13:04:43 +0200 | [diff] [blame] | 398 | if (!reset_value[op_x86_phys_to_virt(i)]) |
| 399 | continue; |
| 400 | rdmsrl(msrs->controls[i].addr, val); |
| 401 | val |= ARCH_PERFMON_EVENTSEL0_ENABLE; |
| 402 | wrmsrl(msrs->controls[i].addr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
Robert Richter | 852402c | 2008-07-22 21:09:06 +0200 | [diff] [blame] | 404 | |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 405 | op_amd_start_ibs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Robert Richter | 6657fe4 | 2008-07-22 21:08:50 +0200 | [diff] [blame] | 408 | static void op_amd_stop(struct op_msrs const * const msrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Robert Richter | dea3766 | 2009-05-25 18:11:52 +0200 | [diff] [blame] | 410 | u64 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | int i; |
| 412 | |
Robert Richter | fd13f6c | 2008-10-19 21:00:09 +0200 | [diff] [blame] | 413 | /* |
| 414 | * Subtle: stop on all counters to avoid race with setting our |
| 415 | * pm callback |
| 416 | */ |
Robert Richter | 6e63ea4 | 2009-07-07 19:25:39 +0200 | [diff] [blame] | 417 | for (i = 0; i < NUM_COUNTERS; ++i) { |
Robert Richter | d8471ad | 2009-07-16 13:04:43 +0200 | [diff] [blame] | 418 | if (!reset_value[op_x86_phys_to_virt(i)]) |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 419 | continue; |
Robert Richter | dea3766 | 2009-05-25 18:11:52 +0200 | [diff] [blame] | 420 | rdmsrl(msrs->controls[i].addr, val); |
| 421 | val &= ~ARCH_PERFMON_EVENTSEL0_ENABLE; |
| 422 | wrmsrl(msrs->controls[i].addr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 424 | |
Robert Richter | 9063759 | 2009-03-10 19:15:57 +0100 | [diff] [blame] | 425 | op_amd_stop_ibs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Robert Richter | 6657fe4 | 2008-07-22 21:08:50 +0200 | [diff] [blame] | 428 | static void op_amd_shutdown(struct op_msrs const * const msrs) |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 429 | { |
| 430 | int i; |
| 431 | |
Robert Richter | 6e63ea4 | 2009-07-07 19:25:39 +0200 | [diff] [blame] | 432 | for (i = 0; i < NUM_COUNTERS; ++i) { |
Robert Richter | 217d3cf | 2009-06-04 02:36:44 +0200 | [diff] [blame] | 433 | if (msrs->counters[i].addr) |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 434 | release_perfctr_nmi(MSR_K7_PERFCTR0 + i); |
| 435 | } |
Robert Richter | 5e766e3 | 2009-07-08 14:54:17 +0200 | [diff] [blame] | 436 | for (i = 0; i < NUM_CONTROLS; ++i) { |
Robert Richter | 217d3cf | 2009-06-04 02:36:44 +0200 | [diff] [blame] | 437 | if (msrs->controls[i].addr) |
Don Zickus | cb9c448 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 438 | release_evntsel_nmi(MSR_K7_EVNTSEL0 + i); |
| 439 | } |
| 440 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Robert Richter | 7d77f2d | 2008-07-22 21:08:57 +0200 | [diff] [blame] | 442 | static u8 ibs_eilvt_off; |
| 443 | |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 444 | static inline void apic_init_ibs_nmi_per_cpu(void *arg) |
| 445 | { |
Robert Richter | 7d77f2d | 2008-07-22 21:08:57 +0200 | [diff] [blame] | 446 | ibs_eilvt_off = setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_NMI, 0); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static inline void apic_clear_ibs_nmi_per_cpu(void *arg) |
| 450 | { |
| 451 | setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1); |
| 452 | } |
| 453 | |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 454 | static int init_ibs_nmi(void) |
Robert Richter | 7d77f2d | 2008-07-22 21:08:57 +0200 | [diff] [blame] | 455 | { |
| 456 | #define IBSCTL_LVTOFFSETVAL (1 << 8) |
| 457 | #define IBSCTL 0x1cc |
| 458 | struct pci_dev *cpu_cfg; |
| 459 | int nodes; |
| 460 | u32 value = 0; |
| 461 | |
| 462 | /* per CPU setup */ |
Robert Richter | ebb535d | 2008-07-22 21:08:59 +0200 | [diff] [blame] | 463 | on_each_cpu(apic_init_ibs_nmi_per_cpu, NULL, 1); |
Robert Richter | 7d77f2d | 2008-07-22 21:08:57 +0200 | [diff] [blame] | 464 | |
| 465 | nodes = 0; |
| 466 | cpu_cfg = NULL; |
| 467 | do { |
| 468 | cpu_cfg = pci_get_device(PCI_VENDOR_ID_AMD, |
| 469 | PCI_DEVICE_ID_AMD_10H_NB_MISC, |
| 470 | cpu_cfg); |
| 471 | if (!cpu_cfg) |
| 472 | break; |
| 473 | ++nodes; |
| 474 | pci_write_config_dword(cpu_cfg, IBSCTL, ibs_eilvt_off |
| 475 | | IBSCTL_LVTOFFSETVAL); |
| 476 | pci_read_config_dword(cpu_cfg, IBSCTL, &value); |
| 477 | if (value != (ibs_eilvt_off | IBSCTL_LVTOFFSETVAL)) { |
Robert Richter | 83bd924 | 2008-12-15 15:09:50 +0100 | [diff] [blame] | 478 | pci_dev_put(cpu_cfg); |
Robert Richter | 7d77f2d | 2008-07-22 21:08:57 +0200 | [diff] [blame] | 479 | printk(KERN_DEBUG "Failed to setup IBS LVT offset, " |
| 480 | "IBSCTL = 0x%08x", value); |
| 481 | return 1; |
| 482 | } |
| 483 | } while (1); |
| 484 | |
| 485 | if (!nodes) { |
| 486 | printk(KERN_DEBUG "No CPU node configured for IBS"); |
| 487 | return 1; |
| 488 | } |
| 489 | |
Robert Richter | 7d77f2d | 2008-07-22 21:08:57 +0200 | [diff] [blame] | 490 | return 0; |
| 491 | } |
| 492 | |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 493 | /* uninitialize the APIC for the IBS interrupts if needed */ |
| 494 | static void clear_ibs_nmi(void) |
| 495 | { |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 496 | if (ibs_caps) |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 497 | on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1); |
| 498 | } |
| 499 | |
Robert Richter | fd13f6c | 2008-10-19 21:00:09 +0200 | [diff] [blame] | 500 | /* initialize the APIC for the IBS interrupts if available */ |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 501 | static void ibs_init(void) |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 502 | { |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 503 | ibs_caps = get_ibs_caps(); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 504 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 505 | if (!ibs_caps) |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 506 | return; |
| 507 | |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 508 | if (init_ibs_nmi()) { |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 509 | ibs_caps = 0; |
Robert Richter | 852402c | 2008-07-22 21:09:06 +0200 | [diff] [blame] | 510 | return; |
| 511 | } |
| 512 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 513 | printk(KERN_INFO "oprofile: AMD IBS detected (0x%08x)\n", |
| 514 | (unsigned)ibs_caps); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 517 | static void ibs_exit(void) |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 518 | { |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 519 | if (!ibs_caps) |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 520 | return; |
| 521 | |
| 522 | clear_ibs_nmi(); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 525 | static int (*create_arch_files)(struct super_block *sb, struct dentry *root); |
Robert Richter | 270d3e1 | 2008-07-22 21:09:01 +0200 | [diff] [blame] | 526 | |
Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 527 | static int setup_ibs_files(struct super_block *sb, struct dentry *root) |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 528 | { |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 529 | struct dentry *dir; |
Robert Richter | 270d3e1 | 2008-07-22 21:09:01 +0200 | [diff] [blame] | 530 | int ret = 0; |
| 531 | |
| 532 | /* architecture specific files */ |
| 533 | if (create_arch_files) |
| 534 | ret = create_arch_files(sb, root); |
| 535 | |
| 536 | if (ret) |
| 537 | return ret; |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 538 | |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 539 | if (!ibs_caps) |
Robert Richter | 270d3e1 | 2008-07-22 21:09:01 +0200 | [diff] [blame] | 540 | return ret; |
| 541 | |
| 542 | /* model specific files */ |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 543 | |
| 544 | /* setup some reasonable defaults */ |
| 545 | ibs_config.max_cnt_fetch = 250000; |
| 546 | ibs_config.fetch_enabled = 0; |
| 547 | ibs_config.max_cnt_op = 250000; |
| 548 | ibs_config.op_enabled = 0; |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 549 | ibs_config.dispatched_ops = 0; |
Robert Richter | 2d55a47 | 2008-07-18 17:56:05 +0200 | [diff] [blame] | 550 | |
| 551 | dir = oprofilefs_mkdir(sb, root, "ibs_fetch"); |
| 552 | oprofilefs_create_ulong(sb, dir, "enable", |
| 553 | &ibs_config.fetch_enabled); |
| 554 | oprofilefs_create_ulong(sb, dir, "max_count", |
| 555 | &ibs_config.max_cnt_fetch); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 556 | oprofilefs_create_ulong(sb, dir, "rand_enable", |
| 557 | &ibs_config.rand_en); |
Robert Richter | 2d55a47 | 2008-07-18 17:56:05 +0200 | [diff] [blame] | 558 | |
Robert Richter | ccd755c | 2008-07-29 16:57:10 +0200 | [diff] [blame] | 559 | dir = oprofilefs_mkdir(sb, root, "ibs_op"); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 560 | oprofilefs_create_ulong(sb, dir, "enable", |
Robert Richter | 2d55a47 | 2008-07-18 17:56:05 +0200 | [diff] [blame] | 561 | &ibs_config.op_enabled); |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 562 | oprofilefs_create_ulong(sb, dir, "max_count", |
Robert Richter | 2d55a47 | 2008-07-18 17:56:05 +0200 | [diff] [blame] | 563 | &ibs_config.max_cnt_op); |
Robert Richter | 64683da | 2010-02-04 10:57:23 +0100 | [diff] [blame] | 564 | if (ibs_caps & IBS_CAPS_OPCNT) |
| 565 | oprofilefs_create_ulong(sb, dir, "dispatched_ops", |
| 566 | &ibs_config.dispatched_ops); |
Robert Richter | fc2bd73 | 2008-07-22 21:09:00 +0200 | [diff] [blame] | 567 | |
| 568 | return 0; |
Barry Kasindorf | 56784f1 | 2008-07-22 21:08:55 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Robert Richter | adf5ec0 | 2008-07-22 21:08:48 +0200 | [diff] [blame] | 571 | static int op_amd_init(struct oprofile_operations *ops) |
| 572 | { |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 573 | ibs_init(); |
Robert Richter | 270d3e1 | 2008-07-22 21:09:01 +0200 | [diff] [blame] | 574 | create_arch_files = ops->create_files; |
| 575 | ops->create_files = setup_ibs_files; |
Robert Richter | adf5ec0 | 2008-07-22 21:08:48 +0200 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | static void op_amd_exit(void) |
| 580 | { |
Robert Richter | fe615cb | 2008-11-24 14:58:03 +0100 | [diff] [blame] | 581 | ibs_exit(); |
Robert Richter | adf5ec0 | 2008-07-22 21:08:48 +0200 | [diff] [blame] | 582 | } |
| 583 | |
Robert Richter | 259a83a | 2009-07-09 15:12:35 +0200 | [diff] [blame] | 584 | struct op_x86_model_spec op_amd_spec = { |
Robert Richter | c92960f | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 585 | .num_counters = NUM_COUNTERS, |
| 586 | .num_controls = NUM_CONTROLS, |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 587 | .num_virt_counters = NUM_VIRT_COUNTERS, |
Robert Richter | 3370d35 | 2009-05-25 15:10:32 +0200 | [diff] [blame] | 588 | .reserved = MSR_AMD_EVENTSEL_RESERVED, |
| 589 | .event_mask = OP_EVENT_MASK, |
| 590 | .init = op_amd_init, |
| 591 | .exit = op_amd_exit, |
Robert Richter | c92960f | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 592 | .fill_in_addresses = &op_amd_fill_in_addresses, |
| 593 | .setup_ctrs = &op_amd_setup_ctrs, |
| 594 | .check_ctrs = &op_amd_check_ctrs, |
| 595 | .start = &op_amd_start, |
| 596 | .stop = &op_amd_stop, |
Robert Richter | 3370d35 | 2009-05-25 15:10:32 +0200 | [diff] [blame] | 597 | .shutdown = &op_amd_shutdown, |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 598 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
Robert Richter | 7e7478c | 2009-07-16 13:09:53 +0200 | [diff] [blame] | 599 | .switch_ctrl = &op_mux_switch_ctrl, |
Jason Yeh | 4d4036e | 2009-07-08 13:49:38 +0200 | [diff] [blame] | 600 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | }; |