diff options
26 files changed, 2228 insertions, 385 deletions
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index c78f14a0df00..dab39350e51e 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h | |||
@@ -234,7 +234,7 @@ extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); | |||
234 | extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap); | 234 | extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap); |
235 | extern void perf_check_microcode(void); | 235 | extern void perf_check_microcode(void); |
236 | #else | 236 | #else |
237 | static inline perf_guest_switch_msr *perf_guest_get_msrs(int *nr) | 237 | static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) |
238 | { | 238 | { |
239 | *nr = 0; | 239 | *nr = 0; |
240 | return NULL; | 240 | return NULL; |
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h index a15df4be151f..821d53b696d1 100644 --- a/arch/x86/kernel/cpu/perf_event.h +++ b/arch/x86/kernel/cpu/perf_event.h | |||
@@ -374,7 +374,7 @@ struct x86_pmu { | |||
374 | /* | 374 | /* |
375 | * Intel DebugStore bits | 375 | * Intel DebugStore bits |
376 | */ | 376 | */ |
377 | int bts :1, | 377 | unsigned int bts :1, |
378 | bts_active :1, | 378 | bts_active :1, |
379 | pebs :1, | 379 | pebs :1, |
380 | pebs_active :1, | 380 | pebs_active :1, |
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c index 7a8b9d0abcaa..382366977d4c 100644 --- a/arch/x86/kernel/cpu/perf_event_intel.c +++ b/arch/x86/kernel/cpu/perf_event_intel.c | |||
@@ -138,6 +138,84 @@ static u64 intel_pmu_event_map(int hw_event) | |||
138 | return intel_perfmon_event_map[hw_event]; | 138 | return intel_perfmon_event_map[hw_event]; |
139 | } | 139 | } |
140 | 140 | ||
141 | #define SNB_DMND_DATA_RD (1ULL << 0) | ||
142 | #define SNB_DMND_RFO (1ULL << 1) | ||
143 | #define SNB_DMND_IFETCH (1ULL << 2) | ||
144 | #define SNB_DMND_WB (1ULL << 3) | ||
145 | #define SNB_PF_DATA_RD (1ULL << 4) | ||
146 | #define SNB_PF_RFO (1ULL << 5) | ||
147 | #define SNB_PF_IFETCH (1ULL << 6) | ||
148 | #define SNB_LLC_DATA_RD (1ULL << 7) | ||
149 | #define SNB_LLC_RFO (1ULL << 8) | ||
150 | #define SNB_LLC_IFETCH (1ULL << 9) | ||
151 | #define SNB_BUS_LOCKS (1ULL << 10) | ||
152 | #define SNB_STRM_ST (1ULL << 11) | ||
153 | #define SNB_OTHER (1ULL << 15) | ||
154 | #define SNB_RESP_ANY (1ULL << 16) | ||
155 | #define SNB_NO_SUPP (1ULL << 17) | ||
156 | #define SNB_LLC_HITM (1ULL << 18) | ||
157 | #define SNB_LLC_HITE (1ULL << 19) | ||
158 | #define SNB_LLC_HITS (1ULL << 20) | ||
159 | #define SNB_LLC_HITF (1ULL << 21) | ||
160 | #define SNB_LOCAL (1ULL << 22) | ||
161 | #define SNB_REMOTE (0xffULL << 23) | ||
162 | #define SNB_SNP_NONE (1ULL << 31) | ||
163 | #define SNB_SNP_NOT_NEEDED (1ULL << 32) | ||
164 | #define SNB_SNP_MISS (1ULL << 33) | ||
165 | #define SNB_NO_FWD (1ULL << 34) | ||
166 | #define SNB_SNP_FWD (1ULL << 35) | ||
167 | #define SNB_HITM (1ULL << 36) | ||
168 | #define SNB_NON_DRAM (1ULL << 37) | ||
169 | |||
170 | #define SNB_DMND_READ (SNB_DMND_DATA_RD|SNB_LLC_DATA_RD) | ||
171 | #define SNB_DMND_WRITE (SNB_DMND_RFO|SNB_LLC_RFO) | ||
172 | #define SNB_DMND_PREFETCH (SNB_PF_DATA_RD|SNB_PF_RFO) | ||
173 | |||
174 | #define SNB_SNP_ANY (SNB_SNP_NONE|SNB_SNP_NOT_NEEDED| \ | ||
175 | SNB_SNP_MISS|SNB_NO_FWD|SNB_SNP_FWD| \ | ||
176 | SNB_HITM) | ||
177 | |||
178 | #define SNB_DRAM_ANY (SNB_LOCAL|SNB_REMOTE|SNB_SNP_ANY) | ||
179 | #define SNB_DRAM_REMOTE (SNB_REMOTE|SNB_SNP_ANY) | ||
180 | |||
181 | #define SNB_L3_ACCESS SNB_RESP_ANY | ||
182 | #define SNB_L3_MISS (SNB_DRAM_ANY|SNB_NON_DRAM) | ||
183 | |||
184 | static __initconst const u64 snb_hw_cache_extra_regs | ||
185 | [PERF_COUNT_HW_CACHE_MAX] | ||
186 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
187 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | ||
188 | { | ||
189 | [ C(LL ) ] = { | ||
190 | [ C(OP_READ) ] = { | ||
191 | [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_L3_ACCESS, | ||
192 | [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_L3_MISS, | ||
193 | }, | ||
194 | [ C(OP_WRITE) ] = { | ||
195 | [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_L3_ACCESS, | ||
196 | [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_L3_MISS, | ||
197 | }, | ||
198 | [ C(OP_PREFETCH) ] = { | ||
199 | [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_L3_ACCESS, | ||
200 | [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_L3_MISS, | ||
201 | }, | ||
202 | }, | ||
203 | [ C(NODE) ] = { | ||
204 | [ C(OP_READ) ] = { | ||
205 | [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_DRAM_ANY, | ||
206 | [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_DRAM_REMOTE, | ||
207 | }, | ||
208 | [ C(OP_WRITE) ] = { | ||
209 | [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_DRAM_ANY, | ||
210 | [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_DRAM_REMOTE, | ||
211 | }, | ||
212 | [ C(OP_PREFETCH) ] = { | ||
213 | [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_DRAM_ANY, | ||
214 | [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_DRAM_REMOTE, | ||
215 | }, | ||
216 | }, | ||
217 | }; | ||
218 | |||
141 | static __initconst const u64 snb_hw_cache_event_ids | 219 | static __initconst const u64 snb_hw_cache_event_ids |
142 | [PERF_COUNT_HW_CACHE_MAX] | 220 | [PERF_COUNT_HW_CACHE_MAX] |
143 | [PERF_COUNT_HW_CACHE_OP_MAX] | 221 | [PERF_COUNT_HW_CACHE_OP_MAX] |
@@ -235,16 +313,16 @@ static __initconst const u64 snb_hw_cache_event_ids | |||
235 | }, | 313 | }, |
236 | [ C(NODE) ] = { | 314 | [ C(NODE) ] = { |
237 | [ C(OP_READ) ] = { | 315 | [ C(OP_READ) ] = { |
238 | [ C(RESULT_ACCESS) ] = -1, | 316 | [ C(RESULT_ACCESS) ] = 0x01b7, |
239 | [ C(RESULT_MISS) ] = -1, | 317 | [ C(RESULT_MISS) ] = 0x01b7, |
240 | }, | 318 | }, |
241 | [ C(OP_WRITE) ] = { | 319 | [ C(OP_WRITE) ] = { |
242 | [ C(RESULT_ACCESS) ] = -1, | 320 | [ C(RESULT_ACCESS) ] = 0x01b7, |
243 | [ C(RESULT_MISS) ] = -1, | 321 | [ C(RESULT_MISS) ] = 0x01b7, |
244 | }, | 322 | }, |
245 | [ C(OP_PREFETCH) ] = { | 323 | [ C(OP_PREFETCH) ] = { |
246 | [ C(RESULT_ACCESS) ] = -1, | 324 | [ C(RESULT_ACCESS) ] = 0x01b7, |
247 | [ C(RESULT_MISS) ] = -1, | 325 | [ C(RESULT_MISS) ] = 0x01b7, |
248 | }, | 326 | }, |
249 | }, | 327 | }, |
250 | 328 | ||
@@ -1964,6 +2042,8 @@ __init int intel_pmu_init(void) | |||
1964 | case 58: /* IvyBridge */ | 2042 | case 58: /* IvyBridge */ |
1965 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, | 2043 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, |
1966 | sizeof(hw_cache_event_ids)); | 2044 | sizeof(hw_cache_event_ids)); |
2045 | memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs, | ||
2046 | sizeof(hw_cache_extra_regs)); | ||
1967 | 2047 | ||
1968 | intel_pmu_lbr_init_snb(); | 2048 | intel_pmu_lbr_init_snb(); |
1969 | 2049 | ||
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c index 19faffc60886..7563fda9f033 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c | |||
@@ -18,6 +18,7 @@ static struct event_constraint constraint_empty = | |||
18 | EVENT_CONSTRAINT(0, 0, 0); | 18 | EVENT_CONSTRAINT(0, 0, 0); |
19 | 19 | ||
20 | DEFINE_UNCORE_FORMAT_ATTR(event, event, "config:0-7"); | 20 | DEFINE_UNCORE_FORMAT_ATTR(event, event, "config:0-7"); |
21 | DEFINE_UNCORE_FORMAT_ATTR(event_ext, event, "config:0-7,21"); | ||
21 | DEFINE_UNCORE_FORMAT_ATTR(umask, umask, "config:8-15"); | 22 | DEFINE_UNCORE_FORMAT_ATTR(umask, umask, "config:8-15"); |
22 | DEFINE_UNCORE_FORMAT_ATTR(edge, edge, "config:18"); | 23 | DEFINE_UNCORE_FORMAT_ATTR(edge, edge, "config:18"); |
23 | DEFINE_UNCORE_FORMAT_ATTR(tid_en, tid_en, "config:19"); | 24 | DEFINE_UNCORE_FORMAT_ATTR(tid_en, tid_en, "config:19"); |
@@ -33,10 +34,81 @@ DEFINE_UNCORE_FORMAT_ATTR(filter_tid, filter_tid, "config1:0-4"); | |||
33 | DEFINE_UNCORE_FORMAT_ATTR(filter_nid, filter_nid, "config1:10-17"); | 34 | DEFINE_UNCORE_FORMAT_ATTR(filter_nid, filter_nid, "config1:10-17"); |
34 | DEFINE_UNCORE_FORMAT_ATTR(filter_state, filter_state, "config1:18-22"); | 35 | DEFINE_UNCORE_FORMAT_ATTR(filter_state, filter_state, "config1:18-22"); |
35 | DEFINE_UNCORE_FORMAT_ATTR(filter_opc, filter_opc, "config1:23-31"); | 36 | DEFINE_UNCORE_FORMAT_ATTR(filter_opc, filter_opc, "config1:23-31"); |
36 | DEFINE_UNCORE_FORMAT_ATTR(filter_brand0, filter_brand0, "config1:0-7"); | 37 | DEFINE_UNCORE_FORMAT_ATTR(filter_band0, filter_band0, "config1:0-7"); |
37 | DEFINE_UNCORE_FORMAT_ATTR(filter_brand1, filter_brand1, "config1:8-15"); | 38 | DEFINE_UNCORE_FORMAT_ATTR(filter_band1, filter_band1, "config1:8-15"); |
38 | DEFINE_UNCORE_FORMAT_ATTR(filter_brand2, filter_brand2, "config1:16-23"); | 39 | DEFINE_UNCORE_FORMAT_ATTR(filter_band2, filter_band2, "config1:16-23"); |
39 | DEFINE_UNCORE_FORMAT_ATTR(filter_brand3, filter_brand3, "config1:24-31"); | 40 | DEFINE_UNCORE_FORMAT_ATTR(filter_band3, filter_band3, "config1:24-31"); |
41 | |||
42 | static u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event *event) | ||
43 | { | ||
44 | u64 count; | ||
45 | |||
46 | rdmsrl(event->hw.event_base, count); | ||
47 | |||
48 | return count; | ||
49 | } | ||
50 | |||
51 | /* | ||
52 | * generic get constraint function for shared match/mask registers. | ||
53 | */ | ||
54 | static struct event_constraint * | ||
55 | uncore_get_constraint(struct intel_uncore_box *box, struct perf_event *event) | ||
56 | { | ||
57 | struct intel_uncore_extra_reg *er; | ||
58 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
59 | struct hw_perf_event_extra *reg2 = &event->hw.branch_reg; | ||
60 | unsigned long flags; | ||
61 | bool ok = false; | ||
62 | |||
63 | /* | ||
64 | * reg->alloc can be set due to existing state, so for fake box we | ||
65 | * need to ignore this, otherwise we might fail to allocate proper | ||
66 | * fake state for this extra reg constraint. | ||
67 | */ | ||
68 | if (reg1->idx == EXTRA_REG_NONE || | ||
69 | (!uncore_box_is_fake(box) && reg1->alloc)) | ||
70 | return NULL; | ||
71 | |||
72 | er = &box->shared_regs[reg1->idx]; | ||
73 | raw_spin_lock_irqsave(&er->lock, flags); | ||
74 | if (!atomic_read(&er->ref) || | ||
75 | (er->config1 == reg1->config && er->config2 == reg2->config)) { | ||
76 | atomic_inc(&er->ref); | ||
77 | er->config1 = reg1->config; | ||
78 | er->config2 = reg2->config; | ||
79 | ok = true; | ||
80 | } | ||
81 | raw_spin_unlock_irqrestore(&er->lock, flags); | ||
82 | |||
83 | if (ok) { | ||
84 | if (!uncore_box_is_fake(box)) | ||
85 | reg1->alloc = 1; | ||
86 | return NULL; | ||
87 | } | ||
88 | |||
89 | return &constraint_empty; | ||
90 | } | ||
91 | |||
92 | static void uncore_put_constraint(struct intel_uncore_box *box, struct perf_event *event) | ||
93 | { | ||
94 | struct intel_uncore_extra_reg *er; | ||
95 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
96 | |||
97 | /* | ||
98 | * Only put constraint if extra reg was actually allocated. Also | ||
99 | * takes care of event which do not use an extra shared reg. | ||
100 | * | ||
101 | * Also, if this is a fake box we shouldn't touch any event state | ||
102 | * (reg->alloc) and we don't care about leaving inconsistent box | ||
103 | * state either since it will be thrown out. | ||
104 | */ | ||
105 | if (uncore_box_is_fake(box) || !reg1->alloc) | ||
106 | return; | ||
107 | |||
108 | er = &box->shared_regs[reg1->idx]; | ||
109 | atomic_dec(&er->ref); | ||
110 | reg1->alloc = 0; | ||
111 | } | ||
40 | 112 | ||
41 | /* Sandy Bridge-EP uncore support */ | 113 | /* Sandy Bridge-EP uncore support */ |
42 | static struct intel_uncore_type snbep_uncore_cbox; | 114 | static struct intel_uncore_type snbep_uncore_cbox; |
@@ -64,18 +136,15 @@ static void snbep_uncore_pci_enable_box(struct intel_uncore_box *box) | |||
64 | pci_write_config_dword(pdev, box_ctl, config); | 136 | pci_write_config_dword(pdev, box_ctl, config); |
65 | } | 137 | } |
66 | 138 | ||
67 | static void snbep_uncore_pci_enable_event(struct intel_uncore_box *box, | 139 | static void snbep_uncore_pci_enable_event(struct intel_uncore_box *box, struct perf_event *event) |
68 | struct perf_event *event) | ||
69 | { | 140 | { |
70 | struct pci_dev *pdev = box->pci_dev; | 141 | struct pci_dev *pdev = box->pci_dev; |
71 | struct hw_perf_event *hwc = &event->hw; | 142 | struct hw_perf_event *hwc = &event->hw; |
72 | 143 | ||
73 | pci_write_config_dword(pdev, hwc->config_base, hwc->config | | 144 | pci_write_config_dword(pdev, hwc->config_base, hwc->config | SNBEP_PMON_CTL_EN); |
74 | SNBEP_PMON_CTL_EN); | ||
75 | } | 145 | } |
76 | 146 | ||
77 | static void snbep_uncore_pci_disable_event(struct intel_uncore_box *box, | 147 | static void snbep_uncore_pci_disable_event(struct intel_uncore_box *box, struct perf_event *event) |
78 | struct perf_event *event) | ||
79 | { | 148 | { |
80 | struct pci_dev *pdev = box->pci_dev; | 149 | struct pci_dev *pdev = box->pci_dev; |
81 | struct hw_perf_event *hwc = &event->hw; | 150 | struct hw_perf_event *hwc = &event->hw; |
@@ -83,8 +152,7 @@ static void snbep_uncore_pci_disable_event(struct intel_uncore_box *box, | |||
83 | pci_write_config_dword(pdev, hwc->config_base, hwc->config); | 152 | pci_write_config_dword(pdev, hwc->config_base, hwc->config); |
84 | } | 153 | } |
85 | 154 | ||
86 | static u64 snbep_uncore_pci_read_counter(struct intel_uncore_box *box, | 155 | static u64 snbep_uncore_pci_read_counter(struct intel_uncore_box *box, struct perf_event *event) |
87 | struct perf_event *event) | ||
88 | { | 156 | { |
89 | struct pci_dev *pdev = box->pci_dev; | 157 | struct pci_dev *pdev = box->pci_dev; |
90 | struct hw_perf_event *hwc = &event->hw; | 158 | struct hw_perf_event *hwc = &event->hw; |
@@ -92,14 +160,15 @@ static u64 snbep_uncore_pci_read_counter(struct intel_uncore_box *box, | |||
92 | 160 | ||
93 | pci_read_config_dword(pdev, hwc->event_base, (u32 *)&count); | 161 | pci_read_config_dword(pdev, hwc->event_base, (u32 *)&count); |
94 | pci_read_config_dword(pdev, hwc->event_base + 4, (u32 *)&count + 1); | 162 | pci_read_config_dword(pdev, hwc->event_base + 4, (u32 *)&count + 1); |
163 | |||
95 | return count; | 164 | return count; |
96 | } | 165 | } |
97 | 166 | ||
98 | static void snbep_uncore_pci_init_box(struct intel_uncore_box *box) | 167 | static void snbep_uncore_pci_init_box(struct intel_uncore_box *box) |
99 | { | 168 | { |
100 | struct pci_dev *pdev = box->pci_dev; | 169 | struct pci_dev *pdev = box->pci_dev; |
101 | pci_write_config_dword(pdev, SNBEP_PCI_PMON_BOX_CTL, | 170 | |
102 | SNBEP_PMON_BOX_CTL_INT); | 171 | pci_write_config_dword(pdev, SNBEP_PCI_PMON_BOX_CTL, SNBEP_PMON_BOX_CTL_INT); |
103 | } | 172 | } |
104 | 173 | ||
105 | static void snbep_uncore_msr_disable_box(struct intel_uncore_box *box) | 174 | static void snbep_uncore_msr_disable_box(struct intel_uncore_box *box) |
@@ -112,7 +181,6 @@ static void snbep_uncore_msr_disable_box(struct intel_uncore_box *box) | |||
112 | rdmsrl(msr, config); | 181 | rdmsrl(msr, config); |
113 | config |= SNBEP_PMON_BOX_CTL_FRZ; | 182 | config |= SNBEP_PMON_BOX_CTL_FRZ; |
114 | wrmsrl(msr, config); | 183 | wrmsrl(msr, config); |
115 | return; | ||
116 | } | 184 | } |
117 | } | 185 | } |
118 | 186 | ||
@@ -126,12 +194,10 @@ static void snbep_uncore_msr_enable_box(struct intel_uncore_box *box) | |||
126 | rdmsrl(msr, config); | 194 | rdmsrl(msr, config); |
127 | config &= ~SNBEP_PMON_BOX_CTL_FRZ; | 195 | config &= ~SNBEP_PMON_BOX_CTL_FRZ; |
128 | wrmsrl(msr, config); | 196 | wrmsrl(msr, config); |
129 | return; | ||
130 | } | 197 | } |
131 | } | 198 | } |
132 | 199 | ||
133 | static void snbep_uncore_msr_enable_event(struct intel_uncore_box *box, | 200 | static void snbep_uncore_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) |
134 | struct perf_event *event) | ||
135 | { | 201 | { |
136 | struct hw_perf_event *hwc = &event->hw; | 202 | struct hw_perf_event *hwc = &event->hw; |
137 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | 203 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; |
@@ -150,68 +216,15 @@ static void snbep_uncore_msr_disable_event(struct intel_uncore_box *box, | |||
150 | wrmsrl(hwc->config_base, hwc->config); | 216 | wrmsrl(hwc->config_base, hwc->config); |
151 | } | 217 | } |
152 | 218 | ||
153 | static u64 snbep_uncore_msr_read_counter(struct intel_uncore_box *box, | ||
154 | struct perf_event *event) | ||
155 | { | ||
156 | struct hw_perf_event *hwc = &event->hw; | ||
157 | u64 count; | ||
158 | |||
159 | rdmsrl(hwc->event_base, count); | ||
160 | return count; | ||
161 | } | ||
162 | |||
163 | static void snbep_uncore_msr_init_box(struct intel_uncore_box *box) | 219 | static void snbep_uncore_msr_init_box(struct intel_uncore_box *box) |
164 | { | 220 | { |
165 | unsigned msr = uncore_msr_box_ctl(box); | 221 | unsigned msr = uncore_msr_box_ctl(box); |
222 | |||
166 | if (msr) | 223 | if (msr) |
167 | wrmsrl(msr, SNBEP_PMON_BOX_CTL_INT); | 224 | wrmsrl(msr, SNBEP_PMON_BOX_CTL_INT); |
168 | } | 225 | } |
169 | 226 | ||
170 | static struct event_constraint * | 227 | static int snbep_uncore_hw_config(struct intel_uncore_box *box, struct perf_event *event) |
171 | snbep_uncore_get_constraint(struct intel_uncore_box *box, | ||
172 | struct perf_event *event) | ||
173 | { | ||
174 | struct intel_uncore_extra_reg *er; | ||
175 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
176 | unsigned long flags; | ||
177 | bool ok = false; | ||
178 | |||
179 | if (reg1->idx == EXTRA_REG_NONE || (box->phys_id >= 0 && reg1->alloc)) | ||
180 | return NULL; | ||
181 | |||
182 | er = &box->shared_regs[reg1->idx]; | ||
183 | raw_spin_lock_irqsave(&er->lock, flags); | ||
184 | if (!atomic_read(&er->ref) || er->config1 == reg1->config) { | ||
185 | atomic_inc(&er->ref); | ||
186 | er->config1 = reg1->config; | ||
187 | ok = true; | ||
188 | } | ||
189 | raw_spin_unlock_irqrestore(&er->lock, flags); | ||
190 | |||
191 | if (ok) { | ||
192 | if (box->phys_id >= 0) | ||
193 | reg1->alloc = 1; | ||
194 | return NULL; | ||
195 | } | ||
196 | return &constraint_empty; | ||
197 | } | ||
198 | |||
199 | static void snbep_uncore_put_constraint(struct intel_uncore_box *box, | ||
200 | struct perf_event *event) | ||
201 | { | ||
202 | struct intel_uncore_extra_reg *er; | ||
203 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
204 | |||
205 | if (box->phys_id < 0 || !reg1->alloc) | ||
206 | return; | ||
207 | |||
208 | er = &box->shared_regs[reg1->idx]; | ||
209 | atomic_dec(&er->ref); | ||
210 | reg1->alloc = 0; | ||
211 | } | ||
212 | |||
213 | static int snbep_uncore_hw_config(struct intel_uncore_box *box, | ||
214 | struct perf_event *event) | ||
215 | { | 228 | { |
216 | struct hw_perf_event *hwc = &event->hw; | 229 | struct hw_perf_event *hwc = &event->hw; |
217 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | 230 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; |
@@ -221,14 +234,16 @@ static int snbep_uncore_hw_config(struct intel_uncore_box *box, | |||
221 | SNBEP_CBO_MSR_OFFSET * box->pmu->pmu_idx; | 234 | SNBEP_CBO_MSR_OFFSET * box->pmu->pmu_idx; |
222 | reg1->config = event->attr.config1 & | 235 | reg1->config = event->attr.config1 & |
223 | SNBEP_CB0_MSR_PMON_BOX_FILTER_MASK; | 236 | SNBEP_CB0_MSR_PMON_BOX_FILTER_MASK; |
224 | } else if (box->pmu->type == &snbep_uncore_pcu) { | ||
225 | reg1->reg = SNBEP_PCU_MSR_PMON_BOX_FILTER; | ||
226 | reg1->config = event->attr.config1 & | ||
227 | SNBEP_PCU_MSR_PMON_BOX_FILTER_MASK; | ||
228 | } else { | 237 | } else { |
229 | return 0; | 238 | if (box->pmu->type == &snbep_uncore_pcu) { |
239 | reg1->reg = SNBEP_PCU_MSR_PMON_BOX_FILTER; | ||
240 | reg1->config = event->attr.config1 & SNBEP_PCU_MSR_PMON_BOX_FILTER_MASK; | ||
241 | } else { | ||
242 | return 0; | ||
243 | } | ||
230 | } | 244 | } |
231 | reg1->idx = 0; | 245 | reg1->idx = 0; |
246 | |||
232 | return 0; | 247 | return 0; |
233 | } | 248 | } |
234 | 249 | ||
@@ -272,10 +287,19 @@ static struct attribute *snbep_uncore_pcu_formats_attr[] = { | |||
272 | &format_attr_thresh5.attr, | 287 | &format_attr_thresh5.attr, |
273 | &format_attr_occ_invert.attr, | 288 | &format_attr_occ_invert.attr, |
274 | &format_attr_occ_edge.attr, | 289 | &format_attr_occ_edge.attr, |
275 | &format_attr_filter_brand0.attr, | 290 | &format_attr_filter_band0.attr, |
276 | &format_attr_filter_brand1.attr, | 291 | &format_attr_filter_band1.attr, |
277 | &format_attr_filter_brand2.attr, | 292 | &format_attr_filter_band2.attr, |
278 | &format_attr_filter_brand3.attr, | 293 | &format_attr_filter_band3.attr, |
294 | NULL, | ||
295 | }; | ||
296 | |||
297 | static struct attribute *snbep_uncore_qpi_formats_attr[] = { | ||
298 | &format_attr_event_ext.attr, | ||
299 | &format_attr_umask.attr, | ||
300 | &format_attr_edge.attr, | ||
301 | &format_attr_inv.attr, | ||
302 | &format_attr_thresh8.attr, | ||
279 | NULL, | 303 | NULL, |
280 | }; | 304 | }; |
281 | 305 | ||
@@ -314,15 +338,20 @@ static struct attribute_group snbep_uncore_pcu_format_group = { | |||
314 | .attrs = snbep_uncore_pcu_formats_attr, | 338 | .attrs = snbep_uncore_pcu_formats_attr, |
315 | }; | 339 | }; |
316 | 340 | ||
341 | static struct attribute_group snbep_uncore_qpi_format_group = { | ||
342 | .name = "format", | ||
343 | .attrs = snbep_uncore_qpi_formats_attr, | ||
344 | }; | ||
345 | |||
317 | static struct intel_uncore_ops snbep_uncore_msr_ops = { | 346 | static struct intel_uncore_ops snbep_uncore_msr_ops = { |
318 | .init_box = snbep_uncore_msr_init_box, | 347 | .init_box = snbep_uncore_msr_init_box, |
319 | .disable_box = snbep_uncore_msr_disable_box, | 348 | .disable_box = snbep_uncore_msr_disable_box, |
320 | .enable_box = snbep_uncore_msr_enable_box, | 349 | .enable_box = snbep_uncore_msr_enable_box, |
321 | .disable_event = snbep_uncore_msr_disable_event, | 350 | .disable_event = snbep_uncore_msr_disable_event, |
322 | .enable_event = snbep_uncore_msr_enable_event, | 351 | .enable_event = snbep_uncore_msr_enable_event, |
323 | .read_counter = snbep_uncore_msr_read_counter, | 352 | .read_counter = uncore_msr_read_counter, |
324 | .get_constraint = snbep_uncore_get_constraint, | 353 | .get_constraint = uncore_get_constraint, |
325 | .put_constraint = snbep_uncore_put_constraint, | 354 | .put_constraint = uncore_put_constraint, |
326 | .hw_config = snbep_uncore_hw_config, | 355 | .hw_config = snbep_uncore_hw_config, |
327 | }; | 356 | }; |
328 | 357 | ||
@@ -485,8 +514,13 @@ static struct intel_uncore_type snbep_uncore_qpi = { | |||
485 | .num_counters = 4, | 514 | .num_counters = 4, |
486 | .num_boxes = 2, | 515 | .num_boxes = 2, |
487 | .perf_ctr_bits = 48, | 516 | .perf_ctr_bits = 48, |
517 | .perf_ctr = SNBEP_PCI_PMON_CTR0, | ||
518 | .event_ctl = SNBEP_PCI_PMON_CTL0, | ||
519 | .event_mask = SNBEP_QPI_PCI_PMON_RAW_EVENT_MASK, | ||
520 | .box_ctl = SNBEP_PCI_PMON_BOX_CTL, | ||
521 | .ops = &snbep_uncore_pci_ops, | ||
488 | .event_descs = snbep_uncore_qpi_events, | 522 | .event_descs = snbep_uncore_qpi_events, |
489 | SNBEP_UNCORE_PCI_COMMON_INIT(), | 523 | .format_group = &snbep_uncore_qpi_format_group, |
490 | }; | 524 | }; |
491 | 525 | ||
492 | 526 | ||
@@ -603,10 +637,8 @@ static void snbep_pci2phy_map_init(void) | |||
603 | } | 637 | } |
604 | /* end of Sandy Bridge-EP uncore support */ | 638 | /* end of Sandy Bridge-EP uncore support */ |
605 | 639 | ||
606 | |||
607 | /* Sandy Bridge uncore support */ | 640 | /* Sandy Bridge uncore support */ |
608 | static void snb_uncore_msr_enable_event(struct intel_uncore_box *box, | 641 | static void snb_uncore_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) |
609 | struct perf_event *event) | ||
610 | { | 642 | { |
611 | struct hw_perf_event *hwc = &event->hw; | 643 | struct hw_perf_event *hwc = &event->hw; |
612 | 644 | ||
@@ -616,20 +648,11 @@ static void snb_uncore_msr_enable_event(struct intel_uncore_box *box, | |||
616 | wrmsrl(hwc->config_base, SNB_UNC_CTL_EN); | 648 | wrmsrl(hwc->config_base, SNB_UNC_CTL_EN); |
617 | } | 649 | } |
618 | 650 | ||
619 | static void snb_uncore_msr_disable_event(struct intel_uncore_box *box, | 651 | static void snb_uncore_msr_disable_event(struct intel_uncore_box *box, struct perf_event *event) |
620 | struct perf_event *event) | ||
621 | { | 652 | { |
622 | wrmsrl(event->hw.config_base, 0); | 653 | wrmsrl(event->hw.config_base, 0); |
623 | } | 654 | } |
624 | 655 | ||
625 | static u64 snb_uncore_msr_read_counter(struct intel_uncore_box *box, | ||
626 | struct perf_event *event) | ||
627 | { | ||
628 | u64 count; | ||
629 | rdmsrl(event->hw.event_base, count); | ||
630 | return count; | ||
631 | } | ||
632 | |||
633 | static void snb_uncore_msr_init_box(struct intel_uncore_box *box) | 656 | static void snb_uncore_msr_init_box(struct intel_uncore_box *box) |
634 | { | 657 | { |
635 | if (box->pmu->pmu_idx == 0) { | 658 | if (box->pmu->pmu_idx == 0) { |
@@ -648,15 +671,15 @@ static struct attribute *snb_uncore_formats_attr[] = { | |||
648 | }; | 671 | }; |
649 | 672 | ||
650 | static struct attribute_group snb_uncore_format_group = { | 673 | static struct attribute_group snb_uncore_format_group = { |
651 | .name = "format", | 674 | .name = "format", |
652 | .attrs = snb_uncore_formats_attr, | 675 | .attrs = snb_uncore_formats_attr, |
653 | }; | 676 | }; |
654 | 677 | ||
655 | static struct intel_uncore_ops snb_uncore_msr_ops = { | 678 | static struct intel_uncore_ops snb_uncore_msr_ops = { |
656 | .init_box = snb_uncore_msr_init_box, | 679 | .init_box = snb_uncore_msr_init_box, |
657 | .disable_event = snb_uncore_msr_disable_event, | 680 | .disable_event = snb_uncore_msr_disable_event, |
658 | .enable_event = snb_uncore_msr_enable_event, | 681 | .enable_event = snb_uncore_msr_enable_event, |
659 | .read_counter = snb_uncore_msr_read_counter, | 682 | .read_counter = uncore_msr_read_counter, |
660 | }; | 683 | }; |
661 | 684 | ||
662 | static struct event_constraint snb_uncore_cbox_constraints[] = { | 685 | static struct event_constraint snb_uncore_cbox_constraints[] = { |
@@ -697,12 +720,10 @@ static void nhm_uncore_msr_disable_box(struct intel_uncore_box *box) | |||
697 | 720 | ||
698 | static void nhm_uncore_msr_enable_box(struct intel_uncore_box *box) | 721 | static void nhm_uncore_msr_enable_box(struct intel_uncore_box *box) |
699 | { | 722 | { |
700 | wrmsrl(NHM_UNC_PERF_GLOBAL_CTL, | 723 | wrmsrl(NHM_UNC_PERF_GLOBAL_CTL, NHM_UNC_GLOBAL_CTL_EN_PC_ALL | NHM_UNC_GLOBAL_CTL_EN_FC); |
701 | NHM_UNC_GLOBAL_CTL_EN_PC_ALL | NHM_UNC_GLOBAL_CTL_EN_FC); | ||
702 | } | 724 | } |
703 | 725 | ||
704 | static void nhm_uncore_msr_enable_event(struct intel_uncore_box *box, | 726 | static void nhm_uncore_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) |
705 | struct perf_event *event) | ||
706 | { | 727 | { |
707 | struct hw_perf_event *hwc = &event->hw; | 728 | struct hw_perf_event *hwc = &event->hw; |
708 | 729 | ||
@@ -744,7 +765,7 @@ static struct intel_uncore_ops nhm_uncore_msr_ops = { | |||
744 | .enable_box = nhm_uncore_msr_enable_box, | 765 | .enable_box = nhm_uncore_msr_enable_box, |
745 | .disable_event = snb_uncore_msr_disable_event, | 766 | .disable_event = snb_uncore_msr_disable_event, |
746 | .enable_event = nhm_uncore_msr_enable_event, | 767 | .enable_event = nhm_uncore_msr_enable_event, |
747 | .read_counter = snb_uncore_msr_read_counter, | 768 | .read_counter = uncore_msr_read_counter, |
748 | }; | 769 | }; |
749 | 770 | ||
750 | static struct intel_uncore_type nhm_uncore = { | 771 | static struct intel_uncore_type nhm_uncore = { |
@@ -769,8 +790,1041 @@ static struct intel_uncore_type *nhm_msr_uncores[] = { | |||
769 | }; | 790 | }; |
770 | /* end of Nehalem uncore support */ | 791 | /* end of Nehalem uncore support */ |
771 | 792 | ||
772 | static void uncore_assign_hw_event(struct intel_uncore_box *box, | 793 | /* Nehalem-EX uncore support */ |
773 | struct perf_event *event, int idx) | 794 | #define __BITS_VALUE(x, i, n) ((typeof(x))(((x) >> ((i) * (n))) & \ |
795 | ((1ULL << (n)) - 1))) | ||
796 | |||
797 | DEFINE_UNCORE_FORMAT_ATTR(event5, event, "config:1-5"); | ||
798 | DEFINE_UNCORE_FORMAT_ATTR(counter, counter, "config:6-7"); | ||
799 | DEFINE_UNCORE_FORMAT_ATTR(mm_cfg, mm_cfg, "config:63"); | ||
800 | DEFINE_UNCORE_FORMAT_ATTR(match, match, "config1:0-63"); | ||
801 | DEFINE_UNCORE_FORMAT_ATTR(mask, mask, "config2:0-63"); | ||
802 | |||
803 | static void nhmex_uncore_msr_init_box(struct intel_uncore_box *box) | ||
804 | { | ||
805 | wrmsrl(NHMEX_U_MSR_PMON_GLOBAL_CTL, NHMEX_U_PMON_GLOBAL_EN_ALL); | ||
806 | } | ||
807 | |||
808 | static void nhmex_uncore_msr_disable_box(struct intel_uncore_box *box) | ||
809 | { | ||
810 | unsigned msr = uncore_msr_box_ctl(box); | ||
811 | u64 config; | ||
812 | |||
813 | if (msr) { | ||
814 | rdmsrl(msr, config); | ||
815 | config &= ~((1ULL << uncore_num_counters(box)) - 1); | ||
816 | /* WBox has a fixed counter */ | ||
817 | if (uncore_msr_fixed_ctl(box)) | ||
818 | config &= ~NHMEX_W_PMON_GLOBAL_FIXED_EN; | ||
819 | wrmsrl(msr, config); | ||
820 | } | ||
821 | } | ||
822 | |||
823 | static void nhmex_uncore_msr_enable_box(struct intel_uncore_box *box) | ||
824 | { | ||
825 | unsigned msr = uncore_msr_box_ctl(box); | ||
826 | u64 config; | ||
827 | |||
828 | if (msr) { | ||
829 | rdmsrl(msr, config); | ||
830 | config |= (1ULL << uncore_num_counters(box)) - 1; | ||
831 | /* WBox has a fixed counter */ | ||
832 | if (uncore_msr_fixed_ctl(box)) | ||
833 | config |= NHMEX_W_PMON_GLOBAL_FIXED_EN; | ||
834 | wrmsrl(msr, config); | ||
835 | } | ||
836 | } | ||
837 | |||
838 | static void nhmex_uncore_msr_disable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
839 | { | ||
840 | wrmsrl(event->hw.config_base, 0); | ||
841 | } | ||
842 | |||
843 | static void nhmex_uncore_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
844 | { | ||
845 | struct hw_perf_event *hwc = &event->hw; | ||
846 | |||
847 | if (hwc->idx >= UNCORE_PMC_IDX_FIXED) | ||
848 | wrmsrl(hwc->config_base, NHMEX_PMON_CTL_EN_BIT0); | ||
849 | else if (box->pmu->type->event_mask & NHMEX_PMON_CTL_EN_BIT0) | ||
850 | wrmsrl(hwc->config_base, hwc->config | NHMEX_PMON_CTL_EN_BIT22); | ||
851 | else | ||
852 | wrmsrl(hwc->config_base, hwc->config | NHMEX_PMON_CTL_EN_BIT0); | ||
853 | } | ||
854 | |||
855 | #define NHMEX_UNCORE_OPS_COMMON_INIT() \ | ||
856 | .init_box = nhmex_uncore_msr_init_box, \ | ||
857 | .disable_box = nhmex_uncore_msr_disable_box, \ | ||
858 | .enable_box = nhmex_uncore_msr_enable_box, \ | ||
859 | .disable_event = nhmex_uncore_msr_disable_event, \ | ||
860 | .read_counter = uncore_msr_read_counter | ||
861 | |||
862 | static struct intel_uncore_ops nhmex_uncore_ops = { | ||
863 | NHMEX_UNCORE_OPS_COMMON_INIT(), | ||
864 | .enable_event = nhmex_uncore_msr_enable_event, | ||
865 | }; | ||
866 | |||
867 | static struct attribute *nhmex_uncore_ubox_formats_attr[] = { | ||
868 | &format_attr_event.attr, | ||
869 | &format_attr_edge.attr, | ||
870 | NULL, | ||
871 | }; | ||
872 | |||
873 | static struct attribute_group nhmex_uncore_ubox_format_group = { | ||
874 | .name = "format", | ||
875 | .attrs = nhmex_uncore_ubox_formats_attr, | ||
876 | }; | ||
877 | |||
878 | static struct intel_uncore_type nhmex_uncore_ubox = { | ||
879 | .name = "ubox", | ||
880 | .num_counters = 1, | ||
881 | .num_boxes = 1, | ||
882 | .perf_ctr_bits = 48, | ||
883 | .event_ctl = NHMEX_U_MSR_PMON_EV_SEL, | ||
884 | .perf_ctr = NHMEX_U_MSR_PMON_CTR, | ||
885 | .event_mask = NHMEX_U_PMON_RAW_EVENT_MASK, | ||
886 | .box_ctl = NHMEX_U_MSR_PMON_GLOBAL_CTL, | ||
887 | .ops = &nhmex_uncore_ops, | ||
888 | .format_group = &nhmex_uncore_ubox_format_group | ||
889 | }; | ||
890 | |||
891 | static struct attribute *nhmex_uncore_cbox_formats_attr[] = { | ||
892 | &format_attr_event.attr, | ||
893 | &format_attr_umask.attr, | ||
894 | &format_attr_edge.attr, | ||
895 | &format_attr_inv.attr, | ||
896 | &format_attr_thresh8.attr, | ||
897 | NULL, | ||
898 | }; | ||
899 | |||
900 | static struct attribute_group nhmex_uncore_cbox_format_group = { | ||
901 | .name = "format", | ||
902 | .attrs = nhmex_uncore_cbox_formats_attr, | ||
903 | }; | ||
904 | |||
905 | static struct intel_uncore_type nhmex_uncore_cbox = { | ||
906 | .name = "cbox", | ||
907 | .num_counters = 6, | ||
908 | .num_boxes = 8, | ||
909 | .perf_ctr_bits = 48, | ||
910 | .event_ctl = NHMEX_C0_MSR_PMON_EV_SEL0, | ||
911 | .perf_ctr = NHMEX_C0_MSR_PMON_CTR0, | ||
912 | .event_mask = NHMEX_PMON_RAW_EVENT_MASK, | ||
913 | .box_ctl = NHMEX_C0_MSR_PMON_GLOBAL_CTL, | ||
914 | .msr_offset = NHMEX_C_MSR_OFFSET, | ||
915 | .pair_ctr_ctl = 1, | ||
916 | .ops = &nhmex_uncore_ops, | ||
917 | .format_group = &nhmex_uncore_cbox_format_group | ||
918 | }; | ||
919 | |||
920 | static struct uncore_event_desc nhmex_uncore_wbox_events[] = { | ||
921 | INTEL_UNCORE_EVENT_DESC(clockticks, "event=0xff,umask=0"), | ||
922 | { /* end: all zeroes */ }, | ||
923 | }; | ||
924 | |||
925 | static struct intel_uncore_type nhmex_uncore_wbox = { | ||
926 | .name = "wbox", | ||
927 | .num_counters = 4, | ||
928 | .num_boxes = 1, | ||
929 | .perf_ctr_bits = 48, | ||
930 | .event_ctl = NHMEX_W_MSR_PMON_CNT0, | ||
931 | .perf_ctr = NHMEX_W_MSR_PMON_EVT_SEL0, | ||
932 | .fixed_ctr = NHMEX_W_MSR_PMON_FIXED_CTR, | ||
933 | .fixed_ctl = NHMEX_W_MSR_PMON_FIXED_CTL, | ||
934 | .event_mask = NHMEX_PMON_RAW_EVENT_MASK, | ||
935 | .box_ctl = NHMEX_W_MSR_GLOBAL_CTL, | ||
936 | .pair_ctr_ctl = 1, | ||
937 | .event_descs = nhmex_uncore_wbox_events, | ||
938 | .ops = &nhmex_uncore_ops, | ||
939 | .format_group = &nhmex_uncore_cbox_format_group | ||
940 | }; | ||
941 | |||
942 | static int nhmex_bbox_hw_config(struct intel_uncore_box *box, struct perf_event *event) | ||
943 | { | ||
944 | struct hw_perf_event *hwc = &event->hw; | ||
945 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
946 | struct hw_perf_event_extra *reg2 = &hwc->branch_reg; | ||
947 | int ctr, ev_sel; | ||
948 | |||
949 | ctr = (hwc->config & NHMEX_B_PMON_CTR_MASK) >> | ||
950 | NHMEX_B_PMON_CTR_SHIFT; | ||
951 | ev_sel = (hwc->config & NHMEX_B_PMON_CTL_EV_SEL_MASK) >> | ||
952 | NHMEX_B_PMON_CTL_EV_SEL_SHIFT; | ||
953 | |||
954 | /* events that do not use the match/mask registers */ | ||
955 | if ((ctr == 0 && ev_sel > 0x3) || (ctr == 1 && ev_sel > 0x6) || | ||
956 | (ctr == 2 && ev_sel != 0x4) || ctr == 3) | ||
957 | return 0; | ||
958 | |||
959 | if (box->pmu->pmu_idx == 0) | ||
960 | reg1->reg = NHMEX_B0_MSR_MATCH; | ||
961 | else | ||
962 | reg1->reg = NHMEX_B1_MSR_MATCH; | ||
963 | reg1->idx = 0; | ||
964 | reg1->config = event->attr.config1; | ||
965 | reg2->config = event->attr.config2; | ||
966 | return 0; | ||
967 | } | ||
968 | |||
969 | static void nhmex_bbox_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
970 | { | ||
971 | struct hw_perf_event *hwc = &event->hw; | ||
972 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
973 | struct hw_perf_event_extra *reg2 = &hwc->branch_reg; | ||
974 | |||
975 | if (reg1->idx != EXTRA_REG_NONE) { | ||
976 | wrmsrl(reg1->reg, reg1->config); | ||
977 | wrmsrl(reg1->reg + 1, reg2->config); | ||
978 | } | ||
979 | wrmsrl(hwc->config_base, NHMEX_PMON_CTL_EN_BIT0 | | ||
980 | (hwc->config & NHMEX_B_PMON_CTL_EV_SEL_MASK)); | ||
981 | } | ||
982 | |||
983 | /* | ||
984 | * The Bbox has 4 counters, but each counter monitors different events. | ||
985 | * Use bits 6-7 in the event config to select counter. | ||
986 | */ | ||
987 | static struct event_constraint nhmex_uncore_bbox_constraints[] = { | ||
988 | EVENT_CONSTRAINT(0 , 1, 0xc0), | ||
989 | EVENT_CONSTRAINT(0x40, 2, 0xc0), | ||
990 | EVENT_CONSTRAINT(0x80, 4, 0xc0), | ||
991 | EVENT_CONSTRAINT(0xc0, 8, 0xc0), | ||
992 | EVENT_CONSTRAINT_END, | ||
993 | }; | ||
994 | |||
995 | static struct attribute *nhmex_uncore_bbox_formats_attr[] = { | ||
996 | &format_attr_event5.attr, | ||
997 | &format_attr_counter.attr, | ||
998 | &format_attr_match.attr, | ||
999 | &format_attr_mask.attr, | ||
1000 | NULL, | ||
1001 | }; | ||
1002 | |||
1003 | static struct attribute_group nhmex_uncore_bbox_format_group = { | ||
1004 | .name = "format", | ||
1005 | .attrs = nhmex_uncore_bbox_formats_attr, | ||
1006 | }; | ||
1007 | |||
1008 | static struct intel_uncore_ops nhmex_uncore_bbox_ops = { | ||
1009 | NHMEX_UNCORE_OPS_COMMON_INIT(), | ||
1010 | .enable_event = nhmex_bbox_msr_enable_event, | ||
1011 | .hw_config = nhmex_bbox_hw_config, | ||
1012 | .get_constraint = uncore_get_constraint, | ||
1013 | .put_constraint = uncore_put_constraint, | ||
1014 | }; | ||
1015 | |||
1016 | static struct intel_uncore_type nhmex_uncore_bbox = { | ||
1017 | .name = "bbox", | ||
1018 | .num_counters = 4, | ||
1019 | .num_boxes = 2, | ||
1020 | .perf_ctr_bits = 48, | ||
1021 | .event_ctl = NHMEX_B0_MSR_PMON_CTL0, | ||
1022 | .perf_ctr = NHMEX_B0_MSR_PMON_CTR0, | ||
1023 | .event_mask = NHMEX_B_PMON_RAW_EVENT_MASK, | ||
1024 | .box_ctl = NHMEX_B0_MSR_PMON_GLOBAL_CTL, | ||
1025 | .msr_offset = NHMEX_B_MSR_OFFSET, | ||
1026 | .pair_ctr_ctl = 1, | ||
1027 | .num_shared_regs = 1, | ||
1028 | .constraints = nhmex_uncore_bbox_constraints, | ||
1029 | .ops = &nhmex_uncore_bbox_ops, | ||
1030 | .format_group = &nhmex_uncore_bbox_format_group | ||
1031 | }; | ||
1032 | |||
1033 | static int nhmex_sbox_hw_config(struct intel_uncore_box *box, struct perf_event *event) | ||
1034 | { | ||
1035 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
1036 | struct hw_perf_event_extra *reg2 = &event->hw.branch_reg; | ||
1037 | |||
1038 | if (event->attr.config & NHMEX_S_PMON_MM_CFG_EN) { | ||
1039 | reg1->config = event->attr.config1; | ||
1040 | reg2->config = event->attr.config2; | ||
1041 | } else { | ||
1042 | reg1->config = ~0ULL; | ||
1043 | reg2->config = ~0ULL; | ||
1044 | } | ||
1045 | |||
1046 | if (box->pmu->pmu_idx == 0) | ||
1047 | reg1->reg = NHMEX_S0_MSR_MM_CFG; | ||
1048 | else | ||
1049 | reg1->reg = NHMEX_S1_MSR_MM_CFG; | ||
1050 | |||
1051 | reg1->idx = 0; | ||
1052 | |||
1053 | return 0; | ||
1054 | } | ||
1055 | |||
1056 | static void nhmex_sbox_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
1057 | { | ||
1058 | struct hw_perf_event *hwc = &event->hw; | ||
1059 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
1060 | struct hw_perf_event_extra *reg2 = &hwc->branch_reg; | ||
1061 | |||
1062 | wrmsrl(reg1->reg, 0); | ||
1063 | if (reg1->config != ~0ULL || reg2->config != ~0ULL) { | ||
1064 | wrmsrl(reg1->reg + 1, reg1->config); | ||
1065 | wrmsrl(reg1->reg + 2, reg2->config); | ||
1066 | wrmsrl(reg1->reg, NHMEX_S_PMON_MM_CFG_EN); | ||
1067 | } | ||
1068 | wrmsrl(hwc->config_base, hwc->config | NHMEX_PMON_CTL_EN_BIT22); | ||
1069 | } | ||
1070 | |||
1071 | static struct attribute *nhmex_uncore_sbox_formats_attr[] = { | ||
1072 | &format_attr_event.attr, | ||
1073 | &format_attr_umask.attr, | ||
1074 | &format_attr_edge.attr, | ||
1075 | &format_attr_inv.attr, | ||
1076 | &format_attr_thresh8.attr, | ||
1077 | &format_attr_mm_cfg.attr, | ||
1078 | &format_attr_match.attr, | ||
1079 | &format_attr_mask.attr, | ||
1080 | NULL, | ||
1081 | }; | ||
1082 | |||
1083 | static struct attribute_group nhmex_uncore_sbox_format_group = { | ||
1084 | .name = "format", | ||
1085 | .attrs = nhmex_uncore_sbox_formats_attr, | ||
1086 | }; | ||
1087 | |||
1088 | static struct intel_uncore_ops nhmex_uncore_sbox_ops = { | ||
1089 | NHMEX_UNCORE_OPS_COMMON_INIT(), | ||
1090 | .enable_event = nhmex_sbox_msr_enable_event, | ||
1091 | .hw_config = nhmex_sbox_hw_config, | ||
1092 | .get_constraint = uncore_get_constraint, | ||
1093 | .put_constraint = uncore_put_constraint, | ||
1094 | }; | ||
1095 | |||
1096 | static struct intel_uncore_type nhmex_uncore_sbox = { | ||
1097 | .name = "sbox", | ||
1098 | .num_counters = 4, | ||
1099 | .num_boxes = 2, | ||
1100 | .perf_ctr_bits = 48, | ||
1101 | .event_ctl = NHMEX_S0_MSR_PMON_CTL0, | ||
1102 | .perf_ctr = NHMEX_S0_MSR_PMON_CTR0, | ||
1103 | .event_mask = NHMEX_PMON_RAW_EVENT_MASK, | ||
1104 | .box_ctl = NHMEX_S0_MSR_PMON_GLOBAL_CTL, | ||
1105 | .msr_offset = NHMEX_S_MSR_OFFSET, | ||
1106 | .pair_ctr_ctl = 1, | ||
1107 | .num_shared_regs = 1, | ||
1108 | .ops = &nhmex_uncore_sbox_ops, | ||
1109 | .format_group = &nhmex_uncore_sbox_format_group | ||
1110 | }; | ||
1111 | |||
1112 | enum { | ||
1113 | EXTRA_REG_NHMEX_M_FILTER, | ||
1114 | EXTRA_REG_NHMEX_M_DSP, | ||
1115 | EXTRA_REG_NHMEX_M_ISS, | ||
1116 | EXTRA_REG_NHMEX_M_MAP, | ||
1117 | EXTRA_REG_NHMEX_M_MSC_THR, | ||
1118 | EXTRA_REG_NHMEX_M_PGT, | ||
1119 | EXTRA_REG_NHMEX_M_PLD, | ||
1120 | EXTRA_REG_NHMEX_M_ZDP_CTL_FVC, | ||
1121 | }; | ||
1122 | |||
1123 | static struct extra_reg nhmex_uncore_mbox_extra_regs[] = { | ||
1124 | MBOX_INC_SEL_EXTAR_REG(0x0, DSP), | ||
1125 | MBOX_INC_SEL_EXTAR_REG(0x4, MSC_THR), | ||
1126 | MBOX_INC_SEL_EXTAR_REG(0x5, MSC_THR), | ||
1127 | MBOX_INC_SEL_EXTAR_REG(0x9, ISS), | ||
1128 | /* event 0xa uses two extra registers */ | ||
1129 | MBOX_INC_SEL_EXTAR_REG(0xa, ISS), | ||
1130 | MBOX_INC_SEL_EXTAR_REG(0xa, PLD), | ||
1131 | MBOX_INC_SEL_EXTAR_REG(0xb, PLD), | ||
1132 | /* events 0xd ~ 0x10 use the same extra register */ | ||
1133 | MBOX_INC_SEL_EXTAR_REG(0xd, ZDP_CTL_FVC), | ||
1134 | MBOX_INC_SEL_EXTAR_REG(0xe, ZDP_CTL_FVC), | ||
1135 | MBOX_INC_SEL_EXTAR_REG(0xf, ZDP_CTL_FVC), | ||
1136 | MBOX_INC_SEL_EXTAR_REG(0x10, ZDP_CTL_FVC), | ||
1137 | MBOX_INC_SEL_EXTAR_REG(0x16, PGT), | ||
1138 | MBOX_SET_FLAG_SEL_EXTRA_REG(0x0, DSP), | ||
1139 | MBOX_SET_FLAG_SEL_EXTRA_REG(0x1, ISS), | ||
1140 | MBOX_SET_FLAG_SEL_EXTRA_REG(0x5, PGT), | ||
1141 | MBOX_SET_FLAG_SEL_EXTRA_REG(0x6, MAP), | ||
1142 | EVENT_EXTRA_END | ||
1143 | }; | ||
1144 | |||
1145 | static bool nhmex_mbox_get_shared_reg(struct intel_uncore_box *box, int idx, u64 config) | ||
1146 | { | ||
1147 | struct intel_uncore_extra_reg *er; | ||
1148 | unsigned long flags; | ||
1149 | bool ret = false; | ||
1150 | u64 mask; | ||
1151 | |||
1152 | if (idx < EXTRA_REG_NHMEX_M_ZDP_CTL_FVC) { | ||
1153 | er = &box->shared_regs[idx]; | ||
1154 | raw_spin_lock_irqsave(&er->lock, flags); | ||
1155 | if (!atomic_read(&er->ref) || er->config == config) { | ||
1156 | atomic_inc(&er->ref); | ||
1157 | er->config = config; | ||
1158 | ret = true; | ||
1159 | } | ||
1160 | raw_spin_unlock_irqrestore(&er->lock, flags); | ||
1161 | |||
1162 | return ret; | ||
1163 | } | ||
1164 | /* | ||
1165 | * The ZDP_CTL_FVC MSR has 4 fields which are used to control | ||
1166 | * events 0xd ~ 0x10. Besides these 4 fields, there are additional | ||
1167 | * fields which are shared. | ||
1168 | */ | ||
1169 | idx -= EXTRA_REG_NHMEX_M_ZDP_CTL_FVC; | ||
1170 | if (WARN_ON_ONCE(idx >= 4)) | ||
1171 | return false; | ||
1172 | |||
1173 | /* mask of the shared fields */ | ||
1174 | mask = NHMEX_M_PMON_ZDP_CTL_FVC_MASK; | ||
1175 | er = &box->shared_regs[EXTRA_REG_NHMEX_M_ZDP_CTL_FVC]; | ||
1176 | |||
1177 | raw_spin_lock_irqsave(&er->lock, flags); | ||
1178 | /* add mask of the non-shared field if it's in use */ | ||
1179 | if (__BITS_VALUE(atomic_read(&er->ref), idx, 8)) | ||
1180 | mask |= NHMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx); | ||
1181 | |||
1182 | if (!atomic_read(&er->ref) || !((er->config ^ config) & mask)) { | ||
1183 | atomic_add(1 << (idx * 8), &er->ref); | ||
1184 | mask = NHMEX_M_PMON_ZDP_CTL_FVC_MASK | | ||
1185 | NHMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx); | ||
1186 | er->config &= ~mask; | ||
1187 | er->config |= (config & mask); | ||
1188 | ret = true; | ||
1189 | } | ||
1190 | raw_spin_unlock_irqrestore(&er->lock, flags); | ||
1191 | |||
1192 | return ret; | ||
1193 | } | ||
1194 | |||
1195 | static void nhmex_mbox_put_shared_reg(struct intel_uncore_box *box, int idx) | ||
1196 | { | ||
1197 | struct intel_uncore_extra_reg *er; | ||
1198 | |||
1199 | if (idx < EXTRA_REG_NHMEX_M_ZDP_CTL_FVC) { | ||
1200 | er = &box->shared_regs[idx]; | ||
1201 | atomic_dec(&er->ref); | ||
1202 | return; | ||
1203 | } | ||
1204 | |||
1205 | idx -= EXTRA_REG_NHMEX_M_ZDP_CTL_FVC; | ||
1206 | er = &box->shared_regs[EXTRA_REG_NHMEX_M_ZDP_CTL_FVC]; | ||
1207 | atomic_sub(1 << (idx * 8), &er->ref); | ||
1208 | } | ||
1209 | |||
1210 | u64 nhmex_mbox_alter_er(struct perf_event *event, int new_idx, bool modify) | ||
1211 | { | ||
1212 | struct hw_perf_event *hwc = &event->hw; | ||
1213 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
1214 | int idx, orig_idx = __BITS_VALUE(reg1->idx, 0, 8); | ||
1215 | u64 config = reg1->config; | ||
1216 | |||
1217 | /* get the non-shared control bits and shift them */ | ||
1218 | idx = orig_idx - EXTRA_REG_NHMEX_M_ZDP_CTL_FVC; | ||
1219 | config &= NHMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(idx); | ||
1220 | if (new_idx > orig_idx) { | ||
1221 | idx = new_idx - orig_idx; | ||
1222 | config <<= 3 * idx; | ||
1223 | } else { | ||
1224 | idx = orig_idx - new_idx; | ||
1225 | config >>= 3 * idx; | ||
1226 | } | ||
1227 | |||
1228 | /* add the shared control bits back */ | ||
1229 | config |= NHMEX_M_PMON_ZDP_CTL_FVC_MASK & reg1->config; | ||
1230 | if (modify) { | ||
1231 | /* adjust the main event selector */ | ||
1232 | if (new_idx > orig_idx) | ||
1233 | hwc->config += idx << NHMEX_M_PMON_CTL_INC_SEL_SHIFT; | ||
1234 | else | ||
1235 | hwc->config -= idx << NHMEX_M_PMON_CTL_INC_SEL_SHIFT; | ||
1236 | reg1->config = config; | ||
1237 | reg1->idx = ~0xff | new_idx; | ||
1238 | } | ||
1239 | return config; | ||
1240 | } | ||
1241 | |||
1242 | static struct event_constraint * | ||
1243 | nhmex_mbox_get_constraint(struct intel_uncore_box *box, struct perf_event *event) | ||
1244 | { | ||
1245 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
1246 | struct hw_perf_event_extra *reg2 = &event->hw.branch_reg; | ||
1247 | int i, idx[2], alloc = 0; | ||
1248 | u64 config1 = reg1->config; | ||
1249 | |||
1250 | idx[0] = __BITS_VALUE(reg1->idx, 0, 8); | ||
1251 | idx[1] = __BITS_VALUE(reg1->idx, 1, 8); | ||
1252 | again: | ||
1253 | for (i = 0; i < 2; i++) { | ||
1254 | if (!uncore_box_is_fake(box) && (reg1->alloc & (0x1 << i))) | ||
1255 | idx[i] = 0xff; | ||
1256 | |||
1257 | if (idx[i] == 0xff) | ||
1258 | continue; | ||
1259 | |||
1260 | if (!nhmex_mbox_get_shared_reg(box, idx[i], | ||
1261 | __BITS_VALUE(config1, i, 32))) | ||
1262 | goto fail; | ||
1263 | alloc |= (0x1 << i); | ||
1264 | } | ||
1265 | |||
1266 | /* for the match/mask registers */ | ||
1267 | if ((uncore_box_is_fake(box) || !reg2->alloc) && | ||
1268 | !nhmex_mbox_get_shared_reg(box, reg2->idx, reg2->config)) | ||
1269 | goto fail; | ||
1270 | |||
1271 | /* | ||
1272 | * If it's a fake box -- as per validate_{group,event}() we | ||
1273 | * shouldn't touch event state and we can avoid doing so | ||
1274 | * since both will only call get_event_constraints() once | ||
1275 | * on each event, this avoids the need for reg->alloc. | ||
1276 | */ | ||
1277 | if (!uncore_box_is_fake(box)) { | ||
1278 | if (idx[0] != 0xff && idx[0] != __BITS_VALUE(reg1->idx, 0, 8)) | ||
1279 | nhmex_mbox_alter_er(event, idx[0], true); | ||
1280 | reg1->alloc |= alloc; | ||
1281 | reg2->alloc = 1; | ||
1282 | } | ||
1283 | return NULL; | ||
1284 | fail: | ||
1285 | if (idx[0] != 0xff && !(alloc & 0x1) && | ||
1286 | idx[0] >= EXTRA_REG_NHMEX_M_ZDP_CTL_FVC) { | ||
1287 | /* | ||
1288 | * events 0xd ~ 0x10 are functional identical, but are | ||
1289 | * controlled by different fields in the ZDP_CTL_FVC | ||
1290 | * register. If we failed to take one field, try the | ||
1291 | * rest 3 choices. | ||
1292 | */ | ||
1293 | BUG_ON(__BITS_VALUE(reg1->idx, 1, 8) != 0xff); | ||
1294 | idx[0] -= EXTRA_REG_NHMEX_M_ZDP_CTL_FVC; | ||
1295 | idx[0] = (idx[0] + 1) % 4; | ||
1296 | idx[0] += EXTRA_REG_NHMEX_M_ZDP_CTL_FVC; | ||
1297 | if (idx[0] != __BITS_VALUE(reg1->idx, 0, 8)) { | ||
1298 | config1 = nhmex_mbox_alter_er(event, idx[0], false); | ||
1299 | goto again; | ||
1300 | } | ||
1301 | } | ||
1302 | |||
1303 | if (alloc & 0x1) | ||
1304 | nhmex_mbox_put_shared_reg(box, idx[0]); | ||
1305 | if (alloc & 0x2) | ||
1306 | nhmex_mbox_put_shared_reg(box, idx[1]); | ||
1307 | return &constraint_empty; | ||
1308 | } | ||
1309 | |||
1310 | static void nhmex_mbox_put_constraint(struct intel_uncore_box *box, struct perf_event *event) | ||
1311 | { | ||
1312 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
1313 | struct hw_perf_event_extra *reg2 = &event->hw.branch_reg; | ||
1314 | |||
1315 | if (uncore_box_is_fake(box)) | ||
1316 | return; | ||
1317 | |||
1318 | if (reg1->alloc & 0x1) | ||
1319 | nhmex_mbox_put_shared_reg(box, __BITS_VALUE(reg1->idx, 0, 8)); | ||
1320 | if (reg1->alloc & 0x2) | ||
1321 | nhmex_mbox_put_shared_reg(box, __BITS_VALUE(reg1->idx, 1, 8)); | ||
1322 | reg1->alloc = 0; | ||
1323 | |||
1324 | if (reg2->alloc) { | ||
1325 | nhmex_mbox_put_shared_reg(box, reg2->idx); | ||
1326 | reg2->alloc = 0; | ||
1327 | } | ||
1328 | } | ||
1329 | |||
1330 | static int nhmex_mbox_extra_reg_idx(struct extra_reg *er) | ||
1331 | { | ||
1332 | if (er->idx < EXTRA_REG_NHMEX_M_ZDP_CTL_FVC) | ||
1333 | return er->idx; | ||
1334 | return er->idx + (er->event >> NHMEX_M_PMON_CTL_INC_SEL_SHIFT) - 0xd; | ||
1335 | } | ||
1336 | |||
1337 | static int nhmex_mbox_hw_config(struct intel_uncore_box *box, struct perf_event *event) | ||
1338 | { | ||
1339 | struct intel_uncore_type *type = box->pmu->type; | ||
1340 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
1341 | struct hw_perf_event_extra *reg2 = &event->hw.branch_reg; | ||
1342 | struct extra_reg *er; | ||
1343 | unsigned msr; | ||
1344 | int reg_idx = 0; | ||
1345 | |||
1346 | if (WARN_ON_ONCE(reg1->idx != -1)) | ||
1347 | return -EINVAL; | ||
1348 | /* | ||
1349 | * The mbox events may require 2 extra MSRs at the most. But only | ||
1350 | * the lower 32 bits in these MSRs are significant, so we can use | ||
1351 | * config1 to pass two MSRs' config. | ||
1352 | */ | ||
1353 | for (er = nhmex_uncore_mbox_extra_regs; er->msr; er++) { | ||
1354 | if (er->event != (event->hw.config & er->config_mask)) | ||
1355 | continue; | ||
1356 | if (event->attr.config1 & ~er->valid_mask) | ||
1357 | return -EINVAL; | ||
1358 | if (er->idx == __BITS_VALUE(reg1->idx, 0, 8) || | ||
1359 | er->idx == __BITS_VALUE(reg1->idx, 1, 8)) | ||
1360 | continue; | ||
1361 | if (WARN_ON_ONCE(reg_idx >= 2)) | ||
1362 | return -EINVAL; | ||
1363 | |||
1364 | msr = er->msr + type->msr_offset * box->pmu->pmu_idx; | ||
1365 | if (WARN_ON_ONCE(msr >= 0xffff || er->idx >= 0xff)) | ||
1366 | return -EINVAL; | ||
1367 | |||
1368 | /* always use the 32~63 bits to pass the PLD config */ | ||
1369 | if (er->idx == EXTRA_REG_NHMEX_M_PLD) | ||
1370 | reg_idx = 1; | ||
1371 | |||
1372 | reg1->idx &= ~(0xff << (reg_idx * 8)); | ||
1373 | reg1->reg &= ~(0xffff << (reg_idx * 16)); | ||
1374 | reg1->idx |= nhmex_mbox_extra_reg_idx(er) << (reg_idx * 8); | ||
1375 | reg1->reg |= msr << (reg_idx * 16); | ||
1376 | reg1->config = event->attr.config1; | ||
1377 | reg_idx++; | ||
1378 | } | ||
1379 | /* use config2 to pass the filter config */ | ||
1380 | reg2->idx = EXTRA_REG_NHMEX_M_FILTER; | ||
1381 | if (event->attr.config2 & NHMEX_M_PMON_MM_CFG_EN) | ||
1382 | reg2->config = event->attr.config2; | ||
1383 | else | ||
1384 | reg2->config = ~0ULL; | ||
1385 | if (box->pmu->pmu_idx == 0) | ||
1386 | reg2->reg = NHMEX_M0_MSR_PMU_MM_CFG; | ||
1387 | else | ||
1388 | reg2->reg = NHMEX_M1_MSR_PMU_MM_CFG; | ||
1389 | |||
1390 | return 0; | ||
1391 | } | ||
1392 | |||
1393 | static u64 nhmex_mbox_shared_reg_config(struct intel_uncore_box *box, int idx) | ||
1394 | { | ||
1395 | struct intel_uncore_extra_reg *er; | ||
1396 | unsigned long flags; | ||
1397 | u64 config; | ||
1398 | |||
1399 | if (idx < EXTRA_REG_NHMEX_M_ZDP_CTL_FVC) | ||
1400 | return box->shared_regs[idx].config; | ||
1401 | |||
1402 | er = &box->shared_regs[EXTRA_REG_NHMEX_M_ZDP_CTL_FVC]; | ||
1403 | raw_spin_lock_irqsave(&er->lock, flags); | ||
1404 | config = er->config; | ||
1405 | raw_spin_unlock_irqrestore(&er->lock, flags); | ||
1406 | return config; | ||
1407 | } | ||
1408 | |||
1409 | static void nhmex_mbox_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
1410 | { | ||
1411 | struct hw_perf_event *hwc = &event->hw; | ||
1412 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
1413 | struct hw_perf_event_extra *reg2 = &hwc->branch_reg; | ||
1414 | int idx; | ||
1415 | |||
1416 | idx = __BITS_VALUE(reg1->idx, 0, 8); | ||
1417 | if (idx != 0xff) | ||
1418 | wrmsrl(__BITS_VALUE(reg1->reg, 0, 16), | ||
1419 | nhmex_mbox_shared_reg_config(box, idx)); | ||
1420 | idx = __BITS_VALUE(reg1->idx, 1, 8); | ||
1421 | if (idx != 0xff) | ||
1422 | wrmsrl(__BITS_VALUE(reg1->reg, 1, 16), | ||
1423 | nhmex_mbox_shared_reg_config(box, idx)); | ||
1424 | |||
1425 | wrmsrl(reg2->reg, 0); | ||
1426 | if (reg2->config != ~0ULL) { | ||
1427 | wrmsrl(reg2->reg + 1, | ||
1428 | reg2->config & NHMEX_M_PMON_ADDR_MATCH_MASK); | ||
1429 | wrmsrl(reg2->reg + 2, NHMEX_M_PMON_ADDR_MASK_MASK & | ||
1430 | (reg2->config >> NHMEX_M_PMON_ADDR_MASK_SHIFT)); | ||
1431 | wrmsrl(reg2->reg, NHMEX_M_PMON_MM_CFG_EN); | ||
1432 | } | ||
1433 | |||
1434 | wrmsrl(hwc->config_base, hwc->config | NHMEX_PMON_CTL_EN_BIT0); | ||
1435 | } | ||
1436 | |||
1437 | DEFINE_UNCORE_FORMAT_ATTR(count_mode, count_mode, "config:2-3"); | ||
1438 | DEFINE_UNCORE_FORMAT_ATTR(storage_mode, storage_mode, "config:4-5"); | ||
1439 | DEFINE_UNCORE_FORMAT_ATTR(wrap_mode, wrap_mode, "config:6"); | ||
1440 | DEFINE_UNCORE_FORMAT_ATTR(flag_mode, flag_mode, "config:7"); | ||
1441 | DEFINE_UNCORE_FORMAT_ATTR(inc_sel, inc_sel, "config:9-13"); | ||
1442 | DEFINE_UNCORE_FORMAT_ATTR(set_flag_sel, set_flag_sel, "config:19-21"); | ||
1443 | DEFINE_UNCORE_FORMAT_ATTR(filter_cfg, filter_cfg, "config2:63"); | ||
1444 | DEFINE_UNCORE_FORMAT_ATTR(filter_match, filter_match, "config2:0-33"); | ||
1445 | DEFINE_UNCORE_FORMAT_ATTR(filter_mask, filter_mask, "config2:34-61"); | ||
1446 | DEFINE_UNCORE_FORMAT_ATTR(dsp, dsp, "config1:0-31"); | ||
1447 | DEFINE_UNCORE_FORMAT_ATTR(thr, thr, "config1:0-31"); | ||
1448 | DEFINE_UNCORE_FORMAT_ATTR(fvc, fvc, "config1:0-31"); | ||
1449 | DEFINE_UNCORE_FORMAT_ATTR(pgt, pgt, "config1:0-31"); | ||
1450 | DEFINE_UNCORE_FORMAT_ATTR(map, map, "config1:0-31"); | ||
1451 | DEFINE_UNCORE_FORMAT_ATTR(iss, iss, "config1:0-31"); | ||
1452 | DEFINE_UNCORE_FORMAT_ATTR(pld, pld, "config1:32-63"); | ||
1453 | |||
1454 | static struct attribute *nhmex_uncore_mbox_formats_attr[] = { | ||
1455 | &format_attr_count_mode.attr, | ||
1456 | &format_attr_storage_mode.attr, | ||
1457 | &format_attr_wrap_mode.attr, | ||
1458 | &format_attr_flag_mode.attr, | ||
1459 | &format_attr_inc_sel.attr, | ||
1460 | &format_attr_set_flag_sel.attr, | ||
1461 | &format_attr_filter_cfg.attr, | ||
1462 | &format_attr_filter_match.attr, | ||
1463 | &format_attr_filter_mask.attr, | ||
1464 | &format_attr_dsp.attr, | ||
1465 | &format_attr_thr.attr, | ||
1466 | &format_attr_fvc.attr, | ||
1467 | &format_attr_pgt.attr, | ||
1468 | &format_attr_map.attr, | ||
1469 | &format_attr_iss.attr, | ||
1470 | &format_attr_pld.attr, | ||
1471 | NULL, | ||
1472 | }; | ||
1473 | |||
1474 | static struct attribute_group nhmex_uncore_mbox_format_group = { | ||
1475 | .name = "format", | ||
1476 | .attrs = nhmex_uncore_mbox_formats_attr, | ||
1477 | }; | ||
1478 | |||
1479 | static struct uncore_event_desc nhmex_uncore_mbox_events[] = { | ||
1480 | INTEL_UNCORE_EVENT_DESC(bbox_cmds_read, "inc_sel=0xd,fvc=0x2800"), | ||
1481 | INTEL_UNCORE_EVENT_DESC(bbox_cmds_write, "inc_sel=0xd,fvc=0x2820"), | ||
1482 | { /* end: all zeroes */ }, | ||
1483 | }; | ||
1484 | |||
1485 | static struct intel_uncore_ops nhmex_uncore_mbox_ops = { | ||
1486 | NHMEX_UNCORE_OPS_COMMON_INIT(), | ||
1487 | .enable_event = nhmex_mbox_msr_enable_event, | ||
1488 | .hw_config = nhmex_mbox_hw_config, | ||
1489 | .get_constraint = nhmex_mbox_get_constraint, | ||
1490 | .put_constraint = nhmex_mbox_put_constraint, | ||
1491 | }; | ||
1492 | |||
1493 | static struct intel_uncore_type nhmex_uncore_mbox = { | ||
1494 | .name = "mbox", | ||
1495 | .num_counters = 6, | ||
1496 | .num_boxes = 2, | ||
1497 | .perf_ctr_bits = 48, | ||
1498 | .event_ctl = NHMEX_M0_MSR_PMU_CTL0, | ||
1499 | .perf_ctr = NHMEX_M0_MSR_PMU_CNT0, | ||
1500 | .event_mask = NHMEX_M_PMON_RAW_EVENT_MASK, | ||
1501 | .box_ctl = NHMEX_M0_MSR_GLOBAL_CTL, | ||
1502 | .msr_offset = NHMEX_M_MSR_OFFSET, | ||
1503 | .pair_ctr_ctl = 1, | ||
1504 | .num_shared_regs = 8, | ||
1505 | .event_descs = nhmex_uncore_mbox_events, | ||
1506 | .ops = &nhmex_uncore_mbox_ops, | ||
1507 | .format_group = &nhmex_uncore_mbox_format_group, | ||
1508 | }; | ||
1509 | |||
1510 | void nhmex_rbox_alter_er(struct intel_uncore_box *box, struct perf_event *event) | ||
1511 | { | ||
1512 | struct hw_perf_event *hwc = &event->hw; | ||
1513 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
1514 | int port; | ||
1515 | |||
1516 | /* adjust the main event selector */ | ||
1517 | if (reg1->idx % 2) { | ||
1518 | reg1->idx--; | ||
1519 | hwc->config -= 1 << NHMEX_R_PMON_CTL_EV_SEL_SHIFT; | ||
1520 | } else { | ||
1521 | reg1->idx++; | ||
1522 | hwc->config += 1 << NHMEX_R_PMON_CTL_EV_SEL_SHIFT; | ||
1523 | } | ||
1524 | |||
1525 | /* adjust address or config of extra register */ | ||
1526 | port = reg1->idx / 6 + box->pmu->pmu_idx * 4; | ||
1527 | switch (reg1->idx % 6) { | ||
1528 | case 0: | ||
1529 | reg1->reg = NHMEX_R_MSR_PORTN_IPERF_CFG0(port); | ||
1530 | break; | ||
1531 | case 1: | ||
1532 | reg1->reg = NHMEX_R_MSR_PORTN_IPERF_CFG1(port); | ||
1533 | break; | ||
1534 | case 2: | ||
1535 | /* the 8~15 bits to the 0~7 bits */ | ||
1536 | reg1->config >>= 8; | ||
1537 | break; | ||
1538 | case 3: | ||
1539 | /* the 0~7 bits to the 8~15 bits */ | ||
1540 | reg1->config <<= 8; | ||
1541 | break; | ||
1542 | case 4: | ||
1543 | reg1->reg = NHMEX_R_MSR_PORTN_XBR_SET1_MM_CFG(port); | ||
1544 | break; | ||
1545 | case 5: | ||
1546 | reg1->reg = NHMEX_R_MSR_PORTN_XBR_SET2_MM_CFG(port); | ||
1547 | break; | ||
1548 | }; | ||
1549 | } | ||
1550 | |||
1551 | /* | ||
1552 | * Each rbox has 4 event set which monitor PQI port 0~3 or 4~7. | ||
1553 | * An event set consists of 6 events, the 3rd and 4th events in | ||
1554 | * an event set use the same extra register. So an event set uses | ||
1555 | * 5 extra registers. | ||
1556 | */ | ||
1557 | static struct event_constraint * | ||
1558 | nhmex_rbox_get_constraint(struct intel_uncore_box *box, struct perf_event *event) | ||
1559 | { | ||
1560 | struct hw_perf_event *hwc = &event->hw; | ||
1561 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
1562 | struct hw_perf_event_extra *reg2 = &hwc->branch_reg; | ||
1563 | struct intel_uncore_extra_reg *er; | ||
1564 | unsigned long flags; | ||
1565 | int idx, er_idx; | ||
1566 | u64 config1; | ||
1567 | bool ok = false; | ||
1568 | |||
1569 | if (!uncore_box_is_fake(box) && reg1->alloc) | ||
1570 | return NULL; | ||
1571 | |||
1572 | idx = reg1->idx % 6; | ||
1573 | config1 = reg1->config; | ||
1574 | again: | ||
1575 | er_idx = idx; | ||
1576 | /* the 3rd and 4th events use the same extra register */ | ||
1577 | if (er_idx > 2) | ||
1578 | er_idx--; | ||
1579 | er_idx += (reg1->idx / 6) * 5; | ||
1580 | |||
1581 | er = &box->shared_regs[er_idx]; | ||
1582 | raw_spin_lock_irqsave(&er->lock, flags); | ||
1583 | if (idx < 2) { | ||
1584 | if (!atomic_read(&er->ref) || er->config == reg1->config) { | ||
1585 | atomic_inc(&er->ref); | ||
1586 | er->config = reg1->config; | ||
1587 | ok = true; | ||
1588 | } | ||
1589 | } else if (idx == 2 || idx == 3) { | ||
1590 | /* | ||
1591 | * these two events use different fields in a extra register, | ||
1592 | * the 0~7 bits and the 8~15 bits respectively. | ||
1593 | */ | ||
1594 | u64 mask = 0xff << ((idx - 2) * 8); | ||
1595 | if (!__BITS_VALUE(atomic_read(&er->ref), idx - 2, 8) || | ||
1596 | !((er->config ^ config1) & mask)) { | ||
1597 | atomic_add(1 << ((idx - 2) * 8), &er->ref); | ||
1598 | er->config &= ~mask; | ||
1599 | er->config |= config1 & mask; | ||
1600 | ok = true; | ||
1601 | } | ||
1602 | } else { | ||
1603 | if (!atomic_read(&er->ref) || | ||
1604 | (er->config == (hwc->config >> 32) && | ||
1605 | er->config1 == reg1->config && | ||
1606 | er->config2 == reg2->config)) { | ||
1607 | atomic_inc(&er->ref); | ||
1608 | er->config = (hwc->config >> 32); | ||
1609 | er->config1 = reg1->config; | ||
1610 | er->config2 = reg2->config; | ||
1611 | ok = true; | ||
1612 | } | ||
1613 | } | ||
1614 | raw_spin_unlock_irqrestore(&er->lock, flags); | ||
1615 | |||
1616 | if (!ok) { | ||
1617 | /* | ||
1618 | * The Rbox events are always in pairs. The paired | ||
1619 | * events are functional identical, but use different | ||
1620 | * extra registers. If we failed to take an extra | ||
1621 | * register, try the alternative. | ||
1622 | */ | ||
1623 | if (idx % 2) | ||
1624 | idx--; | ||
1625 | else | ||
1626 | idx++; | ||
1627 | if (idx != reg1->idx % 6) { | ||
1628 | if (idx == 2) | ||
1629 | config1 >>= 8; | ||
1630 | else if (idx == 3) | ||
1631 | config1 <<= 8; | ||
1632 | goto again; | ||
1633 | } | ||
1634 | } else { | ||
1635 | if (!uncore_box_is_fake(box)) { | ||
1636 | if (idx != reg1->idx % 6) | ||
1637 | nhmex_rbox_alter_er(box, event); | ||
1638 | reg1->alloc = 1; | ||
1639 | } | ||
1640 | return NULL; | ||
1641 | } | ||
1642 | return &constraint_empty; | ||
1643 | } | ||
1644 | |||
1645 | static void nhmex_rbox_put_constraint(struct intel_uncore_box *box, struct perf_event *event) | ||
1646 | { | ||
1647 | struct intel_uncore_extra_reg *er; | ||
1648 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
1649 | int idx, er_idx; | ||
1650 | |||
1651 | if (uncore_box_is_fake(box) || !reg1->alloc) | ||
1652 | return; | ||
1653 | |||
1654 | idx = reg1->idx % 6; | ||
1655 | er_idx = idx; | ||
1656 | if (er_idx > 2) | ||
1657 | er_idx--; | ||
1658 | er_idx += (reg1->idx / 6) * 5; | ||
1659 | |||
1660 | er = &box->shared_regs[er_idx]; | ||
1661 | if (idx == 2 || idx == 3) | ||
1662 | atomic_sub(1 << ((idx - 2) * 8), &er->ref); | ||
1663 | else | ||
1664 | atomic_dec(&er->ref); | ||
1665 | |||
1666 | reg1->alloc = 0; | ||
1667 | } | ||
1668 | |||
1669 | static int nhmex_rbox_hw_config(struct intel_uncore_box *box, struct perf_event *event) | ||
1670 | { | ||
1671 | struct hw_perf_event *hwc = &event->hw; | ||
1672 | struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; | ||
1673 | struct hw_perf_event_extra *reg2 = &event->hw.branch_reg; | ||
1674 | int port, idx; | ||
1675 | |||
1676 | idx = (event->hw.config & NHMEX_R_PMON_CTL_EV_SEL_MASK) >> | ||
1677 | NHMEX_R_PMON_CTL_EV_SEL_SHIFT; | ||
1678 | if (idx >= 0x18) | ||
1679 | return -EINVAL; | ||
1680 | |||
1681 | reg1->idx = idx; | ||
1682 | reg1->config = event->attr.config1; | ||
1683 | |||
1684 | port = idx / 6 + box->pmu->pmu_idx * 4; | ||
1685 | idx %= 6; | ||
1686 | switch (idx) { | ||
1687 | case 0: | ||
1688 | reg1->reg = NHMEX_R_MSR_PORTN_IPERF_CFG0(port); | ||
1689 | break; | ||
1690 | case 1: | ||
1691 | reg1->reg = NHMEX_R_MSR_PORTN_IPERF_CFG1(port); | ||
1692 | break; | ||
1693 | case 2: | ||
1694 | case 3: | ||
1695 | reg1->reg = NHMEX_R_MSR_PORTN_QLX_CFG(port); | ||
1696 | break; | ||
1697 | case 4: | ||
1698 | case 5: | ||
1699 | if (idx == 4) | ||
1700 | reg1->reg = NHMEX_R_MSR_PORTN_XBR_SET1_MM_CFG(port); | ||
1701 | else | ||
1702 | reg1->reg = NHMEX_R_MSR_PORTN_XBR_SET2_MM_CFG(port); | ||
1703 | reg2->config = event->attr.config2; | ||
1704 | hwc->config |= event->attr.config & (~0ULL << 32); | ||
1705 | break; | ||
1706 | }; | ||
1707 | return 0; | ||
1708 | } | ||
1709 | |||
1710 | static u64 nhmex_rbox_shared_reg_config(struct intel_uncore_box *box, int idx) | ||
1711 | { | ||
1712 | struct intel_uncore_extra_reg *er; | ||
1713 | unsigned long flags; | ||
1714 | u64 config; | ||
1715 | |||
1716 | er = &box->shared_regs[idx]; | ||
1717 | |||
1718 | raw_spin_lock_irqsave(&er->lock, flags); | ||
1719 | config = er->config; | ||
1720 | raw_spin_unlock_irqrestore(&er->lock, flags); | ||
1721 | |||
1722 | return config; | ||
1723 | } | ||
1724 | |||
1725 | static void nhmex_rbox_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
1726 | { | ||
1727 | struct hw_perf_event *hwc = &event->hw; | ||
1728 | struct hw_perf_event_extra *reg1 = &hwc->extra_reg; | ||
1729 | struct hw_perf_event_extra *reg2 = &hwc->branch_reg; | ||
1730 | int idx, er_idx; | ||
1731 | |||
1732 | idx = reg1->idx % 6; | ||
1733 | er_idx = idx; | ||
1734 | if (er_idx > 2) | ||
1735 | er_idx--; | ||
1736 | er_idx += (reg1->idx / 6) * 5; | ||
1737 | |||
1738 | switch (idx) { | ||
1739 | case 0: | ||
1740 | case 1: | ||
1741 | wrmsrl(reg1->reg, reg1->config); | ||
1742 | break; | ||
1743 | case 2: | ||
1744 | case 3: | ||
1745 | wrmsrl(reg1->reg, nhmex_rbox_shared_reg_config(box, er_idx)); | ||
1746 | break; | ||
1747 | case 4: | ||
1748 | case 5: | ||
1749 | wrmsrl(reg1->reg, reg1->config); | ||
1750 | wrmsrl(reg1->reg + 1, hwc->config >> 32); | ||
1751 | wrmsrl(reg1->reg + 2, reg2->config); | ||
1752 | break; | ||
1753 | }; | ||
1754 | |||
1755 | wrmsrl(hwc->config_base, NHMEX_PMON_CTL_EN_BIT0 | | ||
1756 | (hwc->config & NHMEX_R_PMON_CTL_EV_SEL_MASK)); | ||
1757 | } | ||
1758 | |||
1759 | DEFINE_UNCORE_FORMAT_ATTR(xbr_match, xbr_match, "config:32-63"); | ||
1760 | DEFINE_UNCORE_FORMAT_ATTR(xbr_mm_cfg, xbr_mm_cfg, "config1:0-63"); | ||
1761 | DEFINE_UNCORE_FORMAT_ATTR(xbr_mask, xbr_mask, "config2:0-63"); | ||
1762 | DEFINE_UNCORE_FORMAT_ATTR(qlx_cfg, qlx_cfg, "config1:0-15"); | ||
1763 | DEFINE_UNCORE_FORMAT_ATTR(iperf_cfg, iperf_cfg, "config1:0-31"); | ||
1764 | |||
1765 | static struct attribute *nhmex_uncore_rbox_formats_attr[] = { | ||
1766 | &format_attr_event5.attr, | ||
1767 | &format_attr_xbr_mm_cfg.attr, | ||
1768 | &format_attr_xbr_match.attr, | ||
1769 | &format_attr_xbr_mask.attr, | ||
1770 | &format_attr_qlx_cfg.attr, | ||
1771 | &format_attr_iperf_cfg.attr, | ||
1772 | NULL, | ||
1773 | }; | ||
1774 | |||
1775 | static struct attribute_group nhmex_uncore_rbox_format_group = { | ||
1776 | .name = "format", | ||
1777 | .attrs = nhmex_uncore_rbox_formats_attr, | ||
1778 | }; | ||
1779 | |||
1780 | static struct uncore_event_desc nhmex_uncore_rbox_events[] = { | ||
1781 | INTEL_UNCORE_EVENT_DESC(qpi0_flit_send, "event=0x0,iperf_cfg=0x80000000"), | ||
1782 | INTEL_UNCORE_EVENT_DESC(qpi1_filt_send, "event=0x6,iperf_cfg=0x80000000"), | ||
1783 | INTEL_UNCORE_EVENT_DESC(qpi0_idle_filt, "event=0x0,iperf_cfg=0x40000000"), | ||
1784 | INTEL_UNCORE_EVENT_DESC(qpi1_idle_filt, "event=0x6,iperf_cfg=0x40000000"), | ||
1785 | INTEL_UNCORE_EVENT_DESC(qpi0_date_response, "event=0x0,iperf_cfg=0xc4"), | ||
1786 | INTEL_UNCORE_EVENT_DESC(qpi1_date_response, "event=0x6,iperf_cfg=0xc4"), | ||
1787 | { /* end: all zeroes */ }, | ||
1788 | }; | ||
1789 | |||
1790 | static struct intel_uncore_ops nhmex_uncore_rbox_ops = { | ||
1791 | NHMEX_UNCORE_OPS_COMMON_INIT(), | ||
1792 | .enable_event = nhmex_rbox_msr_enable_event, | ||
1793 | .hw_config = nhmex_rbox_hw_config, | ||
1794 | .get_constraint = nhmex_rbox_get_constraint, | ||
1795 | .put_constraint = nhmex_rbox_put_constraint, | ||
1796 | }; | ||
1797 | |||
1798 | static struct intel_uncore_type nhmex_uncore_rbox = { | ||
1799 | .name = "rbox", | ||
1800 | .num_counters = 8, | ||
1801 | .num_boxes = 2, | ||
1802 | .perf_ctr_bits = 48, | ||
1803 | .event_ctl = NHMEX_R_MSR_PMON_CTL0, | ||
1804 | .perf_ctr = NHMEX_R_MSR_PMON_CNT0, | ||
1805 | .event_mask = NHMEX_R_PMON_RAW_EVENT_MASK, | ||
1806 | .box_ctl = NHMEX_R_MSR_GLOBAL_CTL, | ||
1807 | .msr_offset = NHMEX_R_MSR_OFFSET, | ||
1808 | .pair_ctr_ctl = 1, | ||
1809 | .num_shared_regs = 20, | ||
1810 | .event_descs = nhmex_uncore_rbox_events, | ||
1811 | .ops = &nhmex_uncore_rbox_ops, | ||
1812 | .format_group = &nhmex_uncore_rbox_format_group | ||
1813 | }; | ||
1814 | |||
1815 | static struct intel_uncore_type *nhmex_msr_uncores[] = { | ||
1816 | &nhmex_uncore_ubox, | ||
1817 | &nhmex_uncore_cbox, | ||
1818 | &nhmex_uncore_bbox, | ||
1819 | &nhmex_uncore_sbox, | ||
1820 | &nhmex_uncore_mbox, | ||
1821 | &nhmex_uncore_rbox, | ||
1822 | &nhmex_uncore_wbox, | ||
1823 | NULL, | ||
1824 | }; | ||
1825 | /* end of Nehalem-EX uncore support */ | ||
1826 | |||
1827 | static void uncore_assign_hw_event(struct intel_uncore_box *box, struct perf_event *event, int idx) | ||
774 | { | 1828 | { |
775 | struct hw_perf_event *hwc = &event->hw; | 1829 | struct hw_perf_event *hwc = &event->hw; |
776 | 1830 | ||
@@ -787,8 +1841,7 @@ static void uncore_assign_hw_event(struct intel_uncore_box *box, | |||
787 | hwc->event_base = uncore_perf_ctr(box, hwc->idx); | 1841 | hwc->event_base = uncore_perf_ctr(box, hwc->idx); |
788 | } | 1842 | } |
789 | 1843 | ||
790 | static void uncore_perf_event_update(struct intel_uncore_box *box, | 1844 | static void uncore_perf_event_update(struct intel_uncore_box *box, struct perf_event *event) |
791 | struct perf_event *event) | ||
792 | { | 1845 | { |
793 | u64 prev_count, new_count, delta; | 1846 | u64 prev_count, new_count, delta; |
794 | int shift; | 1847 | int shift; |
@@ -858,14 +1911,12 @@ static void uncore_pmu_init_hrtimer(struct intel_uncore_box *box) | |||
858 | box->hrtimer.function = uncore_pmu_hrtimer; | 1911 | box->hrtimer.function = uncore_pmu_hrtimer; |
859 | } | 1912 | } |
860 | 1913 | ||
861 | struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type, | 1914 | struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type, int cpu) |
862 | int cpu) | ||
863 | { | 1915 | { |
864 | struct intel_uncore_box *box; | 1916 | struct intel_uncore_box *box; |
865 | int i, size; | 1917 | int i, size; |
866 | 1918 | ||
867 | size = sizeof(*box) + type->num_shared_regs * | 1919 | size = sizeof(*box) + type->num_shared_regs * sizeof(struct intel_uncore_extra_reg); |
868 | sizeof(struct intel_uncore_extra_reg); | ||
869 | 1920 | ||
870 | box = kmalloc_node(size, GFP_KERNEL | __GFP_ZERO, cpu_to_node(cpu)); | 1921 | box = kmalloc_node(size, GFP_KERNEL | __GFP_ZERO, cpu_to_node(cpu)); |
871 | if (!box) | 1922 | if (!box) |
@@ -915,12 +1966,11 @@ static struct intel_uncore_box *uncore_event_to_box(struct perf_event *event) | |||
915 | * perf core schedules event on the basis of cpu, uncore events are | 1966 | * perf core schedules event on the basis of cpu, uncore events are |
916 | * collected by one of the cpus inside a physical package. | 1967 | * collected by one of the cpus inside a physical package. |
917 | */ | 1968 | */ |
918 | return uncore_pmu_to_box(uncore_event_to_pmu(event), | 1969 | return uncore_pmu_to_box(uncore_event_to_pmu(event), smp_processor_id()); |
919 | smp_processor_id()); | ||
920 | } | 1970 | } |
921 | 1971 | ||
922 | static int uncore_collect_events(struct intel_uncore_box *box, | 1972 | static int |
923 | struct perf_event *leader, bool dogrp) | 1973 | uncore_collect_events(struct intel_uncore_box *box, struct perf_event *leader, bool dogrp) |
924 | { | 1974 | { |
925 | struct perf_event *event; | 1975 | struct perf_event *event; |
926 | int n, max_count; | 1976 | int n, max_count; |
@@ -952,8 +2002,7 @@ static int uncore_collect_events(struct intel_uncore_box *box, | |||
952 | } | 2002 | } |
953 | 2003 | ||
954 | static struct event_constraint * | 2004 | static struct event_constraint * |
955 | uncore_get_event_constraint(struct intel_uncore_box *box, | 2005 | uncore_get_event_constraint(struct intel_uncore_box *box, struct perf_event *event) |
956 | struct perf_event *event) | ||
957 | { | 2006 | { |
958 | struct intel_uncore_type *type = box->pmu->type; | 2007 | struct intel_uncore_type *type = box->pmu->type; |
959 | struct event_constraint *c; | 2008 | struct event_constraint *c; |
@@ -977,15 +2026,13 @@ uncore_get_event_constraint(struct intel_uncore_box *box, | |||
977 | return &type->unconstrainted; | 2026 | return &type->unconstrainted; |
978 | } | 2027 | } |
979 | 2028 | ||
980 | static void uncore_put_event_constraint(struct intel_uncore_box *box, | 2029 | static void uncore_put_event_constraint(struct intel_uncore_box *box, struct perf_event *event) |
981 | struct perf_event *event) | ||
982 | { | 2030 | { |
983 | if (box->pmu->type->ops->put_constraint) | 2031 | if (box->pmu->type->ops->put_constraint) |
984 | box->pmu->type->ops->put_constraint(box, event); | 2032 | box->pmu->type->ops->put_constraint(box, event); |
985 | } | 2033 | } |
986 | 2034 | ||
987 | static int uncore_assign_events(struct intel_uncore_box *box, | 2035 | static int uncore_assign_events(struct intel_uncore_box *box, int assign[], int n) |
988 | int assign[], int n) | ||
989 | { | 2036 | { |
990 | unsigned long used_mask[BITS_TO_LONGS(UNCORE_PMC_IDX_MAX)]; | 2037 | unsigned long used_mask[BITS_TO_LONGS(UNCORE_PMC_IDX_MAX)]; |
991 | struct event_constraint *c, *constraints[UNCORE_PMC_IDX_MAX]; | 2038 | struct event_constraint *c, *constraints[UNCORE_PMC_IDX_MAX]; |
@@ -1407,8 +2454,7 @@ static bool pcidrv_registered; | |||
1407 | /* | 2454 | /* |
1408 | * add a pci uncore device | 2455 | * add a pci uncore device |
1409 | */ | 2456 | */ |
1410 | static int __devinit uncore_pci_add(struct intel_uncore_type *type, | 2457 | static int __devinit uncore_pci_add(struct intel_uncore_type *type, struct pci_dev *pdev) |
1411 | struct pci_dev *pdev) | ||
1412 | { | 2458 | { |
1413 | struct intel_uncore_pmu *pmu; | 2459 | struct intel_uncore_pmu *pmu; |
1414 | struct intel_uncore_box *box; | 2460 | struct intel_uncore_box *box; |
@@ -1485,6 +2531,7 @@ static int __devinit uncore_pci_probe(struct pci_dev *pdev, | |||
1485 | struct intel_uncore_type *type; | 2531 | struct intel_uncore_type *type; |
1486 | 2532 | ||
1487 | type = (struct intel_uncore_type *)id->driver_data; | 2533 | type = (struct intel_uncore_type *)id->driver_data; |
2534 | |||
1488 | return uncore_pci_add(type, pdev); | 2535 | return uncore_pci_add(type, pdev); |
1489 | } | 2536 | } |
1490 | 2537 | ||
@@ -1612,8 +2659,8 @@ static int __cpuinit uncore_cpu_prepare(int cpu, int phys_id) | |||
1612 | return 0; | 2659 | return 0; |
1613 | } | 2660 | } |
1614 | 2661 | ||
1615 | static void __cpuinit uncore_change_context(struct intel_uncore_type **uncores, | 2662 | static void __cpuinit |
1616 | int old_cpu, int new_cpu) | 2663 | uncore_change_context(struct intel_uncore_type **uncores, int old_cpu, int new_cpu) |
1617 | { | 2664 | { |
1618 | struct intel_uncore_type *type; | 2665 | struct intel_uncore_type *type; |
1619 | struct intel_uncore_pmu *pmu; | 2666 | struct intel_uncore_pmu *pmu; |
@@ -1694,8 +2741,8 @@ static void __cpuinit uncore_event_init_cpu(int cpu) | |||
1694 | uncore_change_context(pci_uncores, -1, cpu); | 2741 | uncore_change_context(pci_uncores, -1, cpu); |
1695 | } | 2742 | } |
1696 | 2743 | ||
1697 | static int __cpuinit uncore_cpu_notifier(struct notifier_block *self, | 2744 | static int |
1698 | unsigned long action, void *hcpu) | 2745 | __cpuinit uncore_cpu_notifier(struct notifier_block *self, unsigned long action, void *hcpu) |
1699 | { | 2746 | { |
1700 | unsigned int cpu = (long)hcpu; | 2747 | unsigned int cpu = (long)hcpu; |
1701 | 2748 | ||
@@ -1732,12 +2779,12 @@ static int __cpuinit uncore_cpu_notifier(struct notifier_block *self, | |||
1732 | } | 2779 | } |
1733 | 2780 | ||
1734 | static struct notifier_block uncore_cpu_nb __cpuinitdata = { | 2781 | static struct notifier_block uncore_cpu_nb __cpuinitdata = { |
1735 | .notifier_call = uncore_cpu_notifier, | 2782 | .notifier_call = uncore_cpu_notifier, |
1736 | /* | 2783 | /* |
1737 | * to migrate uncore events, our notifier should be executed | 2784 | * to migrate uncore events, our notifier should be executed |
1738 | * before perf core's notifier. | 2785 | * before perf core's notifier. |
1739 | */ | 2786 | */ |
1740 | .priority = CPU_PRI_PERF + 1, | 2787 | .priority = CPU_PRI_PERF + 1, |
1741 | }; | 2788 | }; |
1742 | 2789 | ||
1743 | static void __init uncore_cpu_setup(void *dummy) | 2790 | static void __init uncore_cpu_setup(void *dummy) |
@@ -1767,6 +2814,9 @@ static int __init uncore_cpu_init(void) | |||
1767 | snbep_uncore_cbox.num_boxes = max_cores; | 2814 | snbep_uncore_cbox.num_boxes = max_cores; |
1768 | msr_uncores = snbep_msr_uncores; | 2815 | msr_uncores = snbep_msr_uncores; |
1769 | break; | 2816 | break; |
2817 | case 46: | ||
2818 | msr_uncores = nhmex_msr_uncores; | ||
2819 | break; | ||
1770 | default: | 2820 | default: |
1771 | return 0; | 2821 | return 0; |
1772 | } | 2822 | } |
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h index b13e9ea81def..f3851892e077 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h | |||
@@ -5,8 +5,6 @@ | |||
5 | #include "perf_event.h" | 5 | #include "perf_event.h" |
6 | 6 | ||
7 | #define UNCORE_PMU_NAME_LEN 32 | 7 | #define UNCORE_PMU_NAME_LEN 32 |
8 | #define UNCORE_BOX_HASH_SIZE 8 | ||
9 | |||
10 | #define UNCORE_PMU_HRTIMER_INTERVAL (60 * NSEC_PER_SEC) | 8 | #define UNCORE_PMU_HRTIMER_INTERVAL (60 * NSEC_PER_SEC) |
11 | 9 | ||
12 | #define UNCORE_FIXED_EVENT 0xff | 10 | #define UNCORE_FIXED_EVENT 0xff |
@@ -115,6 +113,10 @@ | |||
115 | SNBEP_PCU_MSR_PMON_CTL_OCC_INVERT | \ | 113 | SNBEP_PCU_MSR_PMON_CTL_OCC_INVERT | \ |
116 | SNBEP_PCU_MSR_PMON_CTL_OCC_EDGE_DET) | 114 | SNBEP_PCU_MSR_PMON_CTL_OCC_EDGE_DET) |
117 | 115 | ||
116 | #define SNBEP_QPI_PCI_PMON_RAW_EVENT_MASK \ | ||
117 | (SNBEP_PMON_RAW_EVENT_MASK | \ | ||
118 | SNBEP_PMON_CTL_EV_SEL_EXT) | ||
119 | |||
118 | /* SNB-EP pci control register */ | 120 | /* SNB-EP pci control register */ |
119 | #define SNBEP_PCI_PMON_BOX_CTL 0xf4 | 121 | #define SNBEP_PCI_PMON_BOX_CTL 0xf4 |
120 | #define SNBEP_PCI_PMON_CTL0 0xd8 | 122 | #define SNBEP_PCI_PMON_CTL0 0xd8 |
@@ -158,6 +160,193 @@ | |||
158 | #define SNBEP_PCU_MSR_CORE_C3_CTR 0x3fc | 160 | #define SNBEP_PCU_MSR_CORE_C3_CTR 0x3fc |
159 | #define SNBEP_PCU_MSR_CORE_C6_CTR 0x3fd | 161 | #define SNBEP_PCU_MSR_CORE_C6_CTR 0x3fd |
160 | 162 | ||
163 | /* NHM-EX event control */ | ||
164 | #define NHMEX_PMON_CTL_EV_SEL_MASK 0x000000ff | ||
165 | #define NHMEX_PMON_CTL_UMASK_MASK 0x0000ff00 | ||
166 | #define NHMEX_PMON_CTL_EN_BIT0 (1 << 0) | ||
167 | #define NHMEX_PMON_CTL_EDGE_DET (1 << 18) | ||
168 | #define NHMEX_PMON_CTL_PMI_EN (1 << 20) | ||
169 | #define NHMEX_PMON_CTL_EN_BIT22 (1 << 22) | ||
170 | #define NHMEX_PMON_CTL_INVERT (1 << 23) | ||
171 | #define NHMEX_PMON_CTL_TRESH_MASK 0xff000000 | ||
172 | #define NHMEX_PMON_RAW_EVENT_MASK (NHMEX_PMON_CTL_EV_SEL_MASK | \ | ||
173 | NHMEX_PMON_CTL_UMASK_MASK | \ | ||
174 | NHMEX_PMON_CTL_EDGE_DET | \ | ||
175 | NHMEX_PMON_CTL_INVERT | \ | ||
176 | NHMEX_PMON_CTL_TRESH_MASK) | ||
177 | |||
178 | /* NHM-EX Ubox */ | ||
179 | #define NHMEX_U_MSR_PMON_GLOBAL_CTL 0xc00 | ||
180 | #define NHMEX_U_MSR_PMON_CTR 0xc11 | ||
181 | #define NHMEX_U_MSR_PMON_EV_SEL 0xc10 | ||
182 | |||
183 | #define NHMEX_U_PMON_GLOBAL_EN (1 << 0) | ||
184 | #define NHMEX_U_PMON_GLOBAL_PMI_CORE_SEL 0x0000001e | ||
185 | #define NHMEX_U_PMON_GLOBAL_EN_ALL (1 << 28) | ||
186 | #define NHMEX_U_PMON_GLOBAL_RST_ALL (1 << 29) | ||
187 | #define NHMEX_U_PMON_GLOBAL_FRZ_ALL (1 << 31) | ||
188 | |||
189 | #define NHMEX_U_PMON_RAW_EVENT_MASK \ | ||
190 | (NHMEX_PMON_CTL_EV_SEL_MASK | \ | ||
191 | NHMEX_PMON_CTL_EDGE_DET) | ||
192 | |||
193 | /* NHM-EX Cbox */ | ||
194 | #define NHMEX_C0_MSR_PMON_GLOBAL_CTL 0xd00 | ||
195 | #define NHMEX_C0_MSR_PMON_CTR0 0xd11 | ||
196 | #define NHMEX_C0_MSR_PMON_EV_SEL0 0xd10 | ||
197 | #define NHMEX_C_MSR_OFFSET 0x20 | ||
198 | |||
199 | /* NHM-EX Bbox */ | ||
200 | #define NHMEX_B0_MSR_PMON_GLOBAL_CTL 0xc20 | ||
201 | #define NHMEX_B0_MSR_PMON_CTR0 0xc31 | ||
202 | #define NHMEX_B0_MSR_PMON_CTL0 0xc30 | ||
203 | #define NHMEX_B_MSR_OFFSET 0x40 | ||
204 | #define NHMEX_B0_MSR_MATCH 0xe45 | ||
205 | #define NHMEX_B0_MSR_MASK 0xe46 | ||
206 | #define NHMEX_B1_MSR_MATCH 0xe4d | ||
207 | #define NHMEX_B1_MSR_MASK 0xe4e | ||
208 | |||
209 | #define NHMEX_B_PMON_CTL_EN (1 << 0) | ||
210 | #define NHMEX_B_PMON_CTL_EV_SEL_SHIFT 1 | ||
211 | #define NHMEX_B_PMON_CTL_EV_SEL_MASK \ | ||
212 | (0x1f << NHMEX_B_PMON_CTL_EV_SEL_SHIFT) | ||
213 | #define NHMEX_B_PMON_CTR_SHIFT 6 | ||
214 | #define NHMEX_B_PMON_CTR_MASK \ | ||
215 | (0x3 << NHMEX_B_PMON_CTR_SHIFT) | ||
216 | #define NHMEX_B_PMON_RAW_EVENT_MASK \ | ||
217 | (NHMEX_B_PMON_CTL_EV_SEL_MASK | \ | ||
218 | NHMEX_B_PMON_CTR_MASK) | ||
219 | |||
220 | /* NHM-EX Sbox */ | ||
221 | #define NHMEX_S0_MSR_PMON_GLOBAL_CTL 0xc40 | ||
222 | #define NHMEX_S0_MSR_PMON_CTR0 0xc51 | ||
223 | #define NHMEX_S0_MSR_PMON_CTL0 0xc50 | ||
224 | #define NHMEX_S_MSR_OFFSET 0x80 | ||
225 | #define NHMEX_S0_MSR_MM_CFG 0xe48 | ||
226 | #define NHMEX_S0_MSR_MATCH 0xe49 | ||
227 | #define NHMEX_S0_MSR_MASK 0xe4a | ||
228 | #define NHMEX_S1_MSR_MM_CFG 0xe58 | ||
229 | #define NHMEX_S1_MSR_MATCH 0xe59 | ||
230 | #define NHMEX_S1_MSR_MASK 0xe5a | ||
231 | |||
232 | #define NHMEX_S_PMON_MM_CFG_EN (0x1ULL << 63) | ||
233 | |||
234 | /* NHM-EX Mbox */ | ||
235 | #define NHMEX_M0_MSR_GLOBAL_CTL 0xca0 | ||
236 | #define NHMEX_M0_MSR_PMU_DSP 0xca5 | ||
237 | #define NHMEX_M0_MSR_PMU_ISS 0xca6 | ||
238 | #define NHMEX_M0_MSR_PMU_MAP 0xca7 | ||
239 | #define NHMEX_M0_MSR_PMU_MSC_THR 0xca8 | ||
240 | #define NHMEX_M0_MSR_PMU_PGT 0xca9 | ||
241 | #define NHMEX_M0_MSR_PMU_PLD 0xcaa | ||
242 | #define NHMEX_M0_MSR_PMU_ZDP_CTL_FVC 0xcab | ||
243 | #define NHMEX_M0_MSR_PMU_CTL0 0xcb0 | ||
244 | #define NHMEX_M0_MSR_PMU_CNT0 0xcb1 | ||
245 | #define NHMEX_M_MSR_OFFSET 0x40 | ||
246 | #define NHMEX_M0_MSR_PMU_MM_CFG 0xe54 | ||
247 | #define NHMEX_M1_MSR_PMU_MM_CFG 0xe5c | ||
248 | |||
249 | #define NHMEX_M_PMON_MM_CFG_EN (1ULL << 63) | ||
250 | #define NHMEX_M_PMON_ADDR_MATCH_MASK 0x3ffffffffULL | ||
251 | #define NHMEX_M_PMON_ADDR_MASK_MASK 0x7ffffffULL | ||
252 | #define NHMEX_M_PMON_ADDR_MASK_SHIFT 34 | ||
253 | |||
254 | #define NHMEX_M_PMON_CTL_EN (1 << 0) | ||
255 | #define NHMEX_M_PMON_CTL_PMI_EN (1 << 1) | ||
256 | #define NHMEX_M_PMON_CTL_COUNT_MODE_SHIFT 2 | ||
257 | #define NHMEX_M_PMON_CTL_COUNT_MODE_MASK \ | ||
258 | (0x3 << NHMEX_M_PMON_CTL_COUNT_MODE_SHIFT) | ||
259 | #define NHMEX_M_PMON_CTL_STORAGE_MODE_SHIFT 4 | ||
260 | #define NHMEX_M_PMON_CTL_STORAGE_MODE_MASK \ | ||
261 | (0x3 << NHMEX_M_PMON_CTL_STORAGE_MODE_SHIFT) | ||
262 | #define NHMEX_M_PMON_CTL_WRAP_MODE (1 << 6) | ||
263 | #define NHMEX_M_PMON_CTL_FLAG_MODE (1 << 7) | ||
264 | #define NHMEX_M_PMON_CTL_INC_SEL_SHIFT 9 | ||
265 | #define NHMEX_M_PMON_CTL_INC_SEL_MASK \ | ||
266 | (0x1f << NHMEX_M_PMON_CTL_INC_SEL_SHIFT) | ||
267 | #define NHMEX_M_PMON_CTL_SET_FLAG_SEL_SHIFT 19 | ||
268 | #define NHMEX_M_PMON_CTL_SET_FLAG_SEL_MASK \ | ||
269 | (0x7 << NHMEX_M_PMON_CTL_SET_FLAG_SEL_SHIFT) | ||
270 | #define NHMEX_M_PMON_RAW_EVENT_MASK \ | ||
271 | (NHMEX_M_PMON_CTL_COUNT_MODE_MASK | \ | ||
272 | NHMEX_M_PMON_CTL_STORAGE_MODE_MASK | \ | ||
273 | NHMEX_M_PMON_CTL_WRAP_MODE | \ | ||
274 | NHMEX_M_PMON_CTL_FLAG_MODE | \ | ||
275 | NHMEX_M_PMON_CTL_INC_SEL_MASK | \ | ||
276 | NHMEX_M_PMON_CTL_SET_FLAG_SEL_MASK) | ||
277 | |||
278 | |||
279 | #define NHMEX_M_PMON_ZDP_CTL_FVC_FVID_MASK 0x1f | ||
280 | #define NHMEX_M_PMON_ZDP_CTL_FVC_BCMD_MASK (0x7 << 5) | ||
281 | #define NHMEX_M_PMON_ZDP_CTL_FVC_RSP_MASK (0x7 << 8) | ||
282 | #define NHMEX_M_PMON_ZDP_CTL_FVC_PBOX_INIT_ERR (1 << 23) | ||
283 | #define NHMEX_M_PMON_ZDP_CTL_FVC_MASK \ | ||
284 | (NHMEX_M_PMON_ZDP_CTL_FVC_FVID_MASK | \ | ||
285 | NHMEX_M_PMON_ZDP_CTL_FVC_BCMD_MASK | \ | ||
286 | NHMEX_M_PMON_ZDP_CTL_FVC_RSP_MASK | \ | ||
287 | NHMEX_M_PMON_ZDP_CTL_FVC_PBOX_INIT_ERR) | ||
288 | #define NHMEX_M_PMON_ZDP_CTL_FVC_EVENT_MASK(n) (0x7 << (11 + 3 * (n))) | ||
289 | |||
290 | /* | ||
291 | * use the 9~13 bits to select event If the 7th bit is not set, | ||
292 | * otherwise use the 19~21 bits to select event. | ||
293 | */ | ||
294 | #define MBOX_INC_SEL(x) ((x) << NHMEX_M_PMON_CTL_INC_SEL_SHIFT) | ||
295 | #define MBOX_SET_FLAG_SEL(x) (((x) << NHMEX_M_PMON_CTL_SET_FLAG_SEL_SHIFT) | \ | ||
296 | NHMEX_M_PMON_CTL_FLAG_MODE) | ||
297 | #define MBOX_INC_SEL_MASK (NHMEX_M_PMON_CTL_INC_SEL_MASK | \ | ||
298 | NHMEX_M_PMON_CTL_FLAG_MODE) | ||
299 | #define MBOX_SET_FLAG_SEL_MASK (NHMEX_M_PMON_CTL_SET_FLAG_SEL_MASK | \ | ||
300 | NHMEX_M_PMON_CTL_FLAG_MODE) | ||
301 | #define MBOX_INC_SEL_EXTAR_REG(c, r) \ | ||
302 | EVENT_EXTRA_REG(MBOX_INC_SEL(c), NHMEX_M0_MSR_PMU_##r, \ | ||
303 | MBOX_INC_SEL_MASK, (u64)-1, NHMEX_M_##r) | ||
304 | #define MBOX_SET_FLAG_SEL_EXTRA_REG(c, r) \ | ||
305 | EVENT_EXTRA_REG(MBOX_SET_FLAG_SEL(c), NHMEX_M0_MSR_PMU_##r, \ | ||
306 | MBOX_SET_FLAG_SEL_MASK, \ | ||
307 | (u64)-1, NHMEX_M_##r) | ||
308 | |||
309 | /* NHM-EX Rbox */ | ||
310 | #define NHMEX_R_MSR_GLOBAL_CTL 0xe00 | ||
311 | #define NHMEX_R_MSR_PMON_CTL0 0xe10 | ||
312 | #define NHMEX_R_MSR_PMON_CNT0 0xe11 | ||
313 | #define NHMEX_R_MSR_OFFSET 0x20 | ||
314 | |||
315 | #define NHMEX_R_MSR_PORTN_QLX_CFG(n) \ | ||
316 | ((n) < 4 ? (0xe0c + (n)) : (0xe2c + (n) - 4)) | ||
317 | #define NHMEX_R_MSR_PORTN_IPERF_CFG0(n) (0xe04 + (n)) | ||
318 | #define NHMEX_R_MSR_PORTN_IPERF_CFG1(n) (0xe24 + (n)) | ||
319 | #define NHMEX_R_MSR_PORTN_XBR_OFFSET(n) \ | ||
320 | (((n) < 4 ? 0 : 0x10) + (n) * 4) | ||
321 | #define NHMEX_R_MSR_PORTN_XBR_SET1_MM_CFG(n) \ | ||
322 | (0xe60 + NHMEX_R_MSR_PORTN_XBR_OFFSET(n)) | ||
323 | #define NHMEX_R_MSR_PORTN_XBR_SET1_MATCH(n) \ | ||
324 | (NHMEX_R_MSR_PORTN_XBR_SET1_MM_CFG(n) + 1) | ||
325 | #define NHMEX_R_MSR_PORTN_XBR_SET1_MASK(n) \ | ||
326 | (NHMEX_R_MSR_PORTN_XBR_SET1_MM_CFG(n) + 2) | ||
327 | #define NHMEX_R_MSR_PORTN_XBR_SET2_MM_CFG(n) \ | ||
328 | (0xe70 + NHMEX_R_MSR_PORTN_XBR_OFFSET(n)) | ||
329 | #define NHMEX_R_MSR_PORTN_XBR_SET2_MATCH(n) \ | ||
330 | (NHMEX_R_MSR_PORTN_XBR_SET2_MM_CFG(n) + 1) | ||
331 | #define NHMEX_R_MSR_PORTN_XBR_SET2_MASK(n) \ | ||
332 | (NHMEX_R_MSR_PORTN_XBR_SET2_MM_CFG(n) + 2) | ||
333 | |||
334 | #define NHMEX_R_PMON_CTL_EN (1 << 0) | ||
335 | #define NHMEX_R_PMON_CTL_EV_SEL_SHIFT 1 | ||
336 | #define NHMEX_R_PMON_CTL_EV_SEL_MASK \ | ||
337 | (0x1f << NHMEX_R_PMON_CTL_EV_SEL_SHIFT) | ||
338 | #define NHMEX_R_PMON_CTL_PMI_EN (1 << 6) | ||
339 | #define NHMEX_R_PMON_RAW_EVENT_MASK NHMEX_R_PMON_CTL_EV_SEL_MASK | ||
340 | |||
341 | /* NHM-EX Wbox */ | ||
342 | #define NHMEX_W_MSR_GLOBAL_CTL 0xc80 | ||
343 | #define NHMEX_W_MSR_PMON_CNT0 0xc90 | ||
344 | #define NHMEX_W_MSR_PMON_EVT_SEL0 0xc91 | ||
345 | #define NHMEX_W_MSR_PMON_FIXED_CTR 0x394 | ||
346 | #define NHMEX_W_MSR_PMON_FIXED_CTL 0x395 | ||
347 | |||
348 | #define NHMEX_W_PMON_GLOBAL_FIXED_EN (1ULL << 31) | ||
349 | |||
161 | struct intel_uncore_ops; | 350 | struct intel_uncore_ops; |
162 | struct intel_uncore_pmu; | 351 | struct intel_uncore_pmu; |
163 | struct intel_uncore_box; | 352 | struct intel_uncore_box; |
@@ -178,6 +367,7 @@ struct intel_uncore_type { | |||
178 | unsigned msr_offset; | 367 | unsigned msr_offset; |
179 | unsigned num_shared_regs:8; | 368 | unsigned num_shared_regs:8; |
180 | unsigned single_fixed:1; | 369 | unsigned single_fixed:1; |
370 | unsigned pair_ctr_ctl:1; | ||
181 | struct event_constraint unconstrainted; | 371 | struct event_constraint unconstrainted; |
182 | struct event_constraint *constraints; | 372 | struct event_constraint *constraints; |
183 | struct intel_uncore_pmu *pmus; | 373 | struct intel_uncore_pmu *pmus; |
@@ -213,7 +403,7 @@ struct intel_uncore_pmu { | |||
213 | 403 | ||
214 | struct intel_uncore_extra_reg { | 404 | struct intel_uncore_extra_reg { |
215 | raw_spinlock_t lock; | 405 | raw_spinlock_t lock; |
216 | u64 config1; | 406 | u64 config, config1, config2; |
217 | atomic_t ref; | 407 | atomic_t ref; |
218 | }; | 408 | }; |
219 | 409 | ||
@@ -323,14 +513,16 @@ unsigned uncore_msr_fixed_ctr(struct intel_uncore_box *box) | |||
323 | static inline | 513 | static inline |
324 | unsigned uncore_msr_event_ctl(struct intel_uncore_box *box, int idx) | 514 | unsigned uncore_msr_event_ctl(struct intel_uncore_box *box, int idx) |
325 | { | 515 | { |
326 | return idx + box->pmu->type->event_ctl + | 516 | return box->pmu->type->event_ctl + |
517 | (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx) + | ||
327 | box->pmu->type->msr_offset * box->pmu->pmu_idx; | 518 | box->pmu->type->msr_offset * box->pmu->pmu_idx; |
328 | } | 519 | } |
329 | 520 | ||
330 | static inline | 521 | static inline |
331 | unsigned uncore_msr_perf_ctr(struct intel_uncore_box *box, int idx) | 522 | unsigned uncore_msr_perf_ctr(struct intel_uncore_box *box, int idx) |
332 | { | 523 | { |
333 | return idx + box->pmu->type->perf_ctr + | 524 | return box->pmu->type->perf_ctr + |
525 | (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx) + | ||
334 | box->pmu->type->msr_offset * box->pmu->pmu_idx; | 526 | box->pmu->type->msr_offset * box->pmu->pmu_idx; |
335 | } | 527 | } |
336 | 528 | ||
@@ -422,3 +614,8 @@ static inline void uncore_box_init(struct intel_uncore_box *box) | |||
422 | box->pmu->type->ops->init_box(box); | 614 | box->pmu->type->ops->init_box(box); |
423 | } | 615 | } |
424 | } | 616 | } |
617 | |||
618 | static inline bool uncore_box_is_fake(struct intel_uncore_box *box) | ||
619 | { | ||
620 | return (box->phys_id < 0); | ||
621 | } | ||
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index f93532748bca..c08a22d02f72 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/swap.h> /* try_to_free_swap */ | 32 | #include <linux/swap.h> /* try_to_free_swap */ |
33 | #include <linux/ptrace.h> /* user_enable_single_step */ | 33 | #include <linux/ptrace.h> /* user_enable_single_step */ |
34 | #include <linux/kdebug.h> /* notifier mechanism */ | 34 | #include <linux/kdebug.h> /* notifier mechanism */ |
35 | #include "../../mm/internal.h" /* munlock_vma_page */ | ||
35 | 36 | ||
36 | #include <linux/uprobes.h> | 37 | #include <linux/uprobes.h> |
37 | 38 | ||
@@ -112,14 +113,14 @@ static bool valid_vma(struct vm_area_struct *vma, bool is_register) | |||
112 | return false; | 113 | return false; |
113 | } | 114 | } |
114 | 115 | ||
115 | static loff_t vma_address(struct vm_area_struct *vma, loff_t offset) | 116 | static unsigned long offset_to_vaddr(struct vm_area_struct *vma, loff_t offset) |
116 | { | 117 | { |
117 | loff_t vaddr; | 118 | return vma->vm_start + offset - ((loff_t)vma->vm_pgoff << PAGE_SHIFT); |
118 | 119 | } | |
119 | vaddr = vma->vm_start + offset; | ||
120 | vaddr -= vma->vm_pgoff << PAGE_SHIFT; | ||
121 | 120 | ||
122 | return vaddr; | 121 | static loff_t vaddr_to_offset(struct vm_area_struct *vma, unsigned long vaddr) |
122 | { | ||
123 | return ((loff_t)vma->vm_pgoff << PAGE_SHIFT) + (vaddr - vma->vm_start); | ||
123 | } | 124 | } |
124 | 125 | ||
125 | /** | 126 | /** |
@@ -127,25 +128,27 @@ static loff_t vma_address(struct vm_area_struct *vma, loff_t offset) | |||
127 | * based on replace_page in mm/ksm.c | 128 | * based on replace_page in mm/ksm.c |
128 | * | 129 | * |
129 | * @vma: vma that holds the pte pointing to page | 130 | * @vma: vma that holds the pte pointing to page |
131 | * @addr: address the old @page is mapped at | ||
130 | * @page: the cowed page we are replacing by kpage | 132 | * @page: the cowed page we are replacing by kpage |
131 | * @kpage: the modified page we replace page by | 133 | * @kpage: the modified page we replace page by |
132 | * | 134 | * |
133 | * Returns 0 on success, -EFAULT on failure. | 135 | * Returns 0 on success, -EFAULT on failure. |
134 | */ | 136 | */ |
135 | static int __replace_page(struct vm_area_struct *vma, struct page *page, struct page *kpage) | 137 | static int __replace_page(struct vm_area_struct *vma, unsigned long addr, |
138 | struct page *page, struct page *kpage) | ||
136 | { | 139 | { |
137 | struct mm_struct *mm = vma->vm_mm; | 140 | struct mm_struct *mm = vma->vm_mm; |
138 | unsigned long addr; | ||
139 | spinlock_t *ptl; | 141 | spinlock_t *ptl; |
140 | pte_t *ptep; | 142 | pte_t *ptep; |
143 | int err; | ||
141 | 144 | ||
142 | addr = page_address_in_vma(page, vma); | 145 | /* For try_to_free_swap() and munlock_vma_page() below */ |
143 | if (addr == -EFAULT) | 146 | lock_page(page); |
144 | return -EFAULT; | ||
145 | 147 | ||
148 | err = -EAGAIN; | ||
146 | ptep = page_check_address(page, mm, addr, &ptl, 0); | 149 | ptep = page_check_address(page, mm, addr, &ptl, 0); |
147 | if (!ptep) | 150 | if (!ptep) |
148 | return -EAGAIN; | 151 | goto unlock; |
149 | 152 | ||
150 | get_page(kpage); | 153 | get_page(kpage); |
151 | page_add_new_anon_rmap(kpage, vma, addr); | 154 | page_add_new_anon_rmap(kpage, vma, addr); |
@@ -162,10 +165,16 @@ static int __replace_page(struct vm_area_struct *vma, struct page *page, struct | |||
162 | page_remove_rmap(page); | 165 | page_remove_rmap(page); |
163 | if (!page_mapped(page)) | 166 | if (!page_mapped(page)) |
164 | try_to_free_swap(page); | 167 | try_to_free_swap(page); |
165 | put_page(page); | ||
166 | pte_unmap_unlock(ptep, ptl); | 168 | pte_unmap_unlock(ptep, ptl); |
167 | 169 | ||
168 | return 0; | 170 | if (vma->vm_flags & VM_LOCKED) |
171 | munlock_vma_page(page); | ||
172 | put_page(page); | ||
173 | |||
174 | err = 0; | ||
175 | unlock: | ||
176 | unlock_page(page); | ||
177 | return err; | ||
169 | } | 178 | } |
170 | 179 | ||
171 | /** | 180 | /** |
@@ -206,45 +215,23 @@ static int write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, | |||
206 | unsigned long vaddr, uprobe_opcode_t opcode) | 215 | unsigned long vaddr, uprobe_opcode_t opcode) |
207 | { | 216 | { |
208 | struct page *old_page, *new_page; | 217 | struct page *old_page, *new_page; |
209 | struct address_space *mapping; | ||
210 | void *vaddr_old, *vaddr_new; | 218 | void *vaddr_old, *vaddr_new; |
211 | struct vm_area_struct *vma; | 219 | struct vm_area_struct *vma; |
212 | struct uprobe *uprobe; | ||
213 | int ret; | 220 | int ret; |
221 | |||
214 | retry: | 222 | retry: |
215 | /* Read the page with vaddr into memory */ | 223 | /* Read the page with vaddr into memory */ |
216 | ret = get_user_pages(NULL, mm, vaddr, 1, 0, 0, &old_page, &vma); | 224 | ret = get_user_pages(NULL, mm, vaddr, 1, 0, 0, &old_page, &vma); |
217 | if (ret <= 0) | 225 | if (ret <= 0) |
218 | return ret; | 226 | return ret; |
219 | 227 | ||
220 | ret = -EINVAL; | ||
221 | |||
222 | /* | ||
223 | * We are interested in text pages only. Our pages of interest | ||
224 | * should be mapped for read and execute only. We desist from | ||
225 | * adding probes in write mapped pages since the breakpoints | ||
226 | * might end up in the file copy. | ||
227 | */ | ||
228 | if (!valid_vma(vma, is_swbp_insn(&opcode))) | ||
229 | goto put_out; | ||
230 | |||
231 | uprobe = container_of(auprobe, struct uprobe, arch); | ||
232 | mapping = uprobe->inode->i_mapping; | ||
233 | if (mapping != vma->vm_file->f_mapping) | ||
234 | goto put_out; | ||
235 | |||
236 | ret = -ENOMEM; | 228 | ret = -ENOMEM; |
237 | new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vaddr); | 229 | new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vaddr); |
238 | if (!new_page) | 230 | if (!new_page) |
239 | goto put_out; | 231 | goto put_old; |
240 | 232 | ||
241 | __SetPageUptodate(new_page); | 233 | __SetPageUptodate(new_page); |
242 | 234 | ||
243 | /* | ||
244 | * lock page will serialize against do_wp_page()'s | ||
245 | * PageAnon() handling | ||
246 | */ | ||
247 | lock_page(old_page); | ||
248 | /* copy the page now that we've got it stable */ | 235 | /* copy the page now that we've got it stable */ |
249 | vaddr_old = kmap_atomic(old_page); | 236 | vaddr_old = kmap_atomic(old_page); |
250 | vaddr_new = kmap_atomic(new_page); | 237 | vaddr_new = kmap_atomic(new_page); |
@@ -257,17 +244,13 @@ retry: | |||
257 | 244 | ||
258 | ret = anon_vma_prepare(vma); | 245 | ret = anon_vma_prepare(vma); |
259 | if (ret) | 246 | if (ret) |
260 | goto unlock_out; | 247 | goto put_new; |
261 | 248 | ||
262 | lock_page(new_page); | 249 | ret = __replace_page(vma, vaddr, old_page, new_page); |
263 | ret = __replace_page(vma, old_page, new_page); | ||
264 | unlock_page(new_page); | ||
265 | 250 | ||
266 | unlock_out: | 251 | put_new: |
267 | unlock_page(old_page); | ||
268 | page_cache_release(new_page); | 252 | page_cache_release(new_page); |
269 | 253 | put_old: | |
270 | put_out: | ||
271 | put_page(old_page); | 254 | put_page(old_page); |
272 | 255 | ||
273 | if (unlikely(ret == -EAGAIN)) | 256 | if (unlikely(ret == -EAGAIN)) |
@@ -791,7 +774,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register) | |||
791 | curr = info; | 774 | curr = info; |
792 | 775 | ||
793 | info->mm = vma->vm_mm; | 776 | info->mm = vma->vm_mm; |
794 | info->vaddr = vma_address(vma, offset); | 777 | info->vaddr = offset_to_vaddr(vma, offset); |
795 | } | 778 | } |
796 | mutex_unlock(&mapping->i_mmap_mutex); | 779 | mutex_unlock(&mapping->i_mmap_mutex); |
797 | 780 | ||
@@ -839,12 +822,13 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register) | |||
839 | goto free; | 822 | goto free; |
840 | 823 | ||
841 | down_write(&mm->mmap_sem); | 824 | down_write(&mm->mmap_sem); |
842 | vma = find_vma(mm, (unsigned long)info->vaddr); | 825 | vma = find_vma(mm, info->vaddr); |
843 | if (!vma || !valid_vma(vma, is_register)) | 826 | if (!vma || !valid_vma(vma, is_register) || |
827 | vma->vm_file->f_mapping->host != uprobe->inode) | ||
844 | goto unlock; | 828 | goto unlock; |
845 | 829 | ||
846 | if (vma->vm_file->f_mapping->host != uprobe->inode || | 830 | if (vma->vm_start > info->vaddr || |
847 | vma_address(vma, uprobe->offset) != info->vaddr) | 831 | vaddr_to_offset(vma, info->vaddr) != uprobe->offset) |
848 | goto unlock; | 832 | goto unlock; |
849 | 833 | ||
850 | if (is_register) { | 834 | if (is_register) { |
@@ -960,59 +944,66 @@ void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consume | |||
960 | put_uprobe(uprobe); | 944 | put_uprobe(uprobe); |
961 | } | 945 | } |
962 | 946 | ||
963 | /* | 947 | static struct rb_node * |
964 | * Of all the nodes that correspond to the given inode, return the node | 948 | find_node_in_range(struct inode *inode, loff_t min, loff_t max) |
965 | * with the least offset. | ||
966 | */ | ||
967 | static struct rb_node *find_least_offset_node(struct inode *inode) | ||
968 | { | 949 | { |
969 | struct uprobe u = { .inode = inode, .offset = 0}; | ||
970 | struct rb_node *n = uprobes_tree.rb_node; | 950 | struct rb_node *n = uprobes_tree.rb_node; |
971 | struct rb_node *close_node = NULL; | ||
972 | struct uprobe *uprobe; | ||
973 | int match; | ||
974 | 951 | ||
975 | while (n) { | 952 | while (n) { |
976 | uprobe = rb_entry(n, struct uprobe, rb_node); | 953 | struct uprobe *u = rb_entry(n, struct uprobe, rb_node); |
977 | match = match_uprobe(&u, uprobe); | ||
978 | |||
979 | if (uprobe->inode == inode) | ||
980 | close_node = n; | ||
981 | |||
982 | if (!match) | ||
983 | return close_node; | ||
984 | 954 | ||
985 | if (match < 0) | 955 | if (inode < u->inode) { |
986 | n = n->rb_left; | 956 | n = n->rb_left; |
987 | else | 957 | } else if (inode > u->inode) { |
988 | n = n->rb_right; | 958 | n = n->rb_right; |
959 | } else { | ||
960 | if (max < u->offset) | ||
961 | n = n->rb_left; | ||
962 | else if (min > u->offset) | ||
963 | n = n->rb_right; | ||
964 | else | ||
965 | break; | ||
966 | } | ||
989 | } | 967 | } |
990 | 968 | ||
991 | return close_node; | 969 | return n; |
992 | } | 970 | } |
993 | 971 | ||
994 | /* | 972 | /* |
995 | * For a given inode, build a list of probes that need to be inserted. | 973 | * For a given range in vma, build a list of probes that need to be inserted. |
996 | */ | 974 | */ |
997 | static void build_probe_list(struct inode *inode, struct list_head *head) | 975 | static void build_probe_list(struct inode *inode, |
976 | struct vm_area_struct *vma, | ||
977 | unsigned long start, unsigned long end, | ||
978 | struct list_head *head) | ||
998 | { | 979 | { |
999 | struct uprobe *uprobe; | 980 | loff_t min, max; |
1000 | unsigned long flags; | 981 | unsigned long flags; |
1001 | struct rb_node *n; | 982 | struct rb_node *n, *t; |
1002 | 983 | struct uprobe *u; | |
1003 | spin_lock_irqsave(&uprobes_treelock, flags); | ||
1004 | |||
1005 | n = find_least_offset_node(inode); | ||
1006 | 984 | ||
1007 | for (; n; n = rb_next(n)) { | 985 | INIT_LIST_HEAD(head); |
1008 | uprobe = rb_entry(n, struct uprobe, rb_node); | 986 | min = vaddr_to_offset(vma, start); |
1009 | if (uprobe->inode != inode) | 987 | max = min + (end - start) - 1; |
1010 | break; | ||
1011 | 988 | ||
1012 | list_add(&uprobe->pending_list, head); | 989 | spin_lock_irqsave(&uprobes_treelock, flags); |
1013 | atomic_inc(&uprobe->ref); | 990 | n = find_node_in_range(inode, min, max); |
991 | if (n) { | ||
992 | for (t = n; t; t = rb_prev(t)) { | ||
993 | u = rb_entry(t, struct uprobe, rb_node); | ||
994 | if (u->inode != inode || u->offset < min) | ||
995 | break; | ||
996 | list_add(&u->pending_list, head); | ||
997 | atomic_inc(&u->ref); | ||
998 | } | ||
999 | for (t = n; (t = rb_next(t)); ) { | ||
1000 | u = rb_entry(t, struct uprobe, rb_node); | ||
1001 | if (u->inode != inode || u->offset > max) | ||
1002 | break; | ||
1003 | list_add(&u->pending_list, head); | ||
1004 | atomic_inc(&u->ref); | ||
1005 | } | ||
1014 | } | 1006 | } |
1015 | |||
1016 | spin_unlock_irqrestore(&uprobes_treelock, flags); | 1007 | spin_unlock_irqrestore(&uprobes_treelock, flags); |
1017 | } | 1008 | } |
1018 | 1009 | ||
@@ -1031,7 +1022,7 @@ static void build_probe_list(struct inode *inode, struct list_head *head) | |||
1031 | int uprobe_mmap(struct vm_area_struct *vma) | 1022 | int uprobe_mmap(struct vm_area_struct *vma) |
1032 | { | 1023 | { |
1033 | struct list_head tmp_list; | 1024 | struct list_head tmp_list; |
1034 | struct uprobe *uprobe; | 1025 | struct uprobe *uprobe, *u; |
1035 | struct inode *inode; | 1026 | struct inode *inode; |
1036 | int ret, count; | 1027 | int ret, count; |
1037 | 1028 | ||
@@ -1042,21 +1033,15 @@ int uprobe_mmap(struct vm_area_struct *vma) | |||
1042 | if (!inode) | 1033 | if (!inode) |
1043 | return 0; | 1034 | return 0; |
1044 | 1035 | ||
1045 | INIT_LIST_HEAD(&tmp_list); | ||
1046 | mutex_lock(uprobes_mmap_hash(inode)); | 1036 | mutex_lock(uprobes_mmap_hash(inode)); |
1047 | build_probe_list(inode, &tmp_list); | 1037 | build_probe_list(inode, vma, vma->vm_start, vma->vm_end, &tmp_list); |
1048 | 1038 | ||
1049 | ret = 0; | 1039 | ret = 0; |
1050 | count = 0; | 1040 | count = 0; |
1051 | 1041 | ||
1052 | list_for_each_entry(uprobe, &tmp_list, pending_list) { | 1042 | list_for_each_entry_safe(uprobe, u, &tmp_list, pending_list) { |
1053 | if (!ret) { | 1043 | if (!ret) { |
1054 | loff_t vaddr = vma_address(vma, uprobe->offset); | 1044 | unsigned long vaddr = offset_to_vaddr(vma, uprobe->offset); |
1055 | |||
1056 | if (vaddr < vma->vm_start || vaddr >= vma->vm_end) { | ||
1057 | put_uprobe(uprobe); | ||
1058 | continue; | ||
1059 | } | ||
1060 | 1045 | ||
1061 | ret = install_breakpoint(uprobe, vma->vm_mm, vma, vaddr); | 1046 | ret = install_breakpoint(uprobe, vma->vm_mm, vma, vaddr); |
1062 | /* | 1047 | /* |
@@ -1097,12 +1082,15 @@ int uprobe_mmap(struct vm_area_struct *vma) | |||
1097 | void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end) | 1082 | void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end) |
1098 | { | 1083 | { |
1099 | struct list_head tmp_list; | 1084 | struct list_head tmp_list; |
1100 | struct uprobe *uprobe; | 1085 | struct uprobe *uprobe, *u; |
1101 | struct inode *inode; | 1086 | struct inode *inode; |
1102 | 1087 | ||
1103 | if (!atomic_read(&uprobe_events) || !valid_vma(vma, false)) | 1088 | if (!atomic_read(&uprobe_events) || !valid_vma(vma, false)) |
1104 | return; | 1089 | return; |
1105 | 1090 | ||
1091 | if (!atomic_read(&vma->vm_mm->mm_users)) /* called by mmput() ? */ | ||
1092 | return; | ||
1093 | |||
1106 | if (!atomic_read(&vma->vm_mm->uprobes_state.count)) | 1094 | if (!atomic_read(&vma->vm_mm->uprobes_state.count)) |
1107 | return; | 1095 | return; |
1108 | 1096 | ||
@@ -1110,21 +1098,17 @@ void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned lon | |||
1110 | if (!inode) | 1098 | if (!inode) |
1111 | return; | 1099 | return; |
1112 | 1100 | ||
1113 | INIT_LIST_HEAD(&tmp_list); | ||
1114 | mutex_lock(uprobes_mmap_hash(inode)); | 1101 | mutex_lock(uprobes_mmap_hash(inode)); |
1115 | build_probe_list(inode, &tmp_list); | 1102 | build_probe_list(inode, vma, start, end, &tmp_list); |
1116 | 1103 | ||
1117 | list_for_each_entry(uprobe, &tmp_list, pending_list) { | 1104 | list_for_each_entry_safe(uprobe, u, &tmp_list, pending_list) { |
1118 | loff_t vaddr = vma_address(vma, uprobe->offset); | 1105 | unsigned long vaddr = offset_to_vaddr(vma, uprobe->offset); |
1119 | 1106 | /* | |
1120 | if (vaddr >= start && vaddr < end) { | 1107 | * An unregister could have removed the probe before |
1121 | /* | 1108 | * unmap. So check before we decrement the count. |
1122 | * An unregister could have removed the probe before | 1109 | */ |
1123 | * unmap. So check before we decrement the count. | 1110 | if (is_swbp_at_addr(vma->vm_mm, vaddr) == 1) |
1124 | */ | 1111 | atomic_dec(&vma->vm_mm->uprobes_state.count); |
1125 | if (is_swbp_at_addr(vma->vm_mm, vaddr) == 1) | ||
1126 | atomic_dec(&vma->vm_mm->uprobes_state.count); | ||
1127 | } | ||
1128 | put_uprobe(uprobe); | 1112 | put_uprobe(uprobe); |
1129 | } | 1113 | } |
1130 | mutex_unlock(uprobes_mmap_hash(inode)); | 1114 | mutex_unlock(uprobes_mmap_hash(inode)); |
@@ -1463,12 +1447,9 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) | |||
1463 | vma = find_vma(mm, bp_vaddr); | 1447 | vma = find_vma(mm, bp_vaddr); |
1464 | if (vma && vma->vm_start <= bp_vaddr) { | 1448 | if (vma && vma->vm_start <= bp_vaddr) { |
1465 | if (valid_vma(vma, false)) { | 1449 | if (valid_vma(vma, false)) { |
1466 | struct inode *inode; | 1450 | struct inode *inode = vma->vm_file->f_mapping->host; |
1467 | loff_t offset; | 1451 | loff_t offset = vaddr_to_offset(vma, bp_vaddr); |
1468 | 1452 | ||
1469 | inode = vma->vm_file->f_mapping->host; | ||
1470 | offset = bp_vaddr - vma->vm_start; | ||
1471 | offset += (vma->vm_pgoff << PAGE_SHIFT); | ||
1472 | uprobe = find_uprobe(inode, offset); | 1453 | uprobe = find_uprobe(inode, offset); |
1473 | } | 1454 | } |
1474 | 1455 | ||
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5d011ef4c0df..d325c4b2dcbb 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -1910,12 +1910,12 @@ static inline void | |||
1910 | prepare_task_switch(struct rq *rq, struct task_struct *prev, | 1910 | prepare_task_switch(struct rq *rq, struct task_struct *prev, |
1911 | struct task_struct *next) | 1911 | struct task_struct *next) |
1912 | { | 1912 | { |
1913 | trace_sched_switch(prev, next); | ||
1913 | sched_info_switch(prev, next); | 1914 | sched_info_switch(prev, next); |
1914 | perf_event_task_sched_out(prev, next); | 1915 | perf_event_task_sched_out(prev, next); |
1915 | fire_sched_out_preempt_notifiers(prev, next); | 1916 | fire_sched_out_preempt_notifiers(prev, next); |
1916 | prepare_lock_switch(rq, next); | 1917 | prepare_lock_switch(rq, next); |
1917 | prepare_arch_switch(next); | 1918 | prepare_arch_switch(next); |
1918 | trace_sched_switch(prev, next); | ||
1919 | } | 1919 | } |
1920 | 1920 | ||
1921 | /** | 1921 | /** |
@@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma) | |||
2345 | security_vm_enough_memory_mm(mm, vma_pages(vma))) | 2345 | security_vm_enough_memory_mm(mm, vma_pages(vma))) |
2346 | return -ENOMEM; | 2346 | return -ENOMEM; |
2347 | 2347 | ||
2348 | if (vma->vm_file && uprobe_mmap(vma)) | ||
2349 | return -EINVAL; | ||
2350 | |||
2351 | vma_link(mm, vma, prev, rb_link, rb_parent); | 2348 | vma_link(mm, vma, prev, rb_link, rb_parent); |
2352 | return 0; | 2349 | return 0; |
2353 | } | 2350 | } |
@@ -2418,9 +2415,6 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, | |||
2418 | if (new_vma->vm_file) { | 2415 | if (new_vma->vm_file) { |
2419 | get_file(new_vma->vm_file); | 2416 | get_file(new_vma->vm_file); |
2420 | 2417 | ||
2421 | if (uprobe_mmap(new_vma)) | ||
2422 | goto out_free_mempol; | ||
2423 | |||
2424 | if (vma->vm_flags & VM_EXECUTABLE) | 2418 | if (vma->vm_flags & VM_EXECUTABLE) |
2425 | added_exe_file_vma(mm); | 2419 | added_exe_file_vma(mm); |
2426 | } | 2420 | } |
diff --git a/tools/lib/traceevent/.gitignore b/tools/lib/traceevent/.gitignore new file mode 100644 index 000000000000..35f56be5a4cd --- /dev/null +++ b/tools/lib/traceevent/.gitignore | |||
@@ -0,0 +1 @@ | |||
TRACEEVENT-CFLAGS | |||
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile index 46c2f6b7b123..14131cb0522d 100644 --- a/tools/lib/traceevent/Makefile +++ b/tools/lib/traceevent/Makefile | |||
@@ -207,7 +207,7 @@ libtraceevent.so: $(PEVENT_LIB_OBJS) | |||
207 | libtraceevent.a: $(PEVENT_LIB_OBJS) | 207 | libtraceevent.a: $(PEVENT_LIB_OBJS) |
208 | $(Q)$(do_build_static_lib) | 208 | $(Q)$(do_build_static_lib) |
209 | 209 | ||
210 | $(PEVENT_LIB_OBJS): %.o: $(src)/%.c | 210 | $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS |
211 | $(Q)$(do_fpic_compile) | 211 | $(Q)$(do_fpic_compile) |
212 | 212 | ||
213 | define make_version.h | 213 | define make_version.h |
@@ -272,6 +272,16 @@ ifneq ($(dep_includes),) | |||
272 | include $(dep_includes) | 272 | include $(dep_includes) |
273 | endif | 273 | endif |
274 | 274 | ||
275 | ### Detect environment changes | ||
276 | TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE) | ||
277 | |||
278 | TRACEEVENT-CFLAGS: force | ||
279 | @FLAGS='$(TRACK_CFLAGS)'; \ | ||
280 | if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \ | ||
281 | echo 1>&2 " * new build flags or cross compiler"; \ | ||
282 | echo "$$FLAGS" >TRACEEVENT-CFLAGS; \ | ||
283 | fi | ||
284 | |||
275 | tags: force | 285 | tags: force |
276 | $(RM) tags | 286 | $(RM) tags |
277 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ | 287 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
@@ -297,7 +307,7 @@ install: install_lib | |||
297 | 307 | ||
298 | clean: | 308 | clean: |
299 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d | 309 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d |
300 | $(RM) tags TAGS | 310 | $(RM) TRACEEVENT-CFLAGS tags TAGS |
301 | 311 | ||
302 | endif # skip-makefile | 312 | endif # skip-makefile |
303 | 313 | ||
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 75d74e5db8d5..77f124fe57ad 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -354,6 +354,7 @@ LIB_OBJS += $(OUTPUT)util/usage.o | |||
354 | LIB_OBJS += $(OUTPUT)util/wrapper.o | 354 | LIB_OBJS += $(OUTPUT)util/wrapper.o |
355 | LIB_OBJS += $(OUTPUT)util/sigchain.o | 355 | LIB_OBJS += $(OUTPUT)util/sigchain.o |
356 | LIB_OBJS += $(OUTPUT)util/symbol.o | 356 | LIB_OBJS += $(OUTPUT)util/symbol.o |
357 | LIB_OBJS += $(OUTPUT)util/dso-test-data.o | ||
357 | LIB_OBJS += $(OUTPUT)util/color.o | 358 | LIB_OBJS += $(OUTPUT)util/color.o |
358 | LIB_OBJS += $(OUTPUT)util/pager.o | 359 | LIB_OBJS += $(OUTPUT)util/pager.o |
359 | LIB_OBJS += $(OUTPUT)util/header.o | 360 | LIB_OBJS += $(OUTPUT)util/header.o |
@@ -803,6 +804,9 @@ $(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS | |||
803 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS | 804 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS |
804 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 805 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
805 | 806 | ||
807 | $(OUTPUT)util/parse-events.o: util/parse-events.c $(OUTPUT)PERF-CFLAGS | ||
808 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls $< | ||
809 | |||
806 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS | 810 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS |
807 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< | 811 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< |
808 | 812 | ||
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 5ce30305462b..d909eb74a0eb 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c | |||
@@ -1142,6 +1142,10 @@ static struct test { | |||
1142 | .func = test__perf_pmu, | 1142 | .func = test__perf_pmu, |
1143 | }, | 1143 | }, |
1144 | { | 1144 | { |
1145 | .desc = "Test dso data interface", | ||
1146 | .func = dso__test_data, | ||
1147 | }, | ||
1148 | { | ||
1145 | .func = NULL, | 1149 | .func = NULL, |
1146 | }, | 1150 | }, |
1147 | }; | 1151 | }; |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e3cab5f088f8..35e86c6df713 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -125,7 +125,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) | |||
125 | /* | 125 | /* |
126 | * We can't annotate with just /proc/kallsyms | 126 | * We can't annotate with just /proc/kallsyms |
127 | */ | 127 | */ |
128 | if (map->dso->symtab_type == SYMTAB__KALLSYMS) { | 128 | if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) { |
129 | pr_err("Can't annotate %s: No vmlinux file was found in the " | 129 | pr_err("Can't annotate %s: No vmlinux file was found in the " |
130 | "path\n", sym->name); | 130 | "path\n", sym->name); |
131 | sleep(1); | 131 | sleep(1); |
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 482f0517b61e..413bd62eedb1 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -978,8 +978,8 @@ static int hist_browser__dump(struct hist_browser *browser) | |||
978 | fp = fopen(filename, "w"); | 978 | fp = fopen(filename, "w"); |
979 | if (fp == NULL) { | 979 | if (fp == NULL) { |
980 | char bf[64]; | 980 | char bf[64]; |
981 | strerror_r(errno, bf, sizeof(bf)); | 981 | const char *err = strerror_r(errno, bf, sizeof(bf)); |
982 | ui_helpline__fpush("Couldn't write to %s: %s", filename, bf); | 982 | ui_helpline__fpush("Couldn't write to %s: %s", filename, err); |
983 | return -1; | 983 | return -1; |
984 | } | 984 | } |
985 | 985 | ||
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 8069dfb5ba77..3a282c0057d2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -426,7 +426,18 @@ int symbol__alloc_hist(struct symbol *sym) | |||
426 | { | 426 | { |
427 | struct annotation *notes = symbol__annotation(sym); | 427 | struct annotation *notes = symbol__annotation(sym); |
428 | const size_t size = symbol__size(sym); | 428 | const size_t size = symbol__size(sym); |
429 | size_t sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64)); | 429 | size_t sizeof_sym_hist; |
430 | |||
431 | /* Check for overflow when calculating sizeof_sym_hist */ | ||
432 | if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(u64)) | ||
433 | return -1; | ||
434 | |||
435 | sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64)); | ||
436 | |||
437 | /* Check for overflow in zalloc argument */ | ||
438 | if (sizeof_sym_hist > (SIZE_MAX - sizeof(*notes->src)) | ||
439 | / symbol_conf.nr_events) | ||
440 | return -1; | ||
430 | 441 | ||
431 | notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist); | 442 | notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist); |
432 | if (notes->src == NULL) | 443 | if (notes->src == NULL) |
@@ -777,7 +788,7 @@ fallback: | |||
777 | free_filename = false; | 788 | free_filename = false; |
778 | } | 789 | } |
779 | 790 | ||
780 | if (dso->symtab_type == SYMTAB__KALLSYMS) { | 791 | if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) { |
781 | char bf[BUILD_ID_SIZE * 2 + 16] = " with build id "; | 792 | char bf[BUILD_ID_SIZE * 2 + 16] = " with build id "; |
782 | char *build_id_msg = NULL; | 793 | char *build_id_msg = NULL; |
783 | 794 | ||
diff --git a/tools/perf/util/dso-test-data.c b/tools/perf/util/dso-test-data.c new file mode 100644 index 000000000000..541cdc72c7df --- /dev/null +++ b/tools/perf/util/dso-test-data.c | |||
@@ -0,0 +1,153 @@ | |||
1 | #include "util.h" | ||
2 | |||
3 | #include <stdlib.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <sys/stat.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <string.h> | ||
8 | |||
9 | #include "symbol.h" | ||
10 | |||
11 | #define TEST_ASSERT_VAL(text, cond) \ | ||
12 | do { \ | ||
13 | if (!(cond)) { \ | ||
14 | pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \ | ||
15 | return -1; \ | ||
16 | } \ | ||
17 | } while (0) | ||
18 | |||
19 | static char *test_file(int size) | ||
20 | { | ||
21 | static char buf_templ[] = "/tmp/test-XXXXXX"; | ||
22 | char *templ = buf_templ; | ||
23 | int fd, i; | ||
24 | unsigned char *buf; | ||
25 | |||
26 | fd = mkostemp(templ, O_CREAT|O_WRONLY|O_TRUNC); | ||
27 | |||
28 | buf = malloc(size); | ||
29 | if (!buf) { | ||
30 | close(fd); | ||
31 | return NULL; | ||
32 | } | ||
33 | |||
34 | for (i = 0; i < size; i++) | ||
35 | buf[i] = (unsigned char) ((int) i % 10); | ||
36 | |||
37 | if (size != write(fd, buf, size)) | ||
38 | templ = NULL; | ||
39 | |||
40 | close(fd); | ||
41 | return templ; | ||
42 | } | ||
43 | |||
44 | #define TEST_FILE_SIZE (DSO__DATA_CACHE_SIZE * 20) | ||
45 | |||
46 | struct test_data_offset { | ||
47 | off_t offset; | ||
48 | u8 data[10]; | ||
49 | int size; | ||
50 | }; | ||
51 | |||
52 | struct test_data_offset offsets[] = { | ||
53 | /* Fill first cache page. */ | ||
54 | { | ||
55 | .offset = 10, | ||
56 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
57 | .size = 10, | ||
58 | }, | ||
59 | /* Read first cache page. */ | ||
60 | { | ||
61 | .offset = 10, | ||
62 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
63 | .size = 10, | ||
64 | }, | ||
65 | /* Fill cache boundary pages. */ | ||
66 | { | ||
67 | .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10, | ||
68 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
69 | .size = 10, | ||
70 | }, | ||
71 | /* Read cache boundary pages. */ | ||
72 | { | ||
73 | .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10, | ||
74 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
75 | .size = 10, | ||
76 | }, | ||
77 | /* Fill final cache page. */ | ||
78 | { | ||
79 | .offset = TEST_FILE_SIZE - 10, | ||
80 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
81 | .size = 10, | ||
82 | }, | ||
83 | /* Read final cache page. */ | ||
84 | { | ||
85 | .offset = TEST_FILE_SIZE - 10, | ||
86 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
87 | .size = 10, | ||
88 | }, | ||
89 | /* Read final cache page. */ | ||
90 | { | ||
91 | .offset = TEST_FILE_SIZE - 3, | ||
92 | .data = { 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 }, | ||
93 | .size = 3, | ||
94 | }, | ||
95 | }; | ||
96 | |||
97 | int dso__test_data(void) | ||
98 | { | ||
99 | struct machine machine; | ||
100 | struct dso *dso; | ||
101 | char *file = test_file(TEST_FILE_SIZE); | ||
102 | size_t i; | ||
103 | |||
104 | TEST_ASSERT_VAL("No test file", file); | ||
105 | |||
106 | memset(&machine, 0, sizeof(machine)); | ||
107 | |||
108 | dso = dso__new((const char *)file); | ||
109 | |||
110 | /* Basic 10 bytes tests. */ | ||
111 | for (i = 0; i < ARRAY_SIZE(offsets); i++) { | ||
112 | struct test_data_offset *data = &offsets[i]; | ||
113 | ssize_t size; | ||
114 | u8 buf[10]; | ||
115 | |||
116 | memset(buf, 0, 10); | ||
117 | size = dso__data_read_offset(dso, &machine, data->offset, | ||
118 | buf, 10); | ||
119 | |||
120 | TEST_ASSERT_VAL("Wrong size", size == data->size); | ||
121 | TEST_ASSERT_VAL("Wrong data", !memcmp(buf, data->data, 10)); | ||
122 | } | ||
123 | |||
124 | /* Read cross multiple cache pages. */ | ||
125 | { | ||
126 | ssize_t size; | ||
127 | int c; | ||
128 | u8 *buf; | ||
129 | |||
130 | buf = malloc(TEST_FILE_SIZE); | ||
131 | TEST_ASSERT_VAL("ENOMEM\n", buf); | ||
132 | |||
133 | /* First iteration to fill caches, second one to read them. */ | ||
134 | for (c = 0; c < 2; c++) { | ||
135 | memset(buf, 0, TEST_FILE_SIZE); | ||
136 | size = dso__data_read_offset(dso, &machine, 10, | ||
137 | buf, TEST_FILE_SIZE); | ||
138 | |||
139 | TEST_ASSERT_VAL("Wrong size", | ||
140 | size == (TEST_FILE_SIZE - 10)); | ||
141 | |||
142 | for (i = 0; i < (size_t)size; i++) | ||
143 | TEST_ASSERT_VAL("Wrong data", | ||
144 | buf[i] == (i % 10)); | ||
145 | } | ||
146 | |||
147 | free(buf); | ||
148 | } | ||
149 | |||
150 | dso__delete(dso); | ||
151 | unlink(file); | ||
152 | return 0; | ||
153 | } | ||
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index f74e9560350e..3edfd3483816 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -214,7 +214,7 @@ int perf_evlist__add_tracepoints(struct perf_evlist *evlist, | |||
214 | attrs[i].type = PERF_TYPE_TRACEPOINT; | 214 | attrs[i].type = PERF_TYPE_TRACEPOINT; |
215 | attrs[i].config = err; | 215 | attrs[i].config = err; |
216 | attrs[i].sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | | 216 | attrs[i].sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | |
217 | PERF_SAMPLE_CPU); | 217 | PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD); |
218 | attrs[i].sample_period = 1; | 218 | attrs[i].sample_period = 1; |
219 | } | 219 | } |
220 | 220 | ||
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 5a47aba46759..3a6d20443330 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -1212,6 +1212,12 @@ static void print_event_desc(struct perf_header *ph, int fd, FILE *fp) | |||
1212 | attr.exclude_user, | 1212 | attr.exclude_user, |
1213 | attr.exclude_kernel); | 1213 | attr.exclude_kernel); |
1214 | 1214 | ||
1215 | fprintf(fp, ", excl_host = %d, excl_guest = %d", | ||
1216 | attr.exclude_host, | ||
1217 | attr.exclude_guest); | ||
1218 | |||
1219 | fprintf(fp, ", precise_ip = %d", attr.precise_ip); | ||
1220 | |||
1215 | if (nr) | 1221 | if (nr) |
1216 | fprintf(fp, ", id = {"); | 1222 | fprintf(fp, ", id = {"); |
1217 | 1223 | ||
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 514e2a4b367d..f247ef2789a4 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -708,7 +708,7 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
708 | bool printed = false; | 708 | bool printed = false; |
709 | struct rb_node *node; | 709 | struct rb_node *node; |
710 | int i = 0; | 710 | int i = 0; |
711 | int ret; | 711 | int ret = 0; |
712 | 712 | ||
713 | /* | 713 | /* |
714 | * If have one single callchain root, don't bother printing | 714 | * If have one single callchain root, don't bother printing |
@@ -747,8 +747,11 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
747 | root = &cnode->rb_root; | 747 | root = &cnode->rb_root; |
748 | } | 748 | } |
749 | 749 | ||
750 | return __callchain__fprintf_graph(fp, root, total_samples, | 750 | ret += __callchain__fprintf_graph(fp, root, total_samples, |
751 | 1, 1, left_margin); | 751 | 1, 1, left_margin); |
752 | ret += fprintf(fp, "\n"); | ||
753 | |||
754 | return ret; | ||
752 | } | 755 | } |
753 | 756 | ||
754 | static size_t __callchain__fprintf_flat(FILE *fp, | 757 | static size_t __callchain__fprintf_flat(FILE *fp, |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index a1f4e3669142..cc33486ad9e2 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -7,6 +7,8 @@ | |||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | #include "map.h" | 9 | #include "map.h" |
10 | #include "thread.h" | ||
11 | #include "strlist.h" | ||
10 | 12 | ||
11 | const char *map_type__name[MAP__NR_TYPES] = { | 13 | const char *map_type__name[MAP__NR_TYPES] = { |
12 | [MAP__FUNCTION] = "Functions", | 14 | [MAP__FUNCTION] = "Functions", |
@@ -585,7 +587,21 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid) | |||
585 | self->kmaps.machine = self; | 587 | self->kmaps.machine = self; |
586 | self->pid = pid; | 588 | self->pid = pid; |
587 | self->root_dir = strdup(root_dir); | 589 | self->root_dir = strdup(root_dir); |
588 | return self->root_dir == NULL ? -ENOMEM : 0; | 590 | if (self->root_dir == NULL) |
591 | return -ENOMEM; | ||
592 | |||
593 | if (pid != HOST_KERNEL_ID) { | ||
594 | struct thread *thread = machine__findnew_thread(self, pid); | ||
595 | char comm[64]; | ||
596 | |||
597 | if (thread == NULL) | ||
598 | return -ENOMEM; | ||
599 | |||
600 | snprintf(comm, sizeof(comm), "[guest/%d]", pid); | ||
601 | thread__set_comm(thread, comm); | ||
602 | } | ||
603 | |||
604 | return 0; | ||
589 | } | 605 | } |
590 | 606 | ||
591 | static void dsos__delete(struct list_head *self) | 607 | static void dsos__delete(struct list_head *self) |
@@ -680,7 +696,15 @@ struct machine *machines__findnew(struct rb_root *self, pid_t pid) | |||
680 | (symbol_conf.guestmount)) { | 696 | (symbol_conf.guestmount)) { |
681 | sprintf(path, "%s/%d", symbol_conf.guestmount, pid); | 697 | sprintf(path, "%s/%d", symbol_conf.guestmount, pid); |
682 | if (access(path, R_OK)) { | 698 | if (access(path, R_OK)) { |
683 | pr_err("Can't access file %s\n", path); | 699 | static struct strlist *seen; |
700 | |||
701 | if (!seen) | ||
702 | seen = strlist__new(true, NULL); | ||
703 | |||
704 | if (!strlist__has_entry(seen, path)) { | ||
705 | pr_err("Can't access file %s\n", path); | ||
706 | strlist__add(seen, path); | ||
707 | } | ||
684 | machine = NULL; | 708 | machine = NULL; |
685 | goto out; | 709 | goto out; |
686 | } | 710 | } |
@@ -714,3 +738,16 @@ char *machine__mmap_name(struct machine *self, char *bf, size_t size) | |||
714 | 738 | ||
715 | return bf; | 739 | return bf; |
716 | } | 740 | } |
741 | |||
742 | void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size) | ||
743 | { | ||
744 | struct rb_node *node; | ||
745 | struct machine *machine; | ||
746 | |||
747 | for (node = rb_first(machines); node; node = rb_next(node)) { | ||
748 | machine = rb_entry(node, struct machine, rb_node); | ||
749 | machine->id_hdr_size = id_hdr_size; | ||
750 | } | ||
751 | |||
752 | return; | ||
753 | } | ||
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index c14c665d9a25..03a1e9b08b21 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -151,6 +151,7 @@ struct machine *machines__add(struct rb_root *self, pid_t pid, | |||
151 | struct machine *machines__find_host(struct rb_root *self); | 151 | struct machine *machines__find_host(struct rb_root *self); |
152 | struct machine *machines__find(struct rb_root *self, pid_t pid); | 152 | struct machine *machines__find(struct rb_root *self, pid_t pid); |
153 | struct machine *machines__findnew(struct rb_root *self, pid_t pid); | 153 | struct machine *machines__findnew(struct rb_root *self, pid_t pid); |
154 | void machines__set_id_hdr_size(struct rb_root *self, u16 id_hdr_size); | ||
154 | char *machine__mmap_name(struct machine *self, char *bf, size_t size); | 155 | char *machine__mmap_name(struct machine *self, char *bf, size_t size); |
155 | int machine__init(struct machine *self, const char *root_dir, pid_t pid); | 156 | int machine__init(struct machine *self, const char *root_dir, pid_t pid); |
156 | void machine__exit(struct machine *self); | 157 | void machine__exit(struct machine *self); |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1aa721d7c10f..74a5af4d33ec 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -377,6 +377,7 @@ static int add_tracepoint(struct list_head **list, int *idx, | |||
377 | attr.sample_type |= PERF_SAMPLE_RAW; | 377 | attr.sample_type |= PERF_SAMPLE_RAW; |
378 | attr.sample_type |= PERF_SAMPLE_TIME; | 378 | attr.sample_type |= PERF_SAMPLE_TIME; |
379 | attr.sample_type |= PERF_SAMPLE_CPU; | 379 | attr.sample_type |= PERF_SAMPLE_CPU; |
380 | attr.sample_type |= PERF_SAMPLE_PERIOD; | ||
380 | attr.sample_period = 1; | 381 | attr.sample_period = 1; |
381 | 382 | ||
382 | snprintf(name, MAX_NAME_LEN, "%s:%s", sys_name, evt_name); | 383 | snprintf(name, MAX_NAME_LEN, "%s:%s", sys_name, evt_name); |
@@ -489,6 +490,7 @@ int parse_events_add_breakpoint(struct list_head **list, int *idx, | |||
489 | attr.bp_len = HW_BREAKPOINT_LEN_4; | 490 | attr.bp_len = HW_BREAKPOINT_LEN_4; |
490 | 491 | ||
491 | attr.type = PERF_TYPE_BREAKPOINT; | 492 | attr.type = PERF_TYPE_BREAKPOINT; |
493 | attr.sample_period = 1; | ||
492 | 494 | ||
493 | return add_event(list, idx, &attr, NULL); | 495 | return add_event(list, idx, &attr, NULL); |
494 | } | 496 | } |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 8e485592ca20..8e4f0755d2aa 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -87,6 +87,7 @@ void perf_session__update_sample_type(struct perf_session *self) | |||
87 | self->sample_id_all = perf_evlist__sample_id_all(self->evlist); | 87 | self->sample_id_all = perf_evlist__sample_id_all(self->evlist); |
88 | self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); | 88 | self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); |
89 | self->host_machine.id_hdr_size = self->id_hdr_size; | 89 | self->host_machine.id_hdr_size = self->id_hdr_size; |
90 | machines__set_id_hdr_size(&self->machines, self->id_hdr_size); | ||
90 | } | 91 | } |
91 | 92 | ||
92 | int perf_session__create_kernel_maps(struct perf_session *self) | 93 | int perf_session__create_kernel_maps(struct perf_session *self) |
@@ -918,7 +919,9 @@ static struct machine * | |||
918 | { | 919 | { |
919 | const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 920 | const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
920 | 921 | ||
921 | if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { | 922 | if (perf_guest && |
923 | ((cpumode == PERF_RECORD_MISC_GUEST_KERNEL) || | ||
924 | (cpumode == PERF_RECORD_MISC_GUEST_USER))) { | ||
922 | u32 pid; | 925 | u32 pid; |
923 | 926 | ||
924 | if (event->header.type == PERF_RECORD_MMAP) | 927 | if (event->header.type == PERF_RECORD_MMAP) |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 50958bbeb26a..fdad4eeeb429 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #define NT_GNU_BUILD_ID 3 | 29 | #define NT_GNU_BUILD_ID 3 |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | static void dso_cache__free(struct rb_root *root); | ||
32 | static bool dso__build_id_equal(const struct dso *dso, u8 *build_id); | 33 | static bool dso__build_id_equal(const struct dso *dso, u8 *build_id); |
33 | static int elf_read_build_id(Elf *elf, void *bf, size_t size); | 34 | static int elf_read_build_id(Elf *elf, void *bf, size_t size); |
34 | static void dsos__add(struct list_head *head, struct dso *dso); | 35 | static void dsos__add(struct list_head *head, struct dso *dso); |
@@ -48,6 +49,31 @@ struct symbol_conf symbol_conf = { | |||
48 | .symfs = "", | 49 | .symfs = "", |
49 | }; | 50 | }; |
50 | 51 | ||
52 | static enum dso_binary_type binary_type_symtab[] = { | ||
53 | DSO_BINARY_TYPE__KALLSYMS, | ||
54 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | ||
55 | DSO_BINARY_TYPE__JAVA_JIT, | ||
56 | DSO_BINARY_TYPE__DEBUGLINK, | ||
57 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
58 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | ||
59 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | ||
60 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | ||
61 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
62 | DSO_BINARY_TYPE__GUEST_KMODULE, | ||
63 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | ||
64 | DSO_BINARY_TYPE__NOT_FOUND, | ||
65 | }; | ||
66 | |||
67 | #define DSO_BINARY_TYPE__SYMTAB_CNT sizeof(binary_type_symtab) | ||
68 | |||
69 | static enum dso_binary_type binary_type_data[] = { | ||
70 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
71 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
72 | DSO_BINARY_TYPE__NOT_FOUND, | ||
73 | }; | ||
74 | |||
75 | #define DSO_BINARY_TYPE__DATA_CNT sizeof(binary_type_data) | ||
76 | |||
51 | int dso__name_len(const struct dso *dso) | 77 | int dso__name_len(const struct dso *dso) |
52 | { | 78 | { |
53 | if (!dso) | 79 | if (!dso) |
@@ -318,7 +344,9 @@ struct dso *dso__new(const char *name) | |||
318 | dso__set_short_name(dso, dso->name); | 344 | dso__set_short_name(dso, dso->name); |
319 | for (i = 0; i < MAP__NR_TYPES; ++i) | 345 | for (i = 0; i < MAP__NR_TYPES; ++i) |
320 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; | 346 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; |
321 | dso->symtab_type = SYMTAB__NOT_FOUND; | 347 | dso->cache = RB_ROOT; |
348 | dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
349 | dso->data_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
322 | dso->loaded = 0; | 350 | dso->loaded = 0; |
323 | dso->sorted_by_name = 0; | 351 | dso->sorted_by_name = 0; |
324 | dso->has_build_id = 0; | 352 | dso->has_build_id = 0; |
@@ -352,6 +380,7 @@ void dso__delete(struct dso *dso) | |||
352 | free((char *)dso->short_name); | 380 | free((char *)dso->short_name); |
353 | if (dso->lname_alloc) | 381 | if (dso->lname_alloc) |
354 | free(dso->long_name); | 382 | free(dso->long_name); |
383 | dso_cache__free(&dso->cache); | ||
355 | free(dso); | 384 | free(dso); |
356 | } | 385 | } |
357 | 386 | ||
@@ -806,9 +835,9 @@ int dso__load_kallsyms(struct dso *dso, const char *filename, | |||
806 | symbols__fixup_end(&dso->symbols[map->type]); | 835 | symbols__fixup_end(&dso->symbols[map->type]); |
807 | 836 | ||
808 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) | 837 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
809 | dso->symtab_type = SYMTAB__GUEST_KALLSYMS; | 838 | dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS; |
810 | else | 839 | else |
811 | dso->symtab_type = SYMTAB__KALLSYMS; | 840 | dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS; |
812 | 841 | ||
813 | return dso__split_kallsyms(dso, map, filter); | 842 | return dso__split_kallsyms(dso, map, filter); |
814 | } | 843 | } |
@@ -1660,32 +1689,110 @@ out: | |||
1660 | char dso__symtab_origin(const struct dso *dso) | 1689 | char dso__symtab_origin(const struct dso *dso) |
1661 | { | 1690 | { |
1662 | static const char origin[] = { | 1691 | static const char origin[] = { |
1663 | [SYMTAB__KALLSYMS] = 'k', | 1692 | [DSO_BINARY_TYPE__KALLSYMS] = 'k', |
1664 | [SYMTAB__JAVA_JIT] = 'j', | 1693 | [DSO_BINARY_TYPE__JAVA_JIT] = 'j', |
1665 | [SYMTAB__DEBUGLINK] = 'l', | 1694 | [DSO_BINARY_TYPE__DEBUGLINK] = 'l', |
1666 | [SYMTAB__BUILD_ID_CACHE] = 'B', | 1695 | [DSO_BINARY_TYPE__BUILD_ID_CACHE] = 'B', |
1667 | [SYMTAB__FEDORA_DEBUGINFO] = 'f', | 1696 | [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f', |
1668 | [SYMTAB__UBUNTU_DEBUGINFO] = 'u', | 1697 | [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u', |
1669 | [SYMTAB__BUILDID_DEBUGINFO] = 'b', | 1698 | [DSO_BINARY_TYPE__BUILDID_DEBUGINFO] = 'b', |
1670 | [SYMTAB__SYSTEM_PATH_DSO] = 'd', | 1699 | [DSO_BINARY_TYPE__SYSTEM_PATH_DSO] = 'd', |
1671 | [SYMTAB__SYSTEM_PATH_KMODULE] = 'K', | 1700 | [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE] = 'K', |
1672 | [SYMTAB__GUEST_KALLSYMS] = 'g', | 1701 | [DSO_BINARY_TYPE__GUEST_KALLSYMS] = 'g', |
1673 | [SYMTAB__GUEST_KMODULE] = 'G', | 1702 | [DSO_BINARY_TYPE__GUEST_KMODULE] = 'G', |
1674 | }; | 1703 | }; |
1675 | 1704 | ||
1676 | if (dso == NULL || dso->symtab_type == SYMTAB__NOT_FOUND) | 1705 | if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND) |
1677 | return '!'; | 1706 | return '!'; |
1678 | return origin[dso->symtab_type]; | 1707 | return origin[dso->symtab_type]; |
1679 | } | 1708 | } |
1680 | 1709 | ||
1710 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
1711 | char *root_dir, char *file, size_t size) | ||
1712 | { | ||
1713 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1714 | int ret = 0; | ||
1715 | |||
1716 | switch (type) { | ||
1717 | case DSO_BINARY_TYPE__DEBUGLINK: { | ||
1718 | char *debuglink; | ||
1719 | |||
1720 | strncpy(file, dso->long_name, size); | ||
1721 | debuglink = file + dso->long_name_len; | ||
1722 | while (debuglink != file && *debuglink != '/') | ||
1723 | debuglink--; | ||
1724 | if (*debuglink == '/') | ||
1725 | debuglink++; | ||
1726 | filename__read_debuglink(dso->long_name, debuglink, | ||
1727 | size - (debuglink - file)); | ||
1728 | } | ||
1729 | break; | ||
1730 | case DSO_BINARY_TYPE__BUILD_ID_CACHE: | ||
1731 | /* skip the locally configured cache if a symfs is given */ | ||
1732 | if (symbol_conf.symfs[0] || | ||
1733 | (dso__build_id_filename(dso, file, size) == NULL)) | ||
1734 | ret = -1; | ||
1735 | break; | ||
1736 | |||
1737 | case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: | ||
1738 | snprintf(file, size, "%s/usr/lib/debug%s.debug", | ||
1739 | symbol_conf.symfs, dso->long_name); | ||
1740 | break; | ||
1741 | |||
1742 | case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: | ||
1743 | snprintf(file, size, "%s/usr/lib/debug%s", | ||
1744 | symbol_conf.symfs, dso->long_name); | ||
1745 | break; | ||
1746 | |||
1747 | case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: | ||
1748 | if (!dso->has_build_id) { | ||
1749 | ret = -1; | ||
1750 | break; | ||
1751 | } | ||
1752 | |||
1753 | build_id__sprintf(dso->build_id, | ||
1754 | sizeof(dso->build_id), | ||
1755 | build_id_hex); | ||
1756 | snprintf(file, size, | ||
1757 | "%s/usr/lib/debug/.build-id/%.2s/%s.debug", | ||
1758 | symbol_conf.symfs, build_id_hex, build_id_hex + 2); | ||
1759 | break; | ||
1760 | |||
1761 | case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: | ||
1762 | snprintf(file, size, "%s%s", | ||
1763 | symbol_conf.symfs, dso->long_name); | ||
1764 | break; | ||
1765 | |||
1766 | case DSO_BINARY_TYPE__GUEST_KMODULE: | ||
1767 | snprintf(file, size, "%s%s%s", symbol_conf.symfs, | ||
1768 | root_dir, dso->long_name); | ||
1769 | break; | ||
1770 | |||
1771 | case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: | ||
1772 | snprintf(file, size, "%s%s", symbol_conf.symfs, | ||
1773 | dso->long_name); | ||
1774 | break; | ||
1775 | |||
1776 | default: | ||
1777 | case DSO_BINARY_TYPE__KALLSYMS: | ||
1778 | case DSO_BINARY_TYPE__GUEST_KALLSYMS: | ||
1779 | case DSO_BINARY_TYPE__JAVA_JIT: | ||
1780 | case DSO_BINARY_TYPE__NOT_FOUND: | ||
1781 | ret = -1; | ||
1782 | break; | ||
1783 | } | ||
1784 | |||
1785 | return ret; | ||
1786 | } | ||
1787 | |||
1681 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | 1788 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) |
1682 | { | 1789 | { |
1683 | int size = PATH_MAX; | ||
1684 | char *name; | 1790 | char *name; |
1685 | int ret = -1; | 1791 | int ret = -1; |
1686 | int fd; | 1792 | int fd; |
1793 | u_int i; | ||
1687 | struct machine *machine; | 1794 | struct machine *machine; |
1688 | const char *root_dir; | 1795 | char *root_dir = (char *) ""; |
1689 | int want_symtab; | 1796 | int want_symtab; |
1690 | 1797 | ||
1691 | dso__set_loaded(dso, map->type); | 1798 | dso__set_loaded(dso, map->type); |
@@ -1700,7 +1807,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | |||
1700 | else | 1807 | else |
1701 | machine = NULL; | 1808 | machine = NULL; |
1702 | 1809 | ||
1703 | name = malloc(size); | 1810 | name = malloc(PATH_MAX); |
1704 | if (!name) | 1811 | if (!name) |
1705 | return -1; | 1812 | return -1; |
1706 | 1813 | ||
@@ -1719,81 +1826,27 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | |||
1719 | } | 1826 | } |
1720 | 1827 | ||
1721 | ret = dso__load_perf_map(dso, map, filter); | 1828 | ret = dso__load_perf_map(dso, map, filter); |
1722 | dso->symtab_type = ret > 0 ? SYMTAB__JAVA_JIT : | 1829 | dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT : |
1723 | SYMTAB__NOT_FOUND; | 1830 | DSO_BINARY_TYPE__NOT_FOUND; |
1724 | return ret; | 1831 | return ret; |
1725 | } | 1832 | } |
1726 | 1833 | ||
1834 | if (machine) | ||
1835 | root_dir = machine->root_dir; | ||
1836 | |||
1727 | /* Iterate over candidate debug images. | 1837 | /* Iterate over candidate debug images. |
1728 | * On the first pass, only load images if they have a full symtab. | 1838 | * On the first pass, only load images if they have a full symtab. |
1729 | * Failing that, do a second pass where we accept .dynsym also | 1839 | * Failing that, do a second pass where we accept .dynsym also |
1730 | */ | 1840 | */ |
1731 | want_symtab = 1; | 1841 | want_symtab = 1; |
1732 | restart: | 1842 | restart: |
1733 | for (dso->symtab_type = SYMTAB__DEBUGLINK; | 1843 | for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) { |
1734 | dso->symtab_type != SYMTAB__NOT_FOUND; | ||
1735 | dso->symtab_type++) { | ||
1736 | switch (dso->symtab_type) { | ||
1737 | case SYMTAB__DEBUGLINK: { | ||
1738 | char *debuglink; | ||
1739 | strncpy(name, dso->long_name, size); | ||
1740 | debuglink = name + dso->long_name_len; | ||
1741 | while (debuglink != name && *debuglink != '/') | ||
1742 | debuglink--; | ||
1743 | if (*debuglink == '/') | ||
1744 | debuglink++; | ||
1745 | filename__read_debuglink(dso->long_name, debuglink, | ||
1746 | size - (debuglink - name)); | ||
1747 | } | ||
1748 | break; | ||
1749 | case SYMTAB__BUILD_ID_CACHE: | ||
1750 | /* skip the locally configured cache if a symfs is given */ | ||
1751 | if (symbol_conf.symfs[0] || | ||
1752 | (dso__build_id_filename(dso, name, size) == NULL)) { | ||
1753 | continue; | ||
1754 | } | ||
1755 | break; | ||
1756 | case SYMTAB__FEDORA_DEBUGINFO: | ||
1757 | snprintf(name, size, "%s/usr/lib/debug%s.debug", | ||
1758 | symbol_conf.symfs, dso->long_name); | ||
1759 | break; | ||
1760 | case SYMTAB__UBUNTU_DEBUGINFO: | ||
1761 | snprintf(name, size, "%s/usr/lib/debug%s", | ||
1762 | symbol_conf.symfs, dso->long_name); | ||
1763 | break; | ||
1764 | case SYMTAB__BUILDID_DEBUGINFO: { | ||
1765 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1766 | 1844 | ||
1767 | if (!dso->has_build_id) | 1845 | dso->symtab_type = binary_type_symtab[i]; |
1768 | continue; | ||
1769 | 1846 | ||
1770 | build_id__sprintf(dso->build_id, | 1847 | if (dso__binary_type_file(dso, dso->symtab_type, |
1771 | sizeof(dso->build_id), | 1848 | root_dir, name, PATH_MAX)) |
1772 | build_id_hex); | 1849 | continue; |
1773 | snprintf(name, size, | ||
1774 | "%s/usr/lib/debug/.build-id/%.2s/%s.debug", | ||
1775 | symbol_conf.symfs, build_id_hex, build_id_hex + 2); | ||
1776 | } | ||
1777 | break; | ||
1778 | case SYMTAB__SYSTEM_PATH_DSO: | ||
1779 | snprintf(name, size, "%s%s", | ||
1780 | symbol_conf.symfs, dso->long_name); | ||
1781 | break; | ||
1782 | case SYMTAB__GUEST_KMODULE: | ||
1783 | if (map->groups && machine) | ||
1784 | root_dir = machine->root_dir; | ||
1785 | else | ||
1786 | root_dir = ""; | ||
1787 | snprintf(name, size, "%s%s%s", symbol_conf.symfs, | ||
1788 | root_dir, dso->long_name); | ||
1789 | break; | ||
1790 | |||
1791 | case SYMTAB__SYSTEM_PATH_KMODULE: | ||
1792 | snprintf(name, size, "%s%s", symbol_conf.symfs, | ||
1793 | dso->long_name); | ||
1794 | break; | ||
1795 | default:; | ||
1796 | } | ||
1797 | 1850 | ||
1798 | /* Name is now the name of the next image to try */ | 1851 | /* Name is now the name of the next image to try */ |
1799 | fd = open(name, O_RDONLY); | 1852 | fd = open(name, O_RDONLY); |
@@ -2010,9 +2063,9 @@ struct map *machine__new_module(struct machine *machine, u64 start, | |||
2010 | return NULL; | 2063 | return NULL; |
2011 | 2064 | ||
2012 | if (machine__is_host(machine)) | 2065 | if (machine__is_host(machine)) |
2013 | dso->symtab_type = SYMTAB__SYSTEM_PATH_KMODULE; | 2066 | dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE; |
2014 | else | 2067 | else |
2015 | dso->symtab_type = SYMTAB__GUEST_KMODULE; | 2068 | dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE; |
2016 | map_groups__insert(&machine->kmaps, map); | 2069 | map_groups__insert(&machine->kmaps, map); |
2017 | return map; | 2070 | return map; |
2018 | } | 2071 | } |
@@ -2564,8 +2617,15 @@ int machine__create_kernel_maps(struct machine *machine) | |||
2564 | __machine__create_kernel_maps(machine, kernel) < 0) | 2617 | __machine__create_kernel_maps(machine, kernel) < 0) |
2565 | return -1; | 2618 | return -1; |
2566 | 2619 | ||
2567 | if (symbol_conf.use_modules && machine__create_modules(machine) < 0) | 2620 | if (symbol_conf.use_modules && machine__create_modules(machine) < 0) { |
2568 | pr_debug("Problems creating module maps, continuing anyway...\n"); | 2621 | if (machine__is_host(machine)) |
2622 | pr_debug("Problems creating module maps, " | ||
2623 | "continuing anyway...\n"); | ||
2624 | else | ||
2625 | pr_debug("Problems creating module maps for guest %d, " | ||
2626 | "continuing anyway...\n", machine->pid); | ||
2627 | } | ||
2628 | |||
2569 | /* | 2629 | /* |
2570 | * Now that we have all the maps created, just set the ->end of them: | 2630 | * Now that we have all the maps created, just set the ->end of them: |
2571 | */ | 2631 | */ |
@@ -2905,3 +2965,218 @@ struct map *dso__new_map(const char *name) | |||
2905 | 2965 | ||
2906 | return map; | 2966 | return map; |
2907 | } | 2967 | } |
2968 | |||
2969 | static int open_dso(struct dso *dso, struct machine *machine) | ||
2970 | { | ||
2971 | char *root_dir = (char *) ""; | ||
2972 | char *name; | ||
2973 | int fd; | ||
2974 | |||
2975 | name = malloc(PATH_MAX); | ||
2976 | if (!name) | ||
2977 | return -ENOMEM; | ||
2978 | |||
2979 | if (machine) | ||
2980 | root_dir = machine->root_dir; | ||
2981 | |||
2982 | if (dso__binary_type_file(dso, dso->data_type, | ||
2983 | root_dir, name, PATH_MAX)) { | ||
2984 | free(name); | ||
2985 | return -EINVAL; | ||
2986 | } | ||
2987 | |||
2988 | fd = open(name, O_RDONLY); | ||
2989 | free(name); | ||
2990 | return fd; | ||
2991 | } | ||
2992 | |||
2993 | int dso__data_fd(struct dso *dso, struct machine *machine) | ||
2994 | { | ||
2995 | int i = 0; | ||
2996 | |||
2997 | if (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND) | ||
2998 | return open_dso(dso, machine); | ||
2999 | |||
3000 | do { | ||
3001 | int fd; | ||
3002 | |||
3003 | dso->data_type = binary_type_data[i++]; | ||
3004 | |||
3005 | fd = open_dso(dso, machine); | ||
3006 | if (fd >= 0) | ||
3007 | return fd; | ||
3008 | |||
3009 | } while (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND); | ||
3010 | |||
3011 | return -EINVAL; | ||
3012 | } | ||
3013 | |||
3014 | static void | ||
3015 | dso_cache__free(struct rb_root *root) | ||
3016 | { | ||
3017 | struct rb_node *next = rb_first(root); | ||
3018 | |||
3019 | while (next) { | ||
3020 | struct dso_cache *cache; | ||
3021 | |||
3022 | cache = rb_entry(next, struct dso_cache, rb_node); | ||
3023 | next = rb_next(&cache->rb_node); | ||
3024 | rb_erase(&cache->rb_node, root); | ||
3025 | free(cache); | ||
3026 | } | ||
3027 | } | ||
3028 | |||
3029 | static struct dso_cache* | ||
3030 | dso_cache__find(struct rb_root *root, u64 offset) | ||
3031 | { | ||
3032 | struct rb_node **p = &root->rb_node; | ||
3033 | struct rb_node *parent = NULL; | ||
3034 | struct dso_cache *cache; | ||
3035 | |||
3036 | while (*p != NULL) { | ||
3037 | u64 end; | ||
3038 | |||
3039 | parent = *p; | ||
3040 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
3041 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
3042 | |||
3043 | if (offset < cache->offset) | ||
3044 | p = &(*p)->rb_left; | ||
3045 | else if (offset >= end) | ||
3046 | p = &(*p)->rb_right; | ||
3047 | else | ||
3048 | return cache; | ||
3049 | } | ||
3050 | return NULL; | ||
3051 | } | ||
3052 | |||
3053 | static void | ||
3054 | dso_cache__insert(struct rb_root *root, struct dso_cache *new) | ||
3055 | { | ||
3056 | struct rb_node **p = &root->rb_node; | ||
3057 | struct rb_node *parent = NULL; | ||
3058 | struct dso_cache *cache; | ||
3059 | u64 offset = new->offset; | ||
3060 | |||
3061 | while (*p != NULL) { | ||
3062 | u64 end; | ||
3063 | |||
3064 | parent = *p; | ||
3065 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
3066 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
3067 | |||
3068 | if (offset < cache->offset) | ||
3069 | p = &(*p)->rb_left; | ||
3070 | else if (offset >= end) | ||
3071 | p = &(*p)->rb_right; | ||
3072 | } | ||
3073 | |||
3074 | rb_link_node(&new->rb_node, parent, p); | ||
3075 | rb_insert_color(&new->rb_node, root); | ||
3076 | } | ||
3077 | |||
3078 | static ssize_t | ||
3079 | dso_cache__memcpy(struct dso_cache *cache, u64 offset, | ||
3080 | u8 *data, u64 size) | ||
3081 | { | ||
3082 | u64 cache_offset = offset - cache->offset; | ||
3083 | u64 cache_size = min(cache->size - cache_offset, size); | ||
3084 | |||
3085 | memcpy(data, cache->data + cache_offset, cache_size); | ||
3086 | return cache_size; | ||
3087 | } | ||
3088 | |||
3089 | static ssize_t | ||
3090 | dso_cache__read(struct dso *dso, struct machine *machine, | ||
3091 | u64 offset, u8 *data, ssize_t size) | ||
3092 | { | ||
3093 | struct dso_cache *cache; | ||
3094 | ssize_t ret; | ||
3095 | int fd; | ||
3096 | |||
3097 | fd = dso__data_fd(dso, machine); | ||
3098 | if (fd < 0) | ||
3099 | return -1; | ||
3100 | |||
3101 | do { | ||
3102 | u64 cache_offset; | ||
3103 | |||
3104 | ret = -ENOMEM; | ||
3105 | |||
3106 | cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE); | ||
3107 | if (!cache) | ||
3108 | break; | ||
3109 | |||
3110 | cache_offset = offset & DSO__DATA_CACHE_MASK; | ||
3111 | ret = -EINVAL; | ||
3112 | |||
3113 | if (-1 == lseek(fd, cache_offset, SEEK_SET)) | ||
3114 | break; | ||
3115 | |||
3116 | ret = read(fd, cache->data, DSO__DATA_CACHE_SIZE); | ||
3117 | if (ret <= 0) | ||
3118 | break; | ||
3119 | |||
3120 | cache->offset = cache_offset; | ||
3121 | cache->size = ret; | ||
3122 | dso_cache__insert(&dso->cache, cache); | ||
3123 | |||
3124 | ret = dso_cache__memcpy(cache, offset, data, size); | ||
3125 | |||
3126 | } while (0); | ||
3127 | |||
3128 | if (ret <= 0) | ||
3129 | free(cache); | ||
3130 | |||
3131 | close(fd); | ||
3132 | return ret; | ||
3133 | } | ||
3134 | |||
3135 | static ssize_t dso_cache_read(struct dso *dso, struct machine *machine, | ||
3136 | u64 offset, u8 *data, ssize_t size) | ||
3137 | { | ||
3138 | struct dso_cache *cache; | ||
3139 | |||
3140 | cache = dso_cache__find(&dso->cache, offset); | ||
3141 | if (cache) | ||
3142 | return dso_cache__memcpy(cache, offset, data, size); | ||
3143 | else | ||
3144 | return dso_cache__read(dso, machine, offset, data, size); | ||
3145 | } | ||
3146 | |||
3147 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
3148 | u64 offset, u8 *data, ssize_t size) | ||
3149 | { | ||
3150 | ssize_t r = 0; | ||
3151 | u8 *p = data; | ||
3152 | |||
3153 | do { | ||
3154 | ssize_t ret; | ||
3155 | |||
3156 | ret = dso_cache_read(dso, machine, offset, p, size); | ||
3157 | if (ret < 0) | ||
3158 | return ret; | ||
3159 | |||
3160 | /* Reached EOF, return what we have. */ | ||
3161 | if (!ret) | ||
3162 | break; | ||
3163 | |||
3164 | BUG_ON(ret > size); | ||
3165 | |||
3166 | r += ret; | ||
3167 | p += ret; | ||
3168 | offset += ret; | ||
3169 | size -= ret; | ||
3170 | |||
3171 | } while (size); | ||
3172 | |||
3173 | return r; | ||
3174 | } | ||
3175 | |||
3176 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
3177 | struct machine *machine, u64 addr, | ||
3178 | u8 *data, ssize_t size) | ||
3179 | { | ||
3180 | u64 offset = map->map_ip(map, addr); | ||
3181 | return dso__data_read_offset(dso, machine, offset, data, size); | ||
3182 | } | ||
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index a884b99017f0..1fe733a1e21f 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -155,6 +155,21 @@ struct addr_location { | |||
155 | s32 cpu; | 155 | s32 cpu; |
156 | }; | 156 | }; |
157 | 157 | ||
158 | enum dso_binary_type { | ||
159 | DSO_BINARY_TYPE__KALLSYMS = 0, | ||
160 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | ||
161 | DSO_BINARY_TYPE__JAVA_JIT, | ||
162 | DSO_BINARY_TYPE__DEBUGLINK, | ||
163 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
164 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | ||
165 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | ||
166 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | ||
167 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
168 | DSO_BINARY_TYPE__GUEST_KMODULE, | ||
169 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | ||
170 | DSO_BINARY_TYPE__NOT_FOUND, | ||
171 | }; | ||
172 | |||
158 | enum dso_kernel_type { | 173 | enum dso_kernel_type { |
159 | DSO_TYPE_USER = 0, | 174 | DSO_TYPE_USER = 0, |
160 | DSO_TYPE_KERNEL, | 175 | DSO_TYPE_KERNEL, |
@@ -167,19 +182,31 @@ enum dso_swap_type { | |||
167 | DSO_SWAP__YES, | 182 | DSO_SWAP__YES, |
168 | }; | 183 | }; |
169 | 184 | ||
185 | #define DSO__DATA_CACHE_SIZE 4096 | ||
186 | #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) | ||
187 | |||
188 | struct dso_cache { | ||
189 | struct rb_node rb_node; | ||
190 | u64 offset; | ||
191 | u64 size; | ||
192 | char data[0]; | ||
193 | }; | ||
194 | |||
170 | struct dso { | 195 | struct dso { |
171 | struct list_head node; | 196 | struct list_head node; |
172 | struct rb_root symbols[MAP__NR_TYPES]; | 197 | struct rb_root symbols[MAP__NR_TYPES]; |
173 | struct rb_root symbol_names[MAP__NR_TYPES]; | 198 | struct rb_root symbol_names[MAP__NR_TYPES]; |
199 | struct rb_root cache; | ||
174 | enum dso_kernel_type kernel; | 200 | enum dso_kernel_type kernel; |
175 | enum dso_swap_type needs_swap; | 201 | enum dso_swap_type needs_swap; |
202 | enum dso_binary_type symtab_type; | ||
203 | enum dso_binary_type data_type; | ||
176 | u8 adjust_symbols:1; | 204 | u8 adjust_symbols:1; |
177 | u8 has_build_id:1; | 205 | u8 has_build_id:1; |
178 | u8 hit:1; | 206 | u8 hit:1; |
179 | u8 annotate_warned:1; | 207 | u8 annotate_warned:1; |
180 | u8 sname_alloc:1; | 208 | u8 sname_alloc:1; |
181 | u8 lname_alloc:1; | 209 | u8 lname_alloc:1; |
182 | unsigned char symtab_type; | ||
183 | u8 sorted_by_name; | 210 | u8 sorted_by_name; |
184 | u8 loaded; | 211 | u8 loaded; |
185 | u8 build_id[BUILD_ID_SIZE]; | 212 | u8 build_id[BUILD_ID_SIZE]; |
@@ -253,21 +280,6 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso, | |||
253 | enum map_type type, FILE *fp); | 280 | enum map_type type, FILE *fp); |
254 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); | 281 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); |
255 | 282 | ||
256 | enum symtab_type { | ||
257 | SYMTAB__KALLSYMS = 0, | ||
258 | SYMTAB__GUEST_KALLSYMS, | ||
259 | SYMTAB__JAVA_JIT, | ||
260 | SYMTAB__DEBUGLINK, | ||
261 | SYMTAB__BUILD_ID_CACHE, | ||
262 | SYMTAB__FEDORA_DEBUGINFO, | ||
263 | SYMTAB__UBUNTU_DEBUGINFO, | ||
264 | SYMTAB__BUILDID_DEBUGINFO, | ||
265 | SYMTAB__SYSTEM_PATH_DSO, | ||
266 | SYMTAB__GUEST_KMODULE, | ||
267 | SYMTAB__SYSTEM_PATH_KMODULE, | ||
268 | SYMTAB__NOT_FOUND, | ||
269 | }; | ||
270 | |||
271 | char dso__symtab_origin(const struct dso *dso); | 283 | char dso__symtab_origin(const struct dso *dso); |
272 | void dso__set_long_name(struct dso *dso, char *name); | 284 | void dso__set_long_name(struct dso *dso, char *name); |
273 | void dso__set_build_id(struct dso *dso, void *build_id); | 285 | void dso__set_build_id(struct dso *dso, void *build_id); |
@@ -304,4 +316,14 @@ bool symbol_type__is_a(char symbol_type, enum map_type map_type); | |||
304 | 316 | ||
305 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); | 317 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
306 | 318 | ||
319 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
320 | char *root_dir, char *file, size_t size); | ||
321 | |||
322 | int dso__data_fd(struct dso *dso, struct machine *machine); | ||
323 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
324 | u64 offset, u8 *data, ssize_t size); | ||
325 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
326 | struct machine *machine, u64 addr, | ||
327 | u8 *data, ssize_t size); | ||
328 | int dso__test_data(void); | ||
307 | #endif /* __PERF_SYMBOL */ | 329 | #endif /* __PERF_SYMBOL */ |
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c index 1064d5b148ad..3f59c496e64c 100644 --- a/tools/perf/util/target.c +++ b/tools/perf/util/target.c | |||
@@ -110,8 +110,17 @@ int perf_target__strerror(struct perf_target *target, int errnum, | |||
110 | int idx; | 110 | int idx; |
111 | const char *msg; | 111 | const char *msg; |
112 | 112 | ||
113 | BUG_ON(buflen > 0); | ||
114 | |||
113 | if (errnum >= 0) { | 115 | if (errnum >= 0) { |
114 | strerror_r(errnum, buf, buflen); | 116 | const char *err = strerror_r(errnum, buf, buflen); |
117 | |||
118 | if (err != buf) { | ||
119 | size_t len = strlen(err); | ||
120 | char *c = mempcpy(buf, err, min(buflen - 1, len)); | ||
121 | *c = '\0'; | ||
122 | } | ||
123 | |||
115 | return 0; | 124 | return 0; |
116 | } | 125 | } |
117 | 126 | ||