Skip to content

Commit 5493360

Browse files
author
Kernel Patches Daemon
committed
adding ci files
1 parent 137df11 commit 5493360

21 files changed

+1173
-18
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'run-veristat'
2+
description: 'Run veristat benchmark'
3+
inputs:
4+
veristat_output:
5+
description: 'Veristat output filepath'
6+
required: true
7+
baseline_name:
8+
description: 'Veristat baseline cache name'
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
- uses: actions/upload-artifact@v3
14+
with:
15+
name: ${{ inputs.baseline_name }}
16+
if-no-files-found: error
17+
path: ${{ github.workspace }}/${{ inputs.veristat_output }}
18+
19+
# For pull request:
20+
# - get baseline log from cache
21+
# - compare it to current run
22+
- if: ${{ github.event_name == 'pull_request' }}
23+
uses: actions/cache/restore@v3
24+
with:
25+
key: ${{ inputs.baseline_name }}
26+
restore-keys: |
27+
${{ inputs.baseline_name }}-
28+
path: '${{ github.workspace }}/${{ inputs.baseline_name }}'
29+
30+
- if: ${{ github.event_name == 'pull_request' }}
31+
name: Show veristat comparison
32+
shell: bash
33+
run: ./.github/scripts/compare-veristat-results.sh
34+
env:
35+
BASELINE_PATH: ${{ github.workspace }}/${{ inputs.baseline_name }}
36+
VERISTAT_OUTPUT: ${{ inputs.veristat_output }}
37+
38+
# For push: just put baseline log to cache
39+
- if: ${{ github.event_name == 'push' }}
40+
shell: bash
41+
run: |
42+
mv "${{ github.workspace }}/${{ inputs.veristat_output }}" \
43+
"${{ github.workspace }}/${{ inputs.baseline_name }}"
44+
45+
- if: ${{ github.event_name == 'push' }}
46+
uses: actions/cache/save@v3
47+
with:
48+
key: ${{ inputs.baseline_name }}-${{ github.run_id }}
49+
path: '${{ github.workspace }}/${{ inputs.baseline_name }}'

.github/scripts/bpf-objects-rootfs.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
eval "$(guestfish --listen)"
4+
5+
guestfish --verbose --remote \
6+
add /tmp/root.img label:img : \
7+
launch : \
8+
mount /dev/disk/guestfs/img / : \
9+
copy-in /tmp/bpf_objects / : \
10+
chmod 0755 /bpf_objects
11+
12+
guestfish --remote exit
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
if [[ ! -f "${BASELINE_PATH}" ]]; then
4+
echo "# No ${BASELINE_PATH} available" >> "${GITHUB_STEP_SUMMARY}"
5+
6+
echo "No ${BASELINE_PATH} available"
7+
echo "Printing veristat results"
8+
cat "${VERISTAT_OUTPUT}"
9+
10+
exit
11+
fi
12+
13+
selftests/bpf/veristat \
14+
--output-format csv \
15+
--emit file,prog,verdict,states \
16+
--compare "${BASELINE_PATH}" "${VERISTAT_OUTPUT}" > compare.csv
17+
18+
python3 ./.github/scripts/veristat-compare.py compare.csv
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
branch="${GITHUB_BASE_REF}"
4+
5+
if [ "${GITHUB_EVENT_NAME}" = 'push' ]; then
6+
branch="${GITHUB_REF_NAME}"
7+
fi
8+
9+
echo "branch=${branch}" >> "${GITHUB_OUTPUT}"
10+
11+
upstream="${branch//_base/}"
12+
commit="$(
13+
git rev-parse "origin/${upstream}" &> /dev/null \
14+
|| (
15+
git fetch --quiet --prune --no-tags --depth=1 --no-recurse-submodules origin "+refs/heads/${upstream}:refs/remotes/origin/${upstream}" && \
16+
git rev-parse "origin/${upstream}"
17+
)
18+
)"
19+
timestamp_utc="$(TZ=utc git show --format='%cd' --no-patch --date=iso-strict-local "${commit}")"
20+
21+
echo "timestamp=${timestamp_utc}" >> "${GITHUB_OUTPUT}"
22+
echo "commit=${commit}" >> "${GITHUB_OUTPUT}"
23+
echo "Most recent upstream commit is ${commit}"

.github/scripts/matrix.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env python3
2+
3+
from json import dumps
4+
from enum import Enum
5+
import os
6+
7+
8+
class Arch(Enum):
9+
"""
10+
CPU architecture supported by CI.
11+
"""
12+
13+
AARCH64 = "aarch64"
14+
S390X = "s390x"
15+
X86_64 = "x86_64"
16+
17+
18+
def set_output(name, value):
19+
"""Write an output variable to the GitHub output file."""
20+
with open(os.getenv("GITHUB_OUTPUT"), "a", encoding="utf-8") as file:
21+
file.write(f"{name}={value}\n")
22+
23+
24+
def generate_test_config(test):
25+
"""Create the configuration for the provided test."""
26+
experimental = test.endswith("_parallel")
27+
config = {
28+
"test": test,
29+
"continue_on_error": experimental,
30+
# While in experimental mode, parallel jobs may get stuck
31+
# anywhere, including in user space where the kernel won't detect
32+
# a problem and panic. We add a second layer of (smaller) timeouts
33+
# here such that if we get stuck in a parallel run, we hit this
34+
# timeout and fail without affecting the overall job success (as
35+
# would be the case if we hit the job-wide timeout). For
36+
# non-experimental jobs, 360 is the default which will be
37+
# superseded by the overall workflow timeout (but we need to
38+
# specify something).
39+
"timeout_minutes": 30 if experimental else 360,
40+
}
41+
return config
42+
43+
44+
def get_tests(config):
45+
tests = [
46+
"test_progs",
47+
"test_progs_parallel",
48+
"test_progs_no_alu32",
49+
"test_progs_no_alu32_parallel",
50+
"test_maps",
51+
"test_verifier",
52+
]
53+
if config.get("parallel_tests", True):
54+
return tests
55+
return [test for test in tests if not test.endswith("parallel")]
56+
57+
58+
matrix = [
59+
{
60+
"kernel": "LATEST",
61+
"runs_on": [],
62+
"arch": Arch.X86_64.value,
63+
"toolchain": "gcc",
64+
"llvm-version": "16",
65+
},
66+
{
67+
"kernel": "LATEST",
68+
"runs_on": [],
69+
"arch": Arch.X86_64.value,
70+
"toolchain": "llvm",
71+
"llvm-version": "16",
72+
},
73+
{
74+
"kernel": "LATEST",
75+
"runs_on": [],
76+
"arch": Arch.AARCH64.value,
77+
"toolchain": "gcc",
78+
"llvm-version": "16",
79+
},
80+
# {
81+
# "kernel": "LATEST",
82+
# "runs_on": [],
83+
# "arch": Arch.AARCH64.value,
84+
# "toolchain": "llvm",
85+
# "llvm-version": "16",
86+
# },
87+
{
88+
"kernel": "LATEST",
89+
"runs_on": [],
90+
"arch": Arch.S390X.value,
91+
"toolchain": "gcc",
92+
"llvm-version": "16",
93+
"parallel_tests": False,
94+
},
95+
]
96+
self_hosted_repos = [
97+
"kernel-patches/bpf",
98+
"kernel-patches/vmtest",
99+
]
100+
101+
for idx in range(len(matrix) - 1, -1, -1):
102+
if matrix[idx]["toolchain"] == "gcc":
103+
matrix[idx]["toolchain_full"] = "gcc"
104+
else:
105+
matrix[idx]["toolchain_full"] = "llvm-" + matrix[idx]["llvm-version"]
106+
107+
# Only a few repository within "kernel-patches" use self-hosted runners.
108+
if (
109+
os.environ["GITHUB_REPOSITORY_OWNER"] != "kernel-patches"
110+
or os.environ["GITHUB_REPOSITORY"] not in self_hosted_repos
111+
):
112+
# Outside of those repositories, we only run on x86_64 GH hosted runners (ubuntu-latest)
113+
for idx in range(len(matrix) - 1, -1, -1):
114+
if matrix[idx]["arch"] != Arch.X86_64.value:
115+
del matrix[idx]
116+
else:
117+
matrix[idx]["runs_on"] = ["ubuntu-latest"]
118+
else:
119+
# Otherwise, run on (self-hosted, arch) runners
120+
for idx in range(len(matrix) - 1, -1, -1):
121+
matrix[idx]["runs_on"].extend(["self-hosted", matrix[idx]["arch"]])
122+
123+
build_matrix = {"include": matrix}
124+
set_output("build_matrix", dumps(build_matrix))
125+
126+
test_matrix = {
127+
"include": [
128+
{**config, **generate_test_config(test)}
129+
for config in matrix
130+
for test in get_tests(config)
131+
]
132+
}
133+
set_output("test_matrix", dumps(test_matrix))
134+
135+
veristat_runs_on = next(
136+
x["runs_on"]
137+
for x in matrix
138+
if x["arch"] == os.environ["veristat_arch"]
139+
and x["toolchain"] == os.environ["veristat_toolchain"]
140+
)
141+
set_output("veristat_runs_on", veristat_runs_on)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
commit_id="${1}"
6+
7+
# $1 - the SHA-1 to fetch and check out
8+
fetch_and_checkout() {
9+
local build_base_sha
10+
11+
build_base_sha="${1}"
12+
# If cached artifacts became stale for one reason or another, we
13+
# may not have the build base SHA available. Fetch it and retry.
14+
git fetch origin "${build_base_sha}" && git checkout --quiet "${build_base_sha}"
15+
}
16+
17+
# $1 - value of KBUILD_OUTPUT
18+
clear_cache_artifacts() {
19+
local output_dir
20+
21+
output_dir="${1}"
22+
echo "Unable to find earlier upstream ref. Discarding KBUILD_OUTPUT contents..."
23+
rm --recursive --force "${output_dir}"
24+
mkdir "${output_dir}"
25+
false
26+
}
27+
28+
# $1 - value of KBUILD_OUTPUT
29+
# $2 - current time in ISO 8601 format
30+
restore_source_code_times() {
31+
local build_output
32+
local current_time
33+
local src_time
34+
local obj_time
35+
36+
build_output="${1}"
37+
current_time="${2}"
38+
src_time="$(date --iso-8601=ns --date="${current_time} - 2 minutes")"
39+
obj_time="$(date --iso-8601=ns --date="${current_time} - 1 minute")"
40+
41+
git ls-files | xargs --max-args=10000 touch -m --no-create --date="${src_time}"
42+
find "${build_output}" -type f | xargs --max-args=10000 touch -m --no-create --date="${obj_time}"
43+
git checkout --quiet -
44+
echo "Adjusted src and obj time stamps relative to system time"
45+
}
46+
47+
mkdir --parents "${KBUILD_OUTPUT}"
48+
current_time="$(date --iso-8601=ns)"
49+
50+
if [ -f "${KBUILD_OUTPUT}/.build-base-sha" ]; then
51+
build_base_sha="$(cat "${KBUILD_OUTPUT}/.build-base-sha")"
52+
echo "Setting up base build state for ${build_base_sha}"
53+
54+
(
55+
git checkout --quiet "${build_base_sha}" \
56+
|| fetch_and_checkout "${build_base_sha}" \
57+
|| clear_cache_artifacts "${KBUILD_OUTPUT}"
58+
) && restore_source_code_times "${KBUILD_OUTPUT}" "${current_time}"
59+
else
60+
echo "No previous build data found"
61+
fi
62+
63+
echo -n "${commit_id}" > "${KBUILD_OUTPUT}/.build-base-sha"

.github/scripts/tar-artifact.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
arch="${1}"
6+
toolchain="${2}"
7+
8+
# Remove intermediate object files that we have no use for. Ideally
9+
# we'd just exclude them from tar below, but it does not provide
10+
# options to express the precise constraints.
11+
find selftests/ -name "*.o" -a ! -name "*.bpf.o" -print0 | \
12+
xargs --null --max-args=10000 rm
13+
14+
# Strip debug information, which is excessively large (consuming
15+
# bandwidth) while not actually being used (the kernel does not use
16+
# DWARF to symbolize stacktraces).
17+
strip --strip-debug "${KBUILD_OUTPUT}"/vmlinux
18+
19+
additional_file_list=()
20+
if [ "${GITHUB_REPOSITORY}" == "kernel-patches/vmtest" ]; then
21+
# Package up a bunch of additional infrastructure to support running
22+
# 'make kernelrelease' and bpf tool checks later on.
23+
mapfile -t additional_file_list < <(find . -iname Makefile)
24+
additional_file_list+=(
25+
"scripts/"
26+
"tools/testing/selftests/bpf/"
27+
"tools/include/"
28+
"tools/bpf/bpftool/"
29+
)
30+
fi
31+
32+
image_name=$(make -s image_name)
33+
34+
# zstd is installed by default in the runner images.
35+
tar -cf - \
36+
"${KBUILD_OUTPUT}/.config" \
37+
"${KBUILD_OUTPUT}/${image_name}" \
38+
"${KBUILD_OUTPUT}/include/config/auto.conf" \
39+
"${KBUILD_OUTPUT}/include/generated/autoconf.h" \
40+
"${KBUILD_OUTPUT}/vmlinux" \
41+
"${additional_file_list[@]}" \
42+
--exclude '*.cmd' \
43+
--exclude '*.d' \
44+
--exclude '*.h' \
45+
--exclude '*.output' \
46+
selftests/bpf/ | zstd -T0 -19 -o "vmlinux-${arch}-${toolchain}.tar.zst"

0 commit comments

Comments
 (0)