1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright 2022, Athira Rajeev, IBM Corp.
* Copyright 2022, Madhavan Srinivasan, IBM Corp.
* Copyright 2022, Kajol Jain, IBM Corp.
*/
#include <sys/stat.h>
#include "../event.h"
#define POWER10 0x80
#define POWER9 0x4e
#define PERF_POWER9_MASK 0x7f8ffffffffffff
#define PERF_POWER10_MASK 0x7ffffffffffffff
#define MMCR0_FC56 0x00000010UL /* freeze counters 5 and 6 */
#define MMCR0_PMCCEXT 0x00000200UL /* PMCCEXT control */
#define MMCR1_RSQ 0x200000000000ULL /* radix scope qual field */
#define BHRB_DISABLE 0x2000000000ULL /* MMCRA BHRB DISABLE bit */
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
extern int ev_mask_pmcxsel, ev_shift_pmcxsel;
extern int ev_mask_marked, ev_shift_marked;
extern int ev_mask_comb, ev_shift_comb;
extern int ev_mask_unit, ev_shift_unit;
extern int ev_mask_pmc, ev_shift_pmc;
extern int ev_mask_cache, ev_shift_cache;
extern int ev_mask_sample, ev_shift_sample;
extern int ev_mask_thd_sel, ev_shift_thd_sel;
extern int ev_mask_thd_start, ev_shift_thd_start;
extern int ev_mask_thd_stop, ev_shift_thd_stop;
extern int ev_mask_thd_cmp, ev_shift_thd_cmp;
extern int ev_mask_sm, ev_shift_sm;
extern int ev_mask_rsq, ev_shift_rsq;
extern int ev_mask_l2l3, ev_shift_l2l3;
extern int ev_mask_mmcr3_src, ev_shift_mmcr3_src;
extern int pvr;
extern u64 platform_extended_mask;
extern int check_pvr_for_sampling_tests(void);
extern int platform_check_for_tests(void);
/*
* Event code field extraction macro.
* Raw event code is combination of multiple
* fields. Macro to extract individual fields
*
* x - Raw event code value
* y - Field to extract
*/
#define EV_CODE_EXTRACT(x, y) \
((x >> ev_shift_##y) & ev_mask_##y)
void *event_sample_buf_mmap(int fd, int mmap_pages);
void *__event_read_samples(void *sample_buff, size_t *size, u64 *sample_count);
int collect_samples(void *sample_buff);
u64 *get_intr_regs(struct event *event, void *sample_buff);
u64 get_reg_value(u64 *intr_regs, char *register_name);
int get_thresh_cmp_val(struct event event);
bool check_for_generic_compat_pmu(void);
bool check_for_compat_mode(void);
static inline int get_mmcr0_fc56(u64 mmcr0, int pmc)
{
return (mmcr0 & MMCR0_FC56);
}
static inline int get_mmcr0_pmccext(u64 mmcr0, int pmc)
{
return (mmcr0 & MMCR0_PMCCEXT);
}
static inline int get_mmcr0_pmao(u64 mmcr0, int pmc)
{
return ((mmcr0 >> 7) & 0x1);
}
static inline int get_mmcr0_cc56run(u64 mmcr0, int pmc)
{
return ((mmcr0 >> 8) & 0x1);
}
static inline int get_mmcr0_pmcjce(u64 mmcr0, int pmc)
{
return ((mmcr0 >> 14) & 0x1);
}
static inline int get_mmcr0_pmc1ce(u64 mmcr0, int pmc)
{
return ((mmcr0 >> 15) & 0x1);
}
static inline int get_mmcr0_pmae(u64 mmcr0, int pmc)
{
return ((mmcr0 >> 27) & 0x1);
}
static inline int get_mmcr1_pmcxsel(u64 mmcr1, int pmc)
{
return ((mmcr1 >> ((24 - (((pmc) - 1) * 8))) & 0xff));
}
static inline int get_mmcr1_unit(u64 mmcr1, int pmc)
{
return ((mmcr1 >> ((60 - (4 * ((pmc) - 1))))) & 0xf);
}
static inline int get_mmcr1_comb(u64 mmcr1, int pmc)
{
return ((mmcr1 >> (38 - ((pmc - 1) * 2))) & 0x3);
}
static inline int get_mmcr1_cache(u64 mmcr1, int pmc)
{
return ((mmcr1 >> 46) & 0x3);
}
static inline int get_mmcr1_rsq(u64 mmcr1, int pmc)
{
return mmcr1 & MMCR1_RSQ;
}
static inline int get_mmcr2_fcs(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (63 - (((pmc) - 1) * 9)))) >> (63 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fcp(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (62 - (((pmc) - 1) * 9)))) >> (62 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fcpc(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (61 - (((pmc) - 1) * 9)))) >> (61 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fcm1(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (60 - (((pmc) - 1) * 9)))) >> (60 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fcm0(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (59 - (((pmc) - 1) * 9)))) >> (59 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fcwait(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (58 - (((pmc) - 1) * 9)))) >> (58 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fch(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (57 - (((pmc) - 1) * 9)))) >> (57 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fcti(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (56 - (((pmc) - 1) * 9)))) >> (56 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_fcta(u64 mmcr2, int pmc)
{
return ((mmcr2 & (1ull << (55 - (((pmc) - 1) * 9)))) >> (55 - (((pmc) - 1) * 9)));
}
static inline int get_mmcr2_l2l3(u64 mmcr2, int pmc)
{
if (pvr == POWER10)
return ((mmcr2 & 0xf8) >> 3);
return 0;
}
static inline int get_mmcr3_src(u64 mmcr3, int pmc)
{
if (pvr != POWER10)
return 0;
return ((mmcr3 >> ((49 - (15 * ((pmc) - 1))))) & 0x7fff);
}
static inline int get_mmcra_thd_cmp(u64 mmcra, int pmc)
{
if (pvr == POWER10)
return ((mmcra >> 45) & 0x7ff);
return ((mmcra >> 45) & 0x3ff);
}
static inline int get_mmcra_sm(u64 mmcra, int pmc)
{
return ((mmcra >> 42) & 0x3);
}
static inline u64 get_mmcra_bhrb_disable(u64 mmcra, int pmc)
{
if (pvr == POWER10)
return mmcra & BHRB_DISABLE;
return 0;
}
static inline int get_mmcra_ifm(u64 mmcra, int pmc)
{
return ((mmcra >> 30) & 0x3);
}
static inline int get_mmcra_thd_sel(u64 mmcra, int pmc)
{
return ((mmcra >> 16) & 0x7);
}
static inline int get_mmcra_thd_start(u64 mmcra, int pmc)
{
return ((mmcra >> 12) & 0xf);
}
static inline int get_mmcra_thd_stop(u64 mmcra, int pmc)
{
return ((mmcra >> 8) & 0xf);
}
static inline int get_mmcra_rand_samp_elig(u64 mmcra, int pmc)
{
return ((mmcra >> 4) & 0x7);
}
static inline int get_mmcra_sample_mode(u64 mmcra, int pmc)
{
return ((mmcra >> 1) & 0x3);
}
static inline int get_mmcra_marked(u64 mmcra, int pmc)
{
return mmcra & 0x1;
}
|