Building Guide (benchmark)

From liblfds.org
Jump to navigation Jump to search

Introducton

The benchmark binary is a thin command line veneer which provides convenient access to the benchmark functionality in libbenchmark. The binary depends on liblfds711, liblfds700, libbenchmark and libshared.

The benchmark library uses a porting abstraction layer to mask platform differences. Building benchmark requires build files (makefile, etc) for your toolchain (GCC, gnumake, etc) and a port of the abstraction layer to your platform.

A small number of popular toolchains are supported out-of-the-box, along with porting abstraction layers which cover Windows (user-mode) and Linux (user-mode).

Supported Toolchains

The supported toolchains are;

  • GCC and gnumake
  • MSVC and gnumake (yes, gnumake, not nmake)

Additionally, there is a second variant of the GCC and gnumake toolchain, which adds NUMA support in the form of libnuma. All builds depend on releases 7.1.1 and 7.0.0 of liblfds. This is because the benchmark application benchmarks previous versions, as well as the current version, of liblfds data structures. Releases 7.1.1 and 7.0.0 offer exactly the same platform support, so if 7.1.1 can compile, so can 7.0.0.

The libnuma library is necessary under Linux to access NUMA functionality. However, the library is an installed package and as such may or may not be installed. It is not possible in C to optionally include header files, or to detect whether or not they are present; as such either something must detect the presence of absence of the libnuma library and its header file and then construct the makefile (the route taken with configure) or the makefile must indicate to the build (through, say, a define passed to the compiler command line) whether or not libnuma is present. The makefiles are intended to be platform indepedent, to support for example arbitrary embedded platforms, and so the presence of ldconfig cannot be assumed. As such, there is no obvious way to determine the presence of absence of libnuma - so as such, there is a seperate "toolchain" which is the normal GCC and gnumake makefile but with linking to libnuma and a define passed to the compiler.

Note that in 7.1.1, Visual Studio solution files are not provided. This is because there are over liblfds and the benchmark and benchmark libraries and programmes (seven projects in all) in the end due to the multple build variants (debug, release, library, DLL, kernel library, kernel DLL, and repeated twice, once for VS2012 and once for VS2013) what comes to something like ten thousand settings, all of which have to be set using a mouse and a GUI, which is not only extraordinarily time-consuming and error-prone, but emotionally agonizing.

In all cases, the build files know where the various liblfds header and library files are, and so nothing needs to be installed for benchmark to build.

Mac support is not available due to lack of access to a Mac.

Directory Structure

└── test_and_benchmark
    └── benchmark                                                 : benchmark command line veneer
        ├── bin                                                   : output directory - the binary ends up here
        ├── build                                                 : build configuration directory - contains one directory per platform
        │   ├── gcc_gnumake_hosted_liblfds711_liblfds700          : GCC, gnumake, hosted implementation, liblfds 7.1.1 and liblfds 7.0.0
        │   ├── gcc_gnumake_hosted_liblfds711_liblfds700_libnuma  : GCC, gnumake, hosted implementation, liblfds 7.1.1, liblfds 7.0.0 and libnuma
        │   └── msvc_gnumake_liblfds711_liblfds700                : Microsoft Visual C (command line compiler), gnumake, liblfds 7.1.1 and liblfds 7.0.0
        ├── obj                                                   : temporary directory for object files
        └── src                                                   : the source files

Building

The benchmark directory tree contains at its top level directory called build.

This directory contains one directory per supported toolchain, where each such directory contains the files necessary to build for that toolchain. Detailed descriptions of how to build for each toolchain are given below, with one heading per toolchain.

The benchmark binary depends on liblfds711, liblfds700, libbenchmark and libshared. The benchmark build files are hardcoded with relative paths to find the output from these libraries, so these libraries do not need to be installed.

On all platforms, you need to clean between changing build types (debug, release, static, dynamic, profiled, etc), as there is only one directory used to hold object files.

Per-Toolchain Build Instructions

GCC and gnumake

└── test_and_benchmark
    └── benchmark
        └── build
            └── gcc_gnumake_hosted_liblfds711_liblfds700
                    Makefile

To build, install GCC and gnumake, enter the build directory and type;

make

The following targets are available;

cov     : coverage
dbg     : debug
prof    : profiling
rel     : release
tsan    : thread sanitizer
vanilla : no specific-build arguments

clean   : what you'd expect

When switching from one target to another, clean must be made.

If building *_ar_tsan, libtsan must be installed. This is not necessary if building *_so_tsan.

GCC, gnumake and libnuma

└── test_and_benchmark
    └── benchmark
        └── build
            └── gcc_gnumake_hosted_liblfds711_liblfds700_libnuma
                    Makefile

To build, install GCC, gnumake and libnuma (package name is usually "numctl-dev" or "numactl-devel"), enter the build directory and type;

make

The following targets are available;

cov     : coverage
dbg     : debug
prof    : profiling
rel     : release
tsan    : thread sanitizer
vanilla : no specific-build arguments

clean   : what you'd expect

When switching from one target to another, clean must be made.

If building *_ar_tsan, libtsan must be installed. This is not necessary if building *_so_tsan.

If building for ARM32 with shared object versions of the liblfds libraries, linking will fail, with the error "/usr/bin/ld: ../../bin/benchmark: hidden symbol `__aeabi_uidiv' in /usr/lib/gcc/arm-linux-gnueabihf/4.9/libgcc.a(_udivsi3.o) is referenced by DSO". This means something has attempted to divide a 64 bit value by a 64 bit value, an operation which apparently is costly and usually unnecessary, a 32 bit divisor apparently is normally adequate, and as such is intentionally caught in a link-breaking way.

Unfortunately, as far as can be determined, liblfds itself is not performing this operation - and as such, it is not obvious how to fix it.

MSVC and gnumake

└── test_and_benchmark
    └── benchmark
        └── build
            └── msvc_gnumake_liblfds711_liblfds700
                    makefile

To build, install an MSVC command line compiler, enter the build directory and type;

make

The following targets are available;

dlldbg  : debug   (with liblfds libs built as DLLs)
dllrel  : release (with liblfds libs built as DLLs)
libdbg  : debug   (with liblfds libs built as libs)
librel  : release (with liblfds libs built as libs)

clean   : what you'd expect

When switching from one target to another, clean must be made.

See Also