[+] Unix AuProcesses: missing optAffinity support
This commit is contained in:
parent
841fa39321
commit
644c294c36
@ -34,6 +34,20 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(AURORA_PLATFORM_BSD)
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
|
#include <sys/param.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/cpuset.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
||||||
|
#include <sched.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Aurora::Processes
|
namespace Aurora::Processes
|
||||||
{
|
{
|
||||||
static AuThreadPrimitives::RWLockUnique_t gRWLock;
|
static AuThreadPrimitives::RWLockUnique_t gRWLock;
|
||||||
@ -522,6 +536,62 @@ namespace Aurora::Processes
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (this->startup_.optAffinity)
|
||||||
|
{
|
||||||
|
auto affinity = this->startup_.optAffinity.Value();
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
|
|
||||||
|
cpuset_setid(CPU_WHICH_PID, -1, (cpusetid_t *)&affinity.lower); // I guess?
|
||||||
|
|
||||||
|
#elif defined(AURORA_IS_LINUX_DERIVED) || (defined(AURORA_IS_POSIX_DERIVED) && defined(_GNU_SOURCE))
|
||||||
|
|
||||||
|
cpu_set_t cpuset;
|
||||||
|
CPU_ZERO(&cpuset);
|
||||||
|
|
||||||
|
AuUInt8 index {};
|
||||||
|
while (affinity.CpuBitScanForward(index, index))
|
||||||
|
{
|
||||||
|
CPU_SET(index, &cpuset);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CPU_COUNT(&cpuset))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
||||||
|
sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
|
||||||
|
#else
|
||||||
|
pthread_setaffinity_np(pthread_self(), cpuset_size(cpuSet), &cpuset);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(AURORA_IS_POSIX_DERIVED)
|
||||||
|
|
||||||
|
if (auto cpuSet = cpuset_alloc())
|
||||||
|
{
|
||||||
|
cpuset_init(cpuSet);
|
||||||
|
|
||||||
|
AuUInt8 index {};
|
||||||
|
while (affinity.CpuBitScanForward(index, index))
|
||||||
|
{
|
||||||
|
cpuset_set_cpu(cpuSet, index, 1);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_setaffinity_np(pthread_self(), cpuset_size(cpuSet), cpuSet);
|
||||||
|
|
||||||
|
cpuset_free(cpuSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Who else?
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
::execv(this->startup_.process.c_str(), (char * const *)this->cargs_.data()); // https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
|
::execv(this->startup_.process.c_str(), (char * const *)this->cargs_.data()); // https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
|
||||||
|
|
||||||
SysPushErrorGen("execv didn't overwrite the process map. Launch: {} ({})", this->startup_.process, this->debug_);
|
SysPushErrorGen("execv didn't overwrite the process map. Launch: {} ({})", this->startup_.process, this->debug_);
|
||||||
|
Loading…
Reference in New Issue
Block a user