PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_libpfm_events.h File Reference
Include dependency graph for papi_libpfm_events.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  perf_event_attr
 

Macros

#define PERF_TYPE_RAW   4;
 

Functions

int _papi_libpfm_error (int pfm_error)
 
int _papi_libpfm_setup_presets (char *name, int type, int cidx)
 
int _papi_libpfm_ntv_enum_events (unsigned int *EventCode, int modifier)
 
int _papi_libpfm_ntv_name_to_code (const char *ntv_name, unsigned int *EventCode)
 
int _papi_libpfm_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int _papi_libpfm_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int _papi_libpfm_ntv_code_to_bits (unsigned int EventCode, hwd_register_t *bits)
 
int _papi_libpfm_ntv_code_to_bits_perfctr (unsigned int EventCode, hwd_register_t *bits)
 
int _papi_libpfm_shutdown (void)
 
int _papi_libpfm_init (papi_vector_t *my_vector, int cidx)
 
int _pfm_decode_native_event (unsigned int EventCode, unsigned int *event, unsigned int *umask)
 
unsigned int _pfm_convert_umask (unsigned int event, unsigned int umask)
 
int prepare_umask (unsigned int foo, unsigned int *values)
 
int _papi_libpfm_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 
int _papi_libpfm_setup_counters (struct perf_event_attr *attr, hwd_register_t *ni_bits)
 

Macro Definition Documentation

◆ PERF_TYPE_RAW

#define PERF_TYPE_RAW   4;

Definition at line 47 of file papi_libpfm_events.h.

Function Documentation

◆ _papi_libpfm_error()

int _papi_libpfm_error ( int  pfm_error)

Definition at line 149 of file papi_libpfm3_events.c.

150{
151 switch ( pfm_error ) {
152 case PFMLIB_SUCCESS: return PAPI_OK; /* success */
153 case PFMLIB_ERR_NOTSUPP: return PAPI_ENOSUPP; /* function not supported */
154 case PFMLIB_ERR_INVAL: return PAPI_EINVAL; /* invalid parameters */
155 case PFMLIB_ERR_NOINIT: return PAPI_ENOINIT; /* library was not initialized */
156 case PFMLIB_ERR_NOTFOUND: return PAPI_ENOEVNT; /* event not found */
157 case PFMLIB_ERR_NOASSIGN: return PAPI_ECNFLCT; /* cannot assign events to counters */
158 case PFMLIB_ERR_FULL: return PAPI_EBUF; /* buffer is full or too small */
159 case PFMLIB_ERR_EVTMANY: return PAPI_EMISC; /* event used more than once */
160 case PFMLIB_ERR_MAGIC: return PAPI_EBUG; /* invalid library magic number */
161 case PFMLIB_ERR_FEATCOMB: return PAPI_ECOMBO; /* invalid combination of features */
162 case PFMLIB_ERR_EVTSET: return PAPI_ENOEVST; /* incompatible event sets */
163 case PFMLIB_ERR_EVTINCOMP: return PAPI_ECNFLCT; /* incompatible event combination */
164 case PFMLIB_ERR_TOOMANY: return PAPI_ECOUNT; /* too many events or unit masks */
165 case PFMLIB_ERR_BADHOST: return PAPI_ESYS; /* not supported by host CPU */
166 case PFMLIB_ERR_UMASK: return PAPI_EATTR; /* invalid or missing unit mask */
167 case PFMLIB_ERR_NOMEM: return PAPI_ENOMEM; /* out of memory */
168
169 /* Itanium only */
170 case PFMLIB_ERR_IRRTOOBIG: /* code range too big */
171 case PFMLIB_ERR_IRREMPTY: /* empty code range */
172 case PFMLIB_ERR_IRRINVAL: /* invalid code range */
173 case PFMLIB_ERR_IRRTOOMANY: /* too many code ranges */
174 case PFMLIB_ERR_DRRINVAL: /* invalid data range */
175 case PFMLIB_ERR_DRRTOOMANY: /* too many data ranges */
176 case PFMLIB_ERR_IRRALIGN: /* bad alignment for code range */
177 case PFMLIB_ERR_IRRFLAGS: /* code range missing flags */
178 default:
179 return PAPI_EINVAL;
180 }
181}
#define PAPI_EBUG
Definition: f90papi.h:176
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ECNFLCT
Definition: f90papi.h:234
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_ECOMBO
Definition: f90papi.h:256
#define PAPI_ENOEVST
Definition: f90papi.h:95
#define PAPI_ECOUNT
Definition: f90papi.h:195
#define PAPI_EINVAL
Definition: f90papi.h:115
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_EMISC
Definition: f90papi.h:122
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_ENOMEM
Definition: f90papi.h:16
#define PAPI_ENOINIT
Definition: f90papi.h:160
#define PAPI_EATTR
Definition: f90papi.h:97
#define PAPI_EBUF
Definition: f90papi.h:253
#define PFMLIB_ERR_FEATCOMB
Definition: pfmlib.h:292
#define PFMLIB_ERR_BADHOST
Definition: pfmlib.h:303
#define PFMLIB_ERR_IRRALIGN
Definition: pfmlib.h:304
#define PFMLIB_ERR_MAGIC
Definition: pfmlib.h:291
#define PFMLIB_ERR_UMASK
Definition: pfmlib.h:306
#define PFMLIB_ERR_EVTSET
Definition: pfmlib.h:293
#define PFMLIB_SUCCESS
Definition: pfmlib.h:283
#define PFMLIB_ERR_EVTINCOMP
Definition: pfmlib.h:294
#define PFMLIB_ERR_NOMEM
Definition: pfmlib.h:307
#define PFMLIB_ERR_NOTFOUND
Definition: pfmlib.h:287
#define PFMLIB_ERR_DRRTOOMANY
Definition: pfmlib.h:302
#define PFMLIB_ERR_DRRINVAL
Definition: pfmlib.h:301
#define PFMLIB_ERR_INVAL
Definition: pfmlib.h:285
#define PFMLIB_ERR_TOOMANY
Definition: pfmlib.h:295
#define PFMLIB_ERR_IRRTOOBIG
Definition: pfmlib.h:297
#define PFMLIB_ERR_NOINIT
Definition: pfmlib.h:286
#define PFMLIB_ERR_IRRTOOMANY
Definition: pfmlib.h:300
#define PFMLIB_ERR_NOASSIGN
Definition: pfmlib.h:288
#define PFMLIB_ERR_IRREMPTY
Definition: pfmlib.h:298
#define PFMLIB_ERR_IRRINVAL
Definition: pfmlib.h:299
#define PFMLIB_ERR_IRRFLAGS
Definition: pfmlib.h:305
#define PFMLIB_ERR_NOTSUPP
Definition: pfmlib.h:284
#define PFMLIB_ERR_EVTMANY
Definition: pfmlib.h:290
#define PFMLIB_ERR_FULL
Definition: pfmlib.h:289
Here is the caller graph for this function:

◆ _papi_libpfm_init()

int _papi_libpfm_init ( papi_vector_t my_vector,
int  cidx 
)

Definition at line 442 of file papi_libpfm3_events.c.

442 {
443
444 int retval;
445 unsigned int ncnt;
446 unsigned int version;
447 char pmu_name[PAPI_MIN_STR_LEN];
448
449
450 /* The following checks the version of the PFM library
451 against the version PAPI linked to... */
452 SUBDBG( "pfm_initialize()\n" );
453 if ( ( retval = pfm_initialize( ) ) != PFMLIB_SUCCESS ) {
454 PAPIERROR( "pfm_initialize(): %s", pfm_strerror( retval ) );
455 return PAPI_ESYS;
456 }
457
458 /* Get the libpfm3 version */
459 SUBDBG( "pfm_get_version(%p)\n", &version );
461 PAPIERROR( "pfm_get_version(%p): %s", version, pfm_strerror( retval ) );
462 return PAPI_ESYS;
463 }
464
465 /* Set the version */
466 sprintf( my_vector->cmp_info.support_version, "%d.%d",
468
469 /* Complain if the compiled-against version doesn't match current version */
471 PAPIERROR( "Version mismatch of libpfm: compiled %#x vs. installed %#x\n",
474 return PAPI_ESYS;
475 }
476
477 /* Always initialize globals dynamically to handle forks properly. */
478
480
481 /* Opened once for all threads. */
482 SUBDBG( "pfm_get_pmu_type(%p)\n", &_perfmon2_pfm_pmu_type );
484 PAPIERROR( "pfm_get_pmu_type(%p): %s", _perfmon2_pfm_pmu_type,
485 pfm_strerror( retval ) );
486 return PAPI_ESYS;
487 }
488
489 pmu_name[0] = '\0';
490 if ( pfm_get_pmu_name( pmu_name, PAPI_MIN_STR_LEN ) != PFMLIB_SUCCESS ) {
491 PAPIERROR( "pfm_get_pmu_name(%p,%d): %s", pmu_name, PAPI_MIN_STR_LEN,
492 pfm_strerror( retval ) );
493 return PAPI_ESYS;
494 }
495 SUBDBG( "PMU is a %s, type %d\n", pmu_name, _perfmon2_pfm_pmu_type );
496
497 /* Setup presets */
499 if ( retval )
500 return retval;
501
502 /* Fill in cmp_info */
503
504 SUBDBG( "pfm_get_num_events(%p)\n", &ncnt );
505 if ( ( retval = pfm_get_num_events( &ncnt ) ) != PFMLIB_SUCCESS ) {
506 PAPIERROR( "pfm_get_num_events(%p): %s\n", &ncnt,
507 pfm_strerror( retval ) );
508 return PAPI_ESYS;
509 }
510 SUBDBG( "pfm_get_num_events: %d\n", ncnt );
511 my_vector->cmp_info.num_native_events = ncnt;
512 num_native_events = ncnt;
513
514 pfm_get_num_counters( ( unsigned int * ) &my_vector->cmp_info.num_cntrs );
515 SUBDBG( "pfm_get_num_counters: %d\n", my_vector->cmp_info.num_cntrs );
516
517
519 /* Pentium4 */
521 PAPI_NATIVE_EVENT_AND_MASK = 0x000000ff;
522 PAPI_NATIVE_UMASK_AND_MASK = 0x0fffff00;
524 /* Itanium2 */
525 } else if ( _papi_hwi_system_info.hw_info.cpuid_family == 31 ||
527 PAPI_NATIVE_EVENT_AND_MASK = 0x00000fff;
528 PAPI_NATIVE_UMASK_AND_MASK = 0x0ffff000;
530 }
531 }
532
533
534 return PAPI_OK;
535}
#define PAPI_MIN_STR_LEN
Definition: f90papi.h:208
#define PAPI_VENDOR_INTEL
Definition: f90papi.h:275
#define PFM_VERSION_MAJOR(x)
#define PFM_VERSION_MINOR(x)
uint8_t version
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
void PAPIERROR(char *format,...)
unsigned int PAPI_NATIVE_EVENT_AND_MASK
int _perfmon2_pfm_pmu_type
int num_native_events
unsigned int PAPI_NATIVE_UMASK_AND_MASK
unsigned int PAPI_NATIVE_UMASK_SHIFT
int _papi_load_preset_table(char *pmu_str, int pmu_type, int cidx)
Definition: papi_preset.c:771
static int cidx
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
#define PFMLIB_VERSION
Definition: pfmlib.h:34
pfm_err_t pfm_get_pmu_name(char *name, int maxlen)
char * pfm_strerror(int code)
pfm_err_t pfm_get_num_events(unsigned int *count)
pfm_err_t pfm_initialize(void)
pfm_err_t pfm_get_pmu_type(int *type)
pfm_err_t pfm_get_version(unsigned int *version)
pfm_err_t pfm_get_num_counters(unsigned int *num)
char support_version[PAPI_MIN_STR_LEN]
Definition: papi.h:632
int cpuid_family
Definition: papi.h:786
int vendor
Definition: papi.h:781
PAPI_hw_info_t hw_info
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_libpfm_ntv_code_to_bits()

int _papi_libpfm_ntv_code_to_bits ( unsigned int  EventCode,
hwd_register_t bits 
)

Definition at line 416 of file papi_libpfm3_events.c.

417{
418 unsigned int event, umask;
419 pfmlib_event_t gete;
420
421 /* For PFM & Perfmon, native info is just an index into PFM event table. */
422 if ( _pfm_decode_native_event( EventCode, &event, &umask ) != PAPI_OK )
423 return PAPI_ENOEVNT;
424
425 memset( &gete, 0x0, sizeof ( pfmlib_event_t ) );
426
427 gete.event = event;
428 gete.num_masks = prepare_umask( umask, gete.unit_masks );
429
430 memcpy( bits, &gete, sizeof ( pfmlib_event_t ) );
431
432 return PAPI_OK;
433
434}
int _pfm_decode_native_event(unsigned int EventCode, unsigned int *event, unsigned int *umask)
int prepare_umask(unsigned int foo, unsigned int *values)
unsigned int num_masks
Definition: pfmlib.h:90
unsigned int unit_masks[PFMLIB_MAX_MASKS_PER_EVENT]
Definition: pfmlib.h:89
unsigned int event
Definition: pfmlib.h:86
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_libpfm_ntv_code_to_bits_perfctr()

int _papi_libpfm_ntv_code_to_bits_perfctr ( unsigned int  EventCode,
hwd_register_t bits 
)

Definition at line 1015 of file perfctr-x86.c.

1017{
1018 unsigned int event, umask;
1019
1020 X86_register_t *bits = (X86_register_t *)newbits;
1021
1022 if ( is_pentium4() ) {
1023 pentium4_escr_value_t escr_value;
1024 pentium4_cccr_value_t cccr_value;
1025 unsigned int num_masks, replay_mask, unit_masks[12];
1026 unsigned int event_mask;
1027 unsigned int tag_value, tag_enable;
1028 unsigned int i;
1029 int j, escr, cccr, pmd;
1030
1031 if ( _pfm_decode_native_event( EventCode, &event, &umask ) != PAPI_OK )
1032 return PAPI_ENOEVNT;
1033
1034 /* for each allowed escr (1 or 2) find the allowed cccrs.
1035 for each allowed cccr find the pmd index
1036 convert to an intel counter number; or it into bits->counter */
1037 for ( i = 0; i < MAX_ESCRS_PER_EVENT; i++ ) {
1038 bits->counter[i] = 0;
1039 escr = pentium4_events[event].allowed_escrs[i];
1040 if ( escr < 0 ) {
1041 continue;
1042 }
1043
1044 bits->escr[i] = escr;
1045
1046 for ( j = 0; j < MAX_CCCRS_PER_ESCR; j++ ) {
1047 cccr = pentium4_escrs[escr].allowed_cccrs[j];
1048 if ( cccr < 0 ) {
1049 continue;
1050 }
1051
1052 pmd = pentium4_cccrs[cccr].pmd;
1053 bits->counter[i] |= ( 1 << pfm2intel[pmd] );
1054 }
1055 }
1056
1057 /* if there's only one valid escr, copy the values */
1058 if ( escr < 0 ) {
1059 bits->escr[1] = bits->escr[0];
1060 bits->counter[1] = bits->counter[0];
1061 }
1062
1063 /* Calculate the event-mask value. Invalid masks
1064 * specified by the caller are ignored. */
1065 tag_value = 0;
1066 tag_enable = 0;
1067 event_mask = _pfm_convert_umask( event, umask );
1068
1069 if ( event_mask & 0xF0000 ) {
1070 tag_enable = 1;
1071 tag_value = ( ( event_mask & 0xF0000 ) >> EVENT_MASK_BITS );
1072 }
1073
1074 event_mask &= 0x0FFFF; /* mask off possible tag bits */
1075
1076 /* Set up the ESCR and CCCR register values. */
1077 escr_value.val = 0;
1078 escr_value.bits.t1_usr = 0; /* controlled by kernel */
1079 escr_value.bits.t1_os = 0; /* controlled by kernel */
1080// escr_value.bits.t0_usr = (plm & PFM_PLM3) ? 1 : 0;
1081// escr_value.bits.t0_os = (plm & PFM_PLM0) ? 1 : 0;
1082 escr_value.bits.tag_enable = tag_enable;
1083 escr_value.bits.tag_value = tag_value;
1084 escr_value.bits.event_mask = event_mask;
1085 escr_value.bits.event_select = pentium4_events[event].event_select;
1086 escr_value.bits.reserved = 0;
1087
1088 /* initialize the proper bits in the cccr register */
1089 cccr_value.val = 0;
1090 cccr_value.bits.reserved1 = 0;
1091 cccr_value.bits.enable = 1;
1092 cccr_value.bits.escr_select = pentium4_events[event].escr_select;
1093 cccr_value.bits.active_thread = 3;
1094 /* FIXME: This is set to count when either logical
1095 * CPU is active. Need a way to distinguish
1096 * between logical CPUs when HT is enabled.
1097 * the docs say these bits should always
1098 * be set. */
1099 cccr_value.bits.compare = 0;
1100 /* FIXME: What do we do with "threshold" settings? */
1101 cccr_value.bits.complement = 0;
1102 /* FIXME: What do we do with "threshold" settings? */
1103 cccr_value.bits.threshold = 0;
1104 /* FIXME: What do we do with "threshold" settings? */
1105 cccr_value.bits.force_ovf = 0;
1106 /* FIXME: Do we want to allow "forcing" overflow
1107 * interrupts on all counter increments? */
1108 cccr_value.bits.ovf_pmi_t0 = 0;
1109 cccr_value.bits.ovf_pmi_t1 = 0;
1110 /* PMI taken care of by kernel typically */
1111 cccr_value.bits.reserved2 = 0;
1112 cccr_value.bits.cascade = 0;
1113 /* FIXME: How do we handle "cascading" counters? */
1114 cccr_value.bits.overflow = 0;
1115
1116 /* these flags are always zero, from what I can tell... */
1117 bits->pebs_enable = 0; /* flag for PEBS counting */
1118 bits->pebs_matrix_vert = 0;
1119 /* flag for PEBS_MATRIX_VERT, whatever that is */
1120
1121 /* ...unless the event is replay_event */
1122 if ( !strcmp( pentium4_events[event].name, "replay_event" ) ) {
1123 escr_value.bits.event_mask = event_mask & P4_REPLAY_REAL_MASK;
1124 num_masks = prepare_umask( umask, unit_masks );
1125 for ( i = 0; i < num_masks; i++ ) {
1126 replay_mask = unit_masks[i];
1127 if ( replay_mask > 1 && replay_mask < 11 ) {
1128 /* process each valid mask we find */
1129 bits->pebs_enable |= p4_replay_regs[replay_mask].enb;
1130 bits->pebs_matrix_vert |= p4_replay_regs[replay_mask].mat_vert;
1131 }
1132 }
1133 }
1134
1135 /* store the escr and cccr values */
1136 bits->event = escr_value.val;
1137 bits->cccr = cccr_value.val;
1138 bits->ireset = 0; /* I don't really know what this does */
1139 SUBDBG( "escr: 0x%lx; cccr: 0x%lx\n", escr_value.val, cccr_value.val );
1140 } else {
1141
1142 int ret, code;
1143
1144 if ( _pfm_decode_native_event( EventCode, &event, &umask ) != PAPI_OK )
1145 return PAPI_ENOEVNT;
1146
1147 if ( ( ret = _pfm_get_counter_info( event, &bits->selector,
1148 &code ) ) != PAPI_OK )
1149 return ret;
1150
1151 bits->counter_cmd=(int) (code | ((_pfm_convert_umask(event,umask))<< 8) );
1152
1153 SUBDBG( "selector: %#x\n", bits->selector );
1154 SUBDBG( "event: %#x; umask: %#x; code: %#x; cmd: %#x\n", event,
1155 umask, code, ( ( hwd_register_t * ) bits )->counter_cmd );
1156 }
1157
1158 return PAPI_OK;
1159}
int i
unsigned int _pfm_convert_umask(unsigned int event, unsigned int umask)
static int _pfm_get_counter_info(unsigned int event, unsigned int *selector, int *code)
Definition: perfctr-x86.c:970
#define P4_REPLAY_REAL_MASK
Definition: perfctr-x86.c:903
pentium4_escr_reg_t pentium4_escrs[]
static int is_pentium4(void)
Definition: perfctr-x86.c:75
pentium4_cccr_reg_t pentium4_cccrs[]
static int pfm2intel[]
Definition: perfctr-x86.c:958
pentium4_event_t pentium4_events[]
static pentium4_replay_regs_t p4_replay_regs[]
Definition: perfctr-x86.c:910
static int _pfm_decode_native_event(unsigned int EventCode, unsigned int *event, unsigned int *umask)
static int prepare_umask(unsigned int foo, unsigned int *values)
#define EVENT_MASK_BITS
#define MAX_CCCRS_PER_ESCR
#define MAX_ESCRS_PER_EVENT
const char * name
Definition: rocs.c:225
int
Definition: sde_internal.h:89
unsigned int selector
Definition: perfctr-x86.h:74
unsigned pebs_enable
Definition: perfctr-x86.h:81
unsigned ireset
Definition: perfctr-x86.h:83
unsigned counter[2]
Definition: perfctr-x86.h:77
unsigned event
Definition: perfctr-x86.h:80
unsigned pebs_matrix_vert
Definition: perfctr-x86.h:82
unsigned escr[2]
Definition: perfctr-x86.h:78
unsigned cccr
Definition: perfctr-x86.h:79
int allowed_cccrs[MAX_CCCRS_PER_ESCR]
int allowed_escrs[MAX_ESCRS_PER_EVENT]
unsigned long escr_select
unsigned long complement
unsigned long ovf_pmi_t0
unsigned long ovf_pmi_t1
unsigned long active_thread
struct pentium4_cccr_value_t::@86 bits
unsigned long tag_enable
unsigned long reserved
unsigned long event_select
struct pentium4_escr_value_t::@85 bits
unsigned long tag_value
unsigned long event_mask
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_libpfm_ntv_code_to_descr()

int _papi_libpfm_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 262 of file papi_libpfm3_events.c.

263{
264 unsigned int event, umask;
265 char *eventd, **maskd, *tmp;
266 int i, ret;
267 pfmlib_event_t gete;
268 size_t total_len = 0;
269
270 memset( &gete, 0, sizeof ( gete ) );
271
272 if ( _pfm_decode_native_event( EventCode, &event, &umask ) != PAPI_OK )
273 return ( PAPI_ENOEVNT );
274
275 ret = pfm_get_event_description( event, &eventd );
276 if ( ret != PFMLIB_SUCCESS ) {
277 PAPIERROR( "pfm_get_event_description(%d,%p): %s",
278 event, &eventd, pfm_strerror( ret ) );
279 return ( PAPI_ENOEVNT );
280 }
281
282 if ( ( gete.num_masks =
283 ( unsigned int ) prepare_umask( umask, gete.unit_masks ) ) ) {
284 maskd = ( char ** ) malloc( gete.num_masks * sizeof ( char * ) );
285 if ( maskd == NULL ) {
286 free( eventd );
287 return ( PAPI_ENOMEM );
288 }
289 for ( i = 0; i < ( int ) gete.num_masks; i++ ) {
290 ret =
292 &maskd[i] );
293 if ( ret != PFMLIB_SUCCESS ) {
294 PAPIERROR( "pfm_get_event_mask_description(%d,%d,%p): %s",
295 event, umask, &maskd, pfm_strerror( ret ) );
296 free( eventd );
297 for ( ; i >= 0; i-- )
298 free( maskd[i] );
299 free( maskd );
300 return ( PAPI_EINVAL );
301 }
302 total_len += strlen( maskd[i] );
303 }
304 tmp =
305 ( char * ) malloc( strlen( eventd ) + strlen( ", masks:" ) +
306 total_len + gete.num_masks + 1 );
307 if ( tmp == NULL ) {
308 for ( i = ( int ) gete.num_masks - 1; i >= 0; i-- )
309 free( maskd[i] );
310 free( maskd );
311 free( eventd );
312 }
313 tmp[0] = '\0';
314 strcat( tmp, eventd );
315 strcat( tmp, ", masks:" );
316 for ( i = 0; i < ( int ) gete.num_masks; i++ ) {
317 if ( i != 0 )
318 strcat( tmp, "," );
319 strcat( tmp, maskd[i] );
320 free( maskd[i] );
321 }
322 free( maskd );
323 } else {
324 tmp = ( char * ) malloc( strlen( eventd ) + 1 );
325 if ( tmp == NULL ) {
326 free( eventd );
327 return ( PAPI_ENOMEM );
328 }
329 tmp[0] = '\0';
330 strcat( tmp, eventd );
331 free( eventd );
332 }
333 strncpy( ntv_descr, tmp, ( size_t ) len );
334 if ( ( int ) strlen( tmp ) > len - 1 )
335 ret = PAPI_EBUF;
336 else
337 ret = PAPI_OK;
338 free( tmp );
339 return ( ret );
340}
double tmp
pfm_err_t pfm_get_event_mask_description(unsigned int event_idx, unsigned int mask_idx, char **desc)
pfm_err_t pfm_get_event_description(unsigned int idx, char **str)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_libpfm_ntv_code_to_info()

int _papi_libpfm_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

Definition at line 344 of file papi_libpfm3_events.c.

345{
346
347 SUBDBG("ENTER %#x\n",EventCode);
348
350 sizeof(info->symbol));
351
353 sizeof(info->long_descr));
354
355 return PAPI_OK;
356}
int _papi_libpfm_ntv_code_to_name(unsigned int EventCode, char *ntv_name, int len)
int _papi_libpfm_ntv_code_to_descr(unsigned int EventCode, char *ntv_descr, int len)
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
Here is the call graph for this function:

◆ _papi_libpfm_ntv_code_to_name()

int _papi_libpfm_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 225 of file papi_libpfm3_events.c.

226{
227 int ret;
228 unsigned int event, umask;
229 pfmlib_event_t gete;
230
231 memset( &gete, 0, sizeof ( gete ) );
232
233 if ( _pfm_decode_native_event( EventCode, &event, &umask ) != PAPI_OK )
234 return ( PAPI_ENOEVNT );
235
236 gete.event = event;
237 gete.num_masks = ( unsigned int ) prepare_umask( umask, gete.unit_masks );
238 if ( gete.num_masks == 0 )
239 ret = pfm_get_event_name( gete.event, ntv_name, ( size_t ) len );
240 else
241 ret = pfm_get_full_event_name( &gete, ntv_name, ( size_t ) len );
242 if ( ret != PFMLIB_SUCCESS ) {
244 pfm_get_event_name( gete.event, tmp, sizeof ( tmp ) );
245 /* Skip error message if event is not supported by host cpu;
246 * we don't need to give this info away for papi_native_avail util */
247 if ( ret != PFMLIB_ERR_BADHOST )
249 ( "pfm_get_full_event_name(%p(event %d,%s,%d masks),%p,%d): %d -- %s",
250 &gete, gete.event, tmp, gete.num_masks, ntv_name, len, ret,
251 pfm_strerror( ret ) );
252 if ( ret == PFMLIB_ERR_FULL ) {
253 return PAPI_EBUF;
254 }
255
256 return PAPI_EMISC;
257 }
258 return PAPI_OK;
259}
#define PAPI_2MAX_STR_LEN
Definition: f90papi.h:180
pfm_err_t pfm_get_full_event_name(pfmlib_event_t *e, char *name, size_t maxlen)
pfm_err_t pfm_get_event_name(unsigned int idx, char *name, size_t maxlen)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_libpfm_ntv_enum_events()

int _papi_libpfm_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

Definition at line 360 of file papi_libpfm3_events.c.

361{
362 unsigned int event, umask, num_masks;
363 int ret;
364
365 if ( modifier == PAPI_ENUM_FIRST ) {
366 *EventCode = PAPI_NATIVE_MASK; /* assumes first native event is always 0x4000000 */
367 return ( PAPI_OK );
368 }
369
370 if ( _pfm_decode_native_event( *EventCode, &event, &umask ) != PAPI_OK )
371 return ( PAPI_ENOEVNT );
372
373 ret = pfm_get_num_event_masks( event, &num_masks );
374 if ( ret != PFMLIB_SUCCESS ) {
375 PAPIERROR( "pfm_get_num_event_masks(%d,%p): %s", event, &num_masks,
376 pfm_strerror( ret ) );
377 return ( PAPI_ENOEVNT );
378 }
379 if ( num_masks > PAPI_NATIVE_UMASK_MAX )
380 num_masks = PAPI_NATIVE_UMASK_MAX;
381 SUBDBG( "This is umask %d of %d\n", umask, num_masks );
382
383 if ( modifier == PAPI_ENUM_EVENTS ) {
384 if ( event < ( unsigned int ) num_native_events - 1 ) {
385 *EventCode =
386 ( unsigned int ) encode_native_event_raw( event + 1, 0 );
387 return ( PAPI_OK );
388 }
389 return ( PAPI_ENOEVNT );
390 } else if ( modifier == PAPI_NTV_ENUM_UMASK_COMBOS ) {
391 if ( umask + 1 < ( unsigned int ) ( 1 << num_masks ) ) {
392 *EventCode =
393 ( unsigned int ) encode_native_event_raw( event, umask + 1 );
394 return ( PAPI_OK );
395 }
396 return ( PAPI_ENOEVNT );
397 } else if ( modifier == PAPI_NTV_ENUM_UMASKS ) {
398 int thisbit = ffs( ( int ) umask );
399
400 SUBDBG( "First bit is %d in %08x\b\n", thisbit - 1, umask );
401 thisbit = 1 << thisbit;
402
403 if ( thisbit & ( ( 1 << num_masks ) - 1 ) ) {
404 *EventCode =
405 ( unsigned int ) encode_native_event_raw( event,
406 ( unsigned int )
407 thisbit );
408 return ( PAPI_OK );
409 }
410 return ( PAPI_ENOEVNT );
411 } else
412 return ( PAPI_EINVAL );
413}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_NTV_ENUM_UMASK_COMBOS
Definition: f90papi.h:108
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NTV_ENUM_UMASKS
Definition: f90papi.h:66
#define PAPI_NATIVE_MASK
static int encode_native_event_raw(unsigned int event, unsigned int mask)
unsigned int PAPI_NATIVE_UMASK_MAX
pfm_err_t pfm_get_num_event_masks(unsigned int event_idx, unsigned int *count)
Here is the call graph for this function:

◆ _papi_libpfm_ntv_name_to_code()

int _papi_libpfm_ntv_name_to_code ( const char *  ntv_name,
unsigned int EventCode 
)

Definition at line 184 of file papi_libpfm3_events.c.

185{
186 pfmlib_event_t event;
187 unsigned int i;
188 int ret;
189
190 SUBDBG( "pfm_find_full_event(%s,%p)\n", name, &event );
191 ret = pfm_find_full_event( name, &event );
192 if ( ret == PFMLIB_SUCCESS ) {
193 SUBDBG( "Full event name found\n" );
194 /* we can only capture PAPI_NATIVE_UMASK_MAX or fewer masks */
195 if ( event.num_masks > PAPI_NATIVE_UMASK_MAX ) {
196 SUBDBG( "num_masks (%d) > max masks (%d)\n", event.num_masks,
198 return PAPI_ENOEVNT;
199 } else {
200 /* no mask index can exceed PAPI_NATIVE_UMASK_MAX */
201 for ( i = 0; i < event.num_masks; i++ ) {
202 if ( event.unit_masks[i] > PAPI_NATIVE_UMASK_MAX ) {
203 SUBDBG( "mask index (%d) > max masks (%d)\n",
205 return PAPI_ENOEVNT;
206 }
207 }
208 *event_code =
209 encode_native_event( event.event, event.num_masks,
210 event.unit_masks );
211 return PAPI_OK;
212 }
213 } else if ( ret == PFMLIB_ERR_UMASK ) {
214 SUBDBG( "UMASK error, looking for base event only\n" );
215 ret = pfm_find_event( name, &event.event );
216 if ( ret == PFMLIB_SUCCESS ) {
217 *event_code = encode_native_event( event.event, 0, 0 );
218 return PAPI_EATTR;
219 }
220 }
221 return PAPI_ENOEVNT;
222}
static int encode_native_event(unsigned int event, unsigned int num_mask, unsigned int *mask_values)
pfm_err_t pfm_find_full_event(const char *str, pfmlib_event_t *e)
pfm_err_t pfm_find_event(const char *str, unsigned int *idx)
Here is the call graph for this function:

◆ _papi_libpfm_setup_counters()

int _papi_libpfm_setup_counters ( struct perf_event_attr attr,
hwd_register_t ni_bits 
)

Definition at line 770 of file papi_libpfm3_events.c.

771 {
772
773 int ret,pe_event;
774 (void)ni_bits;
775
776 /*
777 * We need an event code that is common across all counters.
778 * The implementation is required to know how to translate the supplied
779 * code to whichever counter it ends up on.
780 */
781
782#if defined(__powerpc__)
783 int code;
784 ret = pfm_get_event_code_counter( ( ( pfm_register_t * ) ni_bits )->event, 0, &code );
785 if ( ret ) {
786 /* Unrecognized code, but should never happen */
787 return PAPI_EBUG;
788 }
789 pe_event = code;
790 SUBDBG( "Stuffing native event index (code %#x, raw code %#x) into events array.\n",
791 ( ( pfm_register_t * ) ni_bits )->event, code );
792#else
793
796
797 memset( &inp, 0, sizeof ( inp ) );
798 memset( &outp, 0, sizeof ( outp ) );
799 inp.pfp_event_count = 1;
801 pfm_regmask_set( &inp.pfp_unavail_pmcs, 16 ); // mark fixed counters as unavailable
802
803 inp.pfp_events[0] = *( ( pfm_register_t * ) ni_bits );
804 ret = pfm_dispatch_events( &inp, NULL, &outp, NULL );
805 if (ret != PFMLIB_SUCCESS) {
806 SUBDBG( "Error: pfm_dispatch_events returned: %d\n", ret);
807 return PAPI_ESYS;
808 }
809
810 /* Special case p4 */
813
814 pe_event=generate_p4_event( outp.pfp_pmcs[0].reg_value, /* escr */
815 outp.pfp_pmcs[1].reg_value, /* cccr */
816 outp.pfp_pmcs[0].reg_addr); /* escr_addr */
817 }
818 else {
819 pe_event = outp.pfp_pmcs[0].reg_value;
820 }
821 SUBDBG( "pe_event: %#llx\n", outp.pfp_pmcs[0].reg_value );
822#endif
823
824 attr->config=pe_event;
825
826 /* for libpfm3 we currently only handle RAW type */
827 attr->type=PERF_TYPE_RAW;
828
829 return PAPI_OK;
830}
#define PAPI_DOM_USER
Definition: f90papi.h:174
long long generate_p4_event(long long escr, long long cccr, long long escr_addr)
#define PERF_TYPE_RAW
pfm_err_t pfm_dispatch_events(pfmlib_input_param_t *p, void *model_in, pfmlib_output_param_t *q, void *model_out)
pfm_err_t pfm_get_event_code_counter(unsigned int idx, unsigned int cnt, int *code)
static int pfm_regmask_set(pfmlib_regmask_t *h, unsigned int b)
Definition: pfmlib.h:321
unsigned int pfp_dfl_plm
Definition: pfmlib.h:110
pfmlib_regmask_t pfp_unavail_pmcs
Definition: pfmlib.h:114
pfmlib_event_t pfp_events[PFMLIB_MAX_PMCS]
Definition: pfmlib.h:113
unsigned int pfp_event_count
Definition: pfmlib.h:109
pfmlib_reg_t pfp_pmcs[PFMLIB_MAX_PMCS]
Definition: pfmlib.h:129
unsigned long long reg_value
Definition: pfmlib.h:98
unsigned long long reg_addr
Definition: pfmlib.h:99
Here is the call graph for this function:

◆ _papi_libpfm_setup_presets()

int _papi_libpfm_setup_presets ( char *  name,
int  type,
int  cidx 
)

◆ _papi_libpfm_shutdown()

int _papi_libpfm_shutdown ( void  )

Definition at line 833 of file papi_libpfm3_events.c.

833 {
834
835 SUBDBG("shutdown\n");
836
837 return PAPI_OK;
838}

◆ _pfm_convert_umask()

unsigned int _pfm_convert_umask ( unsigned int  event,
unsigned int  umask 
)

Definition at line 137 of file papi_libpfm3_events.c.

138{
139 pfmlib_event_t gete;
140 memset( &gete, 0, sizeof ( gete ) );
141 gete.event = event;
142 gete.num_masks = ( unsigned int ) prepare_umask( umask, gete.unit_masks );
143 return ( convert_pfm_masks( &gete ) );
144}
static unsigned int convert_pfm_masks(pfmlib_event_t *gete)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _pfm_decode_native_event()

int _pfm_decode_native_event ( unsigned int  EventCode,
unsigned int event,
unsigned int umask 
)

Definition at line 79 of file papi_libpfm3_events.c.

81{
82 unsigned int tevent, major, minor;
83
84 tevent = EventCode & PAPI_NATIVE_AND_MASK;
86 if ( ( int ) major >= num_native_events )
87 return PAPI_ENOEVNT;
88
90 *event = major;
91 *umask = minor;
92 SUBDBG( "EventCode %#08x is event %d, umask %#x\n", EventCode, major,
93 minor );
94 return PAPI_OK;
95}
#define PAPI_NATIVE_AND_MASK
unsigned int PAPI_NATIVE_EVENT_SHIFT
Here is the caller graph for this function:

◆ prepare_umask()

int prepare_umask ( unsigned int  foo,
unsigned int values 
)

Definition at line 99 of file papi_libpfm3_events.c.

100{
101 unsigned int tmp = foo, i;
102 int j = 0;
103
104 SUBDBG( "umask %#x\n", tmp );
105 while ( ( i = ( unsigned int ) ffs( ( int ) tmp ) ) ) {
106 tmp = tmp ^ ( 1 << ( i - 1 ) );
107 values[j] = i - 1;
108 SUBDBG( "umask %d is %d\n", j, values[j] );
109 j++;
110 }
111 return ( j );
112}
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
Here is the caller graph for this function: