PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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
 

Macros

#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
 

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 energy_divisor
 
int time_divisor
 

Detailed Description

Author
Vince Weaver

This component enables RAPL (Running Average Power Level) energy measurements on Intel SandyBridge processors.

To work, the x86 generic MSR driver must be installed (CONFIG_X86_MSR) and the /dev/cpu/?/msr files must have read permissions

Definition in file linux-rapl.c.

Macro Definition Documentation

#define ENERGY_UNIT_MASK   0x1f

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

#define ENERGY_UNIT_OFFSET   0x08

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

#define MAXIMUM_POWER_SHIFT   32

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

#define MAXIMUM_TIME_WINDOW_SHIFT   48

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

#define MINIMUM_POWER_SHIFT   16

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

#define MSR_DRAM_ENERGY_STATUS   0x619

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

#define MSR_DRAM_PERF_STATUS   0x61B

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

#define MSR_DRAM_POWER_INFO   0x61C

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

#define MSR_DRAM_POWER_LIMIT   0x618

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

#define MSR_PKG_ENERGY_STATUS   0x611

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

#define MSR_PKG_PERF_STATUS   0x613

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

#define MSR_PKG_POWER_INFO   0x614

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

#define MSR_PKG_RAPL_POWER_LIMIT   0x610

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

#define MSR_PP0_ENERGY_STATUS   0x639

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

#define MSR_PP0_PERF_STATUS   0x63B

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

#define MSR_PP0_POLICY   0x63A

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

#define MSR_PP0_POWER_LIMIT   0x638

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

#define MSR_PP1_ENERGY_STATUS   0x641

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

#define MSR_PP1_POLICY   0x642

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

#define MSR_PP1_POWER_LIMIT   0x640

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

#define MSR_RAPL_POWER_UNIT   0x606

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

#define PACKAGE_ENERGY   0

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

#define PACKAGE_ENERGY_CNT   5

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

#define PACKAGE_MAXIMUM   3

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

#define PACKAGE_MAXIMUM_CNT   8

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

#define PACKAGE_MINIMUM   2

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

#define PACKAGE_MINIMUM_CNT   7

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

#define PACKAGE_THERMAL   1

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

#define PACKAGE_THERMAL_CNT   6

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

#define PACKAGE_TIME_WINDOW   4

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

#define PACKAGE_TIME_WINDOW_CNT   9

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

#define POWER_INFO_UNIT_MASK   0x7fff

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

#define POWER_UNIT_MASK   0x0f

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

#define POWER_UNIT_OFFSET   0

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

#define RAPL_MAX_COUNTERS   64

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

#define THERMAL_SHIFT   0

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

#define TIME_UNIT_MASK   0x0f

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

#define TIME_UNIT_OFFSET   0x10

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

Function Documentation

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

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

816 {
817  ( void ) ctx;
818  ( void ) code;
819  ( void ) option;
820 
821  return PAPI_OK;
822 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _rapl_init_component ( int  cidx)

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

290 {
291  int i,j,k,fd;
292  FILE *fff;
293  char filename[BUFSIZ];
294 
295  int package_avail, dram_avail, pp0_avail, pp1_avail;
296 
297  long long result;
298  int package;
299 
300  const PAPI_hw_info_t *hw_info;
301 
302  int nr_cpus = get_kernel_nr_cpus();
303  int packages[nr_cpus];
304  int cpu_to_use[nr_cpus];
305 
306  /* Fill with sentinel values */
307  for (i=0; i<nr_cpus; ++i) {
308  packages[i] = -1;
309  cpu_to_use[i] = -1;
310  }
311 
312 
313  /* check if Intel processor */
314  hw_info=&(_papi_hwi_system_info.hw_info);
315 
316  /* Ugh can't use PAPI_get_hardware_info() if
317  PAPI library not done initializing yet */
318 
319  if (hw_info->vendor!=PAPI_VENDOR_INTEL) {
321  "Not an Intel processor",PAPI_MAX_STR_LEN);
322  return PAPI_ENOSUPP;
323  }
324 
325  /* check if SandyBridge */
326 
327  if (hw_info->cpuid_family==6) {
328  if (hw_info->cpuid_model==42) {
329  /* SandyBridge */
330  package_avail=1;
331  pp0_avail=1;
332  pp1_avail=1;
333  dram_avail=0;
334  }
335  else if (hw_info->cpuid_model==45) {
336  /* SandyBridge-EP */
337  package_avail=1;
338  pp0_avail=1;
339  pp1_avail=0;
340  dram_avail=1;
341  }
342  else if (hw_info->cpuid_model==58) {
343  /* IvyBridge */
344  package_avail=1;
345  pp0_avail=1;
346  pp1_avail=1;
347  dram_avail=0;
348  }
349  else if (hw_info->cpuid_model==62) {
350  /* IvyBridge-EP */
351  package_avail=1;
352  pp0_avail=1;
353  pp1_avail=0;
354  dram_avail=1;
355  }
356  else if (hw_info->cpuid_model==60 || hw_info->cpuid_model==69 || hw_info->cpuid_model==70 ) {
357  /* Haswell */
358  package_avail=1;
359  pp0_avail=1;
360  pp1_avail=1;dram_avail=0;
361  }
362  else {
363  /* not a supported model */
365  "CPU model not supported",
367  return PAPI_ENOIMPL;
368  }
369  }
370  else {
371  /* Not a family 6 machine */
373  "CPU family not supported",PAPI_MAX_STR_LEN);
374  return PAPI_ENOIMPL;
375  }
376 
377 
378  /* Detect how many packages */
379  j=0;
380  while(1) {
381  int num_read;
382 
383  sprintf(filename,
384  "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",j);
385  fff=fopen(filename,"r");
386  if (fff==NULL) break;
387  num_read=fscanf(fff,"%d",&package);
388  fclose(fff);
389  if (num_read!=1) {
390  fprintf(stderr,"error reading %s\n",filename);
391  }
392 
393  /* Check if a new package */
394  if (package < nr_cpus) {
395  if (packages[package] == -1) {
396  SUBDBG("Found package %d out of total %d\n",package,num_packages);
397  packages[package]=package;
398  cpu_to_use[package]=j;
399  num_packages++;
400  }
401  } else {
402  SUBDBG("Package outside of allowed range\n");
404  "Package outside of allowed range",PAPI_MAX_STR_LEN);
405  return PAPI_ESYS;
406  }
407 
408  j++;
409  }
410  num_cpus=j;
411 
412  if (num_packages==0) {
413  SUBDBG("Can't access /dev/cpu/*/msr\n");
415  "Can't access /dev/cpu/*/msr",PAPI_MAX_STR_LEN);
416  return PAPI_ESYS;
417  }
418 
419  SUBDBG("Found %d packages with %d cpus\n",num_packages,num_cpus);
420 
421  /* Init fd_array */
422 
423  fd_array=papi_calloc(sizeof(struct fd_array_t),num_cpus);
424  if (fd_array==NULL) return PAPI_ENOMEM;
425 
426  fd=open_fd(cpu_to_use[0]);
427  if (fd<0) {
429  "Can't open fd for cpu0: %s",strerror(errno));
430  return PAPI_ESYS;
431  }
432 
433  /* Calculate the units used */
434  result=read_msr(fd,MSR_RAPL_POWER_UNIT);
435 
436  /* units are 0.5^UNIT_VALUE */
437  /* which is the same as 1/(2^UNIT_VALUE) */
438 
442 
443  SUBDBG("Power units = %.3fW\n",1.0/power_divisor);
444  SUBDBG("Energy units = %.8fJ\n",1.0/energy_divisor);
445  SUBDBG("Time units = %.8fs\n",1.0/time_divisor);
446 
447  /* Allocate space for events */
448  /* Include room for both counts and scaled values */
449 
450  num_events= ((package_avail*num_packages) +
451  (pp0_avail*num_packages) +
452  (pp1_avail*num_packages) +
453  (dram_avail*num_packages) +
454  (4*num_packages)) * 2;
455 
458 
459 
460  i = 0;
461  k = num_events/2;
462 
463  /* Create events for package power info */
464 
465  for(j=0;j<num_packages;j++) {
467  "THERMAL_SPEC_CNT:PACKAGE%d",j);
468  sprintf(rapl_native_events[i].description,
469  "Thermal specification in counts; package %d",j);
470  rapl_native_events[i].fd_offset=cpu_to_use[j];
475 
477  "THERMAL_SPEC:PACKAGE%d",j);
478  strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
479  sprintf(rapl_native_events[k].description,
480  "Thermal specification for package %d",j);
481  rapl_native_events[k].fd_offset=cpu_to_use[j];
486 
487  i++;
488  k++;
489  }
490 
491  for(j=0;j<num_packages;j++) {
493  "MINIMUM_POWER_CNT:PACKAGE%d",j);
494  sprintf(rapl_native_events[i].description,
495  "Minimum power in counts; package %d",j);
496  rapl_native_events[i].fd_offset=cpu_to_use[j];
501 
503  "MINIMUM_POWER:PACKAGE%d",j);
504  strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
505  sprintf(rapl_native_events[k].description,
506  "Minimum power for package %d",j);
507  rapl_native_events[k].fd_offset=cpu_to_use[j];
512 
513  i++;
514  k++;
515  }
516 
517  for(j=0;j<num_packages;j++) {
519  "MAXIMUM_POWER_CNT:PACKAGE%d",j);
520  sprintf(rapl_native_events[i].description,
521  "Maximum power in counts; package %d",j);
522  rapl_native_events[i].fd_offset=cpu_to_use[j];
527 
529  "MAXIMUM_POWER:PACKAGE%d",j);
530  strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
531  sprintf(rapl_native_events[k].description,
532  "Maximum power for package %d",j);
533  rapl_native_events[k].fd_offset=cpu_to_use[j];
538 
539  i++;
540  k++;
541  }
542 
543  for(j=0;j<num_packages;j++) {
545  "MAXIMUM_TIME_WINDOW_CNT:PACKAGE%d",j);
546  sprintf(rapl_native_events[i].description,
547  "Maximum time window in counts; package %d",j);
548  rapl_native_events[i].fd_offset=cpu_to_use[j];
553 
555  "MAXIMUM_TIME_WINDOW:PACKAGE%d",j);
556  strncpy(rapl_native_events[k].units,"s",PAPI_MIN_STR_LEN);
557  sprintf(rapl_native_events[k].description,
558  "Maximum time window for package %d",j);
559  rapl_native_events[k].fd_offset=cpu_to_use[j];
564 
565  i++;
566  k++;
567  }
568 
569  /* Create Events for energy measurements */
570 
571  if (package_avail) {
572  for(j=0;j<num_packages;j++) {
574  "PACKAGE_ENERGY_CNT:PACKAGE%d",j);
575  sprintf(rapl_native_events[i].description,
576  "Energy used in counts by chip package %d",j);
577  rapl_native_events[i].fd_offset=cpu_to_use[j];
582 
584  "PACKAGE_ENERGY:PACKAGE%d",j);
585  strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
586  sprintf(rapl_native_events[k].description,
587  "Energy used by chip package %d",j);
588  rapl_native_events[k].fd_offset=cpu_to_use[j];
593 
594  i++;
595  k++;
596  }
597  }
598 
599  if (pp1_avail) {
600  for(j=0;j<num_packages;j++) {
602  "PP1_ENERGY_CNT:PACKAGE%d",j);
603  sprintf(rapl_native_events[i].description,
604  "Energy used in counts by Power Plane 1 (Often GPU) on package %d",j);
605  rapl_native_events[i].fd_offset=cpu_to_use[j];
610 
612  "PP1_ENERGY:PACKAGE%d",j);
613  strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
614  sprintf(rapl_native_events[k].description,
615  "Energy used by Power Plane 1 (Often GPU) on package %d",j);
616  rapl_native_events[k].fd_offset=cpu_to_use[j];
621 
622  i++;
623  k++;
624  }
625  }
626 
627  if (dram_avail) {
628  for(j=0;j<num_packages;j++) {
630  "DRAM_ENERGY_CNT:PACKAGE%d",j);
631  sprintf(rapl_native_events[i].description,
632  "Energy used in counts by DRAM on package %d",j);
633  rapl_native_events[i].fd_offset=cpu_to_use[j];
638 
640  "DRAM_ENERGY:PACKAGE%d",j);
641  strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
642  sprintf(rapl_native_events[k].description,
643  "Energy used by DRAM on package %d",j);
644  rapl_native_events[k].fd_offset=cpu_to_use[j];
649 
650  i++;
651  k++;
652  }
653  }
654 
655  if (pp0_avail) {
656  for(j=0;j<num_packages;j++) {
658  "PP0_ENERGY_CNT:PACKAGE%d",j);
659  sprintf(rapl_native_events[i].description,
660  "Energy used in counts by all cores in package %d",j);
661  rapl_native_events[i].fd_offset=cpu_to_use[j];
666 
668  "PP0_ENERGY:PACKAGE%d",j);
669  strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
670  sprintf(rapl_native_events[k].description,
671  "Energy used by all cores in package %d",j);
672  rapl_native_events[k].fd_offset=cpu_to_use[j];
677 
678  i++;
679  k++;
680  }
681  }
682 
683  /* Export the total number of events available */
685 
688 
689 
690  /* Export the component id */
692 
693  return PAPI_OK;
694 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
#define TIME_UNIT_MASK
Definition: linux-rapl.c:72
#define PACKAGE_MAXIMUM
Definition: linux-rapl.c:141
int errno
#define PAPI_ENOMEM
Definition: fpapi.h:107
#define PAPI_ENOIMPL
Definition: fpapi.h:124
Hardware info structure.
Definition: papi.h:775
static long long read_msr(int fd, int which)
Definition: linux-rapl.c:155
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define PACKAGE_MAXIMUM_CNT
Definition: linux-rapl.c:146
#define PAPI_MIN_STR_LEN
Definition: fpapi.h:41
#define PACKAGE_THERMAL
Definition: linux-rapl.c:139
static int num_events
int fd
Definition: iozone.c:1291
static int get_kernel_nr_cpus(void)
Definition: linux-rapl.c:253
static int num_packages
Definition: linux-rapl.c:133
#define ENERGY_UNIT_OFFSET
Definition: linux-rapl.c:68
return PAPI_OK
Definition: linux-nvml.c:458
char filename[MAXNAMESIZE]
Definition: iozone.c:1360
int type
Definition: linux-rapl.c:94
#define PACKAGE_ENERGY_CNT
Definition: linux-rapl.c:143
fclose(thread_wqfd)
int power_divisor
Definition: linux-rapl.c:135
#define PACKAGE_TIME_WINDOW_CNT
Definition: linux-rapl.c:147
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
#define MSR_RAPL_POWER_UNIT
Definition: linux-rapl.c:39
#define MSR_PP1_ENERGY_STATUS
Definition: linux-rapl.c:55
FILE * fff[MAX_EVENTS]
#define PACKAGE_ENERGY
Definition: linux-rapl.c:138
struct fd_array_t * fd_array
Definition: linux-rapl.c:132
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
papi_vector_t _rapl_vector
Definition: linux-rapl.c:123
#define PACKAGE_MINIMUM_CNT
Definition: linux-rapl.c:145
int i
Definition: fileop.c:140
#define PAPI_ENOSUPP
Definition: fpapi.h:123
unsigned int selector
Definition: linux-rapl.c:84
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
static int cidx
Definition: event_info.c:40
int k
Definition: iozone.c:19136
static int open_fd(int offset)
Definition: linux-rapl.c:167
#define PACKAGE_MINIMUM
Definition: linux-rapl.c:140
#define MSR_PP0_ENERGY_STATUS
Definition: linux-rapl.c:49
int cpuid_model
Definition: papi.h:788
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PACKAGE_THERMAL_CNT
Definition: linux-rapl.c:144
#define ENERGY_UNIT_MASK
Definition: linux-rapl.c:69
#define POWER_UNIT_MASK
Definition: linux-rapl.c:66
int cpuid_family
Definition: papi.h:787
#define PAPI_ESYS
Definition: fpapi.h:108
#define MSR_PKG_ENERGY_STATUS
Definition: linux-rapl.c:43
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:57
PAPI_hw_info_t hw_info
Definition: linux-rapl.c:87
#define PAPI_VENDOR_INTEL
Definition: papi.h:346
static int num_cpus
Definition: linux-rapl.c:133
int vendor
Definition: papi.h:782
char * name
Definition: iozone.c:23648
int time_divisor
Definition: linux-rapl.c:135
_rapl_register_t resources
Definition: linux-rapl.c:96
int return_type
Definition: linux-rapl.c:95
int fd_offset
Definition: linux-rapl.c:92
#define TIME_UNIT_OFFSET
Definition: linux-rapl.c:71
int msr
Definition: linux-rapl.c:93
long j
Definition: iozone.c:19135
#define MSR_DRAM_ENERGY_STATUS
Definition: linux-rapl.c:60
#define PACKAGE_TIME_WINDOW
Definition: linux-rapl.c:142
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
int energy_divisor
Definition: linux-rapl.c:135
#define POWER_UNIT_OFFSET
Definition: linux-rapl.c:65
#define MSR_PKG_POWER_INFO
Definition: linux-rapl.c:45
#define papi_calloc(a, b)
Definition: papi_memory.h:37

Here is the call graph for this function:

int _rapl_init_control_state ( hwd_control_state_t ctl)

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

703 {
704 
706  int i;
707 
708  for(i=0;i<RAPL_MAX_COUNTERS;i++) {
709  control->being_measured[i]=0;
710  }
711 
712  return PAPI_OK;
713 }
return PAPI_OK
Definition: linux-nvml.c:458
#define RAPL_MAX_COUNTERS
Definition: linux-rapl.c:105
int i
Definition: fileop.c:140
int being_measured[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:109
int _rapl_init_thread ( hwd_context_t ctx)

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

277 {
278  ( void ) ctx;
279 
280  return PAPI_OK;
281 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _rapl_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

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

952 {
953  int index = EventCode;
954 
955  if ( index >= 0 && index < num_events ) {
956  strncpy( name, rapl_native_events[index].description, len );
957  return PAPI_OK;
958  }
959  return PAPI_ENOEVNT;
960 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
char * name
Definition: iozone.c:23648
int _rapl_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

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

964 {
965 
966  int index = EventCode;
967 
968  if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
969 
970  strncpy( info->symbol, rapl_native_events[index].name,
971  sizeof(info->symbol));
972 
973  strncpy( info->long_descr, rapl_native_events[index].description,
974  sizeof(info->symbol));
975 
976  strncpy( info->units, rapl_native_events[index].units,
977  sizeof(info->units));
978 
980 
981  return PAPI_OK;
982 }
char name[PAPI_MAX_STR_LEN]
Definition: linux-rapl.c:89
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
char units[PAPI_MIN_STR_LEN]
Definition: linux-rapl.c:90
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
char description[PAPI_MAX_STR_LEN]
Definition: linux-rapl.c:91
int return_type
Definition: linux-rapl.c:95
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:970
int _rapl_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

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

935 {
936 
937  int index = EventCode & PAPI_NATIVE_AND_MASK;
938 
939  if ( index >= 0 && index < num_events ) {
940  strncpy( name, rapl_native_events[index].name, len );
941  return PAPI_OK;
942  }
943 
944  return PAPI_ENOEVNT;
945 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
char * name
Definition: iozone.c:23648
#define PAPI_NATIVE_AND_MASK
int _rapl_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

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

895 {
896 
897  int index;
898 
899  switch ( modifier ) {
900 
901  case PAPI_ENUM_FIRST:
902 
903  if (num_events==0) {
904  return PAPI_ENOEVNT;
905  }
906  *EventCode = 0;
907 
908  return PAPI_OK;
909 
910 
911  case PAPI_ENUM_EVENTS:
912 
913  index = *EventCode & PAPI_NATIVE_AND_MASK;
914 
915  if ( index < num_events - 1 ) {
916  *EventCode = *EventCode + 1;
917  return PAPI_OK;
918  } else {
919  return PAPI_ENOEVNT;
920  }
921  break;
922 
923  default:
924  return PAPI_EINVAL;
925  }
926 
927  return PAPI_EINVAL;
928 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
return PAPI_EINVAL
Definition: linux-nvml.c:408
#define PAPI_NATIVE_AND_MASK
int _rapl_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)

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

778 {
779  (void) flags;
780 
781  _rapl_stop( ctx, ctl );
782 
783  /* Pass back a pointer to our results */
784  *events = ((_rapl_control_state_t*) ctl)->count;
785 
786  return PAPI_OK;
787 }
int _rapl_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
Definition: linux-rapl.c:735
long long flags
Definition: iozone.c:12330
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
char events[MAX_EVENTS][BUFSIZ]

Here is the call graph for this function:

int _rapl_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

882 {
883  ( void ) ctx;
884  ( void ) ctl;
885 
886  return PAPI_OK;
887 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _rapl_set_domain ( hwd_control_state_t ctl,
int  domain 
)

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

869 {
870  ( void ) ctl;
871  (void) domain;
872 
873  /* In theory we only support system-wide mode */
874  /* How to best handle that? */
875 
876  return PAPI_OK;
877 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _rapl_shutdown_component ( void  )

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

795 {
796  int i;
797 
799  if (fd_array) {
800  for(i=0;i<num_cpus;i++) {
801  if (fd_array[i].open) close(fd_array[i].fd);
802  }
804  }
805 
806  return PAPI_OK;
807 }
int close(int fd)
Definition: appio.c:175
#define papi_free(a)
Definition: papi_memory.h:35
int fd
Definition: iozone.c:1291
return PAPI_OK
Definition: linux-nvml.c:458
struct fd_array_t * fd_array
Definition: linux-rapl.c:132
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184
int i
Definition: fileop.c:140
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
static int num_cpus
Definition: linux-rapl.c:133

Here is the call graph for this function:

int _rapl_shutdown_thread ( hwd_context_t ctx)

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

770 {
771  ( void ) ctx;
772  return PAPI_OK;
773 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _rapl_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

717 {
718  _rapl_context_t* context = (_rapl_context_t*) ctx;
720  long long now = PAPI_get_real_usec();
721  int i;
722 
723  for( i = 0; i < RAPL_MAX_COUNTERS; i++ ) {
724  if ((control->being_measured[i]) && (control->need_difference[i])) {
725  context->start_value[i]=read_rapl_value(i);
726  }
727  }
728 
729  control->lastupdate = now;
730 
731  return PAPI_OK;
732 }
return PAPI_OK
Definition: linux-nvml.c:458
#define RAPL_MAX_COUNTERS
Definition: linux-rapl.c:105
int i
Definition: fileop.c:140
static long long read_rapl_value(int index)
Definition: linux-rapl.c:187
long long PAPI_get_real_usec(void)
Definition: papi.c:6125
int being_measured[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:109
int need_difference[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:111
long long start_value[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:118

Here is the call graph for this function:

int _rapl_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

736 {
737 
738  /* read values */
739  _rapl_context_t* context = (_rapl_context_t*) ctx;
741  long long now = PAPI_get_real_usec();
742  int i;
743  long long temp;
744 
745  for ( i = 0; i < RAPL_MAX_COUNTERS; i++ ) {
746  if (control->being_measured[i]) {
747  temp = read_rapl_value(i);
748  if (context->start_value[i])
749  if (control->need_difference[i]) {
750  /* test for wrap around */
751  if (temp < context->start_value[i] ) {
752  SUBDBG("Wraparound!\nstart:\t0x%016x\ttemp:\t0x%016x",
753  (unsigned)context->start_value[i], (unsigned)temp);
754  temp += (0x100000000 - context->start_value[i]);
755  SUBDBG("\tresult:\t0x%016x\n", (unsigned)temp);
756  } else {
757  temp -= context->start_value[i];
758  }
759  }
760  control->count[i] = convert_rapl_energy( i, temp );
761  }
762  }
763  control->lastupdate = now;
764  return PAPI_OK;
765 }
static long long convert_rapl_energy(int index, long long value)
Definition: linux-rapl.c:196
return PAPI_OK
Definition: linux-nvml.c:458
#define RAPL_MAX_COUNTERS
Definition: linux-rapl.c:105
int i
Definition: fileop.c:140
static long long read_rapl_value(int index)
Definition: linux-rapl.c:187
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
long long PAPI_get_real_usec(void)
Definition: papi.c:6125
long long count[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:110
int being_measured[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:109
int temp
Definition: iozone.c:22158
int need_difference[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:111
long long start_value[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:118

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 826 of file linux-rapl.c.

829 {
830  int i, index;
831  ( void ) ctx;
832 
834 
835  /* Ugh, what is this native[] stuff all about ?*/
836  /* Mostly remap stuff in papi_internal */
837 
838  for(i=0;i<RAPL_MAX_COUNTERS;i++) {
839  control->being_measured[i]=0;
840  }
841 
842  for( i = 0; i < count; i++ ) {
843  index=native[i].ni_event&PAPI_NATIVE_AND_MASK;
845  control->being_measured[index]=1;
846 
847  /* Only need to subtract if it's a PACKAGE_ENERGY or ENERGY_CNT type */
848  control->need_difference[index]=
851  }
852 
853  return PAPI_OK;
854 }
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
int type
Definition: linux-rapl.c:94
#define PACKAGE_ENERGY_CNT
Definition: linux-rapl.c:143
void
Definition: iozone.c:18627
#define RAPL_MAX_COUNTERS
Definition: linux-rapl.c:105
#define PACKAGE_ENERGY
Definition: linux-rapl.c:138
int i
Definition: fileop.c:140
unsigned int selector
Definition: linux-rapl.c:84
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
_rapl_register_t resources
Definition: linux-rapl.c:96
int being_measured[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:109
#define PAPI_NATIVE_AND_MASK
int need_difference[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:111
static long long convert_rapl_energy ( int  index,
long long  value 
)
static

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

196  {
197 
198  union {
199  long long ll;
200  double fp;
201  } return_val;
202 
203  return_val.ll = value; /* default case: return raw input value */
204 
205  if (rapl_native_events[index].type==PACKAGE_ENERGY) {
206  return_val.ll = (long long)(((double)value/energy_divisor)*1e9);
207  }
208 
209  if (rapl_native_events[index].type==PACKAGE_THERMAL) {
210  return_val.fp = (double)
212  (double)power_divisor;
213  }
214 
215  if (rapl_native_events[index].type==PACKAGE_MINIMUM) {
216  return_val.fp = (double)
218  (double)power_divisor;
219  }
220 
221  if (rapl_native_events[index].type==PACKAGE_MAXIMUM) {
222  return_val.fp = (double)
224  (double)power_divisor;
225  }
226 
227  if (rapl_native_events[index].type==PACKAGE_TIME_WINDOW) {
228  return_val.fp = (double)
230  (double)time_divisor;
231  }
232 
233  if (rapl_native_events[index].type==PACKAGE_THERMAL_CNT) {
234  return_val.ll = ((value>>THERMAL_SHIFT)&POWER_INFO_UNIT_MASK);
235  }
236 
237  if (rapl_native_events[index].type==PACKAGE_MINIMUM_CNT) {
238  return_val.ll = ((value>>MINIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK);
239  }
240 
241  if (rapl_native_events[index].type==PACKAGE_MAXIMUM_CNT) {
242  return_val.ll = ((value>>MAXIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK);
243  }
244 
245  if (rapl_native_events[index].type==PACKAGE_TIME_WINDOW_CNT) {
247  }
248 
249  return return_val.ll;
250 }
#define PACKAGE_MAXIMUM
Definition: linux-rapl.c:141
#define POWER_INFO_UNIT_MASK
Definition: linux-rapl.c:75
#define PACKAGE_MAXIMUM_CNT
Definition: linux-rapl.c:146
#define PACKAGE_THERMAL
Definition: linux-rapl.c:139
int power_divisor
Definition: linux-rapl.c:135
#define PACKAGE_TIME_WINDOW_CNT
Definition: linux-rapl.c:147
void double value
Definition: iozone.c:18781
static double
Definition: fileop.c:1281
#define PACKAGE_ENERGY
Definition: linux-rapl.c:138
#define PACKAGE_MINIMUM_CNT
Definition: linux-rapl.c:145
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
#define PACKAGE_MINIMUM
Definition: linux-rapl.c:140
long long
Definition: iozone.c:19827
#define PACKAGE_THERMAL_CNT
Definition: linux-rapl.c:144
static FILE * fp
#define MAXIMUM_TIME_WINDOW_SHIFT
Definition: linux-rapl.c:79
#define THERMAL_SHIFT
Definition: linux-rapl.c:76
int time_divisor
Definition: linux-rapl.c:135
#define MAXIMUM_POWER_SHIFT
Definition: linux-rapl.c:78
#define MINIMUM_POWER_SHIFT
Definition: linux-rapl.c:77
#define PACKAGE_TIME_WINDOW
Definition: linux-rapl.c:142
int energy_divisor
Definition: linux-rapl.c:135

Here is the caller graph for this function:

static int get_kernel_nr_cpus ( void  )
static

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

254 {
255  FILE *fff;
256  int num_read, nr_cpus = 1;
257  fff=fopen("/sys/devices/system/cpu/kernel_max","r");
258  if (fff==NULL) return nr_cpus;
259  num_read=fscanf(fff,"%d",&nr_cpus);
260  fclose(fff);
261  if (num_read==1) {
262  nr_cpus++;
263  } else {
264  nr_cpus = 1;
265  }
266  return nr_cpus;
267 }
fclose(thread_wqfd)
FILE * fff[MAX_EVENTS]

Here is the call graph for this function:

Here is the caller graph for this function:

static int open_fd ( int  offset)
static

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

167  {
168 
169  int fd=-1;
170  char filename[BUFSIZ];
171 
172  if (fd_array[offset].open==0) {
173  sprintf(filename,"/dev/cpu/%d/msr",offset);
174  fd = open(filename, O_RDONLY);
175  if (fd>=0) {
176  fd_array[offset].fd=fd;
177  fd_array[offset].open=1;
178  }
179  }
180  else {
181  fd=fd_array[offset].fd;
182  }
183 
184  return fd;
185 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
off64_t offset
Definition: iozone.c:1279
int fd
Definition: iozone.c:1291
char filename[MAXNAMESIZE]
Definition: iozone.c:1360
struct fd_array_t * fd_array
Definition: linux-rapl.c:132
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184

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 155 of file linux-rapl.c.

155  {
156 
157  uint64_t data;
158 
159  if ( fd<0 || pread(fd, &data, sizeof data, which) != sizeof data ) {
160  perror("rdmsr:pread");
161  exit(127);
162  }
163 
164  return (long long)data;
165 }
long which
Definition: iozone.c:19600
int fd
Definition: iozone.c:1291
void exit()

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 187 of file linux-rapl.c.

187  {
188 
189  int fd;
190 
191  fd=open_fd(rapl_native_events[index].fd_offset);
192  return read_msr(fd,rapl_native_events[index].msr);
193 
194 }
static long long read_msr(int fd, int which)
Definition: linux-rapl.c:155
int fd
Definition: iozone.c:1291
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:130
static int open_fd(int offset)
Definition: linux-rapl.c:167

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

papi_vector_t _rapl_vector

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

int energy_divisor

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

struct fd_array_t* fd_array =NULL

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

int num_cpus =0
static

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

int num_events = 0
static

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

int num_packages =0
static

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

int power_divisor

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

_rapl_native_event_entry_t* rapl_native_events =NULL
static

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

int time_divisor

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