amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

120 lines
3.8 KiB
C++

#ifndef STREAM_MODEL_HPP
#define STREAM_MODEL_HPP
#include <array>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <vector>
namespace stream {
constexpr std::size_t slot_count = 4;
constexpr std::size_t capacity = 96;
enum class Direction : unsigned { ToDevice = 1, FromDevice = 2, Both = 3 };
enum class Owner : unsigned { None = 0, Cpu = 1, Device = 2 };
enum class Status : unsigned {
Ok = 0, Slot = 1, Exists = 2, Missing = 3, Busy = 4,
Range = 5, Direction = 6, Ticket = 7, Port = 8
};
struct Receipt {
std::uint64_t ticket = 0;
std::uint64_t generation = 0;
std::size_t offset = 0;
std::size_t count = 0;
std::uint32_t read_hash = 0;
std::uint32_t write_hash = 0;
};
struct Counters {
std::uint64_t maps = 0;
std::uint64_t unmaps = 0;
std::uint64_t prepares = 0;
std::uint64_t reclaims = 0;
std::uint64_t transfers = 0;
std::uint64_t to_bytes = 0;
std::uint64_t from_bytes = 0;
};
struct Observation {
bool live = false;
Owner owner = Owner::None;
Direction direction = Direction::ToDevice;
std::size_t length = 0;
std::uint64_t generation = 0;
Counters counters;
std::vector<std::uint8_t> cpu;
std::vector<std::uint8_t> device;
};
std::uint8_t pattern(std::uint32_t seed, std::size_t index);
std::uint32_t digest(const std::vector<std::uint8_t>& bytes);
class Port {
public:
Port();
~Port();
Port(const Port&) = delete;
Port& operator=(const Port&) = delete;
bool map(std::size_t slot, std::size_t length, Direction direction,
std::uint32_t seed, std::uint64_t& generation);
bool patch(std::size_t slot, std::size_t offset, std::size_t count,
std::uint32_t seed);
bool read(std::size_t slot, std::size_t offset, std::size_t count,
std::vector<std::uint8_t>& result);
bool for_device(std::size_t slot, Direction direction);
bool transfer(std::size_t slot, std::size_t offset, std::size_t count,
std::uint32_t seed, Receipt& result);
bool for_cpu(std::size_t slot, Direction direction);
bool unmap(std::size_t slot);
Observation observe(std::size_t slot) const;
std::uint64_t errors() const;
private:
struct Region {
bool live = false;
bool armed = false;
Owner owner = Owner::None;
Direction direction = Direction::ToDevice;
std::size_t length = 0;
std::uint64_t generation = 0;
Counters counters;
std::array<std::uint8_t, capacity> cpu{};
std::array<std::uint8_t, capacity> device{};
};
std::array<Region, slot_count> regions_;
std::uint64_t next_ticket_ = 1;
std::uint64_t errors_ = 0;
bool fault();
bool cpu_region(std::size_t slot);
bool range(const Region& region, std::size_t offset, std::size_t count) const;
};
struct Reply {
Status status = Status::Ok;
std::vector<std::uint64_t> values;
};
struct SessionInfo {
bool live = false;
bool pending = false;
unsigned direction = 0;
std::size_t length = 0;
std::uint64_t completed = 0;
std::uint64_t ticket = 0;
};
class Session {
public:
explicit Session(Port& port);
~Session();
Session(const Session&) = delete;
Session& operator=(const Session&) = delete;
Reply map(std::size_t slot, std::size_t length, unsigned direction,
std::uint32_t seed);
Reply patch(std::size_t slot, std::size_t offset, std::size_t count,
std::uint32_t seed);
Reply read(std::size_t slot, std::size_t offset, std::size_t count);
Reply begin(std::size_t slot, std::size_t offset, std::size_t count,
std::uint32_t seed);
Reply finish(std::size_t slot, std::uint64_t ticket);
Reply unmap(std::size_t slot);
Reply reset();
SessionInfo inspect(std::size_t slot) const;
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
}
#endif