linux-rapl.c File Reference

rapl component More...

Include dependency graph for linux-rapl.c:

Go to the source code of this file.

Data Structures

struct  _rapl_register_t
struct  _rapl_native_event_entry_t
struct  _rapl_reg_alloc_t
struct  _rapl_control_state_t
struct  _rapl_context_t
struct  fd_array_t

Defines

#define MSR_RAPL_POWER_UNIT   0x606
#define MSR_PKG_RAPL_POWER_LIMIT   0x610
#define MSR_PKG_ENERGY_STATUS   0x611
#define MSR_PKG_PERF_STATUS   0x613
#define MSR_PKG_POWER_INFO   0x614
#define MSR_PP0_POWER_LIMIT   0x638
#define MSR_PP0_ENERGY_STATUS   0x639
#define MSR_PP0_POLICY   0x63A
#define MSR_PP0_PERF_STATUS   0x63B
#define MSR_PP1_POWER_LIMIT   0x640
#define MSR_PP1_ENERGY_STATUS   0x641
#define MSR_PP1_POLICY   0x642
#define MSR_DRAM_POWER_LIMIT   0x618
#define MSR_DRAM_ENERGY_STATUS   0x619
#define MSR_DRAM_PERF_STATUS   0x61B
#define MSR_DRAM_POWER_INFO   0x61C
#define POWER_UNIT_OFFSET   0
#define POWER_UNIT_MASK   0x0f
#define ENERGY_UNIT_OFFSET   0x08
#define ENERGY_UNIT_MASK   0x1f
#define TIME_UNIT_OFFSET   0x10
#define TIME_UNIT_MASK   0x0f
#define POWER_INFO_UNIT_MASK   0x7fff
#define THERMAL_SHIFT   0
#define MINIMUM_POWER_SHIFT   16
#define MAXIMUM_POWER_SHIFT   32
#define MAXIMUM_TIME_WINDOW_SHIFT   48
#define RAPL_MAX_COUNTERS   64
#define PACKAGE_ENERGY   0
#define PACKAGE_THERMAL   1
#define PACKAGE_MINIMUM   2
#define PACKAGE_MAXIMUM   3
#define PACKAGE_TIME_WINDOW   4
#define PACKAGE_ENERGY_CNT   5
#define PACKAGE_THERMAL_CNT   6
#define PACKAGE_MINIMUM_CNT   7
#define PACKAGE_MAXIMUM_CNT   8
#define PACKAGE_TIME_WINDOW_CNT   9
#define DRAM_ENERGY   10

Functions

static long long read_msr (int fd, int which)
static int open_fd (int offset)
static long long read_rapl_value (int index)
static long long convert_rapl_energy (int index, long long value)
static int get_kernel_nr_cpus (void)
int _rapl_init_thread (hwd_context_t *ctx)
int _rapl_init_component (int cidx)
int _rapl_init_control_state (hwd_control_state_t *ctl)
int _rapl_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _rapl_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _rapl_shutdown_thread (hwd_context_t *ctx)
int _rapl_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
int _rapl_shutdown_component (void)
int _rapl_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
int _rapl_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
int _rapl_set_domain (hwd_control_state_t *ctl, int domain)
int _rapl_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _rapl_ntv_enum_events (unsigned int *EventCode, int modifier)
int _rapl_ntv_code_to_name (unsigned int EventCode, char *name, int len)
int _rapl_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
int _rapl_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)

Variables

papi_vector_t _rapl_vector
static _rapl_native_event_entry_trapl_native_events = NULL
static int num_events = 0
struct fd_array_tfd_array = NULL
static int num_packages = 0
static int num_cpus = 0
int power_divisor
int time_divisor
int cpu_energy_divisor
int dram_energy_divisor

Detailed Description

Author:
Vince Weaver

This component enables RAPL (Running Average Power Level) energy measurements on Intel SandyBridge/IvyBridge/Haswell

To work, either msr_safe kernel module from LLNL (https://github.com/scalability-llnl/msr-safe), or the x86 generic MSR driver must be installed (CONFIG_X86_MSR) and the /dev/cpu/?/<msr_safe | msr> files must have read permissions

Definition in file linux-rapl.c.


Define Documentation

#define DRAM_ENERGY   10

Definition at line 150 of file linux-rapl.c.

#define ENERGY_UNIT_MASK   0x1f

Definition at line 71 of file linux-rapl.c.

#define ENERGY_UNIT_OFFSET   0x08

Definition at line 70 of file linux-rapl.c.

#define MAXIMUM_POWER_SHIFT   32

Definition at line 80 of file linux-rapl.c.

#define MAXIMUM_TIME_WINDOW_SHIFT   48

Definition at line 81 of file linux-rapl.c.

#define MINIMUM_POWER_SHIFT   16

Definition at line 79 of file linux-rapl.c.

#define MSR_DRAM_ENERGY_STATUS   0x619

Definition at line 62 of file linux-rapl.c.

#define MSR_DRAM_PERF_STATUS   0x61B

Definition at line 63 of file linux-rapl.c.

#define MSR_DRAM_POWER_INFO   0x61C

Definition at line 64 of file linux-rapl.c.

#define MSR_DRAM_POWER_LIMIT   0x618

Definition at line 61 of file linux-rapl.c.

#define MSR_PKG_ENERGY_STATUS   0x611

Definition at line 45 of file linux-rapl.c.

#define MSR_PKG_PERF_STATUS   0x613

Definition at line 46 of file linux-rapl.c.

#define MSR_PKG_POWER_INFO   0x614

Definition at line 47 of file linux-rapl.c.

#define MSR_PKG_RAPL_POWER_LIMIT   0x610

Definition at line 44 of file linux-rapl.c.

#define MSR_PP0_ENERGY_STATUS   0x639

Definition at line 51 of file linux-rapl.c.

#define MSR_PP0_PERF_STATUS   0x63B

Definition at line 53 of file linux-rapl.c.

#define MSR_PP0_POLICY   0x63A

Definition at line 52 of file linux-rapl.c.

#define MSR_PP0_POWER_LIMIT   0x638

Definition at line 50 of file linux-rapl.c.

#define MSR_PP1_ENERGY_STATUS   0x641

Definition at line 57 of file linux-rapl.c.

#define MSR_PP1_POLICY   0x642

Definition at line 58 of file linux-rapl.c.

#define MSR_PP1_POWER_LIMIT   0x640

Definition at line 56 of file linux-rapl.c.

#define MSR_RAPL_POWER_UNIT   0x606

Definition at line 41 of file linux-rapl.c.

#define PACKAGE_ENERGY   0

Definition at line 140 of file linux-rapl.c.

#define PACKAGE_ENERGY_CNT   5

Definition at line 145 of file linux-rapl.c.

#define PACKAGE_MAXIMUM   3

Definition at line 143 of file linux-rapl.c.

#define PACKAGE_MAXIMUM_CNT   8

Definition at line 148 of file linux-rapl.c.

#define PACKAGE_MINIMUM   2

Definition at line 142 of file linux-rapl.c.

#define PACKAGE_MINIMUM_CNT   7

Definition at line 147 of file linux-rapl.c.

#define PACKAGE_THERMAL   1

Definition at line 141 of file linux-rapl.c.

#define PACKAGE_THERMAL_CNT   6

Definition at line 146 of file linux-rapl.c.

#define PACKAGE_TIME_WINDOW   4

Definition at line 144 of file linux-rapl.c.

#define PACKAGE_TIME_WINDOW_CNT   9

Definition at line 149 of file linux-rapl.c.

#define POWER_INFO_UNIT_MASK   0x7fff

Definition at line 77 of file linux-rapl.c.

#define POWER_UNIT_MASK   0x0f

Definition at line 68 of file linux-rapl.c.

#define POWER_UNIT_OFFSET   0

Definition at line 67 of file linux-rapl.c.

#define RAPL_MAX_COUNTERS   64

Definition at line 107 of file linux-rapl.c.

#define THERMAL_SHIFT   0

Definition at line 78 of file linux-rapl.c.

#define TIME_UNIT_MASK   0x0f

Definition at line 74 of file linux-rapl.c.

#define TIME_UNIT_OFFSET   0x10

Definition at line 73 of file linux-rapl.c.


Function Documentation

int _rapl_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)

Definition at line 859 of file linux-rapl.c.

00860 {
00861     ( void ) ctx;
00862     ( void ) code;
00863     ( void ) option;
00864 
00865     return PAPI_OK;
00866 }

int _rapl_init_component ( int  cidx  ) 

Definition at line 299 of file linux-rapl.c.

00300 {
00301      int i,j,k,fd;
00302      FILE *fff;
00303      char filename[BUFSIZ];
00304 
00305      int package_avail, dram_avail, pp0_avail, pp1_avail;
00306 
00307      long long result;
00308      int package;
00309 
00310      const PAPI_hw_info_t *hw_info;
00311 
00312      int nr_cpus = get_kernel_nr_cpus();
00313      int packages[nr_cpus];
00314      int cpu_to_use[nr_cpus];
00315 
00316      /* Fill with sentinel values */
00317      for (i=0; i<nr_cpus; ++i) {
00318        packages[i] = -1;
00319        cpu_to_use[i] = -1;
00320      }
00321 
00322 
00323      /* check if Intel processor */
00324      hw_info=&(_papi_hwi_system_info.hw_info);
00325 
00326      /* Ugh can't use PAPI_get_hardware_info() if
00327     PAPI library not done initializing yet */
00328 
00329      if (hw_info->vendor!=PAPI_VENDOR_INTEL) {
00330         strncpy(_rapl_vector.cmp_info.disabled_reason,
00331         "Not an Intel processor",PAPI_MAX_STR_LEN);
00332         return PAPI_ENOSUPP;
00333      }
00334 
00335      /* check model to support */
00336      if (hw_info->cpuid_family==6) {
00337        if (hw_info->cpuid_model==42) {
00338       /* SandyBridge */
00339           package_avail=1;
00340           pp0_avail=1;
00341           pp1_avail=1;
00342           dram_avail=0;
00343        }
00344        else if (hw_info->cpuid_model==45) {
00345       /* SandyBridge-EP */
00346           package_avail=1;
00347           pp0_avail=1;
00348           pp1_avail=0;
00349           dram_avail=1;
00350        }
00351        else if (hw_info->cpuid_model==58) {
00352       /* IvyBridge */
00353           package_avail=1;
00354           pp0_avail=1;
00355           pp1_avail=1;
00356           dram_avail=0;
00357        }
00358        else if (hw_info->cpuid_model==62) {
00359       /* IvyBridge-EP */
00360           package_avail=1;
00361           pp0_avail=1;
00362           pp1_avail=0;
00363           dram_avail=1;
00364        }
00365        else if (hw_info->cpuid_model==60 || hw_info->cpuid_model==69 || hw_info->cpuid_model==70 ) {
00366         /* Haswell */
00367         package_avail=1;
00368         pp0_avail=1;
00369         pp1_avail=1;
00370         dram_avail=1;
00371        }
00372     else if ( hw_info->cpuid_model==63) {
00373         /* Haswell-EP */
00374         package_avail=1;
00375         pp0_avail=1;
00376         pp1_avail=0;
00377         dram_avail=1;
00378     }
00379     else if (hw_info->cpuid_model==61) {
00380         /* Broadwell */
00381         package_avail=1;
00382         pp0_avail=1;
00383         pp1_avail=0;
00384         dram_avail=1;
00385     }
00386        else {
00387      /* not a supported model */
00388      strncpy(_rapl_vector.cmp_info.disabled_reason,
00389          "CPU model not supported",
00390          PAPI_MAX_STR_LEN);
00391      return PAPI_ENOIMPL;
00392        }
00393      }
00394      else {
00395        /* Not a family 6 machine */
00396        strncpy(_rapl_vector.cmp_info.disabled_reason,
00397            "CPU family not supported",PAPI_MAX_STR_LEN);
00398        return PAPI_ENOIMPL;
00399      }
00400 
00401 
00402      /* Detect how many packages */
00403      j=0;
00404      while(1) {
00405        int num_read;
00406 
00407        sprintf(filename,
00408            "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",j);
00409        fff=fopen(filename,"r");
00410        if (fff==NULL) break;
00411        num_read=fscanf(fff,"%d",&package);
00412        fclose(fff);
00413        if (num_read!=1) {
00414              strcpy(_rapl_vector.cmp_info.disabled_reason, "Error reading file: ");
00415              strncat(_rapl_vector.cmp_info.disabled_reason, filename, PAPI_MAX_STR_LEN - strlen(_rapl_vector.cmp_info.disabled_reason) - 1);
00416              _rapl_vector.cmp_info.disabled_reason[PAPI_MAX_STR_LEN-1] = '\0';
00417              return PAPI_ESYS;
00418        }
00419 
00420        /* Check if a new package */
00421        if ((package >= 0) && (package < nr_cpus)) {
00422          if (packages[package] == -1) {
00423            SUBDBG("Found package %d out of total %d\n",package,num_packages);
00424        packages[package]=package;
00425        cpu_to_use[package]=j;
00426        num_packages++;
00427          }
00428        } else {
00429      SUBDBG("Package outside of allowed range\n");
00430      strncpy(_rapl_vector.cmp_info.disabled_reason,
00431         "Package outside of allowed range",PAPI_MAX_STR_LEN);
00432      return PAPI_ESYS;
00433        }
00434 
00435        j++;
00436      }
00437      num_cpus=j;
00438 
00439      if (num_packages==0) {
00440         SUBDBG("Can't access /dev/cpu/*/<msr_safe | msr>\n");
00441     strncpy(_rapl_vector.cmp_info.disabled_reason,
00442         "Can't access /dev/cpu/*/<msr_safe | msr>",PAPI_MAX_STR_LEN);
00443     return PAPI_ESYS;
00444      }
00445 
00446      SUBDBG("Found %d packages with %d cpus\n",num_packages,num_cpus);
00447 
00448      /* Init fd_array */
00449 
00450      fd_array=papi_calloc(sizeof(struct fd_array_t),num_cpus);
00451      if (fd_array==NULL) return PAPI_ENOMEM;
00452 
00453      fd=open_fd(cpu_to_use[0]);
00454      if (fd<0) {
00455         sprintf(_rapl_vector.cmp_info.disabled_reason,
00456         "Can't open fd for cpu0: %s",strerror(errno));
00457         return PAPI_ESYS;
00458      }
00459 
00460      /* Verify needed MSR is readable. In a guest VM it may not be readable*/
00461      if (pread(fd, &result, sizeof result, MSR_RAPL_POWER_UNIT) != sizeof result ) {
00462         strncpy(_rapl_vector.cmp_info.disabled_reason,
00463                "Unable to access RAPL registers",PAPI_MAX_STR_LEN);
00464         return PAPI_ESYS;
00465      }
00466 
00467      /* Calculate the units used */
00468      result=read_msr(fd,MSR_RAPL_POWER_UNIT);
00469 
00470      /* units are 0.5^UNIT_VALUE */
00471      /* which is the same as 1/(2^UNIT_VALUE) */
00472 
00473      power_divisor=1<<((result>>POWER_UNIT_OFFSET)&POWER_UNIT_MASK);
00474      cpu_energy_divisor=1<<((result>>ENERGY_UNIT_OFFSET)&ENERGY_UNIT_MASK);
00475      time_divisor=1<<((result>>TIME_UNIT_OFFSET)&TIME_UNIT_MASK);
00476 
00477     /* Note! On Haswell-EP DRAM energy is fixed at 15.3uJ   */
00478     /* see https://lkml.org/lkml/2015/3/20/582      */
00479     if ( hw_info->cpuid_model==63) {
00480         dram_energy_divisor=1<<16;
00481     }
00482     else {
00483         dram_energy_divisor=cpu_energy_divisor;
00484     }
00485 
00486      SUBDBG("Power units = %.3fW\n",1.0/power_divisor);
00487      SUBDBG("CPU Energy units = %.8fJ\n",1.0/cpu_energy_divisor);
00488      SUBDBG("DRAM Energy units = %.8fJ\n",1.0/dram_energy_divisor);
00489      SUBDBG("Time units = %.8fs\n",1.0/time_divisor);
00490 
00491      /* Allocate space for events */
00492      /* Include room for both counts and scaled values */
00493 
00494      num_events= ((package_avail*num_packages) +
00495                  (pp0_avail*num_packages) +
00496                  (pp1_avail*num_packages) +
00497                  (dram_avail*num_packages) +
00498                  (4*num_packages)) * 2;
00499 
00500      rapl_native_events = (_rapl_native_event_entry_t*)
00501           papi_calloc(sizeof(_rapl_native_event_entry_t),num_events);
00502 
00503 
00504      i = 0;
00505      k = num_events/2;
00506 
00507      /* Create events for package power info */
00508 
00509      for(j=0;j<num_packages;j++) {
00510         sprintf(rapl_native_events[i].name,
00511             "THERMAL_SPEC_CNT:PACKAGE%d",j);
00512         sprintf(rapl_native_events[i].description,
00513            "Thermal specification in counts; package %d",j);
00514         rapl_native_events[i].fd_offset=cpu_to_use[j];
00515         rapl_native_events[i].msr=MSR_PKG_POWER_INFO;
00516         rapl_native_events[i].resources.selector = i + 1;
00517         rapl_native_events[i].type=PACKAGE_THERMAL_CNT;
00518         rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00519 
00520         sprintf(rapl_native_events[k].name,
00521             "THERMAL_SPEC:PACKAGE%d",j);
00522         strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
00523         sprintf(rapl_native_events[k].description,
00524            "Thermal specification for package %d",j);
00525         rapl_native_events[k].fd_offset=cpu_to_use[j];
00526         rapl_native_events[k].msr=MSR_PKG_POWER_INFO;
00527         rapl_native_events[k].resources.selector = k + 1;
00528         rapl_native_events[k].type=PACKAGE_THERMAL;
00529         rapl_native_events[k].return_type=PAPI_DATATYPE_FP64;
00530 
00531         i++;
00532         k++;
00533      }
00534 
00535      for(j=0;j<num_packages;j++) {
00536         sprintf(rapl_native_events[i].name,
00537             "MINIMUM_POWER_CNT:PACKAGE%d",j);
00538         sprintf(rapl_native_events[i].description,
00539            "Minimum power in counts; package %d",j);
00540         rapl_native_events[i].fd_offset=cpu_to_use[j];
00541         rapl_native_events[i].msr=MSR_PKG_POWER_INFO;
00542         rapl_native_events[i].resources.selector = i + 1;
00543         rapl_native_events[i].type=PACKAGE_MINIMUM_CNT;
00544         rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00545 
00546         sprintf(rapl_native_events[k].name,
00547             "MINIMUM_POWER:PACKAGE%d",j);
00548         strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
00549         sprintf(rapl_native_events[k].description,
00550            "Minimum power for package %d",j);
00551         rapl_native_events[k].fd_offset=cpu_to_use[j];
00552         rapl_native_events[k].msr=MSR_PKG_POWER_INFO;
00553         rapl_native_events[k].resources.selector = k + 1;
00554         rapl_native_events[k].type=PACKAGE_MINIMUM;
00555         rapl_native_events[k].return_type=PAPI_DATATYPE_FP64;
00556 
00557         i++;
00558         k++;
00559      }
00560 
00561      for(j=0;j<num_packages;j++) {
00562         sprintf(rapl_native_events[i].name,
00563             "MAXIMUM_POWER_CNT:PACKAGE%d",j);
00564         sprintf(rapl_native_events[i].description,
00565            "Maximum power in counts; package %d",j);
00566         rapl_native_events[i].fd_offset=cpu_to_use[j];
00567         rapl_native_events[i].msr=MSR_PKG_POWER_INFO;
00568         rapl_native_events[i].resources.selector = i + 1;
00569         rapl_native_events[i].type=PACKAGE_MAXIMUM_CNT;
00570         rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00571 
00572         sprintf(rapl_native_events[k].name,
00573             "MAXIMUM_POWER:PACKAGE%d",j);
00574         strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
00575         sprintf(rapl_native_events[k].description,
00576            "Maximum power for package %d",j);
00577         rapl_native_events[k].fd_offset=cpu_to_use[j];
00578         rapl_native_events[k].msr=MSR_PKG_POWER_INFO;
00579         rapl_native_events[k].resources.selector = k + 1;
00580         rapl_native_events[k].type=PACKAGE_MAXIMUM;
00581         rapl_native_events[k].return_type=PAPI_DATATYPE_FP64;
00582 
00583         i++;
00584         k++;
00585      }
00586 
00587      for(j=0;j<num_packages;j++) {
00588         sprintf(rapl_native_events[i].name,
00589             "MAXIMUM_TIME_WINDOW_CNT:PACKAGE%d",j);
00590         sprintf(rapl_native_events[i].description,
00591            "Maximum time window in counts; package %d",j);
00592         rapl_native_events[i].fd_offset=cpu_to_use[j];
00593         rapl_native_events[i].msr=MSR_PKG_POWER_INFO;
00594         rapl_native_events[i].resources.selector = i + 1;
00595         rapl_native_events[i].type=PACKAGE_TIME_WINDOW_CNT;
00596         rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00597 
00598         sprintf(rapl_native_events[k].name,
00599             "MAXIMUM_TIME_WINDOW:PACKAGE%d",j);
00600         strncpy(rapl_native_events[k].units,"s",PAPI_MIN_STR_LEN);
00601         sprintf(rapl_native_events[k].description,
00602            "Maximum time window for package %d",j);
00603         rapl_native_events[k].fd_offset=cpu_to_use[j];
00604         rapl_native_events[k].msr=MSR_PKG_POWER_INFO;
00605         rapl_native_events[k].resources.selector = k + 1;
00606         rapl_native_events[k].type=PACKAGE_TIME_WINDOW;
00607         rapl_native_events[k].return_type=PAPI_DATATYPE_FP64;
00608 
00609         i++;
00610         k++;
00611      }
00612 
00613      /* Create Events for energy measurements */
00614 
00615      if (package_avail) {
00616         for(j=0;j<num_packages;j++) {
00617             sprintf(rapl_native_events[i].name,
00618                 "PACKAGE_ENERGY_CNT:PACKAGE%d",j);
00619             sprintf(rapl_native_events[i].description,
00620                 "Energy used in counts by chip package %d",j);
00621             rapl_native_events[i].fd_offset=cpu_to_use[j];
00622             rapl_native_events[i].msr=MSR_PKG_ENERGY_STATUS;
00623             rapl_native_events[i].resources.selector = i + 1;
00624             rapl_native_events[i].type=PACKAGE_ENERGY_CNT;
00625             rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00626 
00627             sprintf(rapl_native_events[k].name,
00628                 "PACKAGE_ENERGY:PACKAGE%d",j);
00629             strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
00630             sprintf(rapl_native_events[k].description,
00631                 "Energy used by chip package %d",j);
00632             rapl_native_events[k].fd_offset=cpu_to_use[j];
00633             rapl_native_events[k].msr=MSR_PKG_ENERGY_STATUS;
00634             rapl_native_events[k].resources.selector = k + 1;
00635             rapl_native_events[k].type=PACKAGE_ENERGY;
00636             rapl_native_events[k].return_type=PAPI_DATATYPE_UINT64;
00637 
00638             i++;
00639             k++;
00640         }
00641      }
00642 
00643      if (pp1_avail) {
00644         for(j=0;j<num_packages;j++) {
00645             sprintf(rapl_native_events[i].name,
00646                 "PP1_ENERGY_CNT:PACKAGE%d",j);
00647             sprintf(rapl_native_events[i].description,
00648                 "Energy used in counts by Power Plane 1 (Often GPU) on package %d",j);
00649             rapl_native_events[i].fd_offset=cpu_to_use[j];
00650             rapl_native_events[i].msr=MSR_PP1_ENERGY_STATUS;
00651             rapl_native_events[i].resources.selector = i + 1;
00652             rapl_native_events[i].type=PACKAGE_ENERGY_CNT;
00653             rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00654 
00655             sprintf(rapl_native_events[k].name,
00656                 "PP1_ENERGY:PACKAGE%d",j);
00657             strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
00658             sprintf(rapl_native_events[k].description,
00659                 "Energy used by Power Plane 1 (Often GPU) on package %d",j);
00660             rapl_native_events[k].fd_offset=cpu_to_use[j];
00661             rapl_native_events[k].msr=MSR_PP1_ENERGY_STATUS;
00662             rapl_native_events[k].resources.selector = k + 1;
00663             rapl_native_events[k].type=PACKAGE_ENERGY;
00664             rapl_native_events[k].return_type=PAPI_DATATYPE_UINT64;
00665 
00666             i++;
00667             k++;
00668         }
00669      }
00670 
00671      if (dram_avail) {
00672         for(j=0;j<num_packages;j++) {
00673             sprintf(rapl_native_events[i].name,
00674                 "DRAM_ENERGY_CNT:PACKAGE%d",j);
00675             sprintf(rapl_native_events[i].description,
00676                 "Energy used in counts by DRAM on package %d",j);
00677             rapl_native_events[i].fd_offset=cpu_to_use[j];
00678             rapl_native_events[i].msr=MSR_DRAM_ENERGY_STATUS;
00679             rapl_native_events[i].resources.selector = i + 1;
00680             rapl_native_events[i].type=PACKAGE_ENERGY_CNT;
00681             rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00682 
00683             sprintf(rapl_native_events[k].name,
00684                 "DRAM_ENERGY:PACKAGE%d",j);
00685             strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
00686             sprintf(rapl_native_events[k].description,
00687                 "Energy used by DRAM on package %d",j);
00688             rapl_native_events[k].fd_offset=cpu_to_use[j];
00689             rapl_native_events[k].msr=MSR_DRAM_ENERGY_STATUS;
00690             rapl_native_events[k].resources.selector = k + 1;
00691             rapl_native_events[k].type=DRAM_ENERGY;
00692             rapl_native_events[k].return_type=PAPI_DATATYPE_UINT64;
00693 
00694             i++;
00695             k++;
00696         }
00697      }
00698 
00699      if (pp0_avail) {
00700         for(j=0;j<num_packages;j++) {
00701             sprintf(rapl_native_events[i].name,
00702                 "PP0_ENERGY_CNT:PACKAGE%d",j);
00703             sprintf(rapl_native_events[i].description,
00704                 "Energy used in counts by all cores in package %d",j);
00705             rapl_native_events[i].fd_offset=cpu_to_use[j];
00706             rapl_native_events[i].msr=MSR_PP0_ENERGY_STATUS;
00707             rapl_native_events[i].resources.selector = i + 1;
00708             rapl_native_events[i].type=PACKAGE_ENERGY_CNT;
00709             rapl_native_events[i].return_type=PAPI_DATATYPE_UINT64;
00710 
00711             sprintf(rapl_native_events[k].name,
00712                 "PP0_ENERGY:PACKAGE%d",j);
00713             strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
00714             sprintf(rapl_native_events[k].description,
00715                 "Energy used by all cores in package %d",j);
00716             rapl_native_events[k].fd_offset=cpu_to_use[j];
00717             rapl_native_events[k].msr=MSR_PP0_ENERGY_STATUS;
00718             rapl_native_events[k].resources.selector = k + 1;
00719             rapl_native_events[k].type=PACKAGE_ENERGY;
00720             rapl_native_events[k].return_type=PAPI_DATATYPE_UINT64;
00721 
00722             i++;
00723             k++;
00724         }
00725      }
00726 
00727      /* Export the total number of events available */
00728      _rapl_vector.cmp_info.num_native_events = num_events;
00729 
00730      _rapl_vector.cmp_info.num_cntrs = num_events;
00731      _rapl_vector.cmp_info.num_mpx_cntrs = num_events;
00732 
00733 
00734      /* Export the component id */
00735      _rapl_vector.cmp_info.CmpIdx = cidx;
00736 
00737      return PAPI_OK;
00738 }

Here is the call graph for this function:

int _rapl_init_control_state ( hwd_control_state_t ctl  ) 

Definition at line 746 of file linux-rapl.c.

00747 {
00748 
00749   _rapl_control_state_t* control = (_rapl_control_state_t*) ctl;
00750   int i;
00751   
00752   for(i=0;i<RAPL_MAX_COUNTERS;i++) {
00753      control->being_measured[i]=0;
00754   }
00755 
00756   return PAPI_OK;
00757 }

int _rapl_init_thread ( hwd_context_t ctx  ) 

Definition at line 286 of file linux-rapl.c.

00287 {
00288   ( void ) ctx;
00289 
00290   return PAPI_OK;
00291 }

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

Definition at line 997 of file linux-rapl.c.

00998 {
00999      int index = EventCode;
01000 
01001      if ( index >= 0 && index < num_events ) {
01002     strncpy( name, rapl_native_events[index].description, len );
01003     return PAPI_OK;
01004      }
01005      return PAPI_ENOEVNT;
01006 }

int _rapl_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

Definition at line 1009 of file linux-rapl.c.

01010 {
01011 
01012   int index = EventCode;
01013 
01014   if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
01015 
01016   strncpy( info->symbol, rapl_native_events[index].name, sizeof(info->symbol)-1);
01017   info->symbol[sizeof(info->symbol)-1] = '\0';
01018 
01019   strncpy( info->long_descr, rapl_native_events[index].description, sizeof(info->long_descr)-1);
01020   info->long_descr[sizeof(info->long_descr)-1] = '\0';
01021 
01022   strncpy( info->units, rapl_native_events[index].units, sizeof(info->units)-1);
01023   info->units[sizeof(info->units)-1] = '\0';
01024 
01025   info->data_type = rapl_native_events[index].return_type;
01026 
01027   return PAPI_OK;
01028 }

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

Definition at line 980 of file linux-rapl.c.

00981 {
00982 
00983      int index = EventCode & PAPI_NATIVE_AND_MASK;
00984 
00985      if ( index >= 0 && index < num_events ) {
00986     strncpy( name, rapl_native_events[index].name, len );
00987     return PAPI_OK;
00988      }
00989 
00990      return PAPI_ENOEVNT;
00991 }

int _rapl_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

Definition at line 940 of file linux-rapl.c.

00941 {
00942 
00943      int index;
00944 
00945      switch ( modifier ) {
00946 
00947     case PAPI_ENUM_FIRST:
00948 
00949        if (num_events==0) {
00950           return PAPI_ENOEVNT;
00951        }
00952        *EventCode = 0;
00953 
00954        return PAPI_OK;
00955         
00956 
00957     case PAPI_ENUM_EVENTS:
00958     
00959        index = *EventCode & PAPI_NATIVE_AND_MASK;
00960 
00961        if ( index < num_events - 1 ) {
00962           *EventCode = *EventCode + 1;
00963           return PAPI_OK;
00964        } else {
00965           return PAPI_ENOEVNT;
00966        }
00967        break;
00968     
00969     default:
00970         return PAPI_EINVAL;
00971     }
00972 
00973     return PAPI_EINVAL;
00974 }

int _rapl_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)

Definition at line 820 of file linux-rapl.c.

00822 {
00823     (void) flags;
00824 
00825     _rapl_stop( ctx, ctl );
00826 
00827     /* Pass back a pointer to our results */
00828     *events = ((_rapl_control_state_t*) ctl)->count;
00829 
00830     return PAPI_OK;
00831 }

Here is the call graph for this function:

int _rapl_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 927 of file linux-rapl.c.

00928 {
00929     ( void ) ctx;
00930     ( void ) ctl;
00931     
00932     return PAPI_OK;
00933 }

int _rapl_set_domain ( hwd_control_state_t ctl,
int  domain 
)

Definition at line 913 of file linux-rapl.c.

00914 {
00915     ( void ) ctl;
00916     
00917     /* In theory we only support system-wide mode */
00918     /* How to best handle that? */
00919     if ( PAPI_DOM_ALL != domain )
00920     return PAPI_EINVAL;
00921 
00922     return PAPI_OK;
00923 }

int _rapl_shutdown_component ( void   ) 

Definition at line 838 of file linux-rapl.c.

00839 {
00840     int i;
00841 
00842     if (rapl_native_events) papi_free(rapl_native_events);
00843     if (fd_array) {
00844        for(i=0;i<num_cpus;i++) {
00845       if (fd_array[i].open) close(fd_array[i].fd);
00846        }
00847        papi_free(fd_array);
00848     }
00849 
00850     return PAPI_OK;
00851 }

Here is the call graph for this function:

int _rapl_shutdown_thread ( hwd_context_t ctx  ) 

Definition at line 813 of file linux-rapl.c.

00814 {
00815   ( void ) ctx;
00816   return PAPI_OK;
00817 }

int _rapl_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 760 of file linux-rapl.c.

00761 {
00762   _rapl_context_t* context = (_rapl_context_t*) ctx;
00763   _rapl_control_state_t* control = (_rapl_control_state_t*) ctl;
00764   long long now = PAPI_get_real_usec();
00765   int i;
00766 
00767   for( i = 0; i < RAPL_MAX_COUNTERS; i++ ) {
00768      if ((control->being_measured[i]) && (control->need_difference[i])) {
00769         context->start_value[i]=read_rapl_value(i);
00770      }
00771   }
00772 
00773   control->lastupdate = now;
00774 
00775   return PAPI_OK;
00776 }

Here is the call graph for this function:

int _rapl_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 779 of file linux-rapl.c.

00780 {
00781 
00782     /* read values */
00783     _rapl_context_t* context = (_rapl_context_t*) ctx;
00784     _rapl_control_state_t* control = (_rapl_control_state_t*) ctl;
00785     long long now = PAPI_get_real_usec();
00786     int i;
00787     long long temp;
00788 
00789     for ( i = 0; i < RAPL_MAX_COUNTERS; i++ ) {
00790         if (control->being_measured[i]) {
00791             temp = read_rapl_value(i);
00792             if (context->start_value[i])
00793             if (control->need_difference[i]) {
00794                 /* test for wrap around */
00795                 if (temp < context->start_value[i] ) {
00796                     SUBDBG("Wraparound!\nstart:\t%#016x\ttemp:\t%#016x",
00797                         (unsigned)context->start_value[i], (unsigned)temp);
00798                     temp += (0x100000000 - context->start_value[i]);
00799                     SUBDBG("\tresult:\t%#016x\n", (unsigned)temp);
00800                 } else {
00801                     temp -= context->start_value[i];
00802                 }
00803             }
00804             control->count[i] = convert_rapl_energy( i, temp );
00805         }
00806     }
00807     control->lastupdate = now;
00808     return PAPI_OK;
00809 }

Here is the call graph for this function:

Here is the caller graph for this function:

int _rapl_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Definition at line 870 of file linux-rapl.c.

00873 {
00874   int i, index;
00875     ( void ) ctx;
00876 
00877     _rapl_control_state_t* control = (_rapl_control_state_t*) ctl;
00878 
00879     /* Ugh, what is this native[] stuff all about ?*/
00880     /* Mostly remap stuff in papi_internal */
00881 
00882     for(i=0;i<RAPL_MAX_COUNTERS;i++) {
00883        control->being_measured[i]=0;
00884     }
00885 
00886     for( i = 0; i < count; i++ ) {
00887        index=native[i].ni_event&PAPI_NATIVE_AND_MASK;
00888        native[i].ni_position=rapl_native_events[index].resources.selector - 1;
00889        control->being_measured[index]=1;
00890 
00891        /* Only need to subtract if it's a PACKAGE_ENERGY or ENERGY_CNT type */
00892        control->need_difference[index]=
00893         (rapl_native_events[index].type==PACKAGE_ENERGY ||
00894         rapl_native_events[index].type==DRAM_ENERGY ||
00895         rapl_native_events[index].type==PACKAGE_ENERGY_CNT);
00896     }
00897 
00898     return PAPI_OK;
00899 }

static long long convert_rapl_energy ( int  index,
long long  value 
) [static]

Definition at line 202 of file linux-rapl.c.

00202                                                                  {
00203 
00204    union {
00205       long long ll;
00206       double fp;
00207    } return_val;
00208 
00209    return_val.ll = value; /* default case: return raw input value */
00210 
00211    if (rapl_native_events[index].type==PACKAGE_ENERGY) {
00212       return_val.ll = (long long)(((double)value/cpu_energy_divisor)*1e9);
00213    }
00214 
00215    if (rapl_native_events[index].type==DRAM_ENERGY) {
00216       return_val.ll = (long long)(((double)value/dram_energy_divisor)*1e9);
00217    }
00218 
00219    if (rapl_native_events[index].type==PACKAGE_THERMAL) {
00220       return_val.fp = (double)
00221                       ((value>>THERMAL_SHIFT)&POWER_INFO_UNIT_MASK) /
00222                        (double)power_divisor;
00223    }
00224 
00225    if (rapl_native_events[index].type==PACKAGE_MINIMUM) {
00226        return_val.fp = (double)
00227                        ((value>>MINIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK)/
00228                         (double)power_divisor;
00229    }
00230 
00231    if (rapl_native_events[index].type==PACKAGE_MAXIMUM) {
00232       return_val.fp = (double)
00233                       ((value>>MAXIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK)/
00234                        (double)power_divisor;
00235    }
00236 
00237    if (rapl_native_events[index].type==PACKAGE_TIME_WINDOW) {
00238       return_val.fp =  (double)
00239                     ((value>>MAXIMUM_TIME_WINDOW_SHIFT)&POWER_INFO_UNIT_MASK)/
00240                      (double)time_divisor;
00241    }
00242 
00243    if (rapl_native_events[index].type==PACKAGE_THERMAL_CNT) {
00244       return_val.ll = ((value>>THERMAL_SHIFT)&POWER_INFO_UNIT_MASK);
00245    }
00246 
00247    if (rapl_native_events[index].type==PACKAGE_MINIMUM_CNT) {
00248        return_val.ll = ((value>>MINIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK);
00249    }
00250 
00251    if (rapl_native_events[index].type==PACKAGE_MAXIMUM_CNT) {
00252       return_val.ll = ((value>>MAXIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK);
00253    }
00254 
00255    if (rapl_native_events[index].type==PACKAGE_TIME_WINDOW_CNT) {
00256       return_val.ll = ((value>>MAXIMUM_TIME_WINDOW_SHIFT)&POWER_INFO_UNIT_MASK);
00257    }
00258 
00259    return return_val.ll;
00260 }

Here is the caller graph for this function:

static int get_kernel_nr_cpus ( void   )  [static]

Definition at line 263 of file linux-rapl.c.

00264 {
00265   FILE *fff;
00266   int num_read, nr_cpus = 1;
00267   fff=fopen("/sys/devices/system/cpu/kernel_max","r");
00268   if (fff==NULL) return nr_cpus;
00269   num_read=fscanf(fff,"%d",&nr_cpus);
00270   fclose(fff);
00271   if (num_read==1) {
00272     nr_cpus++;
00273   } else {
00274     nr_cpus = 1;
00275   }
00276   return nr_cpus;
00277 }

Here is the caller graph for this function:

static int open_fd ( int  offset  )  [static]

Definition at line 169 of file linux-rapl.c.

00169                                {
00170   
00171   int fd=-1;
00172   char filename[BUFSIZ];
00173 
00174   if (fd_array[offset].open==0) {
00175       sprintf(filename,"/dev/cpu/%d/msr_safe",offset);
00176       fd = open(filename, O_RDONLY);
00177       if (fd<0) {
00178           sprintf(filename,"/dev/cpu/%d/msr",offset);
00179           fd = open(filename, O_RDONLY);
00180       }
00181       if (fd>=0) {
00182           fd_array[offset].fd=fd;
00183           fd_array[offset].open=1;
00184       } 
00185   }
00186   else {
00187     fd=fd_array[offset].fd;
00188   }
00189 
00190   return fd;
00191 }

Here is the call graph for this function:

Here is the caller graph for this function:

static long long read_msr ( int  fd,
int  which 
) [static]

Definition at line 157 of file linux-rapl.c.

00157                                              {
00158 
00159   uint64_t data;
00160 
00161   if ( fd<0 || pread(fd, &data, sizeof data, which) != sizeof data ) {
00162     perror("rdmsr:pread");
00163     exit(127);
00164   }
00165 
00166   return (long long)data;
00167 }

Here is the call graph for this function:

Here is the caller graph for this function:

static long long read_rapl_value ( int  index  )  [static]

Definition at line 193 of file linux-rapl.c.

00193                                             {
00194 
00195    int fd;
00196 
00197    fd=open_fd(rapl_native_events[index].fd_offset);
00198    return read_msr(fd,rapl_native_events[index].msr);
00199 
00200 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 125 of file linux-rapl.c.

Definition at line 138 of file linux-rapl.c.

Definition at line 138 of file linux-rapl.c.

struct fd_array_t* fd_array = NULL

Definition at line 134 of file linux-rapl.c.

int num_cpus = 0 [static]

Definition at line 135 of file linux-rapl.c.

int num_events = 0 [static]

Definition at line 133 of file linux-rapl.c.

int num_packages = 0 [static]

Definition at line 135 of file linux-rapl.c.

Definition at line 137 of file linux-rapl.c.

Definition at line 132 of file linux-rapl.c.

Definition at line 137 of file linux-rapl.c.


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1