fearful-symmetry / gorapl

A user-friendly, low-level API for accessing Intel's RAPL feature set
Apache License 2.0
1 stars 1 forks source link

goRAPL

GoDoc Go Report Card CircleCI

A dead-simple, low-level API for accessing the Intel RAPL API. Right now it's only capable of reading from MSRs, and may be expanded to write functionality at a later time.

Install

gorapl uses modules for dependency management. This means you'll need at least go 1.11. With that in mind:

$ go get github.com/fearful-symmetry/gorapl

This is a rather experimental library that's early on in it's life, so it isn't very useful yet! It has a lot of shortcomings, and a lot of things that needs to do, but can't. Most notably, it can only handle systems with one CPU socket. TODOs and progress is being tracked on the issues page.

Usage & caveats

Unless you're using something like msr-safe, gorapl requres root to access the underlying msr device at /dev/cpu/$CPU/msr.

If that device doesn't exist, you might need to load the kernel module:

$ sudo modprobe msr

Not all Intel CPUs support RAPL. The feature was introduced in Sandy Bridge, and available domains vary by processor. A quick way to check:

$ sudo rdmsr -a 0x611 #rdmsr is part of the msr-tools package on most linuxes

#You can check to see if the kernel picked up any RAPL domains too:

$ dmesg | grep rapl

Now that you're ready to go, using gorapl is easy:


    h, err := NewRAPL(0)
    if err != nil {
        // ...
    }

    dat, err := h.ReadPowerLimit(DRAM)
    if err != nil {
        //
    }
    fmt.Printf("Current RAPL power limit settings: %#v\n", dat)