amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

7.6 KiB
Raw Permalink Blame History

Threaded IRQ cycle contract (C++17)

R01. This is an integer, sequential userspace model. There are eight exclusive IRQ lines with ids 0..7; one registration per line. No real interrupt, timer, worker or shared IRQ ownership is involved. A new Model is empty: step=0, next_ticket=1, next_token=1; absent generations are zero. Successful operations are deterministic. R02. Public API is in irq_cycle.hpp. All numeric arguments use signed long long; inputs supplied to the observer are well formed decimal integers within that type, with exactly the command's arguments. Malformed text, extra/missing arguments and integer overflow are outside this exercise. At most 10000 commands are supplied per process. No parser-error behavior is required. R03. Result is {code,value}. Codes: OK=0, RANGE=1, EXISTS=2, MISSING=3, CLOSED=4, CLOSING=5, RUNNING=6, NOT_READY=7, EMPTY=8, BAD_TOKEN=9. Errors return value=0 and change absolutely no state, counters, steps, tickets or tokens. Range validation precedes lookup, then lifecycle validation precedes operation-specific validation. All documented accepted mutators advance step exactly once, including zero-count arrivals and setting an unchanged mode. Queries do not advance step. R04. open(id,oneshot,priority,mode) accepts id 0..7, oneshot 0/1, priority 0..7 and mode 0..2. Validate every numeric range first. Existing open/closing line returns EXISTS; a closed slot may be reopened. Success returns its previous generation+1, resets all per-line fields/counters, sets state OPEN, and retains old token completions. First generation is 1. This operation does not allocate a ready ticket. R05. set_mode(id,mode) validates both ranges before lookup. Missing, closed and closing lines return MISSING, CLOSED and CLOSING respectively. Success changes only mode and step and returns 0. mode=0 means NONE, 1 means HANDLED and 2 means WAKE_THREAD. A replay uses the mode at replay time. R06. arrive(id,count) validates id and count 0..32, then MISSING/CLOSED/CLOSING. It is atomic on error. An accepted call returns count and advances step once. Each arrival increments received. An unmasked arrival invokes top: hard increments and exactly one of none,handled,wakes increments according to mode. NONE and HANDLED do not schedule work. WAKE_THREAD on an idle line makes it ready and allocates its next global FIFO ticket; on an already ready/running non-ONESHOT line it latches one pending activation. It never creates a second simultaneous ready/running instance. R07. ONESHOT masks its line from the instant a WAKE_THREAD makes it ready until that thread ends. Every arrival while masked increments masked_arrivals but does NOT call top. ONESHOT屏蔽期间的同线到达合并为一个pending,thread完成后恰好补派一次,而非按到达次数重放/直接丢弃。 pending is therefore always 0 or 1, irrespective of whether 1 or 32 masked arrivals occurred. The arriving calls do not consume FIFO tickets. Non-ONESHOT lines are never masked. R08. begin(id) validates id then missing/closed; closing lines may drain. RUNNING precedes NOT_READY. It consumes the line's ready entry, sets ready=0 and running=1, clears its ticket to zero, increments begun, advances step once and returns id. A line with no ready work returns NOT_READY. Mask is unchanged by begin. R09. next() selects among ready lines by ascending priority, breaking ties by ascending FIFO ticket, and performs begin on that line with the same result and one step. No ready line returns EMPTY without changes. Running lines do not block other lines. Priority is fixed for a registration. R10. end(id) validates id then missing/closed; closing lines may drain. Without running work it returns NOT_READY. Success clears running, increments ended, and advances step once. It removes the ONESHOT mask. If pending was one, clear it, increment replays and invoke top exactly once, without incrementing received. WAKE_THREAD schedules a fresh ready entry (and re-masks ONESHOT); NONE/HANDLED leave the line idle. The return value is id. A replay creates one fresh ticket and obeys ordinary priority ordering. R11. free(id) validates id then missing. An OPEN line becomes CLOSING, allocates one monotonically increasing token (global starting at 1), advances step once and returns that token. It preserves ready/running/pending and all counters. New arrivals and set_mode are rejected while closing. When ready=running=pending=0 the line becomes CLOSED, mask=0, ticket=0 and its token completes. An idle line closes during free; a busy line closes only when end has drained it, including one pending replay. A duplicate free on CLOSING/CLOSED returns the same token, with no new step or token allocation. R12. poll(token) validates token 1..10000, then returns BAD_TOKEN for a token never allocated. An allocated token returns OK with value 0 until CLOSED, then value 1 forever, even after slot reuse. It never advances step. inspect(id) validates id then MISSING only; CLOSED/CLOSING snapshots are available. Failed inspect returns an all-default View plus its error. Successful inspect returns a copy and does not mutate state. R13. View fields in order are id,generation,state,oneshot,priority,mode,ready,running,masked,pending,ticket,token,received,hard,none,handled,wakes,masked_arrivals,begun,ended,replays. state is 1=OPEN,2=CLOSING,3=CLOSED. Absent View has id=-1 and all other fields zero. Snapshot contains all registered slots (including closed) ordered by id. ready_order contains only ready ids ordered exactly as next(). Counts, generations, step and tickets use uint64_t; given the input bound none overflow. R14. summary() returns slots,open,closing,closed,ready,running,pending,masked,received,hard,none,handled,wakes,masked_arrivals,begun,ended,replays,waiting_tokens,completed_tokens in that order. Slots and lifecycle counts describe current slots; the next thirteen fields sum current per-line fields/counters; token counts describe all historical allocated tokens. After reopen old per-line counters cease contributing, but historical completed tokens remain. R15. invariant() returns true iff lifecycle accounting, per-line counter equations, unique ready tickets, pending in {0,1}, queue membership, mask rules, token linkage/completion, and begun-ended==running all hold. Required equations: received=hard-replays+masked_arrivals, hard=none+handled+wakes; CLOSED has no work/mask/ticket and a completed token; CLOSING has a noncompleted token and outstanding work. OPEN has token=0. Every successful state transition must retain these invariants. R16. encode(Result) returns decimal code + space + decimal value. encode(View) joins R13 fields with commas. encode(Summary) joins R14 fields with commas. render() returns ASCII: S <step> <next_ticket> <next_token>\n, then one L <view>\n for each slot by id, then Q followed by each ready id prefixed with one space and LF, then T followed by token number:done pairs by token ascending each prefixed with one space and LF, then A <summary>\n, then I <0-or-1>\n. No CR, blank lines or trailing spaces. Empty model still renders S,Q,T,A,I. Exact LF bytes are part of the contract. R17. observer.cpp is a raw stdin/API observer, not an oracle. Commands are open id oneshot priority mode, mode id mode, arrive id count, begin id, next, end id, free id, poll token, get id, show, summary, audit. For each command it emits R <encoded-result>\n; get additionally emits V <encoded-view>\n, summary emits U <encoded-summary>\n, audit returns OK with invariant as value; show returns OK,0. It then emits render(). EOF exits zero. Observer does not normalize or validate model observations. All APIs, not just smoke, must satisfy every clause in this document.