omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / runtime / r15_seat_diag.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* r15_seat_diag.h -- per-sample diagnostics for the 1 ms GPU-seat residency |
| 18 | * sampler (spec/r15-performance-proof.md section 6.10, gate G15). |
| 19 | * |
| 20 | * G15 counts a sample "live" when the seat's heartbeat word moved since the |
| 21 | * previous 1 ms sample. A not-live sample can mean the seat really stopped |
| 22 | * (residency loss), or that the sampler ran late or not at all, or that the |
| 23 | * heartbeat read was stale. The counts alone cannot tell these apart, which is |
| 24 | * why CAND-1 window 2 (trial SEQ-06, 16348 of 19253 live) could only be |
| 25 | * explained from outside the evidence. These fields travel with the existing |
| 26 | * "sampler"/"total" objects (additive keys; seat_live and intervals, and so |
| 27 | * G15, are computed exactly as before). |
| 28 | * |
| 29 | * Wake-up lateness is the time between consecutive counted samples (nominal |
| 30 | * 1 ms plus the read); a starved sampler shows large gaps AND fewer samples, |
| 31 | * a stopped seat shows a long run of not-live samples with normal gaps. |
| 32 | */ |
| 33 | #ifndef R15_SEAT_DIAG_H |
| 34 | #define R15_SEAT_DIAG_H |
| 35 | #include <stdint.h> |
| 36 | |
| 37 | typedef struct { |
| 38 | uint64_t last_t, last_change_t; /* monotonic ns of previous sample / last heartbeat move */ |
| 39 | uint64_t late_2ms, late_10ms, max_gap_ns; |
| 40 | uint64_t dead_runs, dead_longest, dead_cur; /* runs of consecutive not-live samples */ |
| 41 | uint64_t first_dead_t, last_live_t; /* monotonic ns; 0 = never */ |
| 42 | uint64_t stale_max_ns; /* longest time the heartbeat had not moved, seen at a sample */ |
| 43 | uint64_t t_first; /* time of the first counted sample */ |
| 44 | uint32_t hb_last; |
| 45 | int have; |
| 46 | } SeatDiag; |
| 47 | |
| 48 | static inline void seat_diag_sample(SeatDiag *d, uint64_t t_ns, int live, uint32_t hb) { |
| 49 | if (!d->have) { d->have = 1; d->t_first = t_ns; d->last_change_t = t_ns; } |
| 50 | else { |
| 51 | uint64_t gap = t_ns - d->last_t; |
| 52 | if (gap > d->max_gap_ns) d->max_gap_ns = gap; |
| 53 | if (gap > 2000000u) d->late_2ms++; |
| 54 | if (gap > 10000000u) d->late_10ms++; |
| 55 | } |
| 56 | d->last_t = t_ns; |
| 57 | d->hb_last = hb; |
| 58 | if (live) { |
| 59 | d->last_change_t = t_ns; |
| 60 | d->last_live_t = t_ns; |
| 61 | d->dead_cur = 0; |
| 62 | } else { |
| 63 | if (d->dead_cur == 0) { |
| 64 | d->dead_runs++; |
| 65 | if (!d->first_dead_t) d->first_dead_t = t_ns; |
| 66 | } |
| 67 | d->dead_cur++; |
| 68 | if (d->dead_cur > d->dead_longest) d->dead_longest = d->dead_cur; |
| 69 | uint64_t age = t_ns - d->last_change_t; |
| 70 | if (age > d->stale_max_ns) d->stale_max_ns = age; |
| 71 | } |
| 72 | } |
| 73 | #endif |