PAPI 7.1.0.0
Loading...
Searching...
No Matches
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 HANDLE_STRING_ERROR   {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}
 
#define MSR_AMD_RAPL_POWER_UNIT   0xc0010299
 
#define MSR_AMD_PKG_ENERGY_STATUS   0xc001029B
 
#define MSR_AMD_PP0_ENERGY_STATUS   0xc001029A
 
#define MSR_INTEL_RAPL_POWER_UNIT   0x606
 
#define MSR_PKG_RAPL_POWER_LIMIT   0x610
 
#define MSR_INTEL_PKG_ENERGY_STATUS   0x611
 
#define MSR_PKG_PERF_STATUS   0x613
 
#define MSR_PKG_POWER_INFO   0x614
 
#define MSR_PP0_POWER_LIMIT   0x638
 
#define MSR_INTEL_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 MSR_PLATFORM_ENERGY_STATUS   0x64d
 
#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
 
#define PLATFORM_ENERGY   11
 

Functions

static long long read_msr (int fd, unsigned 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)
 
static int _rapl_init_thread (hwd_context_t *ctx)
 
static int _rapl_init_component (int cidx)
 
static int _rapl_init_control_state (hwd_control_state_t *ctl)
 
static int _rapl_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _rapl_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static 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)
 
static int _rapl_shutdown_component (void)
 
static int _rapl_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
static int _rapl_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
static int _rapl_set_domain (hwd_control_state_t *ctl, int domain)
 
static int _rapl_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _rapl_ntv_enum_events (unsigned int *EventCode, int modifier)
 
static int _rapl_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
static int _rapl_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
static 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
 
unsigned int msr_rapl_power_unit
 

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.

Macro Definition Documentation

◆ DRAM_ENERGY

#define DRAM_ENERGY   10

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

◆ ENERGY_UNIT_MASK

#define ENERGY_UNIT_MASK   0x1f

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

◆ ENERGY_UNIT_OFFSET

#define ENERGY_UNIT_OFFSET   0x08

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

◆ HANDLE_STRING_ERROR

#define HANDLE_STRING_ERROR   {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}

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

◆ MAXIMUM_POWER_SHIFT

#define MAXIMUM_POWER_SHIFT   32

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

◆ MAXIMUM_TIME_WINDOW_SHIFT

#define MAXIMUM_TIME_WINDOW_SHIFT   48

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

◆ MINIMUM_POWER_SHIFT

#define MINIMUM_POWER_SHIFT   16

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

◆ MSR_AMD_PKG_ENERGY_STATUS

#define MSR_AMD_PKG_ENERGY_STATUS   0xc001029B

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

◆ MSR_AMD_PP0_ENERGY_STATUS

#define MSR_AMD_PP0_ENERGY_STATUS   0xc001029A

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

◆ MSR_AMD_RAPL_POWER_UNIT

#define MSR_AMD_RAPL_POWER_UNIT   0xc0010299

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

◆ MSR_DRAM_ENERGY_STATUS

#define MSR_DRAM_ENERGY_STATUS   0x619

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

◆ MSR_DRAM_PERF_STATUS

#define MSR_DRAM_PERF_STATUS   0x61B

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

◆ MSR_DRAM_POWER_INFO

#define MSR_DRAM_POWER_INFO   0x61C

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

◆ MSR_DRAM_POWER_LIMIT

#define MSR_DRAM_POWER_LIMIT   0x618

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

◆ MSR_INTEL_PKG_ENERGY_STATUS

#define MSR_INTEL_PKG_ENERGY_STATUS   0x611

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

◆ MSR_INTEL_PP0_ENERGY_STATUS

#define MSR_INTEL_PP0_ENERGY_STATUS   0x639

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

◆ MSR_INTEL_RAPL_POWER_UNIT

#define MSR_INTEL_RAPL_POWER_UNIT   0x606

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

◆ MSR_PKG_PERF_STATUS

#define MSR_PKG_PERF_STATUS   0x613

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

◆ MSR_PKG_POWER_INFO

#define MSR_PKG_POWER_INFO   0x614

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

◆ MSR_PKG_RAPL_POWER_LIMIT

#define MSR_PKG_RAPL_POWER_LIMIT   0x610

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

◆ MSR_PLATFORM_ENERGY_STATUS

#define MSR_PLATFORM_ENERGY_STATUS   0x64d

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

◆ MSR_PP0_PERF_STATUS

#define MSR_PP0_PERF_STATUS   0x63B

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

◆ MSR_PP0_POLICY

#define MSR_PP0_POLICY   0x63A

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

◆ MSR_PP0_POWER_LIMIT

#define MSR_PP0_POWER_LIMIT   0x638

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

◆ MSR_PP1_ENERGY_STATUS

#define MSR_PP1_ENERGY_STATUS   0x641

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

◆ MSR_PP1_POLICY

#define MSR_PP1_POLICY   0x642

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

◆ MSR_PP1_POWER_LIMIT

#define MSR_PP1_POWER_LIMIT   0x640

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

◆ PACKAGE_ENERGY

#define PACKAGE_ENERGY   0

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

◆ PACKAGE_ENERGY_CNT

#define PACKAGE_ENERGY_CNT   5

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

◆ PACKAGE_MAXIMUM

#define PACKAGE_MAXIMUM   3

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

◆ PACKAGE_MAXIMUM_CNT

#define PACKAGE_MAXIMUM_CNT   8

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

◆ PACKAGE_MINIMUM

#define PACKAGE_MINIMUM   2

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

◆ PACKAGE_MINIMUM_CNT

#define PACKAGE_MINIMUM_CNT   7

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

◆ PACKAGE_THERMAL

#define PACKAGE_THERMAL   1

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

◆ PACKAGE_THERMAL_CNT

#define PACKAGE_THERMAL_CNT   6

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

◆ PACKAGE_TIME_WINDOW

#define PACKAGE_TIME_WINDOW   4

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

◆ PACKAGE_TIME_WINDOW_CNT

#define PACKAGE_TIME_WINDOW_CNT   9

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

◆ PLATFORM_ENERGY

#define PLATFORM_ENERGY   11

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

◆ POWER_INFO_UNIT_MASK

#define POWER_INFO_UNIT_MASK   0x7fff

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

◆ POWER_UNIT_MASK

#define POWER_UNIT_MASK   0x0f

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

◆ POWER_UNIT_OFFSET

#define POWER_UNIT_OFFSET   0

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

◆ RAPL_MAX_COUNTERS

#define RAPL_MAX_COUNTERS   64

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

◆ THERMAL_SHIFT

#define THERMAL_SHIFT   0

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

◆ TIME_UNIT_MASK

#define TIME_UNIT_MASK   0x0f

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

◆ TIME_UNIT_OFFSET

#define TIME_UNIT_OFFSET   0x10

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

Function Documentation

◆ _rapl_ctl()

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

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

1157{
1158 ( void ) ctx;
1159 ( void ) code;
1160 ( void ) option;
1161
1162 return PAPI_OK;
1163}
#define PAPI_OK
Definition: f90papi.h:73

◆ _rapl_init_component()

static int _rapl_init_component ( int  cidx)
static

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

333{
334 int retval = PAPI_OK;
335 int i,j,k,fd;
336 FILE *fff;
337 char filename[BUFSIZ];
338 long unsigned int strErr;
339 char *strCpy;
340
341 int package_avail, dram_avail, pp0_avail, pp1_avail, psys_avail;
342 int different_units;
343
344 long long result;
345 int package;
346
347 const PAPI_hw_info_t *hw_info;
348
349 int nr_cpus = get_kernel_nr_cpus();
350 int packages[nr_cpus];
351 int cpu_to_use[nr_cpus];
352
353 unsigned int msr_pkg_energy_status,msr_pp0_energy_status;
354
355
356 /* Fill with sentinel values */
357 for (i=0; i<nr_cpus; ++i) {
358 packages[i] = -1;
359 cpu_to_use[i] = -1;
360 }
361
362
363 /* check if supported processor */
365
366 /* Ugh can't use PAPI_get_hardware_info() if
367 PAPI library not done initializing yet */
368
369 switch(hw_info->vendor) {
371 case PAPI_VENDOR_AMD:
372 break;
373 default:
375 "Not a supported processor",PAPI_MAX_STR_LEN);
377 if (strCpy == NULL) HANDLE_STRING_ERROR;
379 goto fn_fail;
380 }
381
382
383 /* Make sure it is a family 6 Intel Chip */
384
386
388 msr_pkg_energy_status=MSR_INTEL_PKG_ENERGY_STATUS;
389 msr_pp0_energy_status=MSR_INTEL_PP0_ENERGY_STATUS;
390
391 if (hw_info->cpuid_family!=6) {
392 /* Not a family 6 machine */
394 "CPU family not supported",PAPI_MAX_STR_LEN);
396 if (strCpy == NULL) HANDLE_STRING_ERROR;
398 goto fn_fail;
399 }
400
401 /* Detect RAPL support */
402 switch(hw_info->cpuid_model) {
403
404 /* Desktop / Laptops */
405
406 case 42: /* SandyBridge */
407 case 58: /* IvyBridge */
408 package_avail=1;
409 pp0_avail=1;
410 pp1_avail=1;
411 dram_avail=0;
412 psys_avail=0;
413 different_units=0;
414 break;
415
416 case 60: /* Haswell */
417 case 69: /* Haswell ULT */
418 case 70: /* Haswell GT3E */
419 case 92: /* Atom Goldmont */
420 case 122: /* Atom Gemini Lake */
421 case 95: /* Atom Denverton */
422 package_avail=1;
423 pp0_avail=1;
424 pp1_avail=1;
425 dram_avail=1;
426 psys_avail=0;
427 different_units=0;
428 break;
429
430 case 61: /* Broadwell */
431 case 71: /* Broadwell-H (GT3E) */
432 case 86: /* Broadwell XEON_D */
433 package_avail=1;
434 pp0_avail=1;
435 pp1_avail=0;
436 dram_avail=1;
437 psys_avail=0;
438 different_units=0;
439 break;
440
441 case 78: /* Skylake Mobile */
442 case 94: /* Skylake Desktop (H/S) */
443 case 142: /* Kabylake Mobile */
444 case 158: /* Kabylake Desktop */
445 package_avail=1;
446 pp0_avail=1;
447 pp1_avail=0;
448 dram_avail=1;
449 psys_avail=1;
450 different_units=0;
451 break;
452
453 /* Server Class Machines */
454
455 case 45: /* SandyBridge-EP */
456 case 62: /* IvyBridge-EP */
457 package_avail=1;
458 pp0_avail=1;
459 pp1_avail=0;
460 dram_avail=1;
461 psys_avail=0;
462 different_units=0;
463 break;
464
465 case 63: /* Haswell-EP */
466 case 79: /* Broadwell-EP */
467 case 85: /* Skylake-X */
468 case 106: /* Icelake-SP */
469 package_avail=1;
470 pp0_avail=1;
471 pp1_avail=0;
472 dram_avail=1;
473 psys_avail=0;
474 different_units=1;
475 break;
476
477
478 case 87: /* Knights Landing (KNL) */
479 case 133: /* Knights Mill (KNM) */
480 package_avail=1;
481 pp0_avail=0;
482 pp1_avail=0;
483 dram_avail=1;
484 psys_avail=0;
485 different_units=1;
486 break;
487
488 default: /* not a supported model */
490 "CPU model not supported",
493 if (strCpy == NULL) HANDLE_STRING_ERROR;
495 goto fn_fail;
496 }
497 }
498
500
502 msr_pkg_energy_status=MSR_AMD_PKG_ENERGY_STATUS;
503 msr_pp0_energy_status=MSR_AMD_PP0_ENERGY_STATUS;
504
505 if (hw_info->cpuid_family!=0x17) {
506 /* Not a family 17h machine */
508 "CPU family not supported",PAPI_MAX_STR_LEN);
510 if (strCpy == NULL) HANDLE_STRING_ERROR;
512 goto fn_fail;
513 }
514
515 package_avail=1;
516 pp0_avail=1; /* Doesn't work on EPYC? */
517 pp1_avail=0;
518 dram_avail=0;
519 psys_avail=0;
520 different_units=0;
521 }
522
523
524 /* Detect how many packages */
525 // Some code below may be flagged by Coverity due to uninitialized array
526 // entries of cpu_to_use[]. This is not a bug; the 'filename' listed below
527 // will have 'cpu0', 'cpu1', sequentially on up to the maximum. Coverity
528 // cannot know that, so its code analysis allows the possibility that the
529 // cpu_to_use[] array is only partially filled in. [Tony C. 11-27-19].
530
531 j=0;
532 while(1) {
533 int num_read;
534
535 strErr=snprintf(filename, BUFSIZ,
536 "/sys/devices/system/cpu/cpu%d/topology/physical_package_id",j);
537 filename[BUFSIZ-1]=0;
538 if (strErr > BUFSIZ) HANDLE_STRING_ERROR;
539 fff=fopen(filename,"r");
540 if (fff==NULL) break;
541 num_read=fscanf(fff,"%d",&package);
542 fclose(fff);
543 if (num_read!=1) {
544 strCpy=strcpy(_rapl_vector.cmp_info.disabled_reason, "Error reading file: ");
545 if (strCpy == NULL) HANDLE_STRING_ERROR;
548 if (strCpy == NULL) HANDLE_STRING_ERROR;
550 goto fn_fail;
551 }
552
553 /* Check if a new package */
554 if ((package >= 0) && (package < nr_cpus)) {
555 if (packages[package] == -1) {
556 SUBDBG("Found package %d out of total %d\n",package,num_packages);
557 packages[package]=package;
558 cpu_to_use[package]=j;
559 num_packages++;
560 }
561 } else {
562 SUBDBG("Package outside of allowed range\n");
564 "Package outside of allowed range",PAPI_MAX_STR_LEN);
566 if (strCpy == NULL) HANDLE_STRING_ERROR;
568 goto fn_fail;
569 }
570
571 j++;
572 }
573 num_cpus=j;
574
575 if (num_packages==0) {
576 SUBDBG("Can't access /dev/cpu/*/<msr_safe | msr>\n");
578 "Can't access /dev/cpu/*/<msr_safe | msr>",PAPI_MAX_STR_LEN);
580 if (strCpy == NULL) HANDLE_STRING_ERROR;
582 goto fn_fail;
583 }
584
585 SUBDBG("Found %d packages with %d cpus\n",num_packages,num_cpus);
586
587 /* Init fd_array */
588
589 fd_array=papi_calloc(num_cpus, sizeof(struct fd_array_t));
590 if (fd_array==NULL) {
592 goto fn_fail;
593 }
594
595 fd=open_fd(cpu_to_use[0]);
596 if (fd<0) {
598 "Can't open fd for cpu0: %s",strerror(errno));
602 goto fn_fail;
603 }
604
605 /* Verify needed MSR is readable. In a guest VM it may not be readable*/
606 if (pread(fd, &result, sizeof result, msr_rapl_power_unit) != sizeof result ) {
608 "Unable to access RAPL registers",PAPI_MAX_STR_LEN);
610 if (strCpy == NULL) HANDLE_STRING_ERROR;
612 goto fn_fail;
613 }
614
615 /* Calculate the units used */
617
618 /* units are 0.5^UNIT_VALUE */
619 /* which is the same as 1/(2^UNIT_VALUE) */
620
624
625 /* Note! On Haswell-EP DRAM energy is fixed at 15.3uJ */
626 /* see https://lkml.org/lkml/2015/3/20/582 */
627 /* Knights Landing is the same */
628 /* so is Broadwell-EP */
629 if ( different_units ) {
631 }
632 else {
634 }
635
636 SUBDBG("Power units = %.3fW\n",1.0/power_divisor);
637 SUBDBG("CPU Energy units = %.8fJ\n",1.0/cpu_energy_divisor);
638 SUBDBG("DRAM Energy units = %.8fJ\n",1.0/dram_energy_divisor);
639 SUBDBG("Time units = %.8fs\n",1.0/time_divisor);
640
641 /* Allocate space for events */
642 /* Include room for both counts and scaled values */
643
644 num_events= ((package_avail*num_packages) +
645 (pp0_avail*num_packages) +
646 (pp1_avail*num_packages) +
647 (dram_avail*num_packages) +
648 (psys_avail*num_packages)) * 2;
649
651 num_events+=(4*num_packages) * 2;
652 }
653
656 if (rapl_native_events == NULL) {
658 "%s:%i rapl_native_events papi_calloc for %lu bytes failed.", __FILE__, __LINE__, num_events*sizeof(_rapl_native_event_entry_t));
662 goto fn_fail;
663 }
664
665 i = 0;
666 k = num_events/2;
667
668 /* Create events for package power info */
669
671 for(j=0;j<num_packages;j++) {
672 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
673 "THERMAL_SPEC_CNT:PACKAGE%d",j);
676
677 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
678 "Thermal specification in counts; package %d",j);
681 rapl_native_events[i].fd_offset=cpu_to_use[j];
686
687 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
688 "THERMAL_SPEC:PACKAGE%d",j);
691
692 strCpy=strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
694 if (strCpy == NULL) HANDLE_STRING_ERROR;
695
696 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
697 "Thermal specification for package %d",j);
700 rapl_native_events[k].fd_offset=cpu_to_use[j];
705
706 i++;
707 k++;
708 }
709
711 for(j=0;j<num_packages;j++) {
712 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
713 "MINIMUM_POWER_CNT:PACKAGE%d",j);
716 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
717 "Minimum power in counts; package %d",j);
720 rapl_native_events[i].fd_offset=cpu_to_use[j];
725
726 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
727 "MINIMUM_POWER:PACKAGE%d",j);
730 strCpy=strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
732 if (strCpy == NULL) HANDLE_STRING_ERROR;
733 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
734 "Minimum power for package %d",j);
737 rapl_native_events[k].fd_offset=cpu_to_use[j];
742
743 i++;
744 k++;
745 }
746
748 for(j=0;j<num_packages;j++) {
749 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
750 "MAXIMUM_POWER_CNT:PACKAGE%d",j);
753 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
754 "Maximum power in counts; package %d",j);
757 rapl_native_events[i].fd_offset=cpu_to_use[j];
762
763 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
764 "MAXIMUM_POWER:PACKAGE%d",j);
767 strCpy=strncpy(rapl_native_events[k].units,"W",PAPI_MIN_STR_LEN);
769 if (strCpy == NULL) HANDLE_STRING_ERROR;
770 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
771 "Maximum power for package %d",j);
774 rapl_native_events[k].fd_offset=cpu_to_use[j];
779
780 i++;
781 k++;
782 }
783
785 for(j=0;j<num_packages;j++) {
786 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
787 "MAXIMUM_TIME_WINDOW_CNT:PACKAGE%d",j);
790 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
791 "Maximum time window in counts; package %d",j);
794 rapl_native_events[i].fd_offset=cpu_to_use[j];
799
800 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
801 "MAXIMUM_TIME_WINDOW:PACKAGE%d",j);
804 strCpy=strncpy(rapl_native_events[k].units,"s",PAPI_MIN_STR_LEN);
806 if (strCpy == NULL) HANDLE_STRING_ERROR;
807 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
808 "Maximum time window for package %d",j);
811 rapl_native_events[k].fd_offset=cpu_to_use[j];
816
817 i++;
818 k++;
819 }
820
821 /* Create Events for energy measurements */
822
823 if (package_avail) {
824 for(j=0;j<num_packages;j++) {
825 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
826 "PACKAGE_ENERGY_CNT:PACKAGE%d",j);
829 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
830 "Energy used in counts by chip package %d",j);
833 rapl_native_events[i].fd_offset=cpu_to_use[j];
834 rapl_native_events[i].msr=msr_pkg_energy_status;
838
839 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
840 "PACKAGE_ENERGY:PACKAGE%d",j);
843 strCpy=strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
845 if (strCpy == NULL) HANDLE_STRING_ERROR;
846 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
847 "Energy used by chip package %d",j);
850 rapl_native_events[k].fd_offset=cpu_to_use[j];
851 rapl_native_events[k].msr=msr_pkg_energy_status;
855
856 i++;
857 k++;
858 }
859 }
860
861 if (pp1_avail) {
862 for(j=0;j<num_packages;j++) {
863 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
864 "PP1_ENERGY_CNT:PACKAGE%d",j);
867 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
868 "Energy used in counts by Power Plane 1 (Often GPU) on package %d",j);
871 rapl_native_events[i].fd_offset=cpu_to_use[j];
876
877 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
878 "PP1_ENERGY:PACKAGE%d",j);
881 strCpy=strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
883 if (strCpy == NULL) HANDLE_STRING_ERROR;
884 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
885 "Energy used by Power Plane 1 (Often GPU) on package %d",j);
888 rapl_native_events[k].fd_offset=cpu_to_use[j];
893
894 i++;
895 k++;
896 }
897 }
898
899 if (dram_avail) {
900 for(j=0;j<num_packages;j++) {
901 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
902 "DRAM_ENERGY_CNT:PACKAGE%d",j);
905 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
906 "Energy used in counts by DRAM on package %d",j);
909 rapl_native_events[i].fd_offset=cpu_to_use[j];
914
915 strErr=snprintf(rapl_native_events[k].name,PAPI_MAX_STR_LEN,
916 "DRAM_ENERGY:PACKAGE%d",j);
919 strCpy=strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
921 if (strCpy == NULL) HANDLE_STRING_ERROR;
922 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
923 "Energy used by DRAM on package %d",j);
926 rapl_native_events[k].fd_offset=cpu_to_use[j];
931
932 i++;
933 k++;
934 }
935 }
936
937 if (psys_avail) {
938 for(j=0;j<num_packages;j++) {
939
940 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
941 "PSYS_ENERGY_CNT:PACKAGE%d",j);
944 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
945 "Energy used in counts by SoC on package %d",j);
948 rapl_native_events[i].fd_offset=cpu_to_use[j];
953
954 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
955 "PSYS_ENERGY:PACKAGE%d",j);
958 strCpy=strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
960 if (strCpy == NULL) HANDLE_STRING_ERROR;
961 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
962 "Energy used by SoC on package %d",j);
965 rapl_native_events[k].fd_offset=cpu_to_use[j];
970
971 i++;
972 k++;
973 }
974 }
975
976 if (pp0_avail) {
977 for(j=0;j<num_packages;j++) {
978 strErr=snprintf(rapl_native_events[i].name, PAPI_MAX_STR_LEN,
979 "PP0_ENERGY_CNT:PACKAGE%d",j);
982 strErr=snprintf(rapl_native_events[i].description, PAPI_MAX_STR_LEN,
983 "Energy used in counts by all cores in package %d",j);
986 rapl_native_events[i].fd_offset=cpu_to_use[j];
987 rapl_native_events[i].msr=msr_pp0_energy_status;
991
992 strErr=snprintf(rapl_native_events[k].name, PAPI_MAX_STR_LEN,
993 "PP0_ENERGY:PACKAGE%d",j);
996 strCpy=strncpy(rapl_native_events[k].units,"nJ",PAPI_MIN_STR_LEN);
998 if (strCpy == NULL) HANDLE_STRING_ERROR;
999 strErr=snprintf(rapl_native_events[k].description, PAPI_MAX_STR_LEN,
1000 "Energy used by all cores in package %d",j);
1003 rapl_native_events[k].fd_offset=cpu_to_use[j];
1004 rapl_native_events[k].msr=msr_pp0_energy_status;
1008
1009 i++;
1010 k++;
1011 }
1012 }
1013
1014 /* Export the total number of events available */
1016
1019
1020
1021 /* Export the component id */
1023
1024 fn_exit:
1025 _papi_hwd[cidx]->cmp_info.disabled = retval;
1026 return retval;
1027 fn_fail:
1028 goto fn_exit;
1029}
volatile int result
int i
int errno
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
struct papi_vectors * _papi_hwd[]
#define PAPI_MIN_STR_LEN
Definition: f90papi.h:208
#define PAPI_DATATYPE_FP64
Definition: f90papi.h:171
#define PAPI_VENDOR_INTEL
Definition: f90papi.h:275
#define PAPI_VENDOR_AMD
Definition: f90papi.h:230
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_DATATYPE_UINT64
Definition: f90papi.h:278
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_ENOMEM
Definition: f90papi.h:16
#define PAPI_ENOIMPL
Definition: f90papi.h:219
FILE * fff[MAX_EVENTS]
#define MSR_INTEL_PKG_ENERGY_STATUS
Definition: linux-rapl.c:62
#define ENERGY_UNIT_OFFSET
Definition: linux-rapl.c:90
struct fd_array_t * fd_array
Definition: linux-rapl.c:160
#define PACKAGE_TIME_WINDOW
Definition: linux-rapl.c:171
#define POWER_UNIT_MASK
Definition: linux-rapl.c:88
#define MSR_AMD_PP0_ENERGY_STATUS
Definition: linux-rapl.c:44
#define PACKAGE_MINIMUM_CNT
Definition: linux-rapl.c:174
#define MSR_PLATFORM_ENERGY_STATUS
Definition: linux-rapl.c:84
static _rapl_native_event_entry_t * rapl_native_events
Definition: linux-rapl.c:158
#define MSR_DRAM_ENERGY_STATUS
Definition: linux-rapl.c:79
#define PACKAGE_MAXIMUM
Definition: linux-rapl.c:170
#define MSR_INTEL_PP0_ENERGY_STATUS
Definition: linux-rapl.c:68
int cpu_energy_divisor
Definition: linux-rapl.c:164
static int num_events
Definition: linux-rapl.c:159
#define TIME_UNIT_OFFSET
Definition: linux-rapl.c:93
#define PACKAGE_THERMAL
Definition: linux-rapl.c:168
#define MSR_PKG_POWER_INFO
Definition: linux-rapl.c:64
#define POWER_UNIT_OFFSET
Definition: linux-rapl.c:87
#define TIME_UNIT_MASK
Definition: linux-rapl.c:94
int dram_energy_divisor
Definition: linux-rapl.c:164
#define MSR_AMD_PKG_ENERGY_STATUS
Definition: linux-rapl.c:43
#define MSR_PP1_ENERGY_STATUS
Definition: linux-rapl.c:74
#define MSR_INTEL_RAPL_POWER_UNIT
Definition: linux-rapl.c:58
#define MSR_AMD_RAPL_POWER_UNIT
Definition: linux-rapl.c:41
unsigned int msr_rapl_power_unit
Definition: linux-rapl.c:165
static int num_packages
Definition: linux-rapl.c:161
#define PACKAGE_MAXIMUM_CNT
Definition: linux-rapl.c:175
papi_vector_t _rapl_vector
Definition: linux-rapl.c:151
#define DRAM_ENERGY
Definition: linux-rapl.c:177
#define PACKAGE_THERMAL_CNT
Definition: linux-rapl.c:173
#define PACKAGE_MINIMUM
Definition: linux-rapl.c:169
int power_divisor
Definition: linux-rapl.c:163
#define PACKAGE_TIME_WINDOW_CNT
Definition: linux-rapl.c:176
#define ENERGY_UNIT_MASK
Definition: linux-rapl.c:91
static int open_fd(int offset)
Definition: linux-rapl.c:198
#define PLATFORM_ENERGY
Definition: linux-rapl.c:178
#define PACKAGE_ENERGY
Definition: linux-rapl.c:167
static long long read_msr(int fd, unsigned int which)
Definition: linux-rapl.c:185
#define PACKAGE_ENERGY_CNT
Definition: linux-rapl.c:172
static int num_cpus
Definition: linux-rapl.c:161
int time_divisor
Definition: linux-rapl.c:163
static int get_kernel_nr_cpus(void)
Definition: linux-rapl.c:296
#define HANDLE_STRING_ERROR
Definition: linux-rapl.c:35
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
int fclose(FILE *__stream)
#define papi_calloc(a, b)
Definition: papi_memory.h:37
static int cidx
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
const char * name
Definition: rocs.c:225
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
Hardware info structure.
Definition: papi.h:774
int cpuid_family
Definition: papi.h:786
int cpuid_model
Definition: papi.h:787
int vendor
Definition: papi.h:781
Definition: linux-rapl.c:110
int return_type
Definition: linux-rapl.c:117
char name[PAPI_MAX_STR_LEN]
Definition: linux-rapl.c:111
char units[PAPI_MIN_STR_LEN]
Definition: linux-rapl.c:112
int fd_offset
Definition: linux-rapl.c:114
char description[PAPI_MAX_STR_LEN]
Definition: linux-rapl.c:113
int msr
Definition: linux-rapl.c:115
_rapl_register_t resources
Definition: linux-rapl.c:118
int type
Definition: linux-rapl.c:116
unsigned int selector
Definition: linux-rapl.c:106
PAPI_hw_info_t hw_info
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ _rapl_init_control_state()

static int _rapl_init_control_state ( hwd_control_state_t ctl)
static

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

1038{
1039
1041 int i;
1042
1043 for(i=0;i<RAPL_MAX_COUNTERS;i++) {
1044 control->being_measured[i]=0;
1045 }
1046
1047 return PAPI_OK;
1048}
#define RAPL_MAX_COUNTERS
Definition: linux-rapl.c:127
int being_measured[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:131

◆ _rapl_init_thread()

static int _rapl_init_thread ( hwd_context_t ctx)
static

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

320{
321 ( void ) ctx;
322
323 return PAPI_OK;
324}

◆ _rapl_ntv_code_to_descr()

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

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

1296{
1297 int index = EventCode;
1298
1299 if ( index >= 0 && index < num_events ) {
1300 strncpy( name, rapl_native_events[index].description, len );
1301 return PAPI_OK;
1302 }
1303 return PAPI_ENOEVNT;
1304}
#define PAPI_ENOEVNT
Definition: f90papi.h:139

◆ _rapl_ntv_code_to_info()

static int _rapl_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)
static

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

1308{
1309
1310 int index = EventCode;
1311
1312 if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
1313
1314 strncpy( info->symbol, rapl_native_events[index].name, sizeof(info->symbol)-1);
1315 info->symbol[sizeof(info->symbol)-1] = '\0';
1316
1317 strncpy( info->long_descr, rapl_native_events[index].description, sizeof(info->long_descr)-1);
1318 info->long_descr[sizeof(info->long_descr)-1] = '\0';
1319
1320 strncpy( info->units, rapl_native_events[index].units, sizeof(info->units)-1);
1321 info->units[sizeof(info->units)-1] = '\0';
1322
1324
1325 return PAPI_OK;
1326}
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963

◆ _rapl_ntv_code_to_name()

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

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

1279{
1280
1281 int index = EventCode & PAPI_NATIVE_AND_MASK;
1282
1283 if ( index >= 0 && index < num_events ) {
1284 strncpy( name, rapl_native_events[index].name, len );
1285 return PAPI_OK;
1286 }
1287
1288 return PAPI_ENOEVNT;
1289}
#define PAPI_NATIVE_AND_MASK

◆ _rapl_ntv_enum_events()

static int _rapl_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)
static

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

1239{
1240
1241 int index;
1242
1243 switch ( modifier ) {
1244
1245 case PAPI_ENUM_FIRST:
1246
1247 if (num_events==0) {
1248 return PAPI_ENOEVNT;
1249 }
1250 *EventCode = 0;
1251
1252 return PAPI_OK;
1253
1254
1255 case PAPI_ENUM_EVENTS:
1256
1257 index = *EventCode & PAPI_NATIVE_AND_MASK;
1258
1259 if ( index < num_events - 1 ) {
1260 *EventCode = *EventCode + 1;
1261 return PAPI_OK;
1262 } else {
1263 return PAPI_ENOEVNT;
1264 }
1265 break;
1266
1267 default:
1268 return PAPI_EINVAL;
1269 }
1270
1271 return PAPI_EINVAL;
1272}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ _rapl_read()

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

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

1119{
1120 (void) flags;
1121
1122 _rapl_stop( ctx, ctl );
1123
1124 /* Pass back a pointer to our results */
1125 *events = ((_rapl_control_state_t*) ctl)->count;
1126
1127 return PAPI_OK;
1128}
char events[MAX_EVENTS][BUFSIZ]
static int _rapl_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
Definition: linux-rapl.c:1072
Here is the call graph for this function:

◆ _rapl_reset()

static int _rapl_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

1226{
1227 ( void ) ctx;
1228 ( void ) ctl;
1229
1230 return PAPI_OK;
1231}

◆ _rapl_set_domain()

static int _rapl_set_domain ( hwd_control_state_t ctl,
int  domain 
)
static

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

1212{
1213 ( void ) ctl;
1214
1215 /* In theory we only support system-wide mode */
1216 /* How to best handle that? */
1217 if ( PAPI_DOM_ALL != domain )
1218 return PAPI_EINVAL;
1219
1220 return PAPI_OK;
1221}
#define PAPI_DOM_ALL
Definition: f90papi.h:261

◆ _rapl_shutdown_component()

static int _rapl_shutdown_component ( void  )
static

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

1136{
1137 int i;
1138
1140 if (fd_array) {
1141 for(i=0;i<num_cpus;i++) {
1142 if (fd_array[i].open) close(fd_array[i].fd);
1143 }
1145 }
1146
1147 return PAPI_OK;
1148}
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:188
int close(int fd)
Definition: appio.c:179
#define papi_free(a)
Definition: papi_memory.h:35
Here is the call graph for this function:

◆ _rapl_shutdown_thread()

static int _rapl_shutdown_thread ( hwd_context_t ctx)
static

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

1111{
1112 ( void ) ctx;
1113 return PAPI_OK;
1114}

◆ _rapl_start()

static int _rapl_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

1052{
1053 _rapl_context_t* context = (_rapl_context_t*) ctx;
1055 long long now = PAPI_get_real_usec();
1056 int i;
1057
1058
1059 for( i = 0; i < RAPL_MAX_COUNTERS; i++ ) {
1060 if ((control->being_measured[i]) && (control->need_difference[i])) {
1061 context->start_value[i]=(read_rapl_value(i) & 0xFFFFFFFF);
1062 context->accumulated_value[i]=0;
1063 }
1064 }
1065
1066 control->lastupdate = now;
1067
1068 return PAPI_OK;
1069}
get real time counter value in microseconds
static long long read_rapl_value(int index)
Definition: linux-rapl.c:222
long long start_value[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:145
long long accumulated_value[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:146
int need_difference[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:133
Here is the call graph for this function:

◆ _rapl_stop()

static int _rapl_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

1073{
1074 /* read values */
1075 _rapl_context_t* context = (_rapl_context_t*) ctx;
1077 long long now = PAPI_get_real_usec();
1078 int i;
1079 long long temp, newstart;
1080
1081 for ( i = 0; i < RAPL_MAX_COUNTERS; i++ ) {
1082 if (control->being_measured[i]) {
1083 temp = read_rapl_value(i);
1084 if (control->need_difference[i]) {
1085 temp &= 0xFFFFFFFF;
1086 newstart = temp;
1087 /* test for wrap around */
1088 if (temp < context->start_value[i] ) {
1089 SUBDBG("Wraparound!\nstart:\t%#016x\ttemp:\t%#016x",
1090 (unsigned)context->start_value[i], (unsigned)temp);
1091 temp += (0x100000000 - context->start_value[i]);
1092 SUBDBG("\tresult:\t%#016x\n", (unsigned)temp);
1093 } else {
1094 temp -= context->start_value[i];
1095 }
1096 // reset the start value, add to accum, set temp for convert call.
1097 context->start_value[i]=newstart;
1098 context->accumulated_value[i] += temp;
1099 temp = context->accumulated_value[i];
1100 }
1101 control->count[i] = convert_rapl_energy( i, temp );
1102 }
1103 }
1104 control->lastupdate = now;
1105 return PAPI_OK;
1106}
static long long convert_rapl_energy(int index, long long value)
Definition: linux-rapl.c:231
long long count[RAPL_MAX_COUNTERS]
Definition: linux-rapl.c:132
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rapl_update_control_state()

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

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

1170{
1171 int i, index;
1172 ( void ) ctx;
1173
1175
1176 /* Ugh, what is this native[] stuff all about ?*/
1177 /* Mostly remap stuff in papi_internal */
1178
1179 for(i=0;i<RAPL_MAX_COUNTERS;i++) {
1180 control->being_measured[i]=0;
1181 }
1182
1183 for( i = 0; i < count; i++ ) {
1184 index=native[i].ni_event&PAPI_NATIVE_AND_MASK;
1185 native[i].ni_position=rapl_native_events[index].resources.selector - 1;
1186 control->being_measured[index]=1;
1187
1188 /* Only need to subtract if it's a PACKAGE_ENERGY or ENERGY_CNT type */
1189 control->need_difference[index]=
1194 }
1195
1196 return PAPI_OK;
1197}
static long count
static int native

◆ convert_rapl_energy()

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

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

231 {
232
233 union {
234 long long ll;
235 double fp;
236 } return_val;
237
238 return_val.ll = value; /* default case: return raw input value */
239
241 return_val.ll = (long long)(((double)value/cpu_energy_divisor)*1e9);
242 }
243
244 if (rapl_native_events[index].type==DRAM_ENERGY) {
245 return_val.ll = (long long)(((double)value/dram_energy_divisor)*1e9);
246 }
247
249 return_val.ll = (long long)(((double)value/cpu_energy_divisor)*1e9);
250 }
251
253 return_val.fp = (double)
255 (double)power_divisor;
256 }
257
259 return_val.fp = (double)
261 (double)power_divisor;
262 }
263
265 return_val.fp = (double)
267 (double)power_divisor;
268 }
269
271 return_val.fp = (double)
273 (double)time_divisor;
274 }
275
277 return_val.ll = ((value>>THERMAL_SHIFT)&POWER_INFO_UNIT_MASK);
278 }
279
281 return_val.ll = ((value>>MINIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK);
282 }
283
285 return_val.ll = ((value>>MAXIMUM_POWER_SHIFT)&POWER_INFO_UNIT_MASK);
286 }
287
289 return_val.ll = ((value>>MAXIMUM_TIME_WINDOW_SHIFT)&POWER_INFO_UNIT_MASK);
290 }
291
292 return return_val.ll;
293}
#define THERMAL_SHIFT
Definition: linux-rapl.c:98
#define MAXIMUM_POWER_SHIFT
Definition: linux-rapl.c:100
#define POWER_INFO_UNIT_MASK
Definition: linux-rapl.c:97
#define MINIMUM_POWER_SHIFT
Definition: linux-rapl.c:99
#define MAXIMUM_TIME_WINDOW_SHIFT
Definition: linux-rapl.c:101
uint16_t type
static FILE * fp
long long int long long
Definition: sde_internal.h:85
Here is the caller graph for this function:

◆ get_kernel_nr_cpus()

static int get_kernel_nr_cpus ( void  )
static

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

297{
298 FILE *fff;
299 int num_read, nr_cpus = 1;
300 fff=fopen("/sys/devices/system/cpu/kernel_max","r");
301 if (fff==NULL) return nr_cpus;
302 num_read=fscanf(fff,"%d",&nr_cpus);
303 fclose(fff);
304 if (num_read==1) {
305 nr_cpus++;
306 } else {
307 nr_cpus = 1;
308 }
309 return nr_cpus;
310}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_fd()

static int open_fd ( int  offset)
static

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

198 {
199
200 int fd=-1;
201 char filename[BUFSIZ];
202
203 if (fd_array[offset].open==0) {
204 sprintf(filename,"/dev/cpu/%d/msr_safe",offset);
205 fd = open(filename, O_RDONLY);
206 if (fd<0) {
207 sprintf(filename,"/dev/cpu/%d/msr",offset);
208 fd = open(filename, O_RDONLY);
209 }
210 if (fd>=0) {
211 fd_array[offset].fd=fd;
212 fd_array[offset].open=1;
213 }
214 }
215 else {
216 fd=fd_array[offset].fd;
217 }
218
219 return fd;
220}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_msr()

static long long read_msr ( int  fd,
unsigned int  which 
)
static

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

185 {
186
187 uint64_t data;
188
189 if ( fd<0 || pread(fd, &data, sizeof data, which) != sizeof data ) {
190 perror("rdmsr:pread");
191 fprintf(stderr,"rdmsr error, msr %x\n",which);
192 exit(127);
193 }
194
195 return (long long)data;
196}
FILE * stderr
Here is the caller graph for this function:

◆ read_rapl_value()

static long long read_rapl_value ( int  index)
static

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

222 {
223
224 int fd;
225
226 fd=open_fd(rapl_native_events[index].fd_offset);
227 return read_msr(fd,rapl_native_events[index].msr);
228
229}
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _rapl_vector

papi_vector_t _rapl_vector

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

◆ cpu_energy_divisor

int cpu_energy_divisor

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

◆ dram_energy_divisor

int dram_energy_divisor

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

◆ fd_array

struct fd_array_t* fd_array =NULL

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

◆ msr_rapl_power_unit

unsigned int msr_rapl_power_unit

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

◆ num_cpus

int num_cpus =0
static

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

◆ num_events

int num_events = 0
static

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

◆ num_packages

int num_packages =0
static

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

◆ power_divisor

int power_divisor

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

◆ rapl_native_events

_rapl_native_event_entry_t* rapl_native_events =NULL
static

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

◆ time_divisor

int time_divisor

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