23#elif defined(__linux__)
26#include <sys/resource.h>
27#define PROCESS_HIGH_PRIORITY -15
35 HANDLE hProcess = GetCurrentProcess();
41 if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
44 ULONG_PTR currentAffinity = affinity & appAff;
47 TC_LOG_ERROR(logChannel,
"Processors marked in UseProcessors bitmask (hex) {:x} are not accessible. Accessible processors bitmask (hex): {:x}", affinity, appAff);
48 else if (SetProcessAffinityMask(hProcess, currentAffinity))
49 TC_LOG_INFO(logChannel,
"Using processors (bitmask, hex): {:x}", currentAffinity);
51 TC_LOG_ERROR(logChannel,
"Can't set used processors (hex): {:x}", currentAffinity);
57 if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
58 TC_LOG_INFO(logChannel,
"Process priority class set to HIGH");
60 TC_LOG_ERROR(logChannel,
"Can't set process priority class.");
63#elif defined(__linux__)
70 for (
unsigned int i = 0; i <
sizeof(affinity) * 8; ++i)
71 if (affinity & (1 << i))
74 if (sched_setaffinity(0,
sizeof(mask), &mask))
75 TC_LOG_ERROR(logChannel,
"Can't set used processors (hex): {:x}, error: {}", affinity, strerror(errno));
79 sched_getaffinity(0,
sizeof(mask), &mask);
80 TC_LOG_INFO(logChannel,
"Using processors (bitmask, hex): {:x}", *(__cpu_mask*)(&mask));
86 if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
87 TC_LOG_ERROR(logChannel,
"Can't set process priority class, error: {}", strerror(errno));
89 TC_LOG_INFO(logChannel,
"Process priority class set to {}", getpriority(PRIO_PROCESS, 0));
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_INFO(filterType__,...)
void SetProcessPriority(std::string const &logChannel, uint32 affinity, bool highPriority)