ci / test (push) Successful in 31s
ci / bench (push) Successful in 14s
ci / mcdc (push) Successful in 26s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 1m18s
ci / badges (push) Skipped
ci / bench (pull_request) Successful in 10s
ci / patches-apply (push) Successful in 52s
ci / qemu-tools (push) Successful in 3m26s
ci / kernel-symbols (push) Successful in 5m12s
ci / test (pull_request) Successful in 8s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / badges (pull_request) Skipped
ci / qemu-tools (pull_request) Successful in 2m59s
ci / mcdc (pull_request) Successful in 19s
ci / patches-apply (pull_request) Successful in 52s
ci / quality (pull_request) Successful in 1m15s
ci / kernel-symbols (pull_request) Successful in 6m57s
On the RV1106 the boot firmware does not enter the kernel in HYP mode and leaves CNTVOFF non-zero. The DT timer node lists no virtual-timer PPI, so the kernel keeps time on the physical counter, while the arm32 vDSO always reads the virtual one: on bench a clock_gettime() ran 738.9 s ahead of the kernel clock (pure offset, -0.1 ppm over 30 s) and every absolute deadline taken from it expired minutes late (flare-edge#2319, the #2311 reset loop). New patch 82-arch-timer-vdso-phys-counter.patch: - rv1106.dtsi and rv1106-warden-m2.dts: the timer node carries arm,cpu-registers-not-fw-configured. The kernel keeps the physical timer it uses today, and arch/arm/kernel/vdso.c drops the vDSO clock symbols, so libc goes straight to the syscall. - arm_arch_timer.c: on arm32, a kernel on the physical counter without HYP mode sets the counter's vdso_clock_mode to VDSO_CLOCKMODE_NONE, the safety net for a device tree without the property. QEMU -M virt (virtual PPI present) is unchanged. tests/arch-timer/check-vdso-counter.py checks both guards in the patched tree; CI's patches-apply job runs it and its 12 regression cases. Fixes #35 Refs flare-edge#2319 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
110 lines
4.7 KiB
Bash
Executable File
110 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Regression tests for tests/arch-timer/check-vdso-counter.py (bfe-core1106-sdk#35).
|
|
#
|
|
# The checker guards the fix for the vDSO clock running 739 s ahead of the
|
|
# kernel clock on the RV1106: the DT timer property and the arm32 fallback in
|
|
# arm_arch_timer.c. Each case builds a small fake kernel tree and expects an
|
|
# exit status; the real patched tree is checked in CI's patches-apply job.
|
|
set -uo pipefail
|
|
|
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
CHECK="$HERE/check-vdso-counter.py"
|
|
TMP="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
TIMER_NODE_GOOD=' timer {
|
|
compatible = "arm,armv7-timer";
|
|
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
|
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
|
clock-frequency = <24000000>;
|
|
arm,cpu-registers-not-fw-configured;
|
|
};'
|
|
TIMER_NODE_BARE=' timer {
|
|
compatible = "arm,armv7-timer";
|
|
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
|
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
|
clock-frequency = <24000000>;
|
|
};'
|
|
TIMER_NODE_COMMENTED=' timer {
|
|
compatible = "arm,armv7-timer";
|
|
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
|
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
|
/* arm,cpu-registers-not-fw-configured; */
|
|
};'
|
|
TIMER_NODE_VIRT=' timer {
|
|
compatible = "arm,armv7-timer";
|
|
interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>,
|
|
<GIC_PPI 11 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 10 IRQ_TYPE_LEVEL_LOW>;
|
|
};'
|
|
TIMER_NODE_CHILD=' timer {
|
|
compatible = "arm,armv7-timer";
|
|
interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>;
|
|
sub {
|
|
arm,cpu-registers-not-fw-configured;
|
|
};
|
|
};'
|
|
|
|
GUARD=' if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
|
|
!is_hyp_mode_available() &&
|
|
clocksource_counter.vdso_clock_mode != VDSO_CLOCKMODE_NONE) {
|
|
clocksource_counter.vdso_clock_mode = VDSO_CLOCKMODE_NONE;
|
|
pr_info("physical counter without HYP: vDSO clock disabled\n");
|
|
}'
|
|
GUARD_WRONG=' if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
|
|
!is_hyp_mode_available()) {
|
|
pr_info("physical counter without HYP\n");
|
|
}'
|
|
DEFAULT=' clocksource_counter.vdso_clock_mode = vdso_default;'
|
|
|
|
mk_tree() { # mk_tree <name> <dtsi timer node> <timer.c body before> <body after>
|
|
local d="$TMP/$1"
|
|
mkdir -p "$d/arch/arm/boot/dts/rockchip" "$d/drivers/clocksource"
|
|
printf '/ {\n\tcpus { cpu@0 { reg = <0>; }; };\n%s\n};\n' "$2" \
|
|
> "$d/arch/arm/boot/dts/rockchip/rv1106.dtsi"
|
|
printf '#include "rv1106.dtsi"\n/ { model = "x"; };\n' \
|
|
> "$d/arch/arm/boot/dts/rockchip/rv1106-warden.dts"
|
|
printf 'static void __init arch_counter_register(void)\n{\n\tu64 (*rd)(void);\n%s\n\n%s\n\twidth = 56;\n}\n' \
|
|
"$3" "$4" > "$d/drivers/clocksource/arm_arch_timer.c"
|
|
echo "$d"
|
|
}
|
|
|
|
fails=0 n=0
|
|
expect() { # expect <name> <exit> <tree>
|
|
local got out
|
|
out="$(python3 "$CHECK" "$3" 2>&1)"; got=$?
|
|
n=$((n + 1))
|
|
if [ "$got" = "$2" ]; then
|
|
echo "PASS: $1"
|
|
else
|
|
echo "FAIL: $1 (wanted exit $2, got $got)"
|
|
while IFS= read -r line; do echo " $line"; done <<< "$out"
|
|
fails=$((fails + 1))
|
|
fi
|
|
}
|
|
|
|
expect "fixed tree passes" 0 "$(mk_tree good "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD")"
|
|
expect "timer node without the property fails" 1 "$(mk_tree bare "$TIMER_NODE_BARE" "$DEFAULT" "$GUARD")"
|
|
expect "property only inside a comment fails" 1 "$(mk_tree comm "$TIMER_NODE_COMMENTED" "$DEFAULT" "$GUARD")"
|
|
expect "property only in a child node fails" 1 "$(mk_tree child "$TIMER_NODE_CHILD" "$DEFAULT" "$GUARD")"
|
|
expect "timer node with a virtual PPI needs no property" 0 "$(mk_tree virt "$TIMER_NODE_VIRT" "$DEFAULT" "$GUARD")"
|
|
expect "missing arm32 fallback fails" 1 "$(mk_tree noguard "$TIMER_NODE_GOOD" "$DEFAULT" "")"
|
|
expect "fallback that does not set VDSO_CLOCKMODE_NONE fails" 1 "$(mk_tree wrong "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD_WRONG")"
|
|
expect "fallback before the vdso_default assignment fails" 1 "$(mk_tree order "$TIMER_NODE_GOOD" "$GUARD" "$DEFAULT")"
|
|
expect "no timer node at all fails" 1 "$(mk_tree none "" "$DEFAULT" "$GUARD")"
|
|
|
|
d="$(mk_tree m2 "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD")"
|
|
printf '/ {\n%s\n};\n' "$TIMER_NODE_BARE" > "$d/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts"
|
|
expect "a second board DTS without the property fails" 1 "$d"
|
|
|
|
rm -f "$d/drivers/clocksource/arm_arch_timer.c"
|
|
expect "missing arm_arch_timer.c fails" 1 "$d"
|
|
|
|
n=$((n + 1))
|
|
if python3 "$CHECK" >/dev/null 2>&1; [ $? = 2 ]; then echo "PASS: no argument is a usage error"
|
|
else echo "FAIL: no argument is a usage error"; fails=$((fails + 1)); fi
|
|
|
|
if [ "$fails" -ne 0 ]; then
|
|
echo "check-vdso-counter: $fails of $n FAILED"; exit 1
|
|
fi
|
|
echo "check-vdso-counter: all $n passed"
|