| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pfmlib.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2001-2007 Hewlett-Packard Development Company, L.P.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #ifndef __PFMLIB_H__
23 #define __PFMLIB_H__
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 #include <stdio.h>
29 #include <inttypes.h>
30
31 #include <perfmon/pfmlib_os.h>
32 #include <perfmon/pfmlib_comp.h>
33
34 #define PFMLIB_VERSION (3 << 16 | 9)
35 #define PFMLIB_MAJ_VERSION(v) ((v)>>16)
36 #define PFMLIB_MIN_VERSION(v) ((v) & 0xffff)
37
38 /*
39 * Maximum number of PMCs/PMDs supported by the library (especially bitmasks)
40 */
41 #define PFMLIB_MAX_PMCS 512 /* maximum number of PMCS supported by the library */
42 #define PFMLIB_MAX_PMDS 512 /* maximum number of PMDS supported by the library */
43
44 /*
45 * privilege level mask (mask can be combined)
46 * The interpretation of the level is specific to each
47 * architecture. Checkout the architecture specific header
48 * file for more details.
49 */
50 #define PFM_PLM0 0x1 /* priv level 0 */
51 #define PFM_PLM1 0x2 /* priv level 1 */
52 #define PFM_PLM2 0x4 /* priv level 2 */
53 #define PFM_PLM3 0x8 /* priv level 3 */
54
55 /*
56 * type used to describe a set of bits in the mask (container type)
57 */
58 typedef unsigned long pfmlib_regmask_bits_t;
59
60 /*
61 * how many elements do we need to represent all the PMCs and PMDs (rounded up)
62 */
63 #if PFMLIB_MAX_PMCS > PFMLIB_MAX_PMDS
64 #define PFMLIB_REG_MAX PFMLIB_MAX_PMCS
65 #else
66 #define PFMLIB_REG_MAX PFMLIB_MAX_PMDS
67 #endif
68
69 #ifndef SWIG
70 #define __PFMLIB_REG_BV_BITS (sizeof(pfmlib_regmask_bits_t)<<3)
71 #define PFMLIB_BVSIZE(x) (((x)+(__PFMLIB_REG_BV_BITS)-1) / __PFMLIB_REG_BV_BITS)
72 #define PFMLIB_REG_BV PFMLIB_BVSIZE(PFMLIB_REG_MAX)
73 #endif
74
75 typedef struct {
76 pfmlib_regmask_bits_t bits[PFMLIB_REG_BV];
77 } pfmlib_regmask_t;
78
79
80 #define PFMLIB_MAX_MASKS_PER_EVENT 48 /* maximum number of unit masks per event */
81
82 /*
83 * event definition for pfmlib_input_param_t
84 */
85 typedef struct {
86 unsigned int event; /* event descriptor */
87 unsigned int plm; /* event privilege level mask */
88 unsigned long flags; /* per-event flag */
89 unsigned int unit_masks[PFMLIB_MAX_MASKS_PER_EVENT]; /* unit-mask identifiers */
90 unsigned int num_masks; /* number of masks specified in 'unit_masks' */
91 unsigned long reserved[2]; /* for future use */
92 } pfmlib_event_t;
93
94 /*
95 * generic register definition
96 */
97 typedef struct {
98 unsigned long long reg_value; /* register value */
99 unsigned long long reg_addr; /* hardware register addr or index */
100 unsigned int reg_num; /* logical register index (perfmon2) */
101 unsigned int reg_reserved1; /* for future use */
102 unsigned long reg_alt_addr; /* alternate hw register addr of index */
103 } pfmlib_reg_t;
104
105 /*
106 * library generic input parameters for pfm_dispatch_event()
107 */
108 typedef struct {
109 unsigned int pfp_event_count; /* how many events specified (input) */
110 unsigned int pfp_dfl_plm; /* default priv level : used when event.plm==0 */
111 unsigned int pfp_flags; /* set of flags for all events used when event.flags==0*/
112 unsigned int reserved1; /* for future use */
113 pfmlib_event_t pfp_events[PFMLIB_MAX_PMCS]; /* event descriptions */
114 pfmlib_regmask_t pfp_unavail_pmcs; /* bitmask of unavailable PMC registers */
115 unsigned long reserved[6]; /* for future use */
116 } pfmlib_input_param_t;
117
118 /*
119 * pfp_flags possible values (apply to all events)
120 */
121 #define PFMLIB_PFP_SYSTEMWIDE 0x1 /* indicate monitors will be used in a system-wide session */
122
123 /*
124 * library generic output parameters for pfm_dispatch_event()
125 */
126 typedef struct {
127 unsigned int pfp_pmc_count; /* number of entries in pfp_pmcs */
128 unsigned int pfp_pmd_count; /* number of entries in pfp_pmds */
129 pfmlib_reg_t pfp_pmcs[PFMLIB_MAX_PMCS]; /* PMC registers number and values */
130 pfmlib_reg_t pfp_pmds[PFMLIB_MAX_PMDS]; /* PMD registers numbers */
131 unsigned long reserved[7]; /* for future use */
132 } pfmlib_output_param_t;
133
134 /*
135 * library configuration options
136 */
137 typedef struct {
138 unsigned int pfm_debug:1; /* set in debug mode */
139 unsigned int pfm_verbose:1; /* set in verbose mode */
140 unsigned int pfm_reserved:30;/* for future use */
141 } pfmlib_options_t;
142
143 /*
144 * special data type for libpfm error value used to help
145 * with Python support and in particular for SWIG. By using
146 * a specific type we can detect library calls and trap errors
147 * in one SWIG statement as opposed to having to keep track of
148 * each call individually. Programs can use 'int' safely for
149 * the return value.
150 */
151 typedef int pfm_err_t; /* error if !PFMLIB_SUCCESS */
152
153 extern pfm_err_t pfm_set_options(pfmlib_options_t *opt);
154 extern pfm_err_t pfm_initialize(void);
155
156 extern pfm_err_t pfm_list_supported_pmus(int (*pf)(const char *fmt,...));
157 extern pfm_err_t pfm_get_pmu_name(char *name, int maxlen);
158 extern pfm_err_t pfm_get_pmu_type(int *type);
159 extern pfm_err_t pfm_get_pmu_name_bytype(int type, char *name, size_t maxlen);
160 extern pfm_err_t pfm_is_pmu_supported(int type);
161 extern pfm_err_t pfm_force_pmu(int type);
162
163 /*
164 * pfm_find_event_byname() is obsolete, use pfm_find_event
165 */
166 extern pfm_err_t pfm_find_event(const char *str, unsigned int *idx);
167 extern pfm_err_t pfm_find_event_byname(const char *name, unsigned int *idx);
168 extern pfm_err_t pfm_find_event_bycode(int code, unsigned int *idx);
169 extern pfm_err_t pfm_find_event_bycode_next(int code, unsigned int start,
170 unsigned int *next);
171 extern pfm_err_t pfm_find_event_mask(unsigned int event_idx, const char *str,
172 unsigned int *mask_idx);
173 extern pfm_err_t pfm_find_full_event(const char *str, pfmlib_event_t *e);
174
175 extern pfm_err_t pfm_get_max_event_name_len(size_t *len);
176
177 extern pfm_err_t pfm_get_num_events(unsigned int *count);
178 extern pfm_err_t pfm_get_num_event_masks(unsigned int event_idx,
179 unsigned int *count);
180 extern pfm_err_t pfm_get_event_name(unsigned int idx, char *name,
181 size_t maxlen);
182 extern pfm_err_t pfm_get_full_event_name(pfmlib_event_t *e, char *name,
183 size_t maxlen);
184 extern pfm_err_t pfm_get_event_code(unsigned int idx, int *code);
185 extern pfm_err_t pfm_get_event_mask_code(unsigned int idx,
186 unsigned int mask_idx,
187 unsigned int *code);
188 extern pfm_err_t pfm_get_event_counters(unsigned int idx,
189 pfmlib_regmask_t *counters);
190 extern pfm_err_t pfm_get_event_description(unsigned int idx, char **str);
191 extern pfm_err_t pfm_get_event_code_counter(unsigned int idx, unsigned int cnt,
192 int *code);
193 extern pfm_err_t pfm_get_event_mask_name(unsigned int event_idx,
194 unsigned int mask_idx,
195 char *name, size_t maxlen);
196 extern pfm_err_t pfm_get_event_mask_description(unsigned int event_idx,
197 unsigned int mask_idx,
198 char **desc);
199
200 extern pfm_err_t pfm_dispatch_events(pfmlib_input_param_t *p,
201 void *model_in,
202 pfmlib_output_param_t *q,
203 void *model_out);
204
205 extern pfm_err_t pfm_get_impl_pmcs(pfmlib_regmask_t *impl_pmcs);
206 extern pfm_err_t pfm_get_impl_pmds(pfmlib_regmask_t *impl_pmds);
207 extern pfm_err_t pfm_get_impl_counters(pfmlib_regmask_t *impl_counters);
208 extern pfm_err_t pfm_get_num_pmds(unsigned int *num);
209 extern pfm_err_t pfm_get_num_pmcs(unsigned int *num);
210 extern pfm_err_t pfm_get_num_counters(unsigned int *num);
211
212 extern pfm_err_t pfm_get_hw_counter_width(unsigned int *width);
213 extern pfm_err_t pfm_get_version(unsigned int *version);
214 extern char *pfm_strerror(int code);
215 extern pfm_err_t pfm_get_cycle_event(pfmlib_event_t *e);
216 extern pfm_err_t pfm_get_inst_retired_event(pfmlib_event_t *e);
217
218 /*
219 * Supported PMU family
220 */
221 #define PFMLIB_NO_PMU -1 /* PMU unused (forced) */
222 #define PFMLIB_UNKNOWN_PMU 0 /* type not yet known (dynamic) */
223 #define PFMLIB_GEN_IA64_PMU 1 /* Intel IA-64 architected PMU */
224 #define PFMLIB_ITANIUM_PMU 2 /* Intel Itanium */
225 #define PFMLIB_ITANIUM2_PMU 3 /* Intel Itanium 2 */
226 #define PFMLIB_MONTECITO_PMU 4 /* Intel Dual-Core Itanium 2 9000 */
227 #define PFMLIB_AMD64_PMU 16 /* AMD AMD64 (K7, K8, Fam 10h) */
228 #define PFMLIB_GEN_IA32_PMU 63 /* Intel architectural PMU for X86 */
229 #define PFMLIB_I386_P6_PMU 32 /* Intel PIII (P6 core) */
230 #define PFMLIB_PENTIUM4_PMU 33 /* Intel Pentium4/Xeon/EM64T */
231 #define PFMLIB_COREDUO_PMU 34 /* Intel Core Duo/Core Solo */
232 #define PFMLIB_I386_PM_PMU 35 /* Intel Pentium M */
233 #define PFMLIB_CORE_PMU 36 /* obsolete, use PFMLIB_INTEL_CORE_PMU */
234 #define PFMLIB_INTEL_CORE_PMU 36 /* Intel Core */
235 #define PFMLIB_INTEL_PPRO_PMU 37 /* Intel Pentium Pro */
236 #define PFMLIB_INTEL_PII_PMU 38 /* Intel Pentium II */
237 #define PFMLIB_INTEL_ATOM_PMU 39 /* Intel Atom */
238 #define PFMLIB_INTEL_NHM_PMU 40 /* Intel Nehalem */
239 #define PFMLIB_INTEL_WSM_PMU 41 /* Intel Westmere */
240
241 #define PFMLIB_MIPS_20KC_PMU 64 /* MIPS 20KC */
242 #define PFMLIB_MIPS_24K_PMU 65 /* MIPS 24K */
243 #define PFMLIB_MIPS_25KF_PMU 66 /* MIPS 25KF */
244 #define PFMLIB_MIPS_34K_PMU 67 /* MIPS 34K */
245 #define PFMLIB_MIPS_5KC_PMU 68 /* MIPS 5KC */
246 #define PFMLIB_MIPS_74K_PMU 69 /* MIPS 74K */
247 #define PFMLIB_MIPS_R10000_PMU 70 /* MIPS R10000 */
248 #define PFMLIB_MIPS_R12000_PMU 71 /* MIPS R12000 */
249 #define PFMLIB_MIPS_RM7000_PMU 72 /* MIPS RM7000 */
250 #define PFMLIB_MIPS_RM9000_PMU 73 /* MIPS RM9000 */
251 #define PFMLIB_MIPS_SB1_PMU 74 /* MIPS SB1/SB1A */
252 #define PFMLIB_MIPS_VR5432_PMU 75 /* MIPS VR5432 */
253 #define PFMLIB_MIPS_VR5500_PMU 76 /* MIPS VR5500 */
254 #define PFMLIB_MIPS_ICE9A_PMU 77 /* SiCortex ICE9A */
255 #define PFMLIB_MIPS_ICE9B_PMU 78 /* SiCortex ICE9B */
256
257 #define PFMLIB_POWERPC_PMU 90 /* POWERPC */
258
259 #define PFMLIB_CRAYX2_PMU 96 /* Cray X2 */
260
261 #define PFMLIB_CELL_PMU 100 /* CELL */
262
263 #define PFMLIB_PPC970_PMU 110 /* IBM PowerPC 970(FX,GX) */
264 #define PFMLIB_PPC970MP_PMU 111 /* IBM PowerPC 970MP */
265 #define PFMLIB_POWER3_PMU 112 /* IBM POWER3 */
266 #define PFMLIB_POWER4_PMU 113 /* IBM POWER4 */
267 #define PFMLIB_POWER5_PMU 114 /* IBM POWER5 */
268 #define PFMLIB_POWER5p_PMU 115 /* IBM POWER5+ */
269 #define PFMLIB_POWER6_PMU 116 /* IBM POWER6 */
270 #define PFMLIB_POWER7_PMU 117 /* IBM POWER7 */
271
272 #define PFMLIB_SPARC_ULTRA12_PMU 130 /* UltraSPARC I, II, IIi, and IIe */
273 #define PFMLIB_SPARC_ULTRA3_PMU 131 /* UltraSPARC III */
274 #define PFMLIB_SPARC_ULTRA3I_PMU 132 /* UltraSPARC IIIi and IIIi+ */
275 #define PFMLIB_SPARC_ULTRA3PLUS_PMU 133 /* UltraSPARC III+ and IV */
276 #define PFMLIB_SPARC_ULTRA4PLUS_PMU 134 /* UltraSPARC IV+ */
277 #define PFMLIB_SPARC_NIAGARA1_PMU 135 /* Niagara-1 */
278 #define PFMLIB_SPARC_NIAGARA2_PMU 136 /* Niagara-2 */
279
280 /*
281 * pfmlib error codes
282 */
283 #define PFMLIB_SUCCESS 0 /* success */
284 #define PFMLIB_ERR_NOTSUPP -1 /* function not supported */
285 #define PFMLIB_ERR_INVAL -2 /* invalid parameters */
286 #define PFMLIB_ERR_NOINIT -3 /* library was not initialized */
287 #define PFMLIB_ERR_NOTFOUND -4 /* event not found */
288 #define PFMLIB_ERR_NOASSIGN -5 /* cannot assign events to counters */
289 #define PFMLIB_ERR_FULL -6 /* buffer is full or too small */
290 #define PFMLIB_ERR_EVTMANY -7 /* event used more than once */
291 #define PFMLIB_ERR_MAGIC -8 /* invalid library magic number */
292 #define PFMLIB_ERR_FEATCOMB -9 /* invalid combination of features */
293 #define PFMLIB_ERR_EVTSET -10 /* incompatible event sets */
294 #define PFMLIB_ERR_EVTINCOMP -11 /* incompatible event combination */
295 #define PFMLIB_ERR_TOOMANY -12 /* too many events or unit masks */
296
297 #define PFMLIB_ERR_IRRTOOBIG -13 /* code range too big */
298 #define PFMLIB_ERR_IRREMPTY -14 /* empty code range */
299 #define PFMLIB_ERR_IRRINVAL -15 /* invalid code range */
300 #define PFMLIB_ERR_IRRTOOMANY -16 /* too many code ranges */
301 #define PFMLIB_ERR_DRRINVAL -17 /* invalid data range */
302 #define PFMLIB_ERR_DRRTOOMANY -18 /* too many data ranges */
303 #define PFMLIB_ERR_BADHOST -19 /* not supported by host CPU */
304 #define PFMLIB_ERR_IRRALIGN -20 /* bad alignment for code range */
305 #define PFMLIB_ERR_IRRFLAGS -21 /* code range missing flags */
306 #define PFMLIB_ERR_UMASK -22 /* invalid or missing unit mask */
307 #define PFMLIB_ERR_NOMEM -23 /* out of memory */
308
309 #define __PFMLIB_REGMASK_EL(g) ((g)/__PFMLIB_REG_BV_BITS)
310 #define __PFMLIB_REGMASK_MASK(g) (((pfmlib_regmask_bits_t)1) << ((g) % __PFMLIB_REG_BV_BITS))
311
312 static inline int
313 pfm_regmask_isset(pfmlib_regmask_t *h, unsigned int b)
314 {
315 if (b >= PFMLIB_REG_MAX)
316 return 0;
317 return (h->bits[__PFMLIB_REGMASK_EL(b)] & __PFMLIB_REGMASK_MASK(b)) != 0;
318 }
319
320 static inline int
321 pfm_regmask_set(pfmlib_regmask_t *h, unsigned int b)
322 {
323 if (b >= PFMLIB_REG_MAX)
324 return PFMLIB_ERR_INVAL;
325
326 h->bits[__PFMLIB_REGMASK_EL(b)] |= __PFMLIB_REGMASK_MASK(b);
327
328 return PFMLIB_SUCCESS;
329 }
330
331 static inline int
332 pfm_regmask_clr(pfmlib_regmask_t *h, unsigned int b)
333 {
334 if (h == NULL || b >= PFMLIB_REG_MAX)
335 return PFMLIB_ERR_INVAL;
336
337 h->bits[__PFMLIB_REGMASK_EL(b)] &= ~ __PFMLIB_REGMASK_MASK(b);
338
339 return PFMLIB_SUCCESS;
340 }
341
342 static inline int
343 pfm_regmask_weight(pfmlib_regmask_t *h, unsigned int *w)
344 {
345 unsigned int pos;
346 unsigned int weight = 0;
347
348 if (h == NULL || w == NULL)
349 return PFMLIB_ERR_INVAL;
350
351 for (pos = 0; pos < PFMLIB_REG_BV; pos++) {
352 weight += (unsigned int)pfmlib_popcnt(h->bits[pos]);
353 }
354 *w = weight;
355 return PFMLIB_SUCCESS;
356 }
357
358 static inline int
359 pfm_regmask_eq(pfmlib_regmask_t *h1, pfmlib_regmask_t *h2)
360 {
361 unsigned int pos;
362
363 if (h1 == NULL || h2 == NULL)
364 return 0;
365
366 for (pos = 0; pos < PFMLIB_REG_BV; pos++) {
367 if (h1->bits[pos] != h2->bits[pos]) return 0;
368 }
369 return 1;
370 }
371
372 static inline int
373 pfm_regmask_and(pfmlib_regmask_t *dst, pfmlib_regmask_t *h1, pfmlib_regmask_t *h2)
374 {
375 unsigned int pos;
376 if (dst == NULL || h1 == NULL || h2 == NULL)
377 return PFMLIB_ERR_INVAL;
378
379 for (pos = 0; pos < PFMLIB_REG_BV; pos++) {
380 dst->bits[pos] = h1->bits[pos] & h2->bits[pos];
381 }
382 return PFMLIB_SUCCESS;
383 }
384
385 static inline int
386 pfm_regmask_andnot(pfmlib_regmask_t *dst, pfmlib_regmask_t *h1, pfmlib_regmask_t *h2)
387 {
388 unsigned int pos;
389 if (dst == NULL || h1 == NULL || h2 == NULL)
390 return PFMLIB_ERR_INVAL;
391
392 for (pos = 0; pos < PFMLIB_REG_BV; pos++) {
393 dst->bits[pos] = h1->bits[pos] & ~h2->bits[pos];
394 }
395 return PFMLIB_SUCCESS;
396 }
397
398 static inline int
399 pfm_regmask_or(pfmlib_regmask_t *dst, pfmlib_regmask_t *h1, pfmlib_regmask_t *h2)
400 {
401 unsigned int pos;
402 if (dst == NULL || h1 == NULL || h2 == NULL)
403 return PFMLIB_ERR_INVAL;
404
405 for (pos = 0; pos < PFMLIB_REG_BV; pos++) {
406 dst->bits[pos] = h1->bits[pos] | h2->bits[pos];
407 }
408 return PFMLIB_SUCCESS;
409 }
410
411 static inline int
412 pfm_regmask_copy(pfmlib_regmask_t *dst, pfmlib_regmask_t *src)
413 {
414 unsigned int pos;
415 if (dst == NULL || src == NULL)
416 return PFMLIB_ERR_INVAL;
417
418 for (pos = 0; pos < PFMLIB_REG_BV; pos++) {
419 dst->bits[pos] = src->bits[pos];
420 }
421 return PFMLIB_SUCCESS;
422 }
423 static inline int
424 pfm_regmask_not(pfmlib_regmask_t *dst)
425 {
426 unsigned int pos;
427 if (dst == NULL)
428 return PFMLIB_ERR_INVAL;
429
430 for (pos = 0; pos < PFMLIB_REG_BV; pos++) {
431 dst->bits[pos] = ~dst->bits[pos];
432 }
433 return PFMLIB_SUCCESS;
434 }
435
436 #ifdef __cplusplus /* extern C */
437 }
438 #endif
439
440 #endif /* __PFMLIB_H__ */