feat(watchdog): L0 in-process wedge detector + PLC seq-echo + fprd-gate CLI

L0 watchdog (async loop):
- reads PLC-echoed processed seq from SM3[8..15] (PLC writes
  nProcessedSeq to aOut1[8..15] every cycle)
- if echoed seq stalls >200ms while tx seq advances -> WEDGE log +
  exit(42) for supervisor restart
- grace: if echo never seen (old PLC config), WARN once and stay
  passive instead of exiting

PLC change (in twincat3-auto-cli repo):
- MAIN.TcPOU: MEMCPY aOut1[8..15] = nProcessedSeq (1 line)

--fprd-gate N CLI flag (default 350us):
- gate=200 optimal (1753Hz, hop 567us, lag 10-11)
- gate=0 starves writes (reverse path dies) - do not use
- FPRD true RTT=346us (old 692us was gate+RTT artifact)

Fault injection verified:
- kill producer -> L1 supervisor restart in ~5s
- 3 rapid restarts -> 60s backoff
- PLC echo activation -> WARN count drops to 0 (active mode)

Production: rfm_rt.1400c --fprd-gate 200 --core 6 --prio 80
This commit is contained in:
Tony Cao 2026-11-10 12:08:07 +08:00
parent ccfab0210d
commit 050a775283

View File

@ -2683,6 +2683,11 @@ async fn rfm_async_loop(
let mut n_wkc0: u64 = 0;
let mut last_wkick: Option<Instant> = None;
let mut rep_gen_done: u32 = 0;
// L0 watchdog: track PLC-echoed processed seq (SM3[8..15]) to detect
// reverse-path wedge (bSync=True illusion). Exit 42 for supervisor restart.
let mut echoed_seq: u64 = 0;
let mut last_echo_advance: Option<Instant> = None;
let mut wd_logged: bool = false;
while !STOP.load(Ordering::Relaxed) {
if duration_sec > 0 && start.elapsed().as_secs() >= duration_sec {
@ -2855,6 +2860,15 @@ async fn rfm_async_loop(
if rx_buf[..8] != prev_rx8 {
prev_rx8.copy_from_slice(&rx_buf[..8]);
n_fresh += 1;
// L0: read PLC-echoed processed seq
if rx_buf.len() >= 16 {
let es = u64::from_le_bytes(rx_buf[8..16].try_into().unwrap());
if es != echoed_seq {
echoed_seq = es;
last_echo_advance = Some(Instant::now());
wd_logged = false;
}
}
{
let p = (rt::now_ns() % 1_000_000) as i64;
let mut adj = p;
@ -2958,6 +2972,26 @@ async fn rfm_async_loop(
core::hint::spin_loop();
// L0 watchdog check: reverse wedge = we wrote seq but PLC echo stopped advancing
if last_echo_advance.is_none() && start.elapsed().as_secs() > 5 {
last_echo_advance = Some(Instant::now()); // grace at startup
}
if let Some(t) = last_echo_advance {
if t.elapsed().as_millis() > 200 && tx_latest_seq > echoed_seq.wrapping_add(1) {
if echoed_seq == 0 {
// PLC echo never seen: old PLC config without aOut1[8..15] echo.
// Warn once, do not exit (not a wedge, just missing PLC feature).
if !wd_logged {
println!("WARN: PLC seq-echo not detected (activate new PLC config); watchdog passive");
wd_logged = true;
}
} else {
println!("WEDGE: tx_seq={} echoed_seq={} stalled {}ms -> exit(42)",
tx_latest_seq, echoed_seq, t.elapsed().as_millis());
std::process::exit(42);
}
}
}
if last_report.elapsed() >= Duration::from_secs(10) {
// SM 鎺㈤拡: 姣?绉掕 SM2/SM3 浣胯兘浣?+ SM2 缂撳啿, 鍖哄垎鍒嗛厤鏈敓鏁?vs 妗ヤ笉杞彂
if start.elapsed().as_secs() % 30 == 0 {