gomsr

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2018 License: Apache-2.0 Imports: 3 Imported by: 10

README

gomsr

GoDoc Go Report Card CircleCI

gomsr is a library for reading from and writing to MSRs. It'll work on any linux machine that supports the msr kernel module. It also supports setting a custom character device location, allowing gomsr to work with utilities such as msr-safe.

A quick and dirty check to see if this will work on your system:

$ ls /dev/cpu/0/msr
/dev/cpu/0/msr

# on some systems, you might need to do this first
$ sudo modprobe msr

This library is a new WIP, and breaking changes should be expected.

Usage

gomsr has no dependencies, and is super easy to use:


//0x198 is IA32_PERF_STATUS on most Intel CPUs

//ReadMSR() takes a CPU and an MSR address
data, err := ReadMSR(0, 0x198)
if err != nil {
	log.Fatalf("Error: %s", err)
}

//You can also write to MSRs
err := WriteMSR(0, 0x401, 0)
if err != nil {
	log.Fatalf("Error: %s", err)
}

//You can also create an msr handler. This is suited for repeated reads/writes

//the MSR() init function just takes a CPU
msr, err := MSR(0)
if err != nil {
	log.Fatalf("Error: %s", err)
}

data, err := msr.Read(0x610)
if err != nil {
	log.Fatalf("Error: %s", err)
}
fmt.Printf("Got 0x%x\n", data)

msr.Close()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadMSR

func ReadMSR(cpu int, msr int64) (uint64, error)

ReadMSR reads the MSR on the given CPU as a one-time operation

func ReadMSRWithLocation

func ReadMSRWithLocation(cpu int, msr int64, fmtStr string) (uint64, error)

ReadMSRWithLocation is like ReadMSR(), but takes a custom location, for use with testing or 3rd party utilities like llnl/msr-safe It takes a string that has a `%d` format specifier for the cpu. For example: /dev/cpu/%d/msr_safe

func WriteMSR

func WriteMSR(cpu int, msr int64, value uint64) error

WriteMSR writes the MSR on the given CPU as a one-time operation

func WriteMSRWithLocation

func WriteMSRWithLocation(cpu int, msr int64, value uint64, fmtStr string) error

WriteMSRWithLocation is like WriteMSR(), but takes a custom location, for use with testing or 3rd party utilities like llnl/msr-safe It takes a string that has a `%d` format specifier for the cpu. For example: /dev/cpu/%d/msr_safe

Types

type MSRDev

type MSRDev struct {
	// contains filtered or unexported fields
}

MSRDev represents a handler for frequent read/write operations for one-off MSR read/writes, gomsr provides {Read,Write}MSR*() functions

func MSR

func MSR(cpu int) (MSRDev, error)

MSR provides an interface for reoccurring access to a given CPU's MSR interface

func MSRWithLocation

func MSRWithLocation(cpu int, fmtString string) (MSRDev, error)

MSRWithLocation is the same as MSR(), but takes a custom location, for use with testing or 3rd party utilities like llnl/msr-safe It takes a string that has a `%d` format specifier for the cpu. For example: /dev/cpu/%d/msr_safe

func (MSRDev) Close

func (d MSRDev) Close() error

Close closes the connection to the MSR

func (MSRDev) Read

func (d MSRDev) Read(msr int64) (uint64, error)

Read reads a given MSR on the CPU and returns the uint64

func (MSRDev) Write

func (d MSRDev) Write(regno int64, value uint64) error

Write writes a given value to the provided register

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL