|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* File: papi_libpfm4_events.c
|
|
Packit |
577717 |
* Author: Vince Weaver vincent.weaver @ maine.edu
|
|
Packit |
577717 |
* based heavily on existing papi_libpfm3_events.c
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <string.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_internal.h"
|
|
Packit |
577717 |
#include "papi_vector.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi_libpfm4_events.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "perfmon/pfmlib.h"
|
|
Packit |
577717 |
#include "perfmon/pfmlib_perf_event.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/**********************************************************/
|
|
Packit |
577717 |
/* Local scope globals */
|
|
Packit |
577717 |
/**********************************************************/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int libpfm4_users=0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/***********************************************************/
|
|
Packit |
577717 |
/* Exported functions */
|
|
Packit |
577717 |
/***********************************************************/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/** @class _papi_libpfm4_error
|
|
Packit |
577717 |
* @brief convert libpfm error codes to PAPI error codes
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* @param[in] pfm_error
|
|
Packit |
577717 |
* -- a libpfm4 error code
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* @returns returns a PAPI error code
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
_papi_libpfm4_error( int pfm_error ) {
|
|
Packit |
577717 |
|
|
Packit |
577717 |
switch ( pfm_error ) {
|
|
Packit |
577717 |
case PFM_SUCCESS: return PAPI_OK; /* success */
|
|
Packit |
577717 |
case PFM_ERR_NOTSUPP: return PAPI_ENOSUPP; /* function not supported */
|
|
Packit |
577717 |
case PFM_ERR_INVAL: return PAPI_EINVAL; /* invalid parameters */
|
|
Packit |
577717 |
case PFM_ERR_NOINIT: return PAPI_ENOINIT; /* library not initialized */
|
|
Packit |
577717 |
case PFM_ERR_NOTFOUND: return PAPI_ENOEVNT; /* event not found */
|
|
Packit |
577717 |
case PFM_ERR_FEATCOMB: return PAPI_ECOMBO; /* invalid combination of features */
|
|
Packit |
577717 |
case PFM_ERR_UMASK: return PAPI_EATTR; /* invalid or missing unit mask */
|
|
Packit |
577717 |
case PFM_ERR_NOMEM: return PAPI_ENOMEM; /* out of memory */
|
|
Packit |
577717 |
case PFM_ERR_ATTR: return PAPI_EATTR; /* invalid event attribute */
|
|
Packit |
577717 |
case PFM_ERR_ATTR_VAL: return PAPI_EATTR; /* invalid event attribute value */
|
|
Packit |
577717 |
case PFM_ERR_ATTR_SET: return PAPI_EATTR; /* attribute value already set */
|
|
Packit |
577717 |
case PFM_ERR_TOOMANY: return PAPI_ECOUNT; /* too many parameters */
|
|
Packit |
577717 |
case PFM_ERR_TOOSMALL: return PAPI_ECOUNT; /* parameter is too small */
|
|
Packit |
577717 |
default:
|
|
Packit |
577717 |
PAPIWARN("Unknown libpfm error code %d, returning PAPI_EINVAL",pfm_error);
|
|
Packit |
577717 |
return PAPI_EINVAL;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/** @class _papi_libpfm4_shutdown
|
|
Packit |
577717 |
* @brief Shutdown any initialization done by the libpfm4 code
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* @param[in] component
|
|
Packit |
577717 |
* -- component doing the shutdown
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* @retval PAPI_OK Success
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
_papi_libpfm4_shutdown(papi_vector_t *my_vector) {
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* clean out and free the native events structure */
|
|
Packit |
577717 |
_papi_hwi_lock( NAMELIB_LOCK );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
libpfm4_users--;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Only free if we're the last user */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!libpfm4_users) {
|
|
Packit |
577717 |
pfm_terminate();
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
_papi_hwi_unlock( NAMELIB_LOCK );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
strcpy(my_vector->cmp_info.support_version,"");
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return PAPI_OK;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/** @class _papi_libpfm4_init
|
|
Packit |
577717 |
* @brief Initialize the libpfm4 code
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* @param[in] my_vector
|
|
Packit |
577717 |
* -- vector of the component doing the initialization
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* @retval PAPI_OK Success
|
|
Packit |
577717 |
* @retval PAPI_ECMP There was an error initializing
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
_papi_libpfm4_init(papi_vector_t *my_vector) {
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int version;
|
|
Packit |
577717 |
pfm_err_t retval = PFM_SUCCESS;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
_papi_hwi_lock( NAMELIB_LOCK );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!libpfm4_users) {
|
|
Packit |
577717 |
retval = pfm_initialize();
|
|
Packit |
577717 |
if ( retval == PFM_SUCCESS ) {
|
|
Packit |
577717 |
libpfm4_users++;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
else {
|
|
Packit |
577717 |
strncpy(my_vector->cmp_info.disabled_reason,
|
|
Packit |
577717 |
pfm_strerror(retval),PAPI_MAX_STR_LEN);
|
|
Packit |
577717 |
_papi_hwi_unlock( NAMELIB_LOCK );
|
|
Packit |
577717 |
return PAPI_ESBSTR;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
else {
|
|
Packit |
577717 |
libpfm4_users++;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
_papi_hwi_unlock( NAMELIB_LOCK );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* get the libpfm4 version */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
version=pfm_get_version( );
|
|
Packit |
577717 |
if (version >= 0) {
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Complain if the compiled-against version */
|
|
Packit |
577717 |
/* doesn't match current version */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( PFM_MAJ_VERSION( version ) !=
|
|
Packit |
577717 |
PFM_MAJ_VERSION( LIBPFM_VERSION ) ) {
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPIWARN( "Version mismatch of libpfm: "
|
|
Packit |
577717 |
"compiled %#x vs. installed %#x\n",
|
|
Packit |
577717 |
PFM_MAJ_VERSION( LIBPFM_VERSION ),
|
|
Packit |
577717 |
PFM_MAJ_VERSION( version ) );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Set the version */
|
|
Packit |
577717 |
sprintf( my_vector->cmp_info.support_version, "%d.%d",
|
|
Packit |
577717 |
PFM_MAJ_VERSION( version ),
|
|
Packit |
577717 |
PFM_MIN_VERSION( version ) );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
PAPIWARN( "pfm_get_version(): %s", pfm_strerror( retval ) );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return PAPI_OK;
|
|
Packit |
577717 |
}
|