From 5cbb04c60a621c0fd6d59644649a35ec596255ac Mon Sep 17 00:00:00 2001 From: Robert Allan James Date: Tue, 11 Aug 2026 10:09:47 -0400 Subject: [PATCH] starkernel: TimeTrustState.ticks -- mark volatile, fixing the one hazard 4.5a found Written directly in ISR context on all three architectures (heartbeat_tick(), heartbeat.c:163) and read directly by mainline (heartbeat_ticks(), including the busy-wait at kernel_main.c:880) without being volatile -- worked by accident at -O0, would be a real bug once the kernel builds with optimization (item 4.5). Every other field in this struct is mainline-only (heartbeat_service()'s deferred window/variance/ trust processing), so only this one field needed the qualifier. Punch list item 4.5b complete. Three-arch acceptance boot clean at unchanged -O0 (no behavior change intended yet -- this is prep for enabling optimization, not the switch itself). Co-Authored-By: Claude Sonnet 5 --- include/starkernel/timer.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/starkernel/timer.h b/include/starkernel/timer.h index 8675b66..79f0d61 100644 --- a/include/starkernel/timer.h +++ b/include/starkernel/timer.h @@ -87,7 +87,14 @@ typedef struct time_window { */ typedef struct time_trust_state { /* Core counters */ - uint64_t ticks; /* TIME-TICKS: monotonic heartbeat count */ + volatile uint64_t ticks; /* TIME-TICKS: monotonic heartbeat count -- + * written directly in ISR context + * (heartbeat_tick(), all three archs) and + * read directly by mainline + * (heartbeat_ticks()); genuinely + * concurrent, unlike every other field in + * this struct (FABRIC.md item 4.5a/4.5b, + * 2026-08-11). */ uint64_t last_tsc; /* TSC at last heartbeat */ uint64_t expected_delta; /* Expected TSC ticks per heartbeat */