Blame benchtests/README

Packit 6c4009
Using the glibc microbenchmark suite
Packit 6c4009
====================================
Packit 6c4009
Packit 6c4009
The glibc microbenchmark suite automatically generates code for specified
Packit 6c4009
functions, builds and calls them repeatedly for given inputs to give some
Packit 6c4009
basic performance properties of the function.
Packit 6c4009
Packit 6c4009
Running the benchmark:
Packit 6c4009
=====================
Packit 6c4009
Packit 6c4009
The benchmark needs python 2.7 or later in addition to the
Packit 6c4009
dependencies required to build the GNU C Library.  One may run the
Packit 6c4009
benchmark by invoking make as follows:
Packit 6c4009
Packit 6c4009
  $ make bench
Packit 6c4009
Packit 6c4009
This runs each function for 10 seconds and appends its output to
Packit 6c4009
benchtests/bench.out.  To ensure that the tests are rebuilt, one could run:
Packit 6c4009
Packit 6c4009
  $ make bench-clean
Packit 6c4009
Packit 6c4009
The duration of each test can be configured setting the BENCH_DURATION variable
Packit 6c4009
in the call to make.  One should run `make bench-clean' before changing
Packit 6c4009
BENCH_DURATION.
Packit 6c4009
Packit 6c4009
  $ make BENCH_DURATION=1 bench
Packit 6c4009
Packit 6c4009
The benchmark suite does function call measurements using architecture-specific
Packit 6c4009
high precision timing instructions whenever available.  When such support is
Packit 6c4009
not available, it uses clock_gettime (CLOCK_PROCESS_CPUTIME_ID).  One can force
Packit 6c4009
the benchmark to use clock_gettime by invoking make as follows:
Packit 6c4009
Packit 6c4009
  $ make USE_CLOCK_GETTIME=1 bench
Packit 6c4009
Packit 6c4009
Again, one must run `make bench-clean' before changing the measurement method.
Packit 6c4009
Packit Service 157b8b
On x86 processors, RDTSCP instruction provides more precise timing data
Packit Service 157b8b
than RDTSC instruction.  All x86 processors since 2010 support RDTSCP
Packit Service 157b8b
instruction.  One can force the benchmark to use RDTSCP by invoking make
Packit Service 157b8b
as follows:
Packit Service 157b8b
Packit Service 157b8b
  $ make USE_RDTSCP=1 bench
Packit Service 157b8b
Packit Service 157b8b
One must run `make bench-clean' before changing the measurement method.
Packit Service 157b8b
Packit 6c4009
Running benchmarks on another target:
Packit 6c4009
====================================
Packit 6c4009
Packit 6c4009
If the target where you want to run benchmarks is not capable of building the
Packit 6c4009
code or you're cross-building, you could build and execute the benchmark in
Packit 6c4009
separate steps.  On the build system run:
Packit 6c4009
Packit 6c4009
  $ make bench-build
Packit 6c4009
Packit 6c4009
and then copy the source and build directories to the target and run the
Packit 6c4009
benchmarks from the build directory as usual:
Packit 6c4009
Packit 6c4009
  $ make bench
Packit 6c4009
Packit 6c4009
make sure the copy preserves timestamps by using either rsync or scp -p
Packit 6c4009
otherwise the above command may try to build the benchmark again.  Benchmarks
Packit 6c4009
that require generated code to be executed during the build are skipped when
Packit 6c4009
cross-building.
Packit 6c4009
Packit 6c4009
Running subsets of benchmarks:
Packit 6c4009
==============================
Packit 6c4009
Packit 6c4009
To run only a subset of benchmarks, one may invoke make as follows
Packit 6c4009
Packit 6c4009
  $ make bench BENCHSET="bench-pthread bench-math malloc-thread"
Packit 6c4009
Packit 6c4009
where BENCHSET may be a space-separated list of the following values:
Packit 6c4009
Packit 6c4009
    bench-math
Packit 6c4009
    bench-pthread
Packit 6c4009
    bench-string
Packit 6c4009
    string-benchset
Packit 6c4009
    wcsmbs-benchset
Packit 6c4009
    stdlib-benchset
Packit 6c4009
    stdio-common-benchset
Packit 6c4009
    math-benchset
Packit 6c4009
    malloc-thread
Packit 6c4009
Packit 6c4009
Adding a function to benchtests:
Packit 6c4009
===============================
Packit 6c4009
Packit 6c4009
If the name of the function is `foo', then the following procedure should allow
Packit 6c4009
one to add `foo' to the bench tests:
Packit 6c4009
Packit 6c4009
- Append the function name to the bench variable in the Makefile.
Packit 6c4009
Packit 6c4009
- Make a file called `foo-inputs` to provide the definition and input for the
Packit 6c4009
  function.  The file should have some directives telling the parser script
Packit 6c4009
  about the function and then one input per line.  Directives are lines that
Packit 6c4009
  have a special meaning for the parser and they begin with two hashes '##'.
Packit 6c4009
  The following directives are recognized:
Packit 6c4009
Packit 6c4009
  - args: This should be assigned a colon separated list of types of the input
Packit 6c4009
    arguments.  This directive may be skipped if the function does not take any
Packit 6c4009
    inputs.  One may identify output arguments by nesting them in <>.  The
Packit 6c4009
    generator will create variables to get outputs from the calling function.
Packit 6c4009
  - ret: This should be assigned the type that the function returns.  This
Packit 6c4009
    directive may be skipped if the function does not return a value.
Packit 6c4009
  - includes: This should be assigned a comma-separated list of headers that
Packit 6c4009
    need to be included to provide declarations for the function and types it
Packit 6c4009
    may need (specifically, this includes using "#include <header>").
Packit 6c4009
  - include-sources: This should be assigned a comma-separated list of source
Packit 6c4009
    files that need to be included to provide definitions of global variables
Packit 6c4009
    and functions (specifically, this includes using "#include "source").
Packit 6c4009
    See pthread_once-inputs and pthreads_once-source.c for an example of how
Packit 6c4009
    to use this to benchmark a function that needs state across several calls.
Packit 6c4009
  - init: Name of an initializer function to call to initialize the benchtest.
Packit 6c4009
  - name: See following section for instructions on how to use this directive.
Packit 6c4009
Packit 6c4009
  Lines beginning with a single hash '#' are treated as comments.  See
Packit 6c4009
  pow-inputs for an example of an input file.
Packit 6c4009
Packit 6c4009
Multiple execution units per function:
Packit 6c4009
=====================================
Packit 6c4009
Packit 6c4009
Some functions have distinct performance characteristics for different input
Packit 6c4009
domains and it may be necessary to measure those separately.  For example, some
Packit 6c4009
math functions perform computations at different levels of precision (64-bit vs
Packit 6c4009
240-bit vs 768-bit) and mixing them does not give a very useful picture of the
Packit 6c4009
performance of these functions.  One could separate inputs for these domains in
Packit 6c4009
the same file by using the `name' directive that looks something like this:
Packit 6c4009
Packit 6c4009
  ##name: 240bit
Packit 6c4009
Packit 6c4009
See the pow-inputs file for an example of what such a partitioned input file
Packit 6c4009
would look like.
Packit 6c4009
Packit 6c4009
It is also possible to measure throughput of a (partial) trace extracted from
Packit 6c4009
a real workload.  In this case the whole trace is iterated over multiple times
Packit 6c4009
rather than repeating every input multiple times.  This can be done via:
Packit 6c4009
Packit 6c4009
  ##name: workload-<name>
Packit 6c4009
Packit 6c4009
Benchmark Sets:
Packit 6c4009
==============
Packit 6c4009
Packit 6c4009
In addition to standard benchmarking of functions, one may also generate
Packit 6c4009
custom outputs for a set of functions.  This is currently used by string
Packit 6c4009
function benchmarks where the aim is to compare performance between
Packit 6c4009
implementations at various alignments and for various sizes.
Packit 6c4009
Packit 6c4009
To add a benchset for `foo':
Packit 6c4009
Packit 6c4009
- Add `foo' to the benchset variable.
Packit 6c4009
- Write your bench-foo.c that prints out the measurements to stdout.
Packit 6c4009
- On execution, a bench-foo.out is created in $(objpfx) with the contents of
Packit 6c4009
  stdout.
Packit 6c4009
Packit 6c4009
Reading String Benchmark Results:
Packit 6c4009
================================
Packit 6c4009
Packit 6c4009
Some of the string benchmark results are now in JSON to make it easier to read
Packit 6c4009
in scripts.  Use the benchtests/compare_strings.py script to show the results
Packit 6c4009
in a tabular format, generate graphs and more. Run
Packit 6c4009
Packit 6c4009
    benchtests/scripts/compare_strings.py -h
Packit 6c4009
Packit 6c4009
for usage information.