Code Monkey home page Code Monkey logo

nanobench's Introduction

nanoBench

This is an experimental fork of the nanoBench Linux x86 microbenchmarking tool. See the original repo for full details; this tool was originally developed by Andreas Abel. I have added support for exception handling (so illegal instructions can be benchmarked) and execution of arbitrary machine code (input as a C string rather than as a binary file as in the original). However, note that this breaks nanoBench's original command-line interface; please use the original repo if you wish to use this interface. The kernel module is also unsupported due to the challenges of exception handling in the kernel.

Installation

sudo apt install msr-tools
git clone https://github.com/cattius/nanoBench.git
cd nanoBench
make

nanoBench might not work if Secure Boot is enabled. Click here for instructions on how to disable Secure Boot.

Usage

The provided example program is usingNanobench.c, which tests a single illegal instruction (0x0f0b, ud2). Update the configuration options with the length of your instruction in bytes (for exception handling), the instruction itself as a string of hex bytes, and the filepath of your chosen configuration file (this is dependent on the microarchitecture of your CPU; opening the performance counters will fail if you choose a file for a different microarchitecture). If the provided length is incorrect, exception handling will fail and the program will hang.

instrLen = 2;
char* instr = "\x0f\x0b";
char* config = "configs/cfg_Broadwell_common.txt";

The profileInstr() function tests a single instruction at a time, but can be called repeatedly with different instructions to test (instr and config are passed as parameters). Further configuration options (such as the number of times to test the instruction per measurement, and the number of measurements to make - 10000 and 10 by default respectively) can be found in nanoBench.h.

To compile and run the program, use:

make
sudo ./run.sh

Counter measurements will be output to the console along with where relevant the signal number (if the instruction causes an exception). Note that if an instruction causes an exception measurements include the overhead of OS-level and user-level exception handling.

For more complex tasks, NanoBench can be used as a shared library. testOpcodeFile.py demonstrates how the shared library can be called from Python to read in a list of instructions from a file and benchmark them. To use this file, first edit runPython.sh to replace 'yourInputFileName' with the filepath of a list of instructions to benchmark in hex. The expected input format is 'opcode length', with one pair of values per line.

make
sudo ./runPython.sh

Performance Counter Config Files

Performance counter configuration files for most recent Intel and AMD CPUs are in the configs folder. These files can be adapted/reduced to the events you are interested in.

The format of the entries in the configuration files is

EvtSel.UMASK(.CMSK=...)(.AnyT)(.EDG)(.INV)(.CTR=...)(.MSR_3F6H=...)(.MSR_PF=...)(.MSR_RSP0=...)(.MSR_RSP1=...) Name

You can find details on the meanings of the different parts of the entries in chapters 18 and 19 of Intel's System Programming Guide.

Supported Platforms

This fork supports Intel processors with architectural performance monitoring version โ‰ฅ 3. Support has also been implemented for AMD Family 17h processors, but note this has not yet been tested. The code was developed and tested using Ubuntu 18.04.

nanobench's People

Contributors

andreas-abel avatar anthonywharton avatar cattius avatar

Watchers

 avatar  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.