Skip to main content

Module suspend

Module suspend 

Source
Expand description

Host suspend/resume detection.

Instant is monotonic and does not advance while the host is asleep; wall-clock time does. Comparing the two across a checkpoint reveals suspend/resume gaps that would otherwise be misread by wall-clock-only comparisons as a stalled tick loop (the watchdog in engine::mod) or a hung agent (stuck_task_timing_from_map in engine::tick).

checkpoint() is the primary detection point, called once per main tick loop iteration; suspended_duration_since pulls from its gap log instead of re-deriving suspend information from its own wall-clock deltas. Callers that run on an independent timer and can’t wait for the main loop’s checkpoint (e.g. the tick watchdog, which would otherwise race it on wake from suspend) should use their own SuspendDetector instance instead.

Structs§

SuspendDetector
Independent suspend detector for callers that run on their own timer and can’t rely on the shared checkpoint()/GAP_LOG pair, which is only written by the main tick loop. Two independently-scheduled tokio tasks that both freeze during a host suspend become “due” at roughly the same instant on wake with no ordering guarantee between them — a caller reading GAP_LOG right after wake can race the main loop’s own checkpoint() call and observe no gap yet. A SuspendDetector avoids the race by tracking its own Instant/wall-clock baseline, so it detects the gap from its own frozen timer instead of waiting on another task to record it.

Functions§

checkpoint
Record a checkpoint and return the suspend gap (if any) detected since the previous one. Call this once per main tick loop iteration.
gap_detected_within
Most recent suspend gap detected within the last window, if any. Lets the tick watchdog downgrade a stale-tick alert to informational when it is fully explained by a host suspend rather than an actual stall.
suspended_duration_since
Total suspend time detected since since. Subtract this from a wall-clock age computation to avoid mistaking suspend time for hung agent/tick runtime.