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>
137 lines
3.7 KiB
C++
137 lines
3.7 KiB
C++
#ifndef COHORT_HOTPLUG_HPP
|
|
#define COHORT_HOTPLUG_HPP
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace hotplug {
|
|
constexpr int max_cpus = 16;
|
|
constexpr int max_keys = 31;
|
|
constexpr int max_states = 8;
|
|
constexpr int invalid = -22;
|
|
constexpr int absent = -2;
|
|
constexpr int duplicate = -17;
|
|
constexpr int not_ready = -19;
|
|
constexpr int full = -28;
|
|
constexpr int callback_failed = -5;
|
|
|
|
enum class StopReason { rollback = 1, offline = 2, removal = 3 };
|
|
|
|
class CpuSet {
|
|
public:
|
|
CpuSet();
|
|
explicit CpuSet(std::uint32_t bits);
|
|
static bool valid_count(long long count);
|
|
static bool valid_mask(long long mask, int count);
|
|
bool contains(int cpu) const;
|
|
bool insert(int cpu);
|
|
bool erase(int cpu);
|
|
bool empty() const;
|
|
int count() const;
|
|
std::uint32_t bits() const;
|
|
std::vector<int> ascending() const;
|
|
std::vector<int> descending() const;
|
|
CpuSet difference(const CpuSet &other) const;
|
|
CpuSet intersect(const CpuSet &other) const;
|
|
bool subset_of(const CpuSet &other) const;
|
|
bool operator==(const CpuSet &other) const;
|
|
private:
|
|
std::uint32_t bits_;
|
|
};
|
|
|
|
struct Descriptor {
|
|
int key = 0;
|
|
int priority = 0;
|
|
int tag = 0;
|
|
int replay = 0;
|
|
};
|
|
struct Lease {
|
|
bool held = false;
|
|
std::uint64_t ticket = 0;
|
|
int tag = 0;
|
|
};
|
|
struct Event {
|
|
char kind = 'S';
|
|
int key = 0;
|
|
int cpu = 0;
|
|
std::uint64_t ticket = 0;
|
|
int detail = 0;
|
|
};
|
|
struct Counters {
|
|
std::uint64_t attempts = 0;
|
|
std::uint64_t failures = 0;
|
|
std::uint64_t stops = 0;
|
|
std::uint64_t registrations = 0;
|
|
std::uint64_t removals = 0;
|
|
std::uint64_t ups = 0;
|
|
std::uint64_t downs = 0;
|
|
std::uint64_t syncs = 0;
|
|
};
|
|
|
|
class Ledger {
|
|
public:
|
|
Ledger();
|
|
void reset();
|
|
void begin_operation();
|
|
void arm(int key, int cpu, int count);
|
|
int budget(int key, int cpu) const;
|
|
int start(const Descriptor &state, int cpu);
|
|
void stop(int key, int cpu, StopReason reason);
|
|
bool held(int key, int cpu) const;
|
|
const Lease &lease(int key, int cpu) const;
|
|
CpuSet cohort(int key) const;
|
|
std::uint64_t next_ticket() const;
|
|
const std::vector<Event> &events() const;
|
|
Counters &counters();
|
|
const Counters &counters() const;
|
|
std::vector<int> held_keys() const;
|
|
bool empty() const;
|
|
private:
|
|
std::array<std::array<Lease, max_cpus>, max_keys + 1> leases_;
|
|
std::array<std::array<int, max_cpus>, max_keys + 1> budgets_;
|
|
std::uint64_t next_;
|
|
Counters counters_;
|
|
std::vector<Event> events_;
|
|
};
|
|
|
|
struct Command {
|
|
std::string name;
|
|
std::vector<long long> args;
|
|
};
|
|
|
|
class Engine {
|
|
public:
|
|
Engine();
|
|
int execute(const Command &command);
|
|
bool ready() const;
|
|
int cpu_count() const;
|
|
CpuSet online() const;
|
|
const Ledger &ledger() const;
|
|
std::vector<Descriptor> descriptors() const;
|
|
std::string observe(int result) const;
|
|
private:
|
|
bool ready_;
|
|
int cpu_count_;
|
|
CpuSet online_;
|
|
std::vector<Descriptor> states_;
|
|
Ledger ledger_;
|
|
static bool valid_key(long long key);
|
|
bool valid_cpu(long long cpu) const;
|
|
const Descriptor *find(int key) const;
|
|
std::vector<Descriptor> ordered() const;
|
|
int reset(const std::vector<long long> &args);
|
|
int arm(const std::vector<long long> &args);
|
|
int add(const std::vector<long long> &args);
|
|
int remove(const std::vector<long long> &args);
|
|
int up(const std::vector<long long> &args);
|
|
int down(const std::vector<long long> &args);
|
|
int sync(const std::vector<long long> &args);
|
|
int replay(const Descriptor &state, const CpuSet &targets,
|
|
std::vector<int> &acquired);
|
|
void rollback_state(int key, const std::vector<int> &acquired);
|
|
void rollback_cpu(int cpu, const std::vector<int> &acquired);
|
|
};
|
|
}
|
|
#endif
|