PAPI  5.3.0.0
papi_libpfm4_events.c
Go to the documentation of this file.
00001 /*
00002 * File:    papi_libpfm4_events.c
00003 * Author:  Vince Weaver vincent.weaver @ maine.edu
00004 *          based heavily on existing papi_libpfm3_events.c
00005 */
00006 
00007 #include <string.h>
00008 
00009 #include "papi.h"
00010 #include "papi_internal.h"
00011 #include "papi_vector.h"
00012 
00013 #include "papi_libpfm4_events.h"
00014 
00015 #include "perfmon/pfmlib.h"
00016 #include "perfmon/pfmlib_perf_event.h"
00017 
00018 /***********************************************************/
00019 /* Exported functions                                      */
00020 /***********************************************************/
00021 
00022 
00033 int
00034 _papi_libpfm4_error( int pfm_error ) {
00035 
00036   switch ( pfm_error ) {
00037   case PFM_SUCCESS:      return PAPI_OK;       /* success */
00038   case PFM_ERR_NOTSUPP:  return PAPI_ENOSUPP;  /* function not supported */
00039   case PFM_ERR_INVAL:    return PAPI_EINVAL;   /* invalid parameters */
00040   case PFM_ERR_NOINIT:   return PAPI_ENOINIT;  /* library not initialized */
00041   case PFM_ERR_NOTFOUND: return PAPI_ENOEVNT;  /* event not found */
00042   case PFM_ERR_FEATCOMB: return PAPI_ECOMBO;   /* invalid combination of features */
00043   case PFM_ERR_UMASK:    return PAPI_EATTR;    /* invalid or missing unit mask */
00044   case PFM_ERR_NOMEM:    return PAPI_ENOMEM;   /* out of memory */
00045   case PFM_ERR_ATTR:     return PAPI_EATTR;    /* invalid event attribute */
00046   case PFM_ERR_ATTR_VAL: return PAPI_EATTR;    /* invalid event attribute value */
00047   case PFM_ERR_ATTR_SET: return PAPI_EATTR;    /* attribute value already set */
00048   case PFM_ERR_TOOMANY:  return PAPI_ECOUNT;   /* too many parameters */
00049   case PFM_ERR_TOOSMALL: return PAPI_ECOUNT;   /* parameter is too small */
00050   default: return PAPI_EINVAL;
00051   }
00052 }
00053 
00054 static int libpfm4_users=0;
00055 
00063 int 
00064 _papi_libpfm4_shutdown(void) {
00065 
00066 
00067   APIDBG("Entry\n");
00068 
00069   /* clean out and free the native events structure */
00070   _papi_hwi_lock( NAMELIB_LOCK );
00071 
00072   libpfm4_users--;
00073 
00074   /* Only free if we're the last user */
00075 
00076   if (!libpfm4_users) {
00077      pfm_terminate();
00078   }
00079 
00080   _papi_hwi_unlock( NAMELIB_LOCK );
00081 
00082   return PAPI_OK;
00083 }
00084 
00096 int
00097 _papi_libpfm4_init(papi_vector_t *my_vector) {
00098 
00099    int version;
00100    pfm_err_t retval = PFM_SUCCESS;
00101 
00102    _papi_hwi_lock( NAMELIB_LOCK );
00103 
00104    if (!libpfm4_users) {
00105       retval = pfm_initialize();
00106       if ( retval != PFM_SUCCESS ) libpfm4_users--;
00107    }
00108    libpfm4_users++;
00109 
00110    _papi_hwi_unlock( NAMELIB_LOCK );
00111 
00112    if ( retval != PFM_SUCCESS ) {
00113       PAPIERROR( "pfm_initialize(): %s", pfm_strerror( retval ) );
00114       return PAPI_ESYS;
00115    }
00116 
00117    /* get the libpfm4 version */
00118    SUBDBG( "pfm_get_version()\n");
00119    if ( (version=pfm_get_version( )) < 0 ) {
00120       PAPIERROR( "pfm_get_version(): %s", pfm_strerror( retval ) );
00121       return PAPI_ESYS;
00122    }
00123 
00124    /* Set the version */
00125    sprintf( my_vector->cmp_info.support_version, "%d.%d",
00126         PFM_MAJ_VERSION( version ), PFM_MIN_VERSION( version ) );
00127 
00128    /* Complain if the compiled-against version doesn't match current version */
00129    if ( PFM_MAJ_VERSION( version ) != PFM_MAJ_VERSION( LIBPFM_VERSION ) ) {
00130       PAPIERROR( "Version mismatch of libpfm: compiled %#x vs. installed %#x\n",
00131                    PFM_MAJ_VERSION( LIBPFM_VERSION ),
00132                    PFM_MAJ_VERSION( version ) );
00133       return PAPI_ESYS;
00134    }
00135 
00136    return PAPI_OK;
00137 }
00138 
00139 
00140 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines