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

199 lines
5.4 KiB
C++

#include "pool.hpp"
#include <array>
#include <utility>
namespace resource_map {
namespace {
struct Device {
bool configured = false;
std::vector<Resource> resources;
std::uint64_t token = 0;
int mem_ordinal = -1;
};
struct Selection {
bool found = false;
unsigned int index = 0;
Resource resource;
};
Selection select_memory(const Device& device, int ordinal)
{
int seen = 0;
for (unsigned int index = 0; index < device.resources.size(); ++index) {
const Resource& resource = device.resources[index];
if (resource.kind != static_cast<int>(Kind::MEM)) {
continue;
}
if (seen == ordinal) {
return {true, index, resource};
}
++seen;
}
return {};
}
Code validate_configuration(int id, const std::vector<Resource>& resources)
{
if (!detail::valid_id(id)) {
return Code::ARG;
}
if (resources.size() > 4) {
return Code::ARG;
}
for (const Resource& resource : resources) {
if (!detail::valid_resource(resource)) {
return Code::ARG;
}
}
return Code::OK;
}
ResourceInfo describe_resource(const Resource& resource)
{
ResourceInfo result;
result.kind = resource.kind;
result.start = resource.start;
result.size = resource.size;
return result;
}
}
struct Manager::Impl {
std::array<Device, 8> devices;
detail::Pool pool;
std::uint64_t successes = 0;
std::uint64_t faults = 0;
};
Manager::Manager() : impl_(new Impl)
{
}
Manager::~Manager() = default;
void Manager::reset()
{
impl_->devices = {};
impl_->pool.clear();
impl_->successes = 0;
impl_->faults = 0;
}
Code Manager::configure(int id, const std::vector<Resource>& resources)
{
const Code code = validate_configuration(id, resources);
if (code != Code::OK) {
return code;
}
Device& device = impl_->devices[static_cast<unsigned int>(id)];
if (device.token != 0) {
return Code::STATE;
}
std::vector<Resource> replacement = resources;
device.resources.swap(replacement);
device.configured = true;
return Code::OK;
}
ProbeResult Manager::probe(int id, int mem_ordinal, int fault)
{
if (!detail::valid_id(id) || mem_ordinal < 0 || mem_ordinal > 3 ||
fault < 0 || fault > 2) {
return {Code::ARG, 0};
}
Device& device = impl_->devices[static_cast<unsigned int>(id)];
if (device.token != 0) {
return {Code::STATE, 0};
}
if (!device.configured) {
return {Code::MISSING, 0};
}
const Selection selected = select_memory(device, mem_ordinal);
if (!selected.found) {
return {Code::MISSING, 0};
}
if (impl_->pool.conflicts(selected.resource)) {
return {Code::BUSY, 0};
}
if (fault == 1) {
++impl_->faults;
return {Code::MAPFAIL, 0};
}
const std::uint64_t token = impl_->pool.create(id, selected.index, selected.resource);
if (fault == 2) {
impl_->pool.release(token);
++impl_->faults;
return {Code::MAPFAIL, 0};
}
device.token = token;
device.mem_ordinal = mem_ordinal;
++impl_->successes;
return {Code::OK, token};
}
Code Manager::remove(int id)
{
if (!detail::valid_id(id)) {
return Code::ARG;
}
Device& device = impl_->devices[static_cast<unsigned int>(id)];
if (device.token == 0) {
return Code::OK;
}
device.token = 0;
device.mem_ordinal = -1;
return Code::OK;
}
ReadResult Manager::read(std::uint64_t token, std::uint64_t offset, int width)
{
return impl_->pool.read(token, offset, width);
}
Code Manager::write(std::uint64_t token, std::uint64_t offset, int width,
std::uint64_t value)
{
return impl_->pool.write(token, offset, width, value);
}
Code Manager::fill(std::uint64_t token, std::uint64_t offset, int count, int value)
{
return impl_->pool.fill(token, offset, count, value);
}
BytesResult Manager::dump(std::uint64_t token, std::uint64_t offset, int count) const
{
return impl_->pool.dump(token, offset, count);
}
DeviceInfo Manager::device(int id) const
{
DeviceInfo result;
if (!detail::valid_id(id)) {
result.code = Code::ARG;
return result;
}
const Device& device = impl_->devices[static_cast<unsigned int>(id)];
result.configured = device.configured;
result.active = device.token != 0;
result.resource_count = static_cast<unsigned int>(device.resources.size());
result.token = device.token;
result.mem_ordinal = device.mem_ordinal;
return result;
}
ResourceInfo Manager::resource(int id, int index) const
{
ResourceInfo result;
if (!detail::valid_id(id) || index < 0 || index > 3) {
result.code = Code::ARG;
return result;
}
const Device& device = impl_->devices[static_cast<unsigned int>(id)];
if (!device.configured || static_cast<unsigned int>(index) >= device.resources.size()) {
result.code = Code::MISSING;
return result;
}
return describe_resource(device.resources[static_cast<unsigned int>(index)]);
}
MappingInfo Manager::mapping(std::uint64_t token) const
{
return impl_->pool.mapping(token);
}
std::vector<MappingInfo> Manager::snapshot() const
{
return impl_->pool.snapshot();
}
Statistics Manager::statistics() const
{
Statistics result = impl_->pool.statistics();
result.probe_success = impl_->successes;
result.probe_faults = impl_->faults;
return result;
}
}