Giter Club home page Giter Club logo

pmu-utils's Introduction

PMU Utils

Requirements

Currently, only Linux is supported. The library does not rely on any other library. It uses only standard C functionality.

Linux Usage

Preparation:

# Building the kernel module requires the kernel headers of the kernel. On Ubuntu or Debian, they can be installed by running
sudo apt install linux-headers-$(uname -r)

# The kernel module can be built by running
make

# The resulting kernel module can be loaded using
sudo insmod module/pmu_utils.ko

# Additionally step for x86_64 chips machines
sudo modprobe msr   # load msr module

Using the library:
Refer to tests directory for more details about how to use the library. All the functions are defined in libpmu/pmu.h.

#include <pmu_utils.h>

For x86_64 chips

uint64_t start_pmc = 0, end_pmc = 0;
uint64_t hexcode = 0x410000, core = 0, pmc_id = 0;
int msr_fd = pmu_open_msr(core);             // open msr
pmu_set_msr_event(msr_fd, hexcode, core);    // set event
pmu_record_start(msr_fd);                    // start record
pmu_set_pmc(msr_fd, pmc_id, 0);              // set 0 for PMC[pmc_id]

start_pmc = pmu_get_rdpmc(pmc_id);        // read PMC[pmc_id]
/*
   code that you want to measure
*/
end_pmc = pmu_get_rdpmc(pmc_id);          // read PMC[pmc_id]

For aarch64 chips

uint64_t pmc_id0 = 0, pmc_id1 = 1;
pmu_set_event(0x0, NULL, evet_code[0], pmc_id0);
pmu_set_event(0x0, NULL, evet_code[0], pmc_id1);
memset(mem, 0, 4096);

pmu_values[0] = pmu_get_rdpmc(0);
pmu_values[1] = pmu_get_rdpmc(1);
/*
code that you want to measure
*/
pmu_values[0] = pmu_get_rdpmc(0) - pmu_values[0];
pmu_values[1] = pmu_get_rdpmc(1) - pmu_values[1];

Test and Example

Seen in tests directory.

cd tests && mkdir -p build && cd build && cmake .. && make tests

Script Utils

Change the directory to scripts and run *utils.py for your architecture.

References

pmu-utils's People

Contributors

kingfish404 avatar

Stargazers

Ruiyi Zhang avatar Amox avatar

Watchers

 avatar

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.