Blame SOURCES/papi-avoid_libpfm_enum.patch

c7ea89
diff -up papi-5.2.0/src/components/perf_event/pe_libpfm4_events.c.orig papi-5.2.0/src/components/perf_event/pe_libpfm4_events.c
c7ea89
--- papi-5.2.0/src/components/perf_event/pe_libpfm4_events.c.orig	2013-08-06 12:12:20.000000000 -0400
c7ea89
+++ papi-5.2.0/src/components/perf_event/pe_libpfm4_events.c	2017-06-15 22:41:58.784904523 -0400
c7ea89
@@ -236,14 +236,15 @@ static int find_next_no_aliases(int code
c7ea89
         current_pmu++;
c7ea89
         SUBDBG("Incrementing PMU: %#x\n",current_pmu);
c7ea89
 
c7ea89
+        memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
+        ret = pfm_get_pmu_info(current_pmu, &pinfo);
c7ea89
+
c7ea89
 	/* Off the end, so done iterating */
c7ea89
-        if (current_pmu>PFM_PMU_MAX) {
c7ea89
+        if (ret==PFM_ERR_INVAL) {
c7ea89
            return PFM_ERR_NOTFOUND;
c7ea89
         }
c7ea89
  
c7ea89
-        memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
-        pfm_get_pmu_info(current_pmu, &pinfo);
c7ea89
-        if (pmu_is_present_and_right_type(&pinfo,pmu_type)) break;
c7ea89
+        if ((ret==PFM_SUCCESS) && pmu_is_present_and_right_type(&pinfo,pmu_type)) break;
c7ea89
      }
c7ea89
 
c7ea89
      current_event=pinfo.first_event;
c7ea89
@@ -533,12 +534,21 @@ get_event_first_active(int pmu_type)
c7ea89
 
c7ea89
   pmu_idx=0;
c7ea89
 
c7ea89
-  while(pmu_idx
c7ea89
+	/* We loop forever here and exit if pfm_get_pmu_info() fails.	*/
c7ea89
+	/* Before we only went up to PFM_PMU_MAX but this is set at	*/
c7ea89
+	/* compile time and might not reflect the number of PMUs if	*/
c7ea89
+	/* PAPI is dynamically linked against libpfm4.			*/
c7ea89
+
c7ea89
+  while(1) {
c7ea89
 
c7ea89
     /* clear the PMU structure (required by libpfm4) */
c7ea89
     memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
     ret=pfm_get_pmu_info(pmu_idx, &pinfo);
c7ea89
 
c7ea89
+    if (ret==PFM_ERR_INVAL) {
c7ea89
+	    break;
c7ea89
+    }
c7ea89
+
c7ea89
     if ((ret==PFM_SUCCESS) && pmu_is_present_and_right_type(&pinfo,pmu_type)) {
c7ea89
 
c7ea89
       pidx=pinfo.first_event;
c7ea89
@@ -1372,14 +1382,23 @@ _pe_libpfm4_init(papi_vector_t *my_vecto
c7ea89
    retval=pfm_get_pmu_info(0, &(event_table->default_pmu));
c7ea89
    
c7ea89
    SUBDBG("Detected pmus:\n");
c7ea89
-   for(i=0;i
c7ea89
+   i=0;
c7ea89
+   while(1) {
c7ea89
       memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
       retval=pfm_get_pmu_info(i, &pinfo);
c7ea89
-      if (retval!=PFM_SUCCESS) {
c7ea89
-	 continue;
c7ea89
+
c7ea89
+      /* We're done if we hit an invalid PMU entry			*/
c7ea89
+      /* We can't check against PFM_PMU_MAX				*/
c7ea89
+      /* as that might not match if libpfm4 is dynamically linked	*/
c7ea89
+
c7ea89
+      if (retval==PFM_ERR_INVAL) {
c7ea89
+	      break;
c7ea89
       }
c7ea89
 
c7ea89
-      if (pmu_is_present_and_right_type(&pinfo,pmu_type)) {
c7ea89
+      if ((retval==PFM_SUCCESS) && (pinfo.name != NULL) &&
c7ea89
+	(pmu_is_present_and_right_type(&pinfo,pmu_type))) {
c7ea89
+
c7ea89
+
c7ea89
 	 SUBDBG("\t%d %s %s %d\n",i,pinfo.name,pinfo.desc,pinfo.type);
c7ea89
 
c7ea89
          detected_pmus++;
c7ea89
@@ -1402,6 +1421,7 @@ _pe_libpfm4_init(papi_vector_t *my_vecto
c7ea89
 	       found_default=1;
c7ea89
 	 }
c7ea89
       }
c7ea89
+	i++;
c7ea89
    }
c7ea89
    SUBDBG("%d native events detected on %d pmus\n",ncnt,detected_pmus);
c7ea89
 
c7ea89
@@ -1421,7 +1441,7 @@ _pe_libpfm4_init(papi_vector_t *my_vecto
c7ea89
                                    event_table->default_pmu.num_fixed_cntrs;
c7ea89
 
c7ea89
    SUBDBG( "num_counters: %d\n", my_vector->cmp_info.num_cntrs );
c7ea89
-   
c7ea89
+
c7ea89
    /* Setup presets, only if Component 0 */
c7ea89
    if (cidx==0) {
c7ea89
       retval = _papi_load_preset_table( (char *)event_table->default_pmu.name, 
c7ea89
diff -up papi-5.2.0/src/components/perf_event_uncore/peu_libpfm4_events.c.orig papi-5.2.0/src/components/perf_event_uncore/peu_libpfm4_events.c
c7ea89
--- papi-5.2.0/src/components/perf_event_uncore/peu_libpfm4_events.c.orig	2013-08-06 12:12:20.000000000 -0400
c7ea89
+++ papi-5.2.0/src/components/perf_event_uncore/peu_libpfm4_events.c	2017-06-15 22:50:08.700238377 -0400
c7ea89
@@ -238,14 +238,15 @@ static int find_next_no_aliases(int code
c7ea89
         current_pmu++;
c7ea89
         SUBDBG("Incrementing PMU: %#x\n",current_pmu);
c7ea89
 
c7ea89
+        memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
+        ret=pfm_get_pmu_info(current_pmu, &pinfo);
c7ea89
+
c7ea89
 	/* Off the end, so done iterating */
c7ea89
-        if (current_pmu>PFM_PMU_MAX) {
c7ea89
+        if (ret==PFM_ERR_INVAL) {
c7ea89
            return PFM_ERR_NOTFOUND;
c7ea89
         }
c7ea89
  
c7ea89
-        memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
-        pfm_get_pmu_info(current_pmu, &pinfo);
c7ea89
-        if (pmu_is_present_and_right_type(&pinfo,pmu_type)) break;
c7ea89
+        if ((ret==PFM_SUCCESS) && pmu_is_present_and_right_type(&pinfo,pmu_type)) break;
c7ea89
      }
c7ea89
 
c7ea89
      current_event=pinfo.first_event;
c7ea89
@@ -531,12 +532,20 @@ get_event_first_active(int pmu_type)
c7ea89
 
c7ea89
   pmu_idx=0;
c7ea89
 
c7ea89
-  while(pmu_idx
c7ea89
+  /* We loop forever here and exit if pfm_get_pmu_info() fails.	*/
c7ea89
+  /* Before we only went up to PFM_PMU_MAX but this is set at	*/
c7ea89
+  /* compile time and might not reflect the number of PMUs if	*/
c7ea89
+  /* PAPI is dynamically linked against libpfm4.		*/
c7ea89
+  while(1) {
c7ea89
 
c7ea89
     /* clear the PMU structure (required by libpfm4) */
c7ea89
     memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
     ret=pfm_get_pmu_info(pmu_idx, &pinfo);
c7ea89
 
c7ea89
+    if (ret==PFM_ERR_INVAL) {
c7ea89
+	    break;
c7ea89
+    }
c7ea89
+
c7ea89
     if ((ret==PFM_SUCCESS) && pmu_is_present_and_right_type(&pinfo,pmu_type)) {
c7ea89
 
c7ea89
       pidx=pinfo.first_event;
c7ea89
@@ -1356,14 +1365,21 @@ _peu_libpfm4_init(papi_vector_t *my_vect
c7ea89
    my_vector->cmp_info.num_cntrs=0;
c7ea89
 
c7ea89
    SUBDBG("Detected pmus:\n");
c7ea89
-   for(i=0;i
c7ea89
+   i=0;
c7ea89
+   while(1) {
c7ea89
       memset(&pinfo,0,sizeof(pfm_pmu_info_t));
c7ea89
       retval=pfm_get_pmu_info(i, &pinfo);
c7ea89
-      if (retval!=PFM_SUCCESS) {
c7ea89
-	 continue;
c7ea89
+
c7ea89
+      /* We're done if we hit an invalid PMU entry                    */
c7ea89
+      /* We can't check against PFM_PMU_MAX                           */
c7ea89
+      /* as that might not match if libpfm4 is dynamically linked     */
c7ea89
+
c7ea89
+      if (retval==PFM_ERR_INVAL) {
c7ea89
+	      break;
c7ea89
       }
c7ea89
 
c7ea89
-      if (pmu_is_present_and_right_type(&pinfo,pmu_type)) {
c7ea89
+      if ((retval==PFM_SUCCESS) && (pinfo.name != NULL) &&
c7ea89
+	  (pmu_is_present_and_right_type(&pinfo,pmu_type))) {
c7ea89
 	 SUBDBG("\t%d %s %s %d\n",i,pinfo.name,pinfo.desc,pinfo.type);
c7ea89
 
c7ea89
          detected_pmus++;
c7ea89
@@ -1372,6 +1388,7 @@ _peu_libpfm4_init(papi_vector_t *my_vect
c7ea89
          my_vector->cmp_info.num_cntrs += pinfo.num_cntrs+
c7ea89
                                    pinfo.num_fixed_cntrs;
c7ea89
       }
c7ea89
+	i++;
c7ea89
    }
c7ea89
    SUBDBG("%d native events detected on %d pmus\n",ncnt,detected_pmus);
c7ea89