Blame benchtests/README

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