PAPI  5.0.1.0
papi_libpfm4_events.h File Reference
Include dependency graph for papi_libpfm4_events.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int _papi_libpfm4_error (int pfm_error)
int _papi_libpfm4_setup_presets (char *name, int type, int cidx)
int _papi_libpfm4_ntv_enum_events (unsigned int *EventCode, int modifier)
int _papi_libpfm4_ntv_name_to_code (char *ntv_name, unsigned int *EventCode)
int _papi_libpfm4_ntv_code_to_name (unsigned int EventCode, char *name, int len)
int _papi_libpfm4_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
int _papi_libpfm4_shutdown (void)
int _papi_libpfm4_init (papi_vector_t *my_vector, int cidx)
int _papi_libpfm4_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
int _papi_libpfm4_setup_counters (struct perf_event_attr *attr, int event)

Function Documentation

int _papi_libpfm4_error ( int  pfm_error)

< No error

< Not supported

< Invalid argument

< PAPI hasn't been initialized yet

< Event does not exist

< Bad combination of features

< Invalid or missing event attributes

< Insufficient memory

< Invalid or missing event attributes

< Invalid or missing event attributes

< Invalid or missing event attributes

< Too many events or attributes

< Too many events or attributes

< Invalid argument

Definition at line 732 of file papi_libpfm4_events.c.

                                     {

  switch ( pfm_error ) {
  case PFM_SUCCESS:      return PAPI_OK;       /* success */
  case PFM_ERR_NOTSUPP:  return PAPI_ENOSUPP;  /* function not supported */
  case PFM_ERR_INVAL:    return PAPI_EINVAL;   /* invalid parameters */
  case PFM_ERR_NOINIT:   return PAPI_ENOINIT;  /* library not initialized */
  case PFM_ERR_NOTFOUND: return PAPI_ENOEVNT;  /* event not found */
  case PFM_ERR_FEATCOMB: return PAPI_ECOMBO;   /* invalid combination of features */
  case PFM_ERR_UMASK:    return PAPI_EATTR;    /* invalid or missing unit mask */
  case PFM_ERR_NOMEM:    return PAPI_ENOMEM;   /* out of memory */
  case PFM_ERR_ATTR:     return PAPI_EATTR;    /* invalid event attribute */
  case PFM_ERR_ATTR_VAL: return PAPI_EATTR;    /* invalid event attribute value */
  case PFM_ERR_ATTR_SET: return PAPI_EATTR;    /* attribute value already set */
  case PFM_ERR_TOOMANY:  return PAPI_ECOUNT;   /* too many parameters */
  case PFM_ERR_TOOSMALL: return PAPI_ECOUNT;   /* parameter is too small */
  default: return PAPI_EINVAL;
  }
}

Here is the caller graph for this function:

int _papi_libpfm4_init ( papi_vector_t my_vector,
int  cidx 
)

< A System/C library call failed

< A System/C library call failed

< A System/C library call failed

< Insufficient memory

< Not supported by component

< Not supported by component

< No error

Definition at line 1294 of file papi_libpfm4_events.c.

                                                       {

   int detected_pmus=0, found_default=0;
   int i, version;
   pfm_err_t retval;
   unsigned int ncnt;
   pfm_pmu_info_t pinfo;

   /* The following checks the version of the PFM library
      against the version PAPI linked to... */
   if ( ( retval = pfm_initialize(  ) ) != PFM_SUCCESS ) {
      PAPIERROR( "pfm_initialize(): %s", pfm_strerror( retval ) );
      return PAPI_ESYS;
   }

   /* get the libpfm4 version */
   SUBDBG( "pfm_get_version()\n");
   if ( (version=pfm_get_version( )) < 0 ) {
      PAPIERROR( "pfm_get_version(): %s", pfm_strerror( retval ) );
      return PAPI_ESYS;
   }

   /* Set the version */
   sprintf( my_vector->cmp_info.support_version, "%d.%d",
        PFM_MAJ_VERSION( version ), PFM_MIN_VERSION( version ) );

   /* Complain if the compiled-against version doesn't match current version */
   if ( PFM_MAJ_VERSION( version ) != PFM_MAJ_VERSION( LIBPFM_VERSION ) ) {
      PAPIERROR( "Version mismatch of libpfm: compiled %x vs. installed %x\n",
                   PFM_MAJ_VERSION( LIBPFM_VERSION ),
                   PFM_MAJ_VERSION( version ) );
      return PAPI_ESYS;
   }

   /* allocate the native event structure */

   num_native_events=0;

   native_events=calloc(NATIVE_EVENT_CHUNK,sizeof(struct native_event_t));
   if (native_events==NULL) {
      return PAPI_ENOMEM;
   }
   allocated_native_events=NATIVE_EVENT_CHUNK;

   /* Count number of present PMUs */
   detected_pmus=0;
   ncnt=0;

   /* need to init pinfo or pfmlib might complain */
   memset(&default_pmu, 0, sizeof(pfm_pmu_info_t));
   /* init default pmu */
   retval=pfm_get_pmu_info(0, &default_pmu);
   
   SUBDBG("Detected pmus:\n");
   for(i=0;i<PFM_PMU_MAX;i++) {
      memset(&pinfo,0,sizeof(pfm_pmu_info_t));
      retval=pfm_get_pmu_info(i, &pinfo);
      if (retval!=PFM_SUCCESS) {
     continue;
      }
      if (pinfo.is_present) {
     SUBDBG("\t%d %s %s %d\n",i,pinfo.name,pinfo.desc,pinfo.type);

         detected_pmus++;
     ncnt+=pinfo.nevents;

     /* Choose default PMU */
     if ( (pinfo.type==PFM_PMU_TYPE_CORE) &&
              strcmp(pinfo.name,"ix86arch")) {

        SUBDBG("\t  %s is default\n",pinfo.name);
        memcpy(&default_pmu,&pinfo,sizeof(pfm_pmu_info_t));
        found_default++;
     }
      }
   }
   SUBDBG("%d native events detected on %d pmus\n",ncnt,detected_pmus);

   if (!found_default) {
      PAPIERROR("Could not find default PMU\n");
      return PAPI_ECMP;
   }

   if (found_default>1) {
     PAPIERROR("Found too many default PMUs!\n");
     return PAPI_ECMP;
   }

   my_vector->cmp_info.num_native_events = ncnt;

   my_vector->cmp_info.num_cntrs = default_pmu.num_cntrs+
                                  default_pmu.num_fixed_cntrs;

   SUBDBG( "num_counters: %d\n", my_vector->cmp_info.num_cntrs );
   
   /* Setup presets */
   retval = _papi_load_preset_table( (char *)default_pmu.name, 
                    default_pmu.pmu, cidx );
   if ( retval ) {
      return retval;
   }    

   return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

< Event does not exist

< Insufficient memory

< Invalid or missing event attributes

< Buffer size exceeded

< No error

Definition at line 871 of file papi_libpfm4_events.c.

{
  int ret,a,first_mask=1;
  char *eventd, *tmp=NULL;
  pfm_event_info_t gete;

  pfm_event_attr_info_t ainfo;
  char *b;
  char event_string[BUFSIZ],*ptr;
  char temp_string[BUFSIZ];

  struct native_event_t *our_event;

  SUBDBG("ENTER %x\n",EventCode);

  our_event=find_existing_event_by_number(EventCode);
  if (our_event==NULL) {
     return PAPI_ENOEVNT;
  }

  SUBDBG("Getting info on %x\n",our_event->libpfm4_idx);
    
  /* libpfm requires the structure be zeroed */
  memset( &gete, 0, sizeof ( gete ) );

  ret=pfm_get_event_info(our_event->libpfm4_idx, PFM_OS_PERF_EVENT, &gete);
  if (ret<0) {
     SUBDBG("Return=%d\n",ret);
     return _papi_libpfm4_error(ret);
  }

  eventd=strdup(gete.desc);

  tmp = ( char * ) malloc( strlen( eventd ) + 1 );
  if ( tmp == NULL ) {
     free( eventd );
     return PAPI_ENOMEM;
  }
    
  tmp[0] = '\0';
  strcat( tmp, eventd );
  free( eventd );
    
  /* Handle Umasks */

  /* attributes concactinated onto end of descr separated by ", masks" */
  /* then comma separated */

  strcpy(event_string,our_event->allocated_name);

  /* Point to first umask */

  /* Skip the pmu name :: if one exists */
  if (strstr(event_string,"::")) {
     ptr=strstr(event_string,"::");
     ptr+=2;
     b=strtok(ptr,":");
  }
  else {
     b=strtok(event_string,":");
  }
  
  /* if no umask, then done */
  if (!b) {
     SUBDBG("No colon!\n"); /* no umask */
     goto descr_in_tmp;
  }

  /* skip first */
  b=strtok(NULL,":");
  if (!b) {
     SUBDBG("Skipping first failed\n");
     goto descr_in_tmp;
  }

  /* loop through all umasks, seeing which match */
  while(b) {
    a=0;
    while(1) {

      SUBDBG("get_event_attr %x %p\n",our_event->libpfm4_idx,&ainfo);

      memset(&ainfo,0,sizeof(pfm_event_attr_info_t));

      ret = pfm_get_event_attr_info(our_event->libpfm4_idx, a, 
                    PFM_OS_PERF_EVENT, &ainfo);
      if (ret != PFM_SUCCESS) {
    SUBDBG("get_event_attr failed %s\n",pfm_strerror(ret));
    return _papi_libpfm4_error(ret);
      }

      /* Plain UMASK case */
      if (ainfo.type == PFM_ATTR_UMASK) {
   
         SUBDBG("Trying %s with %s\n",ainfo.name,b);

         if (!strcasecmp(ainfo.name, b)) {
        int new_length;

        SUBDBG("Found %s\n",b);
        new_length=strlen(ainfo.desc);

        if (first_mask) {
           tmp=realloc(tmp,strlen(tmp)+new_length+1+strlen(", masks:"));
           strcat(tmp,", masks:");
           first_mask=0;
        }
        else {
           tmp=realloc(tmp,strlen(tmp)+new_length+1+strlen(","));
           strcat(tmp,",");
        }
        strcat(tmp,ainfo.desc);

        goto found_attr;
     }
      }

      /* Boolean Case */
      if (ainfo.type == PFM_ATTR_MOD_BOOL) {
    
     sprintf(temp_string,"%s=0",ainfo.name);

         SUBDBG("Trying %s with %s\n",temp_string,b);

         if (!strcasecmp(temp_string, b)) {
        int new_length;

        SUBDBG("Found %s\n",b);
        new_length=strlen(ainfo.desc);

        if (first_mask) {
           tmp=realloc(tmp,strlen(tmp)+new_length+1+strlen(", masks:"));
           strcat(tmp,", masks:");
           first_mask=0;
        }
        else {
           tmp=realloc(tmp,strlen(tmp)+new_length+1+strlen(","));
           strcat(tmp,",");
        }
        strcat(tmp,ainfo.desc);

        goto found_attr;
     }
      }

      /* Integer Case */
      if (ainfo.type == PFM_ATTR_MOD_INTEGER) {

     sprintf(temp_string,"%s=0",ainfo.name);

         SUBDBG("Trying %s with %s\n",temp_string,b);

         if (!strcasecmp(temp_string, b)) {
        int new_length;

        SUBDBG("Found %s\n",b);
        new_length=strlen(ainfo.desc);

        if (first_mask) {
           tmp=realloc(tmp,strlen(tmp)+new_length+1+strlen(", masks:"));
           strcat(tmp,", masks:");
           first_mask=0;
        }
        else {
           tmp=realloc(tmp,strlen(tmp)+new_length+1+strlen(","));
           strcat(tmp,",");
        }
        strcat(tmp,ainfo.desc);

        goto found_attr;
     }
      }

      a++;
    }

    SUBDBG("attr=%s not found for event %s\n", b, ainfo.name);

    return PAPI_EATTR;

found_attr:

    b=strtok(NULL,":");
  }

  /* We are done and the description to copy is in tmp */
descr_in_tmp:
    strncpy( ntv_descr, tmp, ( size_t ) len );
    if ( ( int ) strlen( tmp ) > len - 1 )
        ret = PAPI_EBUF;
    else
        ret = PAPI_OK;
    free( tmp );

    SUBDBG("PFM4 Code: %x %s\n",EventCode,ntv_descr);

    return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_libpfm4_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

< Event does not exist

< Buffer size exceeded

< No error

Definition at line 1073 of file papi_libpfm4_events.c.

{


  struct native_event_t *our_event;

  SUBDBG("ENTER %x\n",EventCode);

  our_event=find_existing_event_by_number(EventCode);
  if (our_event==NULL) {
     return PAPI_ENOEVNT;
  }

  strncpy(info->symbol, our_event->allocated_name, sizeof(info->symbol));

  if (strlen(our_event->allocated_name) > sizeof(info->symbol)) {
     return PAPI_EBUF;
  }

  _papi_libpfm4_ntv_code_to_descr(EventCode,info->long_descr,
                 sizeof(info->long_descr));

  return PAPI_OK;
}

Here is the call graph for this function:

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

< Event does not exist

< Buffer size exceeded

< No error

Definition at line 828 of file papi_libpfm4_events.c.

{

        struct native_event_t *our_event;

        SUBDBG("ENTER %x\n",EventCode);

        our_event=find_existing_event_by_number(EventCode);
    if (our_event==NULL) {
      return PAPI_ENOEVNT;
    }

    strncpy(ntv_name,our_event->allocated_name,len);

    if (strlen(our_event->allocated_name) > (unsigned)len) {
       return PAPI_EBUF;
    }

    return PAPI_OK;
}

Here is the call graph for this function:

int _papi_libpfm4_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

< Event does not exist

< Not implemented

< No error

< Event does not exist

< No error

< Not implemented

Definition at line 1115 of file papi_libpfm4_events.c.

{
    int code,ret;
    struct native_event_t *current_event;

        SUBDBG("ENTER\n");

    /* return first event if so specified */
    if ( modifier == PAPI_ENUM_FIRST ) {

       unsigned int papi_event=0;

           SUBDBG("ENUM_FIRST\n");

       code=get_event_first_active();
       SUBDBG("ENUM_FIRST code: %d\n",code);
       if (code < 0 ) {
          return code;
       }

       /* convert the libpfm4 event to a PAPI event */
       ret=convert_pfmidx_to_native(code, &papi_event);

       *PapiEventCode=(unsigned int)papi_event;

           SUBDBG("FOUND %x (from %x) ret=%d\n",*PapiEventCode,code,ret);

       return ret;
    }

    /* If we get this far, we're looking for a        */
    /* next-event.  So gather info on the current one */
    current_event=find_existing_event_by_number(*PapiEventCode);
    if (current_event==NULL) {
           SUBDBG("EVENTS %x not found\n",*PapiEventCode);
       return PAPI_ENOEVNT;
    }


    /* Handle looking for the next event */

    if ( modifier == PAPI_ENUM_EVENTS ) {

       unsigned int papi_event=0;

       SUBDBG("PAPI_ENUM_EVENTS %x\n",*PapiEventCode);

       code=current_event->libpfm4_idx;

       ret=find_next_no_aliases(code);
       SUBDBG("find_next_no_aliases() Returned %x\n",ret);
       if (ret<0) {
          return ret;
       }

       /* Convert libpfm4 event code to PAPI event code */
       ret=convert_pfmidx_to_native(ret, &papi_event);
       if (ret<0) {
           SUBDBG("Couldn't convert to native %d %s\n",
              ret,PAPI_strerror(ret));
           return ret;
       }

       *PapiEventCode=(unsigned int)papi_event;

           SUBDBG("Returning PAPI_OK\n");

       return ret;
    }

    /* We don't handle PAPI_NTV_ENUM_UMASK_COMBOS */
    if ( modifier == PAPI_NTV_ENUM_UMASK_COMBOS ) {
       return PAPI_ENOIMPL;
    } 

    /* Enumerate PAPI_NTV_ENUM_UMASKS (umasks on an event) */
    if ( modifier == PAPI_NTV_ENUM_UMASKS ) {

       int max_umask,next_umask;
       char umask_string[BUFSIZ],new_name[BUFSIZ];

       SUBDBG("Finding maximum mask in event %s\n",
                  current_event->allocated_name);

       max_umask=find_max_umask(current_event);
       SUBDBG("Found max %d\n",max_umask);

       if (max_umask<0) {
          if (max_umask==PFM_ERR_UMASK) {
             max_umask=-1; /* needed for find_next_umask() to work */
                       /* indicates the event as passed had no */
                       /* umask in it.                         */
          }
          else {
             return _papi_libpfm4_error(max_umask);
          }
       }

       next_umask=find_next_umask(current_event,max_umask,
                      umask_string);

       SUBDBG("Found next %d\n",next_umask);

       if (next_umask>=0) {

          unsigned int papi_event;

          sprintf(new_name,"%s:%s",current_event->base_name,
             umask_string);
     
          SUBDBG("Found new name %s\n",new_name);

              ret=_papi_libpfm4_ntv_name_to_code(new_name,&papi_event);
          if (ret!=PAPI_OK) {
         return PAPI_ENOEVNT;
          }

          *PapiEventCode=(unsigned int)papi_event;
          SUBDBG("found code %x\n",*PapiEventCode);

          return PAPI_OK;
       }

       SUBDBG("couldn't find umask\n");

       return _papi_libpfm4_error(next_umask);

    }
    
    /* An unknown enumeration method was indicated */

    return PAPI_ENOIMPL;
}

Here is the call graph for this function:

int _papi_libpfm4_ntv_name_to_code ( char *  ntv_name,
unsigned int *  EventCode 
)

< Event does not exist

< No error

< Event does not exist

Definition at line 765 of file papi_libpfm4_events.c.

{

  int actual_idx;
  struct native_event_t *our_event;
  int event_num;

  SUBDBG( "Converting %s\n", name);

  event_num=find_existing_event(name);

  if (event_num<0) {

     /* event currently doesn't exist, so try to find it */
     /* using libpfm4                                    */

     SUBDBG("Using pfm to look up event %s\n",name);
     actual_idx=pfm_find_event(name);
     if (actual_idx<0) {
        return _papi_libpfm4_error(actual_idx);
     }

     SUBDBG("Using %x as the index\n",actual_idx);

     /* We were found in libpfm4, so allocate our copy of the event */

     our_event=allocate_native_event(name,actual_idx);
     if (our_event==NULL) return PAPI_ENOEVNT;

     event_num=find_existing_event(name);
  }

  if (event_num>=0) {      
     *event_code=event_num;
     SUBDBG("Found code: %x\n",*event_code);
     return PAPI_OK;
  }

  /* Failure here means allocate_native_event failed */

  SUBDBG("Event %s not found\n",name);

  return PAPI_ENOEVNT;   

}

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_libpfm4_setup_counters ( struct perf_event_attr attr,
int  event 
)

< Event does not exist

< No error

Definition at line 1413 of file papi_libpfm4_events.c.

                             {

  struct native_event_t *our_event;

  our_event=find_existing_event_by_number(event);
  if (our_event==NULL) {
     return PAPI_ENOEVNT;
  }

  attr->config=our_event->config; 
  attr->config1=our_event->config1;
  attr->config2=our_event->config2;
  attr->type=our_event->type;
  
  SUBDBG( "pe_event: config 0x%"PRIx64
          " config1 0x%"PRIx64
          " type 0x%"PRIx32"\n", 
          attr->config, 
      attr->config1,
      attr->type);
      

  return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_libpfm4_setup_presets ( char *  name,
int  type,
int  cidx 
)
int _papi_libpfm4_shutdown ( void  )

< Used with setting up array

< Used with setting up array

< No error

Definition at line 1257 of file papi_libpfm4_events.c.

                             {

  int i;

  SUBDBG("shutdown\n");

  /* clean out and free the native events structure */
  _papi_hwi_lock( NAMELIB_LOCK );

  /* free memory allocate with strdup */
  for( i=0; i<num_native_events; i++) {
     free(native_events[i].base_name);
     free(native_events[i].pmu_plus_name);
     free(native_events[i].pmu);
     free(native_events[i].allocated_name);
  }

  memset(native_events,0,
     sizeof(struct native_event_t)*allocated_native_events);
  num_native_events=0;
  allocated_native_events=0;
  free(native_events);
  _papi_hwi_unlock( NAMELIB_LOCK );

  return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines