Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run-vmtest@v2 and build-selftests@v2 #150

Merged
merged 9 commits into from
Nov 19, 2024
52 changes: 28 additions & 24 deletions .github/workflows/kernel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ jobs:
timeout-minutes: 100
env:
ARTIFACTS_ARCHIVE: "vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst"
BASE_BRANCH: >-
${{ github.event_name == 'push' && github.ref_name
|| github.base_ref
|| 'bpf-next'
}}
BUILD_SCHED_EXT_SELFTESTS: ${{ inputs.arch == 'x86_64' || inputs.arch == 'aarch64' && 'true' || '' }}
CACHED_KERNEL_BUILD: ${{ github.event_name == 'push' || github.repository == 'libbpf/ci' && 'true' || '' }}
KBUILD_OUTPUT: ${{ github.workspace }}/kbuild-output
KERNEL: ${{ inputs.kernel }}
REPO_PATH: ""
REPO_ROOT: ${{ github.workspace }}
KERNEL_ROOT: ${{ github.workspace }}
steps:
- uses: actions/checkout@v4
# We fetch an actual bit of history here to facilitate incremental
Expand All @@ -64,23 +61,32 @@ jobs:
fetch-depth: 50
- if: ${{ inputs.download_sources }}
name: Download bpf-next tree
env:
FETCH_DEPTH: ${{ env.CACHED_KERNEL_BUILD && 16 || 0 }}
uses: ./get-linux-source
with:
dest: '.kernel'
- if: ${{ inputs.download_sources }}
name: Move linux source in place
shell: bash
run: |
rm -rf .kernel/.git
cp -rf .kernel/. .
rm -rf .kernel
- uses: ./prepare-incremental-build
- if: ${{ env.CACHED_KERNEL_BUILD }}
uses: ./prepare-incremental-build
with:
repo-root: ${{ env.REPO_ROOT }}
base-branch: ${{ env.BASE_BRANCH }}
repo-root: ${{ inputs.download_sources && '.kernel' || env.REPO_ROOT }}
base-branch: >-
${{ github.repository == 'kernel-patches/bpf' && github.event_name == 'push' && github.ref_name
|| github.repository == 'kernel-patches/bpf' && github.event_name != 'push' && github.base_ref
|| 'master'
}}
arch: ${{ inputs.arch }}
toolchain_full: ${{ inputs.toolchain_full }}
kbuild-output: ${{ env.KBUILD_OUTPUT }}
- if: ${{ inputs.download_sources }}
name: Move linux source in place
shell: bash
run: |
cd .kernel
rm -rf .git
mv -t .. $(ls -A)
cd ..
rmdir .kernel
- uses: ./patch-kernel
with:
patches-root: '${{ github.workspace }}/ci/diffs'
Expand Down Expand Up @@ -109,17 +115,15 @@ jobs:
llvm-version: ${{ inputs.llvm-version }}
- name: Build selftests/bpf
uses: ./build-selftests
env:
MAX_MAKE_JOBS: 32
RELEASE: ${{ inputs.release && '1' || '' }}
with:
arch: ${{ inputs.arch }}
toolchain: ${{ inputs.toolchain }}
kbuild-output: ${{ env.KBUILD_OUTPUT }}
max-make-jobs: 32
kernel-root: ${{ env.KERNEL_ROOT }}
llvm-version: ${{ inputs.llvm-version }}
env:
# RELEASE= disables all optimizaions
# RELEASE=0 adds -O0 make flag
# RELEASE=1 adds -O2 make flag
RELEASE: ${{ inputs.release && '1' || '' }}
toolchain: ${{ inputs.toolchain }}

- if: ${{ env.BUILD_SCHED_EXT_SELFTESTS }}
name: Build selftests/sched_ext
uses: ./build-scx-selftests
Expand Down Expand Up @@ -151,7 +155,7 @@ jobs:
archive: ${{ env.ARTIFACTS_ARCHIVE }}
kbuild-output: ${{ env.KBUILD_OUTPUT }}
repo-root: ${{ env.REPO_ROOT }}
- if: ${{ github.event_name != 'push' }}
- if: ${{ ! env.CACHED_KERNEL_BUILD }}
name: Remove KBUILD_OUTPUT content
shell: bash
run: |
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/kernel-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,46 @@ jobs:
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: 100
env:
ARCH: ${{ inputs.arch }}
KERNEL: ${{ inputs.kernel }}
REPO_ROOT: ${{ github.workspace }}
REPO_PATH: ""
# https://github.com/actions/runner/issues/1483#issuecomment-1031671517
# booleans are weird in GH.
CONTINUE_ON_ERROR: ${{ inputs.continue_on_error }}
DEPLOYMENT: ${{ github.repository == 'kernel-patches/bpf' && 'prod' || 'rc' }}
ALLOWLIST_FILE: /tmp/allowlist
DENYLIST_FILE: /tmp/denylist
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}
path: .

- name: Untar artifacts
# zstd is installed by default in the runner images.
run: zstd -d -T0 vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst --stdout | tar -xf -

- name: Prepare ALLOW/DENYLIST
env:
SELFTESTS_BPF: ${{ github.workspace }}/selftests/bpf
VMTEST_CONFIGS: ${{ github.workspace }}/ci/vmtest/configs
run: |
cat "${SELFTESTS_BPF}/ALLOWLIST" \
"${SELFTESTS_BPF}/ALLOWLIST.${ARCH}" \
"${VMTEST_CONFIGS}/ALLOWLIST" \
"${VMTEST_CONFIGS}/ALLOWLIST.${ARCH}" \
2> /dev/null > "${ALLOWLIST_FILE}" || true

cat "${SELFTESTS_BPF}/DENYLIST" \
"${SELFTESTS_BPF}/DENYLIST.${ARCH}" \
"${VMTEST_CONFIGS}/DENYLIST" \
"${VMTEST_CONFIGS}/DENYLIST.${ARCH}" \
"${VMTEST_CONFIGS}/DENYLIST.${DEPLOYMENT}" \
2> /dev/null > "${DENYLIST_FILE}" || true

- name: Run selftests
uses: ./run-vmtest
# https://github.com/actions/runner/issues/1483#issuecomment-1031671517
Expand Down
33 changes: 13 additions & 20 deletions build-selftests/action.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
name: 'build selftests'
description: 'Build BPF selftests'
inputs:
kernel:
description: 'kernel version'
default: 'LATEST'
toolchain:
description: 'what toolchain to use'
default: 'gcc'
kbuild-output:
description: 'relative or absolute path to use for storing build artifacts'
arch:
description: 'arch'
required: true
kernel-root:
description: 'Path to the root of the kernel source tree'
required: true
max-make-jobs:
description: 'Maximum number of jobs to use when running make (e.g argument to -j). Default: 4*nproc'
default: ''
llvm-version:
description: 'llvm version'
required: false
default: '16'
arch:
description: 'arch'
required: true
default: '18'
toolchain:
description: 'gcc or llvm'
default: 'gcc'

runs:
using: "composite"
steps:
- name: build selftests
shell: bash
run: |
kbuild_output="$(realpath ${{ inputs.kbuild-output }})"
export LLVM_VERSION=${{ inputs.llvm-version }}
${GITHUB_ACTION_PATH}/build_selftests.sh "${{ inputs.arch }}" "${{ inputs.kernel }}" "${{ inputs.toolchain }}" "${kbuild_output}"
env:
MAX_MAKE_JOBS: ${{ inputs.max-make-jobs }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this used to be used to control how many cpus were used when compiling. On bare metal, with 96 CPUs, if all containers are building at the same time, they will all use that many CPUs, bringing the machine to a crawl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still used, it's just not an action input anymore. A caller can set it like here.

The default is 4*nproc, controlled here.

LLVM_VERSION: ${{ inputs.llvm-version }}
run: |
${GITHUB_ACTION_PATH}/build_selftests.sh "${{ inputs.arch }}" "${{ inputs.toolchain }}" "${{ inputs.kernel-root }}"

32 changes: 10 additions & 22 deletions build-selftests/build_selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

set -euo pipefail

THISDIR="$(cd $(dirname $0) && pwd)"

source "${THISDIR}"/../helpers.sh
source "${GITHUB_ACTION_PATH}/../helpers.sh"

TARGET_ARCH="$1"
KERNEL="$2"
TOOLCHAIN="$3"
export KBUILD_OUTPUT="$4"
TOOLCHAIN="$2"
KERNEL_ROOT="$(realpath $3)"

export KBUILD_OUTPUT="${KBUILD_OUTPUT:-${KERNEL_ROOT}}"
export VMLINUX_BTF="${VMLINUX_BTF:-${KBUILD_OUTPUT}/vmlinux}"
export VMLINUX_H="${VMLINUX_H:-}"

ARCH="$(platform_to_kernel_arch ${TARGET_ARCH})"
CROSS_COMPILE=""
Expand All @@ -26,34 +27,21 @@ fi

foldable start build_selftests "Building selftests with $TOOLCHAIN"

PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh
if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then
(cd "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT})
fi

if [[ "${KERNEL}" = 'LATEST' ]]; then
VMLINUX_H=
else
VMLINUX_H=${THISDIR}/vmlinux.h
fi

cd ${REPO_ROOT}/${REPO_PATH}

MAKE_OPTS=$(cat <<EOF
ARCH=${ARCH}
CROSS_COMPILE=${CROSS_COMPILE}
CLANG=clang-${LLVM_VERSION}
LLC=llc-${LLVM_VERSION}
LLVM_STRIP=llvm-strip-${LLVM_VERSION}
VMLINUX_BTF=${KBUILD_OUTPUT}/vmlinux
VMLINUX_BTF=${VMLINUX_BTF}
VMLINUX_H=${VMLINUX_H}
EOF
)
SELF_OPTS=$(cat <<EOF
-C ${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf
-C ${KERNEL_ROOT}/tools/testing/selftests/bpf
EOF
)
make ${MAKE_OPTS} headers
make ${MAKE_OPTS} -C ${KERNEL_ROOT} headers
make ${MAKE_OPTS} ${SELF_OPTS} clean
make ${MAKE_OPTS} ${SELF_OPTS} -j $(kernel_build_make_jobs)

Expand Down
73 changes: 44 additions & 29 deletions get-linux-source/checkout_latest_kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ source $(cd $(dirname $0) && pwd)/../helpers.sh

CWD=$(pwd)

# 0 means just download a snapshot
FETCH_DEPTH=${FETCH_DEPTH:-0}

echo KERNEL_ORIGIN = ${KERNEL_ORIGIN}
echo KERNEL_BRANCH = ${KERNEL_BRANCH}
echo REPO_PATH = ${REPO_PATH}
Expand All @@ -22,33 +25,45 @@ SNAPSHOT_URL=${KERNEL_ORIGIN}/snapshot/bpf-next-${LINUX_SHA}.tar.gz
echo LINUX_SHA = ${LINUX_SHA}
echo SNAPSHOT_URL = ${SNAPSHOT_URL}

if [ ! -d "${REPO_PATH}" ]; then
echo
foldable start pull_kernel_srcs "Fetching kernel sources"

mkdir -p $(dirname "${REPO_PATH}")
cd $(dirname "${REPO_PATH}")
# attempt to fetch desired bpf-next repo snapshot
if [ -n "${SNAPSHOT_URL}" ] && \
wget -U 'BPFCIBot/1.0 (bpf@vger.kernel.org)' -nv ${SNAPSHOT_URL} && \
tar xf bpf-next-${LINUX_SHA}.tar.gz --totals ; then
mv bpf-next-${LINUX_SHA} $(basename ${REPO_PATH})
else
# but fallback to git fetch approach if that fails
mkdir -p $(basename ${REPO_PATH})
cd $(basename ${REPO_PATH})
git init
git remote add bpf-next ${KERNEL_ORIGIN}
# try shallow clone first
git fetch --depth 32 bpf-next
# check if desired SHA exists
if ! git cat-file -e ${LINUX_SHA}^{commit} ; then
# if not, fetch all of bpf-next; slow and painful
git fetch bpf-next
fi
git reset --hard ${LINUX_SHA}
fi
rm -rf ${REPO_PATH}/.git || true

foldable end pull_kernel_srcs
if [ -d "${REPO_PATH}" ]; then
echo "${REPO_PATH} directory already exists, will not download kernel sources"
exit 0
fi

mkdir -p $(dirname "${REPO_PATH}")
cd $(dirname "${REPO_PATH}")

# attempt to fetch desired bpf-next repo snapshot
if [[ -n "${SNAPSHOT_URL}" && "${FETCH_DEPTH}" -le 0 ]]; then
wget -U 'BPFCIBot/1.0 (bpf@vger.kernel.org)' -nv ${SNAPSHOT_URL} || true
PRESERVE_DOT_GIT=
else
PRESERVE_DOT_GIT=true
fi

tarball=bpf-next-${LINUX_SHA}.tar.gz
if [[ -f "$tarball" ]]; then
tar xf "$tarball" --totals
mv bpf-next-${LINUX_SHA} $(basename ${REPO_PATH})
else
# FETCH_DEPTH can be 0 here in case snapshot download has failed
if [ "${FETCH_DEPTH}" -le 0 ]; then
FETCH_DEPTH=1
fi

git clone --depth ${FETCH_DEPTH} ${KERNEL_ORIGIN} ${REPO_PATH}

cd "${REPO_PATH}"
# check if desired SHA exists
if ! git cat-file -e ${LINUX_SHA}^{commit} ; then
# if not, fetch all of bpf-next; slow and painful
git fetch origin
fi
git reset --hard ${LINUX_SHA}
cd -
fi

if [ -z "${PRESERVE_DOT_GIT}" ]; then
rm -rf ${REPO_PATH}/.git || true
fi

2 changes: 1 addition & 1 deletion patch-kernel/patch_kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIFF_DIR=$1
for ext in diff patch; do
if ls ${DIFF_DIR}/*.${ext} 1>/dev/null 2>&1; then
for file in ${DIFF_DIR}/*.${ext}; do
if patch --dry-run -p1 -s < "${file}" 2>/dev/null; then
if patch --dry-run -N --silent -p1 -s < "${file}" 2>/dev/null; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for the -N here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From man:

-N or --forward
When a patch does not apply, patch usually checks if the patch
looks like it has been applied already by trying to reverse-
apply the first hunk. The --forward option prevents that.
See also -R.

This is to avoid prints like this in the job logs:

1 out of 1 hunk ignored
Reversed (or previously applied) patch detected! Assume -R? [n]
Apply anyway? [n]

IIRC --silent does not prevent this prompt.

patch -s -p1 < "${file}" 2>/dev/null
echo "Successfully applied ${file}!"
else
Expand Down
Loading
Loading