Skip to content

Commit

Permalink
config: Cleanup, TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejKafka committed Jul 22, 2021
1 parent bd9d4a4 commit 357e6e7
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ using namespace std;
using namespace YAML;
namespace fs = std::filesystem;

template<typename T_all>
static cpu_set parse_cpu_set(const string &cpulist, T_all all_cpus)
{
// "all" = use all available CPUs
// MK: imo, it would be nicer to use *, but that (along with most other
// special characters) has special meaning in YAML, and must be quoted
if (cpulist == "all") return cpu_set(all_cpus);
return cpu_set(cpulist);
}
template<typename T_all>
static cpu_set parse_cpu_set(const YAML::Node &node, T_all all_cpus)
{
return parse_cpu_set<T_all>(node.as<string>(), all_cpus);
}

void Config::load_from_file(const string &file_name)
{
try {
Expand Down Expand Up @@ -228,10 +243,9 @@ Node Config::normalize_slice(const Node &slice,

if (!norm_slice["cpu"]) {
throw runtime_error("Missing cpu set in slice definition (`cpu` property)");
} else if (norm_slice["cpu"].as<string>() != "all") {
// validate that the cpulist is in correct format
cpu_set{ norm_slice["cpu"].as<string>() };
}
// validate that the cpulist is in correct format
parse_cpu_set(norm_slice["cpu"], 0);
return norm_slice;
}

Expand Down Expand Up @@ -298,6 +312,11 @@ void Config::normalize()
throw runtime_error("Config must be YAML mapping node");
}

// TODO: allow setting power policy in the config file

// TODO: change `partitions` from list of definitions to a map from partition
// name to process list

// clang-format off
bool set_cwd = config["set_cwd"]
? config_file_path
Expand All @@ -313,10 +332,8 @@ void Config::normalize()
}

string demos_cpu = config["demos_cpu"] ? config["demos_cpu"].as<string>() : "all";
if (demos_cpu != "all") {
// validate that the cpulist is in correct format
cpu_set{ demos_cpu };
}
// validate that the cpulist is in correct format
parse_cpu_set(demos_cpu, 0);
config.remove("demos_cpu");

Node norm_partitions;
Expand Down Expand Up @@ -398,8 +415,7 @@ void Config::create_scheduler_objects(const CgroupConfig &c,
cpu_set allowed_cpus;
sched_getaffinity(0, allowed_cpus.size(), allowed_cpus.ptr());

auto demos_cpu_str = config["demos_cpu"].as<string>();
demos_cpuset = demos_cpu_str == "all" ? cpu_set(allowed_cpus) : cpu_set(demos_cpu_str);
demos_cpuset = parse_cpu_set(config["demos_cpu"], allowed_cpus);

for (const auto &ywindow : config["windows"]) {
int length = ywindow["length"].as<int>();
Expand All @@ -416,11 +432,7 @@ void Config::create_scheduler_objects(const CgroupConfig &c,
be_part_ptr = find_partition(yslice["be_partition"].as<string>(), partitions);
}

// "all" = use all available CPUs
// MK: imo, it would be nicer to use *, but that (along with most other
// special characters) has special meaning in YAML, and must be quoted
auto cpu_str = yslice["cpu"].as<string>();
cpu_set cpus = cpu_str == "all" ? cpu_set(allowed_cpus) : cpu_set(cpu_str);
cpu_set cpus = parse_cpu_set(yslice["cpu"], allowed_cpus);

if ((cpus & allowed_cpus).count() == 0) {
logger->warn(
Expand Down

0 comments on commit 357e6e7

Please sign in to comment.