mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
affinity operator<<
This commit is contained in:
parent
9c5ece44a7
commit
afaa541013
1 changed files with 16 additions and 1 deletions
|
@ -12,6 +12,17 @@ namespace nix {
|
||||||
#if __linux__
|
#if __linux__
|
||||||
static bool didSaveAffinity = false;
|
static bool didSaveAffinity = false;
|
||||||
static cpu_set_t savedAffinity;
|
static cpu_set_t savedAffinity;
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream &os, const cpu_set_t &cset)
|
||||||
|
{
|
||||||
|
auto count = CPU_COUNT(&cset);
|
||||||
|
for (int i=0; i < count; ++i)
|
||||||
|
{
|
||||||
|
os << (CPU_ISSET(i,&cset) ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +58,11 @@ void restoreAffinity()
|
||||||
#if __linux__
|
#if __linux__
|
||||||
if (!didSaveAffinity) return;
|
if (!didSaveAffinity) return;
|
||||||
if (sched_setaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1)
|
if (sched_setaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1)
|
||||||
_printError("failed to restore affinity");
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << savedAffinity;
|
||||||
|
printError("failed to restore CPU affinity %1%", oss.str());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue