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>
7.5 KiB
Cohort service API and observation contract
This is an original, deterministic C++17 userspace model. CPU numbers are labels; it does not call kernel hotplug APIs or depend on elapsed time. Implement every clause in this document, including combinations absent from the field replay.
Domain and lifetime
- A fresh Engine is unready: CPU count and mask are zero, no descriptors, leases or budgets, next ticket is 1, and all eight counters are zero.
- Configured CPU count is 1..16; CPU IDs are 0..count-1. A mask is a nonnegative integer strictly below 2^count. Keys are 1..31. At most eight descriptors are registered, regardless of how many leases they hold.
- A descriptor contains key, priority (-100..100), tag (0..65535), and replay (0 or 1). Key is its identity; reusing a removed or failed key is allowed.
- Each successful startup owns one lease for (key, CPU), with the descriptor's tag and a globally increasing ticket. Tickets start at 1, are allocated only on successful startup, and are never reused until RESET. A failed startup allocates no ticket and owns no lease. No pair can own two leases.
- An ARM budget belongs to a (key, CPU) independently of registration. Replacing a budget or setting it to zero is allowed. Neither REMOVE nor failed REG clears a budget. Each reached startup with a positive budget decrements it once and fails; an unreached callback does not consume a budget.
- An operation clears the previous operation's event list before validating. Invalid or refused operations preserve all other state. Diagnostic events, attempted/failed/stopped counters, consumed budgets and issued tickets are retained after callback failure; successful structural commits are not.
Commands and error precedence
The observer reads one command per line from stdin. Blank lines produce no output. Names are case sensitive; integer tokens use [+-]?[0-9]+ (ASCII digits) and must fit signed 64-bit. A wrong argument count, unknown name, malformed integer, or argument outside the command's global range returns -22. Then unready returns -19. Then a CPU ID outside the configured count returns -22. Then identity/capacity checks below apply. Validation happens before callbacks, budgets or counters can change.
RESET count mask: validates count and mask as above, then atomically replaces the complete Engine with a ready empty registry and that topology. It resets budgets, events, counters and next ticket to 1; it emits no teardown callbacks, even if the discarded model held leases. Valid RESET always returns 0.ARM key cpu budget: global ranges key 1..31, CPU 0..15, budget 0..4. After readiness and configured CPU validation, replaces that budget; returns 0.REG key priority tag replay: global ranges as above. After readiness, an existing key returns -17 even if all eight slots are occupied. Otherwise a full registry returns -28 before any callback or budget consumption.REMOVE key: global range key 1..31. After readiness a missing key returns -2.UP cpuandDOWN cpu: global range CPU 0..15, then readiness and configured CPU validation. Repeating the current topology state returns 0 with no events or counters. UP on an online CPU does not fill leases skipped by replay=0.SYNC key: global range key 1..31, then readiness, then missing key returns -2.SNAP: no arguments. Returns 0 when ready, otherwise -19; changes no state.
Every callback failure returns -5. All other successful operations return 0. The only failures are the errors specified here; teardown callbacks cannot fail.
Callback order and transactions
- REG with replay=1 starts the new descriptor on every currently online CPU in ascending CPU order. Replay=0 starts none. The descriptor and registrations counter commit only after all required startups succeed. On failure, stop exactly the successful startups from this REG in reverse acquisition order, reason 1; the failing CPU gets no stop and no descriptor remains registered.
- UP on an offline CPU starts every registered descriptor sorted by increasing priority, breaking ties by increasing key (not registration order). If one fails, stop exactly the successful startups from this UP in reverse order, reason 1; keep the CPU offline and preserve every preexisting lease. On full success set the CPU online and increment ups, including an empty registry.
- DOWN on an online CPU visits registered descriptors in reverse of that sorted order, stops only leases actually held for that CPU with reason 2, clears its online bit and increments downs, including an empty registry. Other CPUs and ARM budgets are unchanged.
- REMOVE stops the key's held leases in descending CPU order, reason 3, then removes its descriptor and increments removals. It leaves topology, tickets, other descriptors and budgets intact.
- SYNC starts only the key's currently online CPUs lacking a lease, in ascending CPU order. If none are missing it is a counter-free no-op. Failure stops only leases newly acquired by this SYNC, in reverse order, reason 1, preserving all preexisting leases. Success increments syncs once. The replay field remains the descriptor's original registration mode.
- On every attempted startup increment attempts; on failure also increment failures. On every actual stop increment stops. REG success increments registrations once even with empty replay. No other events increment counters.
C++ API and observations
hotplug.hpp declares CpuSet, Descriptor, Lease, Event, Counters, Ledger, Command
and Engine. Engine::execute(Command{name,args}) applies exactly one command;
Engine::observe(result) serializes the raw events and resulting state below.
The other declared accessors expose the same raw state, not extra policy.
CpuSet masks to 16 bits; out-of-domain contains/insert/erase return false and
insert/erase report whether a bit changed; count counts bits; ascending and
descending are numerical orders; difference/intersect/subset/equality have
ordinary set meanings. Ledger start/stop are internal primitives called only
with valid IDs and successful-start pairs; stop on a missing lease is a no-op.
No specific container type, helper layout, algorithm or allocation strategy is
required; changing the declared private implementation is permitted.
For every nonblank input line, output the following lines, with decimal integers separated by a single space and a final newline. Do not print extra diagnostics to stdout. stderr is unconstrained. Lists may be empty.
R result- For each callback in actual call order:
E S key cpu ticket resultfor start, orE T key cpu ticket reasonfor stop. A failed start uses ticket 0 and -5; a successful start uses its allocated ticket and result 0. Stop reports the released ticket and reason 1/2/3 above. S ready count mask online_count next_ticket attempts failures stops registrations removals ups downs syncs registered_count- For each descriptor in increasing key order:
D key priority tag replay held_cpu_mask - For every held lease, ordered by increasing key then CPU:
L key cpu ticket tag. Include any lease even if a buggy model has no owner. - For every nonzero budget, ordered by increasing key then CPU:
F key cpu remaining END
observer.cpp is a raw stdin adapter. It contains no test inputs or expected
answers. The build must succeed with a normal C++17 compiler and the documented
Makefile. Only the five named submission files are frozen for grading; added
files are not collected. Implementations must work for the complete API contract.