67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#ifndef EMBEDDED_AFFINITY_HPP
|
|
#define EMBEDDED_AFFINITY_HPP
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace affinity {
|
|
|
|
enum class Error { none = 0, invalid = 1 };
|
|
enum class SetOperation { unite = 0, intersect = 1, subtract = 2 };
|
|
|
|
struct CoreSet {
|
|
std::vector<std::uint16_t> ids;
|
|
};
|
|
|
|
struct Core {
|
|
std::uint16_t id = 0;
|
|
std::uint8_t capacity = 0;
|
|
};
|
|
|
|
struct Job {
|
|
std::string id;
|
|
std::int32_t priority = 0;
|
|
CoreSet allowed;
|
|
std::optional<std::uint16_t> previous;
|
|
};
|
|
|
|
struct Problem {
|
|
std::vector<Core> cores;
|
|
std::vector<Job> jobs;
|
|
};
|
|
|
|
struct Binding {
|
|
std::string job;
|
|
std::optional<std::uint16_t> core;
|
|
};
|
|
|
|
struct CoreLoad {
|
|
std::uint16_t core = 0;
|
|
std::uint8_t used = 0;
|
|
};
|
|
|
|
struct Plan {
|
|
std::size_t accepted = 0;
|
|
std::size_t retained = 0;
|
|
std::vector<Binding> bindings;
|
|
std::vector<CoreLoad> loads;
|
|
};
|
|
|
|
bool valid_job_id(const std::string &text);
|
|
Error parse_list(const std::string &text, CoreSet &output);
|
|
Error format_list(const CoreSet &input, std::string &output);
|
|
Error parse_mask(const std::string &text, CoreSet &output);
|
|
Error format_mask(const CoreSet &input, std::string &output);
|
|
Error combine(const CoreSet &left, const CoreSet &right,
|
|
SetOperation operation, CoreSet &output);
|
|
Error canonical_problem(const Problem &input, Problem &output);
|
|
Error encode_problem(const Problem &input, std::vector<std::uint8_t> &output);
|
|
Error decode_problem(const std::vector<std::uint8_t> &input, Problem &output);
|
|
Error make_plan(const Problem &input, Plan &output);
|
|
|
|
}
|
|
#endif
|