1
0
Fork 0

Expand use and support for LTO and FDO builds

Adds LTO to the CI build for Linux, which bring it as close as possible
to the planned formal release, which will additionally use FDO.

Adds some helper scripts to work with FDO files.

Improves the build notes for how to create and use FDO files.
This commit is contained in:
krcroft 2020-03-28 13:12:31 -07:00 committed by Patryk Obara
parent 0759165f45
commit 78ae277d28
9 changed files with 393 additions and 71 deletions

64
.github/scripts/build-autofdo.sh vendored Executable file
View file

@ -0,0 +1,64 @@
#!/bin/bash
# Copyright (c) 2020 Kevin R Croft <krcroft@gmail.com>
# SPDX-License-Identifier: GPL-2.0-or-later
# Builds and installs the AutoFDO package from
# https://github.com/google/autofdo
#
# AutoFDO is used to convert sample profiling data (collected using perf
# or ocperf.py from a Linux kernel built with with last branch
# record (LBR) tracing support running on an Intel CPU with LBR
# support) to GCC-specific AutoFDO records or LLVM's raw profile
# records.
#
# Pre-requisites: autoconf automake git libelf-dev libssl-dev pkg-config
# If building for LLVM, clang and llvm-dev are needed.
#
# Usage: build-autofdo.sh [LLVM version]
# Examples: ./build-autofdo.sh
# ./build-autofdo.sh 10
#
# Where the optional [LLVM version] allows building with LLVM support
# for the provided LLVM version.
set -euo pipefail
rootdir="$(pwd)"
prefix="$rootdir/afdo"
# Clone the repo
if [[ ! -d autofdo ]]; then
git clone --depth 1 --recursive https://github.com/google/autofdo.git
fi
# Enter and sync the repo (if it already exists)
pushd autofdo
git pull
# Initialize auto-tools
aclocal -I .
autoheader
autoconf
automake --add-missing -c
# Configure with the specified LLVM version if provided
if [[ -n "${1:-}" ]]; then
ver="$1"
withllvm="--with-llvm=$(command -v llvm-config-"$ver")"
fi
# Configure
flags="-Os -DNDEBUG -pipe"
./configure CFLAGS="$flags" CXXFLAGS="$flags" --prefix="$prefix" "${withllvm:-}"
# Build and install
# Note: make cannot be run in parallel because the sub-projects'
# need to be configured serially with respect to eachother
make
make install
popd
# Strip the binaries
cd "$prefix/bin"
strip ./*

30
.github/scripts/fetch-and-merge-afdo.sh vendored Executable file
View file

@ -0,0 +1,30 @@
#!/bin/bash
# Copyright (c) 2019-2020 Kevin R Croft <krcroft@gmail.com>
# SPDX-License-Identifier: GPL-2.0-or-later
# A helper script that fetches, converts, and merges kernel sample
# (.prof) files (collected during prior DOSBox testing) into a single
# GCC-compatible AutoFDO record that can be used to optimize builds.
# Depedencies:
# - zstd
# - autofdo
set -euo pipefail
# Tarball containing profile records
PROFILES="https://gitlab.com/luxtorpeda/dosbox-tests/-/raw/master/archives/profiles.tar.zst"
BINARY="tests/dosbox"
# Move to our repo root
cd "$(git rev-parse --show-toplevel)"
# Fetch and unpack the profiles
wget "${PROFILES}" -O - | zstd -d | tar -x
# Convert and merge the profiles
find . -name '*.prof' -print0 \
| xargs -0 -P "$(nproc)" -I {} \
create_gcov --binary="${BINARY}" --profile="{}" -gcov="{}".afdo -gcov_version=1
profile_merger -gcov_version=1 -output_file=current.afdo tests/*/*.afdo

30
.github/scripts/fetch-and-merge-profraw.sh vendored Executable file
View file

@ -0,0 +1,30 @@
#!/bin/bash
# Copyright (c) 2020 Kevin R Croft <krcroft@gmail.com>
# SPDX-License-Identifier: GPL-2.0-or-later
# A helper script that fetches, converts, and merges kernel sample
# (.prof) files (collected during prior DOSBox testing) into a single
# LLVM-compatible Raw Profile record that can be used to optimize builds.
# Depedencies:
# - zstd
# - autofdo
set -euo pipefail
# The tarball containing one or more profile records
PROFILES="https://gitlab.com/luxtorpeda/dosbox-tests/-/raw/master/archives/profiles.tar.zst"
BINARY="tests/dosbox"
# Move to our repo root
cd "$(git rev-parse --show-toplevel)"
# Fetch and unpack the profiles
wget "${PROFILES}" -O - | zstd -d | tar -x
# Convert and merge the profiles
find . -name '*.prof' -print0 \
| xargs -0 -P "$(nproc)" -I {} \
create_llvm_prof --binary="${BINARY}" --profile="{}" --out="{}".profraw
llvm-profdata-9 merge -sample -output=current.profraw tests/*/*.profraw