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.4 KiB
Python
Executable File
110 lines
4.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Check that a patched kernel tree keeps the arm32 vDSO clock off the
|
|
virtual counter when the kernel times on the physical one (bfe-core1106-sdk#35).
|
|
|
|
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 counter: clock_gettime() then runs about 739 s ahead of the kernel
|
|
clock and every absolute deadline taken from it expires late (flare-edge#2319).
|
|
|
|
Two guards must both be present in the patched tree:
|
|
|
|
1. Every armv7/armv8 timer node in the RV1106 device trees that has no
|
|
virtual-timer PPI (GIC_PPI 11) carries `arm,cpu-registers-not-fw-configured`,
|
|
which makes arch/arm/kernel/vdso.c drop the vDSO clock symbols.
|
|
2. drivers/clocksource/arm_arch_timer.c sets the counter's vdso_clock_mode to
|
|
VDSO_CLOCKMODE_NONE on arm32 when the kernel uses the physical counter
|
|
without HYP mode (the safety net for a device tree without the property).
|
|
|
|
Usage: check-vdso-counter.py <patched kernel source dir>
|
|
Exit 0 when both hold, 1 with one FAIL line per problem, 2 on bad usage.
|
|
"""
|
|
import pathlib
|
|
import re
|
|
import sys
|
|
|
|
DTS_GLOB = "arch/arm/boot/dts/rockchip/rv1106*.dts*"
|
|
TIMER_C = "drivers/clocksource/arm_arch_timer.c"
|
|
PROPERTY = "arm,cpu-registers-not-fw-configured"
|
|
|
|
|
|
def strip_comments(text):
|
|
text = re.sub(r"/\*.*?\*/", "", text, flags=re.S)
|
|
return re.sub(r"//[^\n]*", "", text)
|
|
|
|
|
|
def timer_nodes(text):
|
|
"""Yield the body of every node whose compatible is an arch timer."""
|
|
for m in re.finditer(r"\b[\w@,.-]+\s*\{", text):
|
|
depth, i = 1, m.end()
|
|
while depth and i < len(text):
|
|
depth += {"{": 1, "}": -1}.get(text[i], 0)
|
|
i += 1
|
|
body = text[m.end():i - 1]
|
|
# Only the node's own properties, not its children's.
|
|
own = re.sub(r"\{.*\}", "", body, flags=re.S)
|
|
if re.search(r'compatible\s*=\s*"arm,armv[78]-timer"', own):
|
|
yield own
|
|
|
|
|
|
def check_dts(root):
|
|
problems, seen = [], 0
|
|
for path in sorted(root.glob(DTS_GLOB)):
|
|
text = strip_comments(path.read_text(errors="replace"))
|
|
for own in timer_nodes(text):
|
|
seen += 1
|
|
has_virt = re.search(r"GIC_PPI\s+11\b", own) is not None
|
|
has_prop = re.search(r"(^|[\s;])" + re.escape(PROPERTY) + r"\s*;", own) is not None
|
|
if not has_virt and not has_prop:
|
|
problems.append(f"{path.relative_to(root)}: timer node has no virtual-timer "
|
|
f"PPI and no {PROPERTY}")
|
|
if not seen:
|
|
problems.append(f"no arm,armv7-timer node found under {DTS_GLOB}")
|
|
return problems
|
|
|
|
|
|
def check_timer_c(root):
|
|
path = root / TIMER_C
|
|
if not path.is_file():
|
|
return [f"{TIMER_C} missing"]
|
|
text = strip_comments(path.read_text(errors="replace"))
|
|
m = re.search(r"static void __init arch_counter_register\(void\)\s*\{", text)
|
|
if not m:
|
|
return [f"{TIMER_C}: arch_counter_register() not found"]
|
|
depth, i = 1, m.end()
|
|
while depth and i < len(text):
|
|
depth += {"{": 1, "}": -1}.get(text[i], 0)
|
|
i += 1
|
|
body = text[m.end():i - 1]
|
|
guard = re.search(
|
|
r"if\s*\(\s*IS_ENABLED\(CONFIG_ARM\)\s*&&\s*"
|
|
r"arch_timer_uses_ppi\s*!=\s*ARCH_TIMER_VIRT_PPI\s*&&\s*"
|
|
r"!\s*is_hyp_mode_available\(\)[^{]*\{([^}]*)\}", body)
|
|
if not guard or not re.search(
|
|
r"clocksource_counter\.vdso_clock_mode\s*=\s*VDSO_CLOCKMODE_NONE\s*;", guard.group(1)):
|
|
return [f"{TIMER_C}: arch_counter_register() lacks the arm32 physical-counter "
|
|
"vDSO fallback (vdso_clock_mode = VDSO_CLOCKMODE_NONE)"]
|
|
default_at = body.find("clocksource_counter.vdso_clock_mode = vdso_default;")
|
|
if default_at < 0 or default_at > guard.start():
|
|
return [f"{TIMER_C}: the vDSO fallback must come after the vdso_default assignment"]
|
|
return []
|
|
|
|
|
|
def main(argv):
|
|
if len(argv) != 2 or not pathlib.Path(argv[1]).is_dir():
|
|
print("usage: check-vdso-counter.py <patched kernel source dir>", file=sys.stderr)
|
|
return 2
|
|
root = pathlib.Path(argv[1])
|
|
problems = check_dts(root) + check_timer_c(root)
|
|
for p in problems:
|
|
print(f"FAIL: {p}")
|
|
if problems:
|
|
return 1
|
|
print("vdso-counter: ok (DT property and arm32 physical-counter fallback present)")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv))
|