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

100 lines
2.4 KiB
C++

#include "hotplug.hpp"
namespace hotplug {
Ledger::Ledger() {
reset();
}
void Ledger::reset() {
for (auto &row : leases_) {
for (auto &entry : row) {
entry = Lease{};
}
}
for (auto &row : budgets_) {
row.fill(0);
}
next_ = 1;
counters_ = Counters{};
events_.clear();
}
void Ledger::begin_operation() {
events_.clear();
}
void Ledger::arm(int key, int cpu, int count) {
budgets_[key][cpu] = count;
}
int Ledger::budget(int key, int cpu) const {
return budgets_[key][cpu];
}
int Ledger::start(const Descriptor &state, int cpu) {
++counters_.attempts;
int &remaining = budgets_[state.key][cpu];
if (remaining > 0) {
--remaining;
++counters_.failures;
events_.push_back(Event{'S', state.key, cpu, 0, callback_failed});
return callback_failed;
}
Lease &target = leases_[state.key][cpu];
target.held = true;
target.ticket = next_++;
target.tag = state.tag;
events_.push_back(Event{'S', state.key, cpu, target.ticket, 0});
return 0;
}
void Ledger::stop(int key, int cpu, StopReason reason) {
Lease &target = leases_[key][cpu];
if (!target.held) {
return;
}
++counters_.stops;
events_.push_back(Event{'T', key, cpu, target.ticket,
static_cast<int>(reason)});
target = Lease{};
}
bool Ledger::held(int key, int cpu) const {
return leases_[key][cpu].held;
}
const Lease &Ledger::lease(int key, int cpu) const {
return leases_[key][cpu];
}
CpuSet Ledger::cohort(int key) const {
CpuSet result;
for (int cpu = 0; cpu < max_cpus; ++cpu) {
if (held(key, cpu)) {
result.insert(cpu);
}
}
return result;
}
std::uint64_t Ledger::next_ticket() const {
return next_;
}
const std::vector<Event> &Ledger::events() const {
return events_;
}
Counters &Ledger::counters() {
return counters_;
}
const Counters &Ledger::counters() const {
return counters_;
}
std::vector<int> Ledger::held_keys() const {
std::vector<int> result;
for (int key = 1; key <= max_keys; ++key) {
if (!cohort(key).empty()) {
result.push_back(key);
}
}
return result;
}
bool Ledger::empty() const {
for (int key = 1; key <= max_keys; ++key) {
if (!cohort(key).empty()) {
return false;
}
}
return true;
}
}