mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
rt: fix cpuset affinity
This commit is contained in:
parent
447567fe8d
commit
74db55e846
3 changed files with 13 additions and 12 deletions
|
@ -61,6 +61,8 @@ public:
|
|||
*/
|
||||
CpuSet(const std::string &str);
|
||||
|
||||
CpuSet(const char *str);
|
||||
|
||||
/** Convert integer to cpu_set_t.
|
||||
*
|
||||
* @param set An integer number which is used as the mask
|
||||
|
|
|
@ -87,6 +87,10 @@ CpuSet::CpuSet(const std::string &str) :
|
|||
}
|
||||
}
|
||||
|
||||
CpuSet::CpuSet(const char *str)
|
||||
: CpuSet(std::string(str))
|
||||
{ }
|
||||
|
||||
CpuSet::operator std::string ()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
|
|
@ -81,29 +81,24 @@ void setAffinity(int affinity)
|
|||
Logger logger = logging.get("kernel:rt");
|
||||
|
||||
/* Pin threads to CPUs by setting the affinity */
|
||||
CpuSet cset_pin, cset_isol, cset_non_isol;
|
||||
|
||||
cset_pin = CpuSet(affinity);
|
||||
CpuSet cset_pin(affinity);
|
||||
|
||||
is_isol = kernel_get_cmdline_param("isolcpus", isolcpus, sizeof(isolcpus));
|
||||
if (is_isol) {
|
||||
if (is_isol)
|
||||
logger->warn("You should reserve some cores for " PROJECT_NAME " (see 'isolcpus')");
|
||||
|
||||
cset_isol.zero();
|
||||
}
|
||||
else {
|
||||
cset_isol = CpuSet(isolcpus);
|
||||
cset_non_isol = cset_isol ^ cset_pin;
|
||||
CpuSet cset_isol(isolcpus);
|
||||
CpuSet cset_non_isol = ~cset_isol & cset_pin;
|
||||
|
||||
if (cset_non_isol.count() > 0)
|
||||
logger->warn("Affinity setting includes cores which are not isolated: affinity={} isolcpus={}", (std::string) cset_pin, (std::string) cset_isol);
|
||||
logger->warn("Affinity setting includes cores which are not isolated: affinity={}, isolcpus={}, non_isolated={}", (std::string) cset_pin, (std::string) cset_isol, (std::string) cset_non_isol);
|
||||
}
|
||||
|
||||
ret = sched_setaffinity(0, cset_pin.size(), cset_pin);
|
||||
if (ret)
|
||||
throw SystemError("Failed to set CPU affinity to {}", (std::string) cset_pin);
|
||||
throw SystemError("Failed to set CPU affinity to cores: {}", (std::string) cset_pin);
|
||||
|
||||
logger->debug("Set affinity to {}", (std::string) cset_pin);
|
||||
logger->debug("Set affinity to cores: {}", (std::string) cset_pin);
|
||||
}
|
||||
|
||||
void setPriority(int priority)
|
||||
|
|
Loading…
Add table
Reference in a new issue