aboutsummaryrefslogtreecommitdiff
path: root/afdo_tools/update_kernel_afdo
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-09-21 22:05:43 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-09-21 22:05:43 +0000
commit73fde5d5e2d64f4806fef172dbc064a8e5228694 (patch)
tree3e4cabab5a57ae288c245cff9a1a6ff7926a3207 /afdo_tools/update_kernel_afdo
parent40214b48188358a80b7478bfff21d4814dd9177c (diff)
parent0348d10214299073ea59bda4987dd8813a9e7812 (diff)
downloadtoolchain-utils-73fde5d5e2d64f4806fef172dbc064a8e5228694.tar.gz
Change-Id: Ia39ecafdc4b00a0b2505b638c14b80c02e34d4b6
Diffstat (limited to 'afdo_tools/update_kernel_afdo')
-rwxr-xr-xafdo_tools/update_kernel_afdo161
1 files changed, 112 insertions, 49 deletions
diff --git a/afdo_tools/update_kernel_afdo b/afdo_tools/update_kernel_afdo
index 9e4d645d..6bfa53fa 100755
--- a/afdo_tools/update_kernel_afdo
+++ b/afdo_tools/update_kernel_afdo
@@ -9,14 +9,17 @@
#
USAGE="
-Usage: $(basename "$0") [--noupload|-upload] [main|beta|stable|all] [--help]
+Usage: $(basename "$0") [--help] [--(no)upload] [--nointeractive]
+ [main|beta|stable|all]
Description:
The script takes one optional argument which is the channel where we want
to update the kernel afdo and creates a commit (or commits with \"all\"
channels) in the corresponding branch.
No arguments defaults to \"all\".
- Follow the prompt to upload the changes.
+ Follow the prompt to upload the changes with --noupload. Otherwise
+ the script will automatically create CL and send to the detective
+ for review.
NO CLEAN-UP NEEDED. The script ignores any local changes and keeps
the current branch unchanged.
@@ -24,43 +27,43 @@ the current branch unchanged.
--help Show this help.
--upload Upload CLs when the update succeeded (default).
--noupload Do not upload CLs. Instead, print the upload commands.
+ --nointeractive Runs the script without user interaction.
main|beta|stable Update metadata only on the specified channel.
"
set -eu
set -o pipefail
-AMD_GS_BASE=gs://chromeos-prebuilt/afdo-job/vetted/kernel
+# Branch independent constants.
+# Changes here will affect kernel afdo update in cros branches.
+# -------------------
+ARCHS="amd arm"
+AMD_GS_BASE=gs://chromeos-prebuilt/afdo-job/vetted/kernel/amd64
ARM_GS_BASE=gs://chromeos-prebuilt/afdo-job/vetted/kernel/arm
-AMD_KVERS="4.14 4.19 5.4 5.10"
-ARM_KVERS="5.15"
-failed_channels=""
+UPDATE_CONFIG_FILE="afdo_tools/update_kernel_afdo.cfg"
+# CL reviewers and cc.
+REVIEWERS="c-compiler-chrome@google.com"
+CC="denik@google.com,gbiv@google.com"
# Add skipped chrome branches in ascending order here.
SKIPPED_BRANCHES="95"
-
# NOTE: We enable/disable kernel AFDO starting from a particular branch.
# For example if we want to enable kernel AFDO in 5.15, first, we do it
# in main. In this case we want to disable it in beta and stable branches.
# The second scenario is when we want to disable kernel AFDO (when all devices
# move to kernelnext and there are no new profiles from the field). In this
# case we disable AFDO in main but still keep it live in beta and stable.
-declare -A SKIPPED_KVERS_IN_BRANCHES
-# In SKIPPED_KVERS_IN_BRANCHES
+declare -A SKIPPED_ARCHKVERS_IN_BRANCHES
+# In SKIPPED_ARCHKVERS_IN_BRANCHES
# - key is a branch number string;
-# - value is the list of kernels separated by space.
-# Example: SKIPPED_KVERS_IN_BRANCHES["105"]="4.4 4.14"
-
-# b/223115767. In M-100 there are no new profiles in 5.10. And AFDO is not
-# enabled on any 5.10 board in M-100 either.
-SKIPPED_KVERS_IN_BRANCHES["100"]="5.10"
+# - value is the list of arch/kver separated by space.
+# Example: SKIPPED_ARCHKVERS_IN_BRANCHES["105"]="amd/4.4 arm/5.15"
+# -------------------
+# Kernel tracing was disabled on arm in 114, b/275560674.
+SKIPPED_ARCHKVERS_IN_BRANCHES["114"]="arm/5.15"
+SKIPPED_ARCHKVERS_IN_BRANCHES["115"]="arm/5.15"
script_dir=$(dirname "$0")
tc_utils_dir="${script_dir}/.."
-metadata_dir="${tc_utils_dir}/afdo_metadata"
-amd_outfile="$(realpath --relative-to="${tc_utils_dir}" \
- "${metadata_dir}"/kernel_afdo.json)"
-arm_outfile="$(realpath --relative-to="${tc_utils_dir}" \
- "${metadata_dir}"/kernel_arm_afdo.json)"
# Convert toolchain_utils into the absolute path.
abs_tc_utils_dir="$(realpath "${tc_utils_dir}")"
@@ -68,16 +71,13 @@ abs_tc_utils_dir="$(realpath "${tc_utils_dir}")"
expected_time=$(date +%s -d "week ago")
# Upload CLs on success.
upload_cl=true
+# Interactive mode.
+interactive=true
+# Without arguments the script updates all branches.
+channels=""
+failed_channels=""
-ARCHS="amd arm"
declare -A arch_gsbase arch_kvers arch_outfile
-arch_gsbase["amd"]="${AMD_GS_BASE}"
-arch_gsbase["arm"]="${ARM_GS_BASE}"
-arch_kvers["amd"]="${AMD_KVERS}"
-arch_kvers["arm"]="${ARM_KVERS}"
-arch_outfile["amd"]="${amd_outfile}"
-arch_outfile["arm"]="${arm_outfile}"
-
declare -A branch branch_number commit
remote_repo=$(git -C "${tc_utils_dir}" remote)
canary_ref="refs/heads/main"
@@ -103,9 +103,9 @@ for skipped_branch in ${SKIPPED_BRANCHES} ; do
((branch_number[canary]++))
fi
done
+config_file="$(realpath --relative-to="${tc_utils_dir}" \
+ "${tc_utils_dir}/${UPDATE_CONFIG_FILE}")"
-# Without arguments the script updates all branches.
-channels=""
for arg in "$@"
do
case "${arg}" in
@@ -124,12 +124,15 @@ do
--upload)
upload_cl=true
;;
+ --nointeractive)
+ interactive=false
+ ;;
--help | help | -h )
echo "${USAGE}"
exit 0
;;
-*)
- echo "Option \"${arg}\" is not supported." >&2
+ echo "ERROR: Option \"${arg}\" is not supported." >&2
echo "${USAGE}"
exit 1
;;
@@ -155,7 +158,8 @@ echo "-> Working in ${worktree_dir}"
# This way we don't need to clean-up and sync toolchain_utils before the
# change. Neither we should care about clean-up after the submit.
git -C "${tc_utils_dir}" worktree add --detach "${worktree_dir}"
-trap 'git -C "${abs_tc_utils_dir}" worktree remove -f "${worktree_dir}"' EXIT
+trap 'git -C "${abs_tc_utils_dir}" worktree remove -f "${worktree_dir}" \
+ && git -C "${abs_tc_utils_dir}" branch -D ${channels}' EXIT
pushd "${worktree_dir}"
for channel in ${channels}
@@ -178,8 +182,37 @@ do
echo "branch_number=${curr_branch_number} branch=${curr_branch}"
git reset --hard HEAD
- git checkout "${remote_repo}/${curr_branch}"
+ git checkout -b "${channel}" "${remote_repo}/${curr_branch}"
+ # Read branch-dependent constants from $remote_repo.
+ # shellcheck source=afdo_tools/update_kernel_afdo.cfg
+ if [[ -e "${config_file}" ]]
+ then
+ # Branch dependent constants were moved to config_file.
+ # IMPORTANT: Starting from M-113 update_kernel_afdo reads branch-dependent
+ # constants from config_file from remote refs.
+ source "${config_file}"
+ else
+ # DON'T UPDATE THESE CONSTANTS HERE!
+ # Update ${config_file} instead.
+ AMD_KVERS="4.14 4.19 5.4 5.10"
+ ARM_KVERS="5.15"
+ AMD_METADATA_FILE="afdo_metadata/kernel_afdo.json"
+ ARM_METADATA_FILE="afdo_metadata/kernel_arm_afdo.json"
+ fi
+
+ amd_outfile="$(realpath --relative-to="${tc_utils_dir}" \
+ "${tc_utils_dir}/${AMD_METADATA_FILE}")"
+ arm_outfile="$(realpath --relative-to="${tc_utils_dir}" \
+ "${tc_utils_dir}/${ARM_METADATA_FILE}")"
+ arch_gsbase["amd"]="${AMD_GS_BASE}"
+ arch_gsbase["arm"]="${ARM_GS_BASE}"
+ arch_kvers["amd"]="${AMD_KVERS}"
+ arch_kvers["arm"]="${ARM_KVERS}"
+ arch_outfile["amd"]="${amd_outfile}"
+ arch_outfile["arm"]="${arm_outfile}"
+
+ new_changes=false
for arch in ${ARCHS}
do
json="{"
@@ -188,15 +221,16 @@ do
do
# Skip kernels disabled in this branch.
skipped=false
- for skipped_branch in "${!SKIPPED_KVERS_IN_BRANCHES[@]}"
+ for skipped_branch in "${!SKIPPED_ARCHKVERS_IN_BRANCHES[@]}"
do
if [[ ${curr_branch_number} == "${skipped_branch}" ]]
then
- # Current branch is in the keys of SKIPPED_KVERS_IN_BRANCHES.
- # Now lets check if $kver is in the list.
- for skipped_kver in ${SKIPPED_KVERS_IN_BRANCHES[${skipped_branch}]}
+ # Current branch is in the keys of SKIPPED_ARCHKVERS_IN_BRANCHES.
+ # Now lets check if $arch/$kver is in the list.
+ for skipped_archkver in \
+ ${SKIPPED_ARCHKVERS_IN_BRANCHES[${skipped_branch}]}
do
- if [[ ${kver} == "${skipped_kver}" ]]
+ if [[ "${arch}/${kver}" == "${skipped_archkver}" ]]
then
skipped=true
break
@@ -206,7 +240,7 @@ do
done
if ${skipped}
then
- echo "${kver} is skipped in branch ${curr_branch_number}. Skip it."
+ echo "${arch}/${kver} is skipped in branch ${curr_branch_number}."
continue
fi
# Sort the gs output by timestamp, default ordering is by name. So
@@ -214,11 +248,20 @@ do
# R86-13310.18-1595237847.gcov.xz.
latest=$(gsutil.py ls -l "${arch_gsbase[${arch}]}/${kver}/" | sort -k2 | \
grep "R${curr_branch_number}" | tail -1 || true)
+ prev_branch=$((curr_branch_number - 1))
if [[ -z "${latest}" && "${channel}" != "stable" ]]
then
# if no profiles exist for the current branch, try the previous branch
latest=$(gsutil.py ls -l "${arch_gsbase[${arch}]}/${kver}/" | \
- sort -k2 | grep "R$((curr_branch_number - 1))" | tail -1)
+ sort -k2 | grep "R${prev_branch}" | tail -1 || true)
+ fi
+ if [[ -z "${latest}" ]]
+ then
+ echo "ERROR: No M${curr_branch_number}, M${prev_branch} profiles in\
+ ${arch_gsbase[${arch}]}/${kver}/" >&2
+ echo "Skipping ${arch}/${kver}" >&2
+ errs="${errs} ${kver}"
+ continue
fi
# Verify that the file has the expected date.
@@ -227,7 +270,8 @@ do
if [ "${file_time_unix}" -lt "${expected_time}" ]
then
expected=$(env TZ=UTC date +%Y-%m-%dT%H:%M:%SZ -d @"${expected_time}")
- echo "Wrong date for ${kver}: ${file_time} is before ${expected}" >&2
+ echo "ERROR: Wrong date for ${kver}: ${file_time} is before\
+ ${expected}" >&2
errs="${errs} ${kver}"
continue
fi
@@ -256,7 +300,7 @@ EOT
# If we did not succeed for any kvers, exit now.
if [[ ${successes} -eq 0 ]]
then
- echo "error: AFDO profiles out of date for all kernel versions" >&2
+ echo "ERROR: AFDO profiles out of date for all kernel versions" >&2
failed_channels="${failed_channels} ${channel}"
continue
fi
@@ -276,14 +320,21 @@ EOT
# If we had any errors, warn about them.
if [[ -n "${errs}" ]]
then
- echo "warning: failed to update ${errs} in ${channel}" >&2
+ echo "WARNING: failed to update ${errs} in ${channel}" >&2
failed_channels="${failed_channels} ${channel}"
continue
fi
git add "${arch_outfile[${arch}]}"
+ new_changes=true
done # ARCHS loop
+ if ! ${new_changes}
+ then
+ echo "Skipping \"${channel}\" - all profiles are up to date"
+ continue
+ fi
+
case "${channel}" in
canary )
commit_contents=$'afdo_metadata: Publish the new kernel profiles\n\n'
@@ -308,11 +359,16 @@ BUG=None
TEST=Verified in kernel-release-afdo-verify-orchestrator"
;;
* )
- echo "internal error: unhandled channel \"${channel}\"" >&2
+ echo "Internal error: unhandled channel \"${channel}\"" >&2
exit 2
esac
- git commit -v -e -m "${commit_contents}"
+ if ${interactive}
+ then
+ git commit -v -e -m "${commit_contents}"
+ else
+ git commit -m "${commit_contents}"
+ fi
commit[${channel}]=$(git -C "${worktree_dir}" rev-parse HEAD)
done
@@ -329,8 +385,15 @@ then
then
for channel in "${!commit[@]}"
do
- git -C "${tc_utils_dir}" push "${remote_repo}" \
- "${commit[${channel}]}:refs/for/${branch[${channel}]}"
+ if ${interactive}
+ then
+ (cd "${tc_utils_dir}" && \
+ repo upload --br="${channel}" --re="${REVIEWERS}" --cc="${CC}" .)
+ else
+ (cd "${tc_utils_dir}" && \
+ repo upload --br="${channel}" --no-verify -y --re="${REVIEWERS}" \
+ --cc="${CC}" .)
+ fi
done
else
echo "Run these commands to upload the change:"
@@ -346,7 +409,7 @@ then
if [[ -n "${failed_channels}" ]]
then
echo
- echo "error: failed to update kernel afdo in ${failed_channels}" >&2
+ echo "ERROR: failed to update kernel afdo in ${failed_channels}" >&2
exit 3
fi
else
@@ -355,7 +418,7 @@ else
then
echo "No changes are applied. It looks like AFDO versions are up to date."
else
- echo "error: update in ${failed_channels} failed" >&2
+ echo "ERROR: update in ${failed_channels} failed" >&2
exit 3
fi
fi