c7ea89
commit a5ecda79870b41f5b2ee21975f0f1c931114d258
c7ea89
Author: sangamesh <sragate@vols.utk.edu>
c7ea89
Date:   Thu Jun 11 17:48:36 2015 -0400
c7ea89
c7ea89
    Thanks to William Cohen for the patch which does the following:
c7ea89
    Checking the cpu family and module number is not sufficient to determine
c7ea89
    whether RAPL can be used.  If the papi is running inside a guest VM,
c7ea89
    the MSR used by the PAPI RAPL component may not be available.  There
c7ea89
    should be a simple read test to verify the RAPL MSR registers are
c7ea89
    available.  This allows the component to more clearly report that RAPL
c7ea89
    is unsupported rather than just exiting program when the RAPL
c7ea89
c7ea89
diff --git a/src/components/rapl/linux-rapl.c b/src/components/rapl/linux-rapl.c
c7ea89
index f0d376e..8dff3fe 100644
c7ea89
--- a/src/components/rapl/linux-rapl.c
c7ea89
+++ b/src/components/rapl/linux-rapl.c
c7ea89
@@ -447,6 +447,13 @@ _rapl_init_component( int cidx )
c7ea89
         return PAPI_ESYS;
c7ea89
      }
c7ea89
 
c7ea89
+     /* Verify needed MSR is readable. In a guest VM it may not be readable*/
c7ea89
+     if (pread(fd, &result, sizeof result, MSR_RAPL_POWER_UNIT) != sizeof result ) {
c7ea89
+        strncpy(_rapl_vector.cmp_info.disabled_reason,
c7ea89
+               "Unable to access RAPL registers",PAPI_MAX_STR_LEN);
c7ea89
+        return PAPI_ESYS;
c7ea89
+     }
c7ea89
+
c7ea89
      /* Calculate the units used */
c7ea89
      result=read_msr(fd,MSR_RAPL_POWER_UNIT);
c7ea89