scx/scheds/sync-to-kernel.sh

85 lines
2.0 KiB
Bash
Raw Normal View History

2023-11-28 01:40:34 +00:00
#!/bin/bash
2023-12-04 00:22:59 +00:00
set -e
2023-11-28 01:40:34 +00:00
if [ $# -ne 1 ]; then
2023-12-04 00:22:59 +00:00
echo "Usage: sync-to-kernel.sh KERNEL_TREE_TO_SYNC_TO" 1>&2
2023-11-28 01:40:34 +00:00
exit 1
fi
# We sync these schedulers
rust_scheds=()
c_scheds=(scx_simple scx_qmap scx_central scx_flatcg)
2023-12-04 00:22:59 +00:00
headers=($(git ls-files include | grep -v include/vmlinux))
scheds=()
for rust_sched in ${rust_scheds[@]}; do
scheds+=($(git ls-files rust/${rust_sched} | grep -Ev 'meson.build|LICENSE'))
done
for c_sched in ${c_scheds[@]}; do
scheds+=($(git ls-files c/${c_sched}*))
done
2023-11-28 01:40:34 +00:00
kernel="$1/tools/sched_ext"
echo "Syncing ${#headers[@]} headers and ${#scheds[@]} scheduler source files to $kernel"
srcs=("${headers[@]}" "${scheds[@]}")
dsts=()
# Header paths are the same relative to the base directories.
for file in ${headers[@]}; do
dsts+=("$kernel/${file}")
done
# Sched files should drop the first directory component. ie.
# c/scx_simple.bpf.c should be synced to
# $kernel/scx_simple.bpf.c.
for file in ${scheds[@]}; do
dsts+=("$kernel/${file#*/}")
done
## debug
# for ((i=0;i<${#srcs[@]};i++)); do
# echo "${srcs[i]} -> ${dsts[i]}"
# done
2023-11-28 01:40:34 +00:00
nr_missing=0
nr_skipped=0
for ((i=0;i<${#srcs[@]};i++)); do
src="${srcs[i]}"
dst="${dsts[i]}"
orig="$src"
if [ ! -f "$dst" ]; then
echo "WARNING: $dst does not exist" 1>&2
nr_missing=$((nr_missing+1))
continue
fi
#
# As scx_utils is in this repo, rust schedulers point directly to
# the source in the tree. As they break outside this tree, drop them
# before syncing Cargo.toml files.
#
if [[ "$src" == */Cargo.toml ]]; then
tmp=$(mktemp)
sed -r 's/^scx_utils =.*version\s*=\s*"([^"]*)".*$/scx_utils = \"\1"/' < "$src" > "$tmp"
src="$tmp"
fi
if cmp -s "$src" "$dst"; then
2023-11-28 01:40:34 +00:00
nr_skipped=$((nr_skipped+1))
continue
fi
if [[ "$orig" == */Cargo.toml ]]; then
echo "Syncing $orig (dropped path from scx_utils dependency)"
else
echo "Syncing $orig"
fi
cp -f "$src" "$dst"
2023-11-28 01:40:34 +00:00
done
echo "Skipped $nr_skipped unchanged and $nr_missing new files"