PAPI  5.3.0.0
pe_libpfm4_events.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int _pe_libpfm4_setup_presets (char *name, int type, int cidx)
int _pe_libpfm4_ntv_enum_events (unsigned int *EventCode, int modifier, struct native_event_table_t *event_table)
int _pe_libpfm4_ntv_name_to_code (char *ntv_name, unsigned int *EventCode, struct native_event_table_t *event_table)
int _pe_libpfm4_ntv_code_to_name (unsigned int EventCode, char *name, int len, struct native_event_table_t *event_table)
int _pe_libpfm4_ntv_code_to_descr (unsigned int EventCode, char *name, int len, struct native_event_table_t *event_table)
int _pe_libpfm4_shutdown (struct native_event_table_t *event_table)
int _pe_libpfm4_init (papi_vector_t *my_vector, int cidx, struct native_event_table_t *event_table, int pmu_type)
int _pe_libpfm4_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info, struct native_event_table_t *event_table)
int _pe_libpfm4_setup_counters (struct perf_event_attr *attr, int event, struct native_event_table_t *event_table)

Function Documentation

int _pe_libpfm4_init ( papi_vector_t my_vector,
int  cidx,
struct native_event_table_t event_table,
int  pmu_type 
)

Definition at line 1343 of file pe_libpfm4_events.c.

                         {

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

   /* allocate the native event structure */

   event_table->num_native_events=0;
   event_table->pmu_type=pmu_type;

   event_table->native_events=calloc(NATIVE_EVENT_CHUNK,
                       sizeof(struct native_event_t));
   if (event_table->native_events==NULL) {
      return PAPI_ENOMEM;
   }
   event_table->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(&(event_table->default_pmu), 0, sizeof(pfm_pmu_info_t));
   /* init default pmu */
   retval=pfm_get_pmu_info(0, &(event_table->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 (pmu_is_present_and_right_type(&pinfo,pmu_type)) {
     SUBDBG("\t%d %s %s %d\n",i,pinfo.name,pinfo.desc,pinfo.type);

         detected_pmus++;
     ncnt+=pinfo.nevents;
       
         if (pmu_type&PMU_TYPE_CORE) {

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

           SUBDBG("\t  %s is default\n",pinfo.name);
           memcpy(&(event_table->default_pmu),
              &pinfo,sizeof(pfm_pmu_info_t));
           found_default++;
        }
     }
         if (pmu_type==PMU_TYPE_UNCORE) {
         /* To avoid confusion, no "default" CPU for uncore */
           found_default=1;
     }
      }
   }
   SUBDBG("%d native events detected on %d pmus\n",ncnt,detected_pmus);

   if (!found_default) {
      SUBDBG("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 = event_table->default_pmu.num_cntrs+
                                   event_table->default_pmu.num_fixed_cntrs;

   SUBDBG( "num_counters: %d\n", my_vector->cmp_info.num_cntrs );
   
   /* Setup presets, only if Component 0 */
   if (cidx==0) {
      retval = _papi_load_preset_table( (char *)event_table->default_pmu.name, 
                     event_table->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 _pe_libpfm4_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len,
struct native_event_table_t event_table 
)

Definition at line 902 of file pe_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,event_table);
  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) {
    free( tmp );
    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 _pe_libpfm4_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info,
struct native_event_table_t event_table 
)

Definition at line 1106 of file pe_libpfm4_events.c.

{


  struct native_event_t *our_event;

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

  our_event=find_existing_event_by_number(EventCode,event_table);
  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;
  }

  _pe_libpfm4_ntv_code_to_descr(EventCode,info->long_descr,
                  sizeof(info->long_descr),event_table);

  return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _pe_libpfm4_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len,
struct native_event_table_t event_table 
)

Definition at line 855 of file pe_libpfm4_events.c.

{

        struct native_event_t *our_event;

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

        our_event=find_existing_event_by_number(EventCode,event_table);
    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:

Here is the caller graph for this function:

int _pe_libpfm4_ntv_enum_events ( unsigned int *  EventCode,
int  modifier,
struct native_event_table_t event_table 
)

Definition at line 1152 of file pe_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(event_table->pmu_type);
       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,event_table);

       *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,
                            event_table);
    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,event_table->pmu_type);
       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, event_table);
       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=_pe_libpfm4_ntv_name_to_code(new_name,&papi_event,
                         event_table);
          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:

Here is the caller graph for this function:

int _pe_libpfm4_ntv_name_to_code ( char *  ntv_name,
unsigned int *  EventCode,
struct native_event_table_t event_table 
)

Definition at line 788 of file pe_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,event_table);

  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=find_event(name, event_table->pmu_type);
     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,event_table);
     if (our_event==NULL) return PAPI_ENOEVNT;

     event_num=find_existing_event(name,event_table);
  }

  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 _pe_libpfm4_setup_counters ( struct perf_event_attr attr,
int  event,
struct native_event_table_t event_table 
)

Definition at line 1453 of file pe_libpfm4_events.c.

                                                            {

  struct native_event_t *our_event;

  our_event=find_existing_event_by_number(event,event_table);
  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 _pe_libpfm4_setup_presets ( char *  name,
int  type,
int  cidx 
)
int _pe_libpfm4_shutdown ( struct native_event_table_t event_table)

Definition at line 1302 of file pe_libpfm4_events.c.

                                                               {

  int i;

  APIDBG("Entry\n");

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

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

     memset(event_table->native_events,0,
     sizeof(struct native_event_t)*event_table->allocated_native_events);
     event_table->num_native_events=0;
     event_table->allocated_native_events=0;
     free(event_table->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