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>
96 lines
2.3 KiB
C++
96 lines
2.3 KiB
C++
#include "hotplug.hpp"
|
|
|
|
namespace hotplug {
|
|
CpuSet::CpuSet() : bits_(0) {
|
|
}
|
|
CpuSet::CpuSet(std::uint32_t bits) : bits_(bits & 65535U) {
|
|
}
|
|
bool CpuSet::valid_count(long long count) {
|
|
return count >= 1 && count <= max_cpus;
|
|
}
|
|
bool CpuSet::valid_mask(long long mask, int count) {
|
|
if (!valid_count(count)) {
|
|
return false;
|
|
}
|
|
if (mask < 0) {
|
|
return false;
|
|
}
|
|
const auto limit = std::uint32_t(1) << count;
|
|
return static_cast<unsigned long long>(mask) < limit;
|
|
}
|
|
bool CpuSet::contains(int cpu) const {
|
|
if (cpu < 0 || cpu >= max_cpus) {
|
|
return false;
|
|
}
|
|
return (bits_ & (std::uint32_t(1) << cpu)) != 0;
|
|
}
|
|
bool CpuSet::insert(int cpu) {
|
|
if (cpu < 0 || cpu >= max_cpus) {
|
|
return false;
|
|
}
|
|
const auto bit = std::uint32_t(1) << cpu;
|
|
const bool changed = (bits_ & bit) == 0;
|
|
bits_ |= bit;
|
|
return changed;
|
|
}
|
|
bool CpuSet::erase(int cpu) {
|
|
if (cpu < 0 || cpu >= max_cpus) {
|
|
return false;
|
|
}
|
|
const auto bit = std::uint32_t(1) << cpu;
|
|
const bool changed = (bits_ & bit) != 0;
|
|
bits_ &= ~bit;
|
|
return changed;
|
|
}
|
|
bool CpuSet::empty() const {
|
|
return bits_ == 0;
|
|
}
|
|
int CpuSet::count() const {
|
|
auto remaining = bits_;
|
|
int result = 0;
|
|
while (remaining != 0) {
|
|
remaining &= remaining - 1;
|
|
++result;
|
|
}
|
|
return result;
|
|
}
|
|
std::uint32_t CpuSet::bits() const {
|
|
return bits_;
|
|
}
|
|
std::vector<int> CpuSet::ascending() const {
|
|
std::vector<int> result;
|
|
result.reserve(count());
|
|
for (int cpu = 0; cpu < max_cpus; ++cpu) {
|
|
if (contains(cpu)) {
|
|
result.push_back(cpu);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
std::vector<int> CpuSet::descending() const {
|
|
auto result = ascending();
|
|
for (std::size_t left = 0, right = result.size(); left < right; ++left) {
|
|
--right;
|
|
if (left >= right) {
|
|
break;
|
|
}
|
|
const int saved = result[left];
|
|
result[left] = result[right];
|
|
result[right] = saved;
|
|
}
|
|
return result;
|
|
}
|
|
CpuSet CpuSet::difference(const CpuSet &other) const {
|
|
return CpuSet(bits_ & ~other.bits_);
|
|
}
|
|
CpuSet CpuSet::intersect(const CpuSet &other) const {
|
|
return CpuSet(bits_ & other.bits_);
|
|
}
|
|
bool CpuSet::subset_of(const CpuSet &other) const {
|
|
return (bits_ & ~other.bits_) == 0;
|
|
}
|
|
bool CpuSet::operator==(const CpuSet &other) const {
|
|
return bits_ == other.bits_;
|
|
}
|
|
}
|