libmsr  0.3.0
A friendlier interface to accessing MSRs on Intel platforms
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Functions
msr_rapl.c File Reference
#include <math.h>
#include <omp.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <tgmath.h>
#include "msr_core.h"
#include "memhdlr.h"
#include "cpuid.h"
#include "msr_rapl.h"
#include "msr_turbo.h"
#include "libmsr_error.h"
#include "libmsr_debug.h"
Include dependency graph for msr_rapl.c:

Functions

int rapl_storage (struct rapl_data **data, uint64_t **flags)
 Store the RAPL data and flags on the heap.
 
int print_available_rapl (void)
 Print available RAPL registers based on platform-dependent flags.
 
int rapl_init (struct rapl_data **rapl, uint64_t **rapl_flags)
 Initialize storage for Running Average Power Limit (RAPL) data and flags.
 
int set_pkg_rapl_limit (const unsigned socket, struct rapl_limit *limit1, struct rapl_limit *limit2)
 Determine the steps necessary to set the user-supplied package-level power limit(s).
 
int set_dram_rapl_limit (const unsigned socket, struct rapl_limit *limit)
 Determine the steps necessary to set the user-supplied DRAM limit.
 
int set_pp_rapl_limit (const unsigned socket, struct rapl_limit *limit0, struct rapl_limit *limit1)
 Determine the steps necessary to set the user-supplied power plane limit.
 
int get_rapl_power_info (const unsigned socket, struct rapl_power_info *info)
 Get power info data for all RAPL power domains.
 
int set_pp_rapl_policies (const unsigned socket, uint64_t *pp0, uint64_t *pp1)
 Determine the steps necessary to set the user-supplied power plane policy.
 
int get_pp_rapl_policies (const unsigned socket, uint64_t *pp0, uint64_t *pp1)
 Get RAPL policies for the power plane domains.
 
int get_pkg_rapl_limit (const unsigned socket, struct rapl_limit *limit1, struct rapl_limit *limit2)
 Get RAPL power limit for the package domain.
 
int get_dram_rapl_limit (const unsigned socket, struct rapl_limit *limit)
 Get RAPL power limit for the DRAM domain.
 
int get_pp_rapl_limit (const unsigned socket, struct rapl_limit *limit0, struct rapl_limit *limit1)
 Get RAPL power limit for the power plane domains.
 
void dump_rapl_limit (struct rapl_limit *L, FILE *writedest)
 Print out RAPL power limit.
 
int dump_rapl_data_terse_label (FILE *writedest)
 Print the label for the abbreviated RAPL data print out.
 
int dump_rapl_data_terse (FILE *writedest)
 Print abbreviated RAPL data.
 
int dump_rapl_data (FILE *writedest)
 Print out a specified RAPL data item.
 
int dump_rapl_power_info (FILE *writedest)
 Print out only RAPL power data.
 
void get_rapl_power_unit (struct rapl_units *ru)
 Get units for RAPL power data.
 
void dump_rapl_power_unit (FILE *writedest)
 Print out RAPL power units (power, energy, time).
 
int poll_rapl_data (void)
 Read the current RAPL data and calculate the deltas from the previous call to this function.
 
int delta_rapl_data (void)
 Check how much the RAPL data has changed overtime to derive time-based values, such as power.
 
int read_rapl_data (void)
 Read all available RAPL data for a given socket.
 

Function Documentation

int delta_rapl_data ( void  )

Check how much the RAPL data has changed overtime to derive time-based values, such as power.

Returns
0 if successful, else -1 if rapl_storage() fails.
int dump_rapl_data ( FILE *  writedest)

Print out a specified RAPL data item.

Parameters
[in]writedestFile stream where output will be written to.
Returns
0 if successful, else -1 if rapl_storage() fails.
int dump_rapl_data_terse ( FILE *  writedest)

Print abbreviated RAPL data.

Parameters
[in]writedestFile stream where output will be written to.
Returns
0 if successful, else -1 if rapl_storage() fails.
int dump_rapl_data_terse_label ( FILE *  writedest)

Print the label for the abbreviated RAPL data print out.

Parameters
[in]writedestFile stream where output will be written to.
Returns
0 if successful, else -1 if rapl_storage() fails.
void dump_rapl_limit ( struct rapl_limit L,
FILE *  writedest 
)

Print out RAPL power limit.

Parameters
[in]LRAPL power limit for a given domain.
[in]writedestFile stream where output will be written to.
int dump_rapl_power_info ( FILE *  writedest)

Print out only RAPL power data.

Parameters
[in]writedestFile stream where output will be written to.
Returns
0 if successful, else -1 if rapl_storage() fails.
void dump_rapl_power_unit ( FILE *  writedest)

Print out RAPL power units (power, energy, time).

Parameters
[in]writedestFile stream where output will be written to.
Returns
0 if successful, else -1 if rapl_storage() fails.
int get_dram_rapl_limit ( const unsigned  socket,
struct rapl_limit limit 
)

Get RAPL power limit for the DRAM domain.

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds. If the bit vector is zero, read the msr value into the bit vector and translate into watts and seconds.

Parameters
[in]socketIdentifier of socket to read
[out]limitData for DRAM domain RAPL power limit.
Returns
0 if successful, else -1 if rapl_storage() fails.
int get_pkg_rapl_limit ( const unsigned  socket,
struct rapl_limit limit1,
struct rapl_limit limit2 
)

Get RAPL power limit for the package domain.

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds. If the bit vector is zero, read the msr value into the bit vector and translate into watts and seconds.

Parameters
[in]socketIdentifier of socket to read
[out]limit1Data for package domain RAPL power limit 1 (lower).
[out]limit2Data for package domain RAPL power limit 2 (upper).
Returns
0 if successful, else -1 if rapl_storage() fails.
int get_pp_rapl_limit ( const unsigned  socket,
struct rapl_limit limit0,
struct rapl_limit limit1 
)

Get RAPL power limit for the power plane domains.

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds. If the bit vector is zero, read the msr value into the bit vector and translate into watts and seconds.

Parameters
[in]socketIdentifier of socket to read
[out]limit0Data for PP0 domain RAPL power limit.
[out]limit1Data for PP1 domain RAPL power limit.
Returns
0 if successful, else -1 if rapl_storage() fails.
int get_pp_rapl_policies ( const unsigned  socket,
uint64_t *  pp0,
uint64_t *  pp1 
)

Get RAPL policies for the power plane domains.

Parameters
[in]socketUnique socket/package identifier.
[out]pp0Raw 64-bit value stored in MSR_PP0_POLICY.
[out]pp1Raw 64-bit value stored in MSR_PP1_POLICY.
Returns
0 if successful, else -1 if rapl_storage() fails.
int get_rapl_power_info ( const unsigned  socket,
struct rapl_power_info info 
)

Get power info data for all RAPL power domains.

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds. If the bit vector is zero, read the msr value into the bit vector and translate into watts and seconds.

Parameters
[in]socketUnique socket/package identifier.
[out]infoData for domain-specific power range info for RAPL usage.
Returns
0 if successful, else -1 if rapl_storage() fails.
void get_rapl_power_unit ( struct rapl_units ru)

Get units for RAPL power data.

Parameters
[out]ruData for RAPL power units.
int poll_rapl_data ( void  )

Read the current RAPL data and calculate the deltas from the previous call to this function.

If this function has not been called at least once, then the data will be initialized to zeros. NOTE: This is now what you use instead of read_rapl_data().

Returns
0 if successful, else -1 if rapl_storage() fails.
int print_available_rapl ( void  )

Print available RAPL registers based on platform-dependent flags.

Returns
0 if successful, else -1 if rapl_storage() fails.
int rapl_init ( struct rapl_data **  rapl,
uint64_t **  rapl_flags 
)

Initialize storage for Running Average Power Limit (RAPL) data and flags.

Be sure to put this function before any other RAPL functions.

Parameters
[out]raplPointer to storage for energy, time, and power data measurements from a given RAPL power domain.
[out]rapl_flagsPointer to storage for flags indicating available on registers on platform.
Returns
Number of locked registers, else -1 if rapl_storage() fails.
int rapl_storage ( struct rapl_data **  data,
uint64_t **  flags 
)

Store the RAPL data and flags on the heap.

This data will be used by nearly all other RAPL APIs. A user can retrieve only RAPL data or only RAPL flags by passing a NULL argument.

Parameters
[out]dataPointer to measurements of energy, time, and power data from a given RAPL power domain.
[out]flagsPointer to RAPL flags indicating available registers on a given platform.
Returns
0 if successful, else -1 if setflags() fails.
int read_rapl_data ( void  )

Read all available RAPL data for a given socket.

Returns
0 if successful, else -1 if rapl_storage() fails.
int set_dram_rapl_limit ( const unsigned  socket,
struct rapl_limit limit 
)

Determine the steps necessary to set the user-supplied DRAM limit.

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds and write the bit vector to the msr. If the bit vector is zero, translate the watts and seconds to the appropriate bit vector and write the bit vector to the msr.

Parameters
[in]socketUnique socket/package identifier.
[out]limitRAPL power limit data for DRAM power domain.
Returns
0 if successful, else -1 if rapl_storage() fails, if calc_std_rapl_limit() fails, or if DRAM RAPL domain power limit is not supported on the platform.
int set_pkg_rapl_limit ( const unsigned  socket,
struct rapl_limit limit1,
struct rapl_limit limit2 
)

Determine the steps necessary to set the user-supplied package-level power limit(s).

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds and write the bit vector to the msr. If the bit vector is zero, translate the watts and seconds to the appropriate bit vector and write the bit vector to the msr.

Parameters
[in]socketUnique socket/package identifier.
[in]limit1Data for lower power limit 1.
[in]limit2Data for upper power limit 2.
Returns
0 if successful, else -1 if rapl_storage() fails or if package RAPL domain power limit is not supported on the platform.
int set_pp_rapl_limit ( const unsigned  socket,
struct rapl_limit limit0,
struct rapl_limit limit1 
)

Determine the steps necessary to set the user-supplied power plane limit.

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds and write the bit vector to the msr. If the bit vector is zero, translate the watts and seconds to the appropriate bit vector and write the bit vector to the msr.

Parameters
[in]socketUnique socket/package identifier.
[in]limit0Data for PP0 power limit.
[in]limit1Data for PP1 power limit.
Returns
0 if successful, else -1 if rapl_storage() or calc_std_rapl_limit() fails.
int set_pp_rapl_policies ( const unsigned  socket,
uint64_t *  pp0,
uint64_t *  pp1 
)

Determine the steps necessary to set the user-supplied power plane policy.

If a pointer is null, do nothing. If the bit vector is nonzero, translate the bit vector to watts and seconds and write the bit vector to the msr. If the bit vector is zero, translate the watts and seconds to the appropriate bit vector and write the bit vector to the msr.

Parameters
[in]socketUnique socket/package identifier.
[in]pp0Raw 64-bit value specifying desired policy for PP0.
[in]pp1Raw 64-bit value specifying desired policy for PP1.
Returns
0 if successful, else -1 if rapl_storage() fails.