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

150 lines
5.8 KiB
C++

#include "irq_internal.hpp"
namespace irqcycle {
View Model::Impl::project(const State& s,int id) {
View v;
const auto& reg=s.registrations.at(id);
const auto& c=s.counters.at(id);
v.id=id; v.generation=reg.generation; v.state=reg.state;
v.oneshot=reg.oneshot; v.priority=reg.priority; v.mode=reg.mode; v.token=reg.token;
const auto work=s.activations.find(id);
if (work!=s.activations.end()) {
v.running=work->second.executing;
v.ready=!work->second.executing;
v.ticket=work->second.ticket;
v.masked=reg.oneshot;
}
v.pending=s.pending.count(id);
v.received=c.received; v.hard=c.hard; v.none=c.none; v.handled=c.handled;
v.wakes=c.wakes; v.masked_arrivals=c.masked_arrivals;
v.begun=c.begun; v.ended=c.ended; v.replays=c.replays;
return v;
}
Summary Model::summary() const {
Summary sum;
const auto& s=impl_->state;
for (const auto& entry:s.registrations) {
const auto v=Impl::project(s,entry.first);
++sum.slots;
sum.open+=(v.state==1); sum.closing+=(v.state==2); sum.closed+=(v.state==3);
sum.ready+=v.ready; sum.running+=v.running; sum.pending+=v.pending; sum.masked+=v.masked;
sum.received+=v.received; sum.hard+=v.hard; sum.none+=v.none; sum.handled+=v.handled;
sum.wakes+=v.wakes; sum.masked_arrivals+=v.masked_arrivals;
sum.begun+=v.begun; sum.ended+=v.ended; sum.replays+=v.replays;
}
for (const auto& token:s.tokens) {
if (token.second) ++sum.completed_tokens;
else ++sum.waiting_tokens;
}
return sum;
}
bool Model::invariant() const {
const auto& s=impl_->state;
std::set<int> scheduled;
std::set<std::uint64_t> tickets,tokens;
for (std::size_t priority=0;priority<s.buckets.size();++priority) {
for (const auto& entry:s.buckets[priority]) {
const int id=entry.second;
if (!scheduled.insert(id).second || !tickets.insert(entry.first).second) return false;
auto reg=s.registrations.find(id);
auto work=s.activations.find(id);
if (reg==s.registrations.end() || reg->second.priority!=priority) return false;
if (work==s.activations.end() || work->second.executing || work->second.ticket!=entry.first) return false;
}
}
if (s.counters.size()!=s.registrations.size()) return false;
for (const auto& entry:s.registrations) {
const int id=entry.first;
const auto& r=entry.second;
if (!Impl::valid_id(id) || !r.generation || r.state<1 || r.state>3) return false;
if (r.oneshot>1 || r.priority>7 || r.mode>2 || !s.counters.count(id)) return false;
const auto& c=s.counters.at(id);
auto work=s.activations.find(id);
const bool active=work!=s.activations.end();
const bool executing=active && work->second.executing;
if ((scheduled.count(id)!=0)!=(active && !executing)) return false;
if (active && ((executing && work->second.ticket) || (!executing && (!work->second.ticket || work->second.ticket>=s.next_ticket)))) return false;
if (s.pending.count(id) && !active) return false;
if (c.hard!=c.none+c.handled+c.wakes || c.hard<c.replays) return false;
if (c.received!=c.hard-c.replays+c.masked_arrivals || c.begun<c.ended) return false;
if (c.begun-c.ended!=static_cast<std::uint64_t>(executing)) return false;
if (r.state==1) { if (r.token) return false; }
else {
auto token=s.tokens.find(r.token);
if (token==s.tokens.end() || !tokens.insert(r.token).second) return false;
if (r.state==3 && (!token->second || active || s.pending.count(id))) return false;
if (r.state==2 && (token->second || !active)) return false;
}
}
for (const auto& work:s.activations) if (!s.registrations.count(work.first)) return false;
for (int id:s.pending) if (!s.activations.count(id)) return false;
std::uint64_t serial=1;
for (const auto& token:s.tokens) {
if (token.first!=serial++ || (!token.second && !tokens.count(token.first))) return false;
}
return serial==s.next_token;
}
std::string encode(const Result& value) {
return std::to_string(value.code)+" "+std::to_string(value.value);
}
std::string encode(const View& v) {
std::ostringstream out;
out<<v.id;
out<<','<<v.generation;
out<<','<<v.state;
out<<','<<v.oneshot;
out<<','<<v.priority;
out<<','<<v.mode;
out<<','<<v.ready;
out<<','<<v.running;
out<<','<<v.masked;
out<<','<<v.pending;
out<<','<<v.ticket;
out<<','<<v.token;
out<<','<<v.received;
out<<','<<v.hard;
out<<','<<v.none;
out<<','<<v.handled;
out<<','<<v.wakes;
out<<','<<v.masked_arrivals;
out<<','<<v.begun;
out<<','<<v.ended;
out<<','<<v.replays;
return out.str();
}
std::string encode(const Summary& v) {
std::ostringstream out;
out<<v.slots;
out<<','<<v.open;
out<<','<<v.closing;
out<<','<<v.closed;
out<<','<<v.ready;
out<<','<<v.running;
out<<','<<v.pending;
out<<','<<v.masked;
out<<','<<v.received;
out<<','<<v.hard;
out<<','<<v.none;
out<<','<<v.handled;
out<<','<<v.wakes;
out<<','<<v.masked_arrivals;
out<<','<<v.begun;
out<<','<<v.ended;
out<<','<<v.replays;
out<<','<<v.waiting_tokens;
out<<','<<v.completed_tokens;
return out.str();
}
std::string Model::render() const {
const auto& s=impl_->state;
std::ostringstream out;
out<<"S "<<s.step<<' '<<s.next_ticket<<' '<<s.next_token<<'\n';
for (const auto& entry:s.registrations) out<<"L "<<encode(Impl::project(s,entry.first))<<'\n';
out<<'Q';
for (int id:ready_order()) out<<' '<<id;
out<<'\n'<<'T';
for (const auto& token:s.tokens) out<<' '<<token.first<<':'<<(token.second?1:0);
out<<"\nA "<<encode(summary())<<"\nI "<<(invariant()?1:0)<<'\n';
return out.str();
}
}