mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
minor fixes for affinity code
This commit is contained in:
parent
8ad3ac265b
commit
eb81ab4545
3 changed files with 21 additions and 17 deletions
|
@ -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");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue