Git Product home page Git Product logo

raplcap's Introduction

RAPLCap

This project provides a C interface for managing Intel Running Average Power Limit (RAPL) power caps.

RAPLCap is primarily intended for use by researchers and software developers. Most Linux users and system administrators looking to manage RAPL should prefer the powercap-info and powercap-set command-line utilities from the powercap project.

RAPLCap supports multiple implementations with different backends:

It also provides binaries for getting/setting RAPL configurations from the command line. Each provides the same command line interface, but use different RAPLCap library backends.

  • rapl-configure-msr
  • rapl-configure-powercap

If using this project for other scientific works or publications, please reference:

  • Connor Imes, Huazhe Zhang, Kevin Zhao, Henry Hoffmann. "CoPPer: Soft Real-time Application Performance Using Hardware Power Capping". In: IEEE International Conference on Autonomic Computing (ICAC). 2019. DOI: https://doi.org/10.1109/ICAC.2019.00015

    BibTex
    @inproceedings{imes2019copper,
      author={Imes, Connor and Zhang, Huazhe and Zhao, Kevin and Hoffmann, Henry},
      booktitle={2019 IEEE International Conference on Autonomic Computing (ICAC)},
      title={{CoPPer}: Soft Real-Time Application Performance Using Hardware Power Capping},
      year={2019},
      pages={31-41},
      doi={10.1109/ICAC.2019.00015}
    }

Prerequisites

First, you must be using an Intel® processor that supports RAPL - Sandy Bridge (2nd generation Intel® Core) or newer.

Currently only Linux systems are supported by the primary implementations.

This project depends on:

  • powercap - backend required to compile and run the powercap implementation (or install the libpowercap-dev package on recent Debian-based Linux distributions).

If dependencies with sufficient versions are not found, backends that require them will not be compiled.

Users are expected to be familiar with basic RAPL capabilities and terminology, like zones (domains) and long/short term power constraints. Refer to Intel RAPL documentation for more technical information, especially the Intel® 64 and IA-32 Architectures Software Developer Manual, Volume 3: System Programming Guide.

Due to lack of portability in backends and data availability on some systems, the interface does not support discovering processor min/max power caps or thermal design power. Users should reference their hardware documentation or other system utilities to discover this information as needed.

Running Average Power Limit

Intel RAPL allows software to configure power caps on hardware components, like processors or main memory. Components manage themselves to respect the power cap while attempting to optimize performance. Note that power caps are NOT the same as power consumption, they only specify an upper bound on power consumption over a time window.

For example, processors use Dynamic Voltage and Frequency Scaling (DVFS) to trade performance and power consumption, where power P is proportional to capacitance C, the square of the voltage V, and clock frequency f: P ~ C * V^2 * f. An increase in frequency usually necessitates an increase in voltage, and vice versa, resulting in a non-linear tradeoff between performance (frequency) and power consumption. With RAPL, hardware manages voltage and frequency at finer-grained time intervals and with lower overhead than software-based DVFS controllers.

Building

This project uses CMake.

To build all libraries, run:

mkdir _build
cd _build
cmake ..
make

Installing

To install all libraries and headers, run with proper privileges:

make install

On Linux, installation typically places libraries in /usr/local/lib and header files in /usr/local/include.

Uninstalling

Install must be run before uninstalling in order to have a manifest.

To remove libraries and headers installed to the system, run with proper privileges:

make uninstall

Linking

CMake

If your project uses CMake, import targets from the RAPLCap package by specifying the MSR and/or Powercap components as needed. For example:

find_package(RAPLCap REQUIRED COMPONENTS MSR Powercap)
target_link_libraries(foo PRIVATE RAPLCap::raplcap-msr)
target_link_libraries(bar PRIVATE RAPLCap::raplcap-powercap)

Pkg-config

If not using CMake, get linker information (including transitive dependencies) with pkg-config, e.g., one of:

pkg-config --libs --static raplcap-msr
pkg-config --libs --static raplcap-powercap

Or in your Makefile, add to your linker flags one of:

$(shell pkg-config --libs --static raplcap-msr)
$(shell pkg-config --libs --static raplcap-powercap)

You may leave off the --static option if you built shared object libraries.

Depending on your install location, you may also need to augment your compiler flags with one of:

pkg-config --cflags raplcap-msr
pkg-config --cflags raplcap-powercap

Usage

See the man pages for the rapl-configure binaries, or run them with the -h or --help option for instructions.

The raplcap.h header provides the C interface along with detailed function documentation for using the libraries.

For backend-specific runtime dependencies, see the README files in their implementation subdirectories (links above).

The following is a simple example of setting power caps that assumes a homogeneous architecture.

  // Note: more robust error handling may be desirable for a real application
  raplcap rc;
  raplcap_limit rl_short, rl_long;
  uint32_t i, j, n, d;

  // get the number of RAPL packages
  n = raplcap_get_num_packages(NULL);
  if (n == 0) {
    perror("raplcap_get_num_packages");
    return -1;
  }

  // initialize
  if (raplcap_init(&rc)) {
    perror("raplcap_init");
    return -1;
  }

  // assuming each package has the same number of die, only querying for package=0
  d = raplcap_get_num_die(rc, 0);
  if (d == 0) {
    perror("raplcap_get_num_die");
    raplcap_destroy(&rc);
    return -1;
  }

  // for each package die, set a power cap of 100 Watts for short_term and 50 Watts for long_term constraints
  // a time window of 0 leaves the time window unchanged
  rl_short.watts = 100.0;
  rl_short.seconds = 0.0;
  rl_long.watts = 50.0;
  rl_long.seconds = 0.0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < d; j++) {
      if (raplcap_pd_set_limits(&rc, i, j, RAPLCAP_ZONE_PACKAGE, &rl_long, &rl_short)) {
        perror("raplcap_pd_set_limits");
      }
    }
  }

  // for each package die, enable the power caps
  // this could be done before setting caps, at the risk of enabling unknown power cap values first
  for (i = 0; i < n; i++) {
    for (j = 0; j < d; j++) {
      if (raplcap_pd_set_zone_enabled(&rc, i, j, RAPLCAP_ZONE_PACKAGE, 1)) {
        perror("raplcap_pd_set_zone_enabled");
      }
    }
  }

  // cleanup
  if (raplcap_destroy(&rc)) {
    perror("raplcap_destroy");
  }

Project Source

Find this and related project sources at the powercap organization on GitHub.
This project originates at: https://github.com/powercap/raplcap

Bug reports and pull requests for new implementations, bug fixes, and enhancements are welcome.

raplcap's People

Contributors

cimes-isi avatar connorimes avatar girardm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

raplcap's Issues

Intel i9-13900HX is not supported.

Hi there!

It was a long and torturous road that led me here.
My i9-13900HX CPU in a Sager laptop is getting heavily throttled in Linux.

This utility is telling me my CPU is not supported:

[evert@Evert ~]$ sudo rapl-configure-powercap 
[ERROR] [raplcap-powercap] powercap_intel_rapl_get_time_window_us: No data available
Failed to get peak power limit: No data available

And:

[evert@Evert ~]$ sudo rapl-configure-msr 
[ERROR] [raplcap-msr] CPU not supported: Family=6, Model=B7
Failed to initialize: Operation not supported

Rapl-info is providing some useful info:

[evert@Evert ~]$ rapl-info 
Zone 0
  name: package-0
  enabled: 1
  max_energy_range_uj: 262143328850
  Constraint 0
    name: long_term
    power_limit_uw: 135000000
    time_window_us: 95944704
    max_power_uw: 55000000
  Constraint 1
    name: short_term
    power_limit_uw: 162000000
    time_window_us: 2440
    max_power_uw: 0
  Constraint 2
    name: peak_power
    power_limit_uw: 315000000
    max_power_uw: 0
  Subzone 0
    name: core
    enabled: 0
    max_energy_range_uj: 262143328850
    Constraint 0
      name: long_term
      power_limit_uw: 0
      time_window_us: 976
  Subzone 1
    name: uncore
    enabled: 0
    max_energy_range_uj: 262143328850
    Constraint 0
      name: long_term
      power_limit_uw: 0
      time_window_us: 976
Zone 1
  name: psys
  enabled: 1
  max_energy_range_uj: 262143328850
  Constraint 0
    name: long_term
    power_limit_uw: 280000000
    time_window_us: 95944704
  Constraint 1
    name: short_term
    power_limit_uw: 300000000
    time_window_us: 976

Supporting power limit = 0

This issue is filed mostly to document the idea, although it is unlikely to be implemented.

Currently there is only one way to set a power value to 0, however undesirable that may be. A user must specify a really small watts (still > DBL_EPSILON) value that is ultimately rounded down when converting to microwatts or truncated at the bit-level when writing to MSRs. We might consider allowing watts=0 and only ignoring the watts and seconds fields when they are negative. This would require, in the very least:

  • A silent interface change (resulting in a major version bump and loss of backward compatibility)!
  • An additional burden on the user to set negative values (not as convenient as 0)
  • Changing interface description of and implementations of raplcap_set_limits(...)
  • Updates to rapl-configure (possibly with the addition of a -e/--enabled flag instead of accepting negative values. We note, however, that not all implementations support direct enabling/disabling, e.g., raplcap-libmsr.

Some interfaces might support seconds=0, but in reality this would result in the smallest possible time window due to how the bit values for time windows in MSRs are interpreted.

msr: ATOM_SILVERMONT_D energy units appear to be incorrect

The energy values on ATOM_SILVERMONT_D (model 0x4D) appear to be too large. When used for measuring power, it produces values > 10k Watts.

The Intel SDM Vol. 4 (as of December 2021) documents in Table 2-10 that the energy unit multiplier is 2^ESU microJoules, like with some other Atom CPUs. RAPLCap currently implements energy measurements as the SDM documents, but we see:

$ rapl-configure-msr        
      enabled: true
   watts_long: 15.000000000000
 seconds_long: 10.000000000000
  watts_short: 18.000000000000
seconds_short: 0.009765625000
       joules: 211875753.099263995886
   joules_max: 281474976.710655987263

However, if we use the standard energy multiplier of 1/2^ESU Joules, we see:

$ rapl-configure-msr      
      enabled: true
   watts_long: 15.000000000000
 seconds_long: 10.000000000000
  watts_short: 18.000000000000
seconds_short: 0.009765625000
       joules: 49373.058593750000
   joules_max: 65536.000000000000

which is much more reasonable. Measuring power then gives values < 10 W.

It appears that the Intel SDM is incorrect.

raplcap_set_zone_enabled in README

Hi,
I tried to use the library on my system by using the example provided in the README.
However, to let it work I had to add 'raplcap_set_zone_enabled(..)' before setting the cap. Adding it to the example would probably be helpful for other users.

Best,
Daniele

msr: Ice Lake Xeon CPUs: incorrect DRAM power limit lock bit, no clamping bit

The April 2021 Intel Software Developer's Manual Volume 4 adds Table 2-47 in Section 2.17.6 with new information on the MSR_DRAM_POWER_LIMIT register for Ice Lake Xeon CPUs (0x6A and 0x6C). Per the combined volume Section 14.10.5, bit 31 is the standard lock bit, but this particular Ice Lake documentation says it's at bit 63.

Additionally, there does not appear to be a clamping bit (bit 16 is now Reserved).

It would be really nice if somebody could confirm the correct behavior, since I don't have any Ice Lake Xeon CPUs to test.

[raplcap-libmsr] Can't set power value separately on power planes that haven’t been enabled before when seconds are not also set

This is a weird issue that we won't likely try to do anything to fix. It's probably a bug in libmsr, and they have removed support for PP0 and PP1 power planes.

Note entirely sure what versions of libmsr this affects. Based on my poorly written notes about this, it seem like the problem is that both the watts and seconds fields have to be set when a zone hasn't been enabled before. libmsr returns seconds=0 when we read before setting a new watts value in isolation, so we’re trying to set seconds=0 if the raplcap user didn't explicitly request a positive seconds value. The problem is exacerbated by not being able to enable the zone prior to setting values. Perhaps we'd have to set values twice?

I noted an error like:

Error: <libmsr> Invalid bit field values: calc_rapl_bits(): Seconds value is too large: (null):/local/third-party-tools/libmsr/src/msr_rapl.c::440

[raplcap-libmsr] May show Package as disabled if only one constraint is set/enabled

libmsr enables Package long and short term constraints separately, but doesn't offer a function to check enable statuses. We only say a Package or Platform zone is enabled if both long and short term are enabled.

This is likely only a problem if a constraint was actually disabled, as Package constraints are usually enabled by default.

FYI, it looks like the kernel sysfs interface via raplcap-powercap only checks a single (long term) constraint to determine enabled status. For example, see the 4.13 kernel release: https://github.com/torvalds/linux/blob/v4.13/drivers/powercap/intel_rapl.c#L362

PKG power limit

Hi,

after i set the PKG power limit to 55 watts and run an application whose peak power is over this value, the measured power consumption is about 50 watts, i.e. 5 watts difference. What is happening?

Hardware: Broadwell E5-2650V4
Release 0.1.1
RAPL setting: two time windows with 1 seconds, PKG to 55 watts
Measured power with: perf stat .... sleep 1

Best,
Bo

[powercap] PSYS is a top-level zone, not a subzone of PACKAGE

Currently the raplcap-powercap implementation expects all top-level zones to be PACKAGE type. With the introduction of platforms that actually support PSYS, we see that this is not the case -- PSYS zones are actually top-level zones like PACKAGE.

This also screws up the raplcap API that is centered around sockets. That problem will be addressed later in another issue, which will require API changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.