Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -635,18 +635,27 @@ jobs:
${{ steps.dep_vars.outputs.CARGO_UTILITY_LIST_OPTIONS }} -p coreutils
env:
RUST_BACKTRACE: "1"
- name: Decide whether to train PGO
shell: bash
run: |
## PGO needs to run the instrumented binary, so it is limited to the
## natively-built, published targets. x86_64-apple-darwin is excluded:
## it is cross-compiled on an arm64 runner, which cannot execute it.
PGO=0
if [ '${{ matrix.job.skip-publish }}' != 'true' ] && \
[ '${{ matrix.job.check-only }}' != 'true' ] && \
[ '${{ matrix.job.use-cross }}' != 'use-cross' ]; then
case '${{ matrix.job.target }}' in
x86_64-unknown-linux-gnu|aarch64-unknown-linux-gnu|aarch64-apple-darwin) PGO=1 ;;
esac
fi
echo "PGO=${PGO}" >> "$GITHUB_ENV"
- name: Install llvm-tools (PGO)
if: |
matrix.job.skip-publish != true && matrix.job.check-only != true &&
matrix.job.use-cross != 'use-cross' &&
(matrix.job.target == 'x86_64-unknown-linux-gnu' || matrix.job.target == 'aarch64-unknown-linux-gnu')
if: env.PGO == '1'
shell: bash
run: rustup component add llvm-tools
- name: Train PGO profiles
if: |
matrix.job.skip-publish != true && matrix.job.check-only != true &&
matrix.job.use-cross != 'use-cross' &&
(matrix.job.target == 'x86_64-unknown-linux-gnu' || matrix.job.target == 'aarch64-unknown-linux-gnu')
if: env.PGO == '1'
shell: bash
run: |
./util/build-pgo.sh \
Expand All @@ -655,10 +664,7 @@ jobs:
--train-only
echo "RUSTFLAGS=${RUSTFLAGS:+${RUSTFLAGS} }-Cprofile-use=${{ github.workspace }}/target/coreutils-pgo/coreutils.profdata" >> "$GITHUB_ENV"
- name: Verify PGO is applied to the published build
if: |
matrix.job.skip-publish != true && matrix.job.check-only != true &&
matrix.job.use-cross != 'use-cross' &&
(matrix.job.target == 'x86_64-unknown-linux-gnu' || matrix.job.target == 'aarch64-unknown-linux-gnu')
if: env.PGO == '1'
shell: bash
run: |
## The release artifact must be the PGO build: if RUSTFLAGS did not
Expand Down
10 changes: 6 additions & 4 deletions util/build-pgo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ echo "llvm-profdata: ${LLVM_PROFDATA}"
cargo_build() {
# $1: target dir, $2: extra rustflags
local feature_args=()
[ -n "$FEATURES" ] && feature_args=(--features="$FEATURES")
if [ -n "$FEATURES" ]; then feature_args=(--features="$FEATURES"); fi
(
cd "$REPO_ROOT"
export CARGO_TARGET_DIR="$1"
export CARGO_INCREMENTAL=0
export RUSTFLAGS="${RUSTFLAGS:+${RUSTFLAGS} }$2"
echo "Running: cargo build --release ${feature_args[*]}"
# bash 3.2 (macOS) errors on an empty array expansion under `set -u`,
# hence the `[@]+` guard on both expansions below.
echo "Running: cargo build --release ${feature_args[@]+${feature_args[*]}}"
echo " RUSTFLAGS=${RUSTFLAGS}"
cargo build --release "${feature_args[@]}"
cargo build --release ${feature_args[@]+"${feature_args[@]}"}
)
}

Expand Down Expand Up @@ -119,7 +121,7 @@ awk 'BEGIN { for (i = 0; i < 2000; i++) printf "user%d:x:%d:%d:User %d:/home/use
end_step

begin_step "Step 3: training workloads"
WORK="$(mktemp -d)"
WORK="$(mktemp -d "${TMPDIR:-/tmp}/coreutils-pgo.XXXXXX")"
trap 'rm -rf "$WORK"' EXIT

# Individual workloads are allowed to fail (a util may be absent from the
Expand Down
Loading