PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
papi_libpfm4_events.c
Go to the documentation of this file.
1 /*
2 * File: papi_libpfm4_events.c
3 * Author: Vince Weaver vincent.weaver @ maine.edu
4 * based heavily on existing papi_libpfm3_events.c
5 */
6 
7 #include <string.h>
8 
9 #include "papi.h"
10 #include "papi_internal.h"
11 #include "papi_vector.h"
12 
13 #include "papi_libpfm4_events.h"
14 
15 #include "perfmon/pfmlib.h"
16 #include "perfmon/pfmlib_perf_event.h"
17 
18 /**********************************************************/
19 /* Local scope globals */
20 /**********************************************************/
21 
22 static int libpfm4_users=0;
23 
24 /***********************************************************/
25 /* Exported functions */
26 /***********************************************************/
27 
38 int
39 _papi_libpfm4_error( int pfm_error ) {
40 
41  switch ( pfm_error ) {
42  case PFM_SUCCESS: return PAPI_OK; /* success */
43  case PFM_ERR_NOTSUPP: return PAPI_ENOSUPP; /* function not supported */
44  case PFM_ERR_INVAL: return PAPI_EINVAL; /* invalid parameters */
45  case PFM_ERR_NOINIT: return PAPI_ENOINIT; /* library not initialized */
46  case PFM_ERR_NOTFOUND: return PAPI_ENOEVNT; /* event not found */
47  case PFM_ERR_FEATCOMB: return PAPI_ECOMBO; /* invalid combination of features */
48  case PFM_ERR_UMASK: return PAPI_EATTR; /* invalid or missing unit mask */
49  case PFM_ERR_NOMEM: return PAPI_ENOMEM; /* out of memory */
50  case PFM_ERR_ATTR: return PAPI_EATTR; /* invalid event attribute */
51  case PFM_ERR_ATTR_VAL: return PAPI_EATTR; /* invalid event attribute value */
52  case PFM_ERR_ATTR_SET: return PAPI_EATTR; /* attribute value already set */
53  case PFM_ERR_TOOMANY: return PAPI_ECOUNT; /* too many parameters */
54  case PFM_ERR_TOOSMALL: return PAPI_ECOUNT; /* parameter is too small */
55  default:
56  PAPIWARN("Unknown libpfm error code %d, returning PAPI_EINVAL",pfm_error);
57  return PAPI_EINVAL;
58  }
59 }
60 
71 int
73 
74  /* clean out and free the native events structure */
76 
77  libpfm4_users--;
78 
79  /* Only free if we're the last user */
80 
81  if (!libpfm4_users) {
82  pfm_terminate();
83  }
84 
86 
87  strcpy(my_vector->cmp_info.support_version,"");
88 
89  return PAPI_OK;
90 }
91 
103 int
105 
106  int version;
107  pfm_err_t retval = PFM_SUCCESS;
108 
110 
111  if (!libpfm4_users) {
112  retval = pfm_initialize();
113  if ( retval == PFM_SUCCESS ) {
114  libpfm4_users++;
115  }
116  else {
117  strncpy(my_vector->cmp_info.disabled_reason,
118  pfm_strerror(retval),PAPI_MAX_STR_LEN);
120  return PAPI_ESBSTR;
121  }
122  }
123  else {
124  libpfm4_users++;
125  }
126 
128 
129  /* get the libpfm4 version */
130 
131  version=pfm_get_version( );
132  if (version >= 0) {
133 
134  /* Complain if the compiled-against version */
135  /* doesn't match current version */
136 
137  if ( PFM_MAJ_VERSION( version ) !=
138  PFM_MAJ_VERSION( LIBPFM_VERSION ) ) {
139 
140  PAPIWARN( "Version mismatch of libpfm: "
141  "compiled %#x vs. installed %#x\n",
142  PFM_MAJ_VERSION( LIBPFM_VERSION ),
143  PFM_MAJ_VERSION( version ) );
144 
145  }
146 
147  /* Set the version */
148  sprintf( my_vector->cmp_info.support_version, "%d.%d",
149  PFM_MAJ_VERSION( version ),
150  PFM_MIN_VERSION( version ) );
151 
152  } else {
153  PAPIWARN( "pfm_get_version(): %s", pfm_strerror( retval ) );
154  }
155 
156  return PAPI_OK;
157 }
#define PAPI_ENOEVNT
Definition: papi.h:260
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int _papi_libpfm4_init(papi_vector_t *my_vector)
void PAPIWARN(char *format,...)
#define PAPI_ENOSUPP
Definition: papi.h:271
return PAPI_OK
Definition: linux-nvml.c:497
return PAPI_EINVAL
Definition: linux-nvml.c:436
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
static int libpfm4_users
int _papi_libpfm4_error(int pfm_error)
Return codes and api definitions.
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:636
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
#define PAPI_EATTR
Definition: papi.h:275
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
int _papi_libpfm4_shutdown(papi_vector_t *my_vector)
char version[]
Definition: fileop.c:134
#define PAPI_ENOMEM
Definition: papi.h:254
#define NAMELIB_LOCK
Definition: papi_internal.h:94
strcpy(filename, default_filename)
char support_version[PAPI_MIN_STR_LEN]
Definition: papi.h:634
#define PAPI_ENOINIT
Definition: papi.h:269
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
#define PAPI_ECOMBO
Definition: papi.h:277
ssize_t retval
Definition: libasync.c:338
#define PAPI_ECOUNT
Definition: papi.h:276
#define PAPI_ESBSTR
Definition: papi.h:257