Commit 892b4c71 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

minor fixes for affinity code

parent f0059871
......@@ -28,18 +28,6 @@ using namespace villas::utils;
#ifdef __linux__
CpuSet::operator uintmax_t()
{
uintmax_t iset = 0;
for (size_t i = 0; i < num_cpus; i++) {
if (isset(i))
iset |= 1ULL << i;
}
return iset;
}
CpuSet::CpuSet(uintmax_t iset) :
CpuSet()
{
......@@ -91,6 +79,18 @@ CpuSet::CpuSet(const char *str)
: CpuSet(std::string(str))
{ }
CpuSet::operator uintmax_t()
{
uintmax_t iset = 0;
for (size_t i = 0; i < num_cpus; i++) {
if (isset(i))
iset |= 1ULL << i;
}
return iset;
}
CpuSet::operator std::string ()
{
std::stringstream ss;
......
......@@ -91,6 +91,8 @@ void setProcessAffinity(int affinity)
{
int ret;
assert(affinity != 0);
Logger logger = logging.get("kernel:rt");
/* Pin threads to CPUs by setting the affinity */
......@@ -98,24 +100,26 @@ void setProcessAffinity(int affinity)
ret = sched_setaffinity(0, cset_pin.size(), cset_pin);
if (ret)
throw SystemError("Failed to set CPU affinity to cores: {}", (std::string) cset_pin);
throw SystemError("Failed to set CPU affinity of process");
logger->debug("Set affinity to cores: {}", (std::string) cset_pin);
logger->debug("Set affinity to {} {}", cset_pin.count() == 1 ? "core" : "cores", (std::string) cset_pin);
}
void setThreadAffinity(pthread_t thread, int affinity)
{
int ret;
assert(affinity != 0);
Logger logger = logging.get("kernel:rt");
CpuSet cset_pin(affinity);
ret = pthread_setaffinity_np(thread, cset_pin.size(), cset_pin);
if (ret)
throw SystemError("Failed to set CPU affinity to cores: {}", (std::string) cset_pin);
throw SystemError("Failed to set CPU affinity of thread");
logger->debug("Set affinity of thread {} to cores: {}", (long unsigned) thread, (std::string) cset_pin);
logger->debug("Set affinity of thread {} to {} {}", (long unsigned) thread, cset_pin.count() == 1 ? "core" : "cores", (std::string) cset_pin);
}
void setPriority(int priority)
......
......@@ -76,7 +76,7 @@ namespace villas {
Container::Container()
: iova_next(0)
: iova_next(0)
{
Logger logger = logging.get("kernel:vfio");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment