Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on:
types:
- labeled

env:
CARGO_TERM_COLOR: always

jobs:
build-and-test:
if: ${{ github.event.label.name == 'run-build-test' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct sched_attr {
};
#endif

int sched_setattr(pid_t pid, const struct sched_attr *attr,
unsigned int flags) {
inline int sched_setattr(pid_t pid, const struct sched_attr *attr,
unsigned int flags) {
return syscall(__NR_sched_setattr, pid, attr, flags);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class ThreadConfiguratorNode : public rclcpp::Node {
int64_t thread_id = -1;
std::vector<int> affinity;
std::string policy;
int priority;
int priority = 0;

// For SCHED_DEADLINE
unsigned int runtime;
unsigned int period;
unsigned int deadline;
unsigned int runtime = 0;
unsigned int period = 0;
unsigned int deadline = 0;

bool applied = false;
};
Expand Down
23 changes: 21 additions & 2 deletions cie_thread_configurator/src/thread_configurator_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <error.h>
Expand Down Expand Up @@ -71,13 +72,23 @@ ThreadConfiguratorNode::ThreadConfiguratorNode(
return s;
};

static const std::unordered_set<std::string> valid_policies = {
"SCHED_OTHER", "SCHED_BATCH", "SCHED_IDLE",
"SCHED_FIFO", "SCHED_RR", "SCHED_DEADLINE",
};

// Common lambda to load thread configuration from YAML
auto load_thread_config = [](ThreadConfig &config, const YAML::Node &node) {
config.thread_str = node["id"].as<std::string>();
for (auto &cpu : node["affinity"])
config.affinity.push_back(cpu.as<int>());
config.policy = node["policy"].as<std::string>();

if (valid_policies.find(config.policy) == valid_policies.end()) {
throw std::runtime_error("Unknown scheduling policy '" + config.policy +
"' for id=" + config.thread_str);
Comment thread
atsushi421 marked this conversation as resolved.
}

if (config.policy == "SCHED_DEADLINE") {
config.runtime = node["runtime"].as<unsigned int>();
config.period = node["period"].as<unsigned int>();
Expand Down Expand Up @@ -197,8 +208,11 @@ bool ThreadConfiguratorNode::set_affinity_by_cgroup(

std::string cpus_path = cgroup_path + "/cpuset.cpus";
if (std::ofstream cpus_file{cpus_path}) {
for (int cpu : cpus)
cpus_file << cpu << ",";
for (size_t i = 0; i < cpus.size(); i++) {
if (i > 0)
cpus_file << ",";
cpus_file << cpus[i];
}
} else {
return false;
}
Expand Down Expand Up @@ -288,6 +302,11 @@ bool ThreadConfiguratorNode::issue_syscalls(const ThreadConfig &config) {
config.thread_str.c_str(), config.thread_id, strerror(errno));
return false;
}
} else {
RCLCPP_ERROR(
this->get_logger(), "Unknown scheduling policy '%s' (id=%s, tid=%ld)",
config.policy.c_str(), config.thread_str.c_str(), config.thread_id);
return false;
}

if (config.affinity.size() > 0) {
Expand Down
Loading