Remove CPU locking
This was already accidentally disabled in ba87b08
. It also no longer
appears to be beneficial, and in fact slow things down, e.g. when
evaluating a NixOS system configuration:
elapsed time: median = 3.8170 mean = 3.8202 stddev = 0.0195 min = 3.7894 max = 3.8600 [rejected, p=0.00000, Δ=0.36929±0.02513]
This commit is contained in:
parent
ddd7839154
commit
9747ea84b4
|
@ -4,7 +4,6 @@
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "path-with-outputs.hh"
|
#include "path-with-outputs.hh"
|
||||||
#include "finally.hh"
|
#include "finally.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "args.hh"
|
#include "args.hh"
|
||||||
|
@ -960,8 +959,8 @@ void processConnection(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) {
|
if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) {
|
||||||
auto affinity = readInt(from);
|
// Obsolete CPU affinity.
|
||||||
setAffinityTo(affinity);
|
readInt(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
readInt(from); // obsolete reserveSpace
|
readInt(from); // obsolete reserveSpace
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "remote-store.hh"
|
#include "remote-store.hh"
|
||||||
#include "worker-protocol.hh"
|
#include "worker-protocol.hh"
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "pool.hh"
|
#include "pool.hh"
|
||||||
|
@ -184,11 +183,8 @@ void RemoteStore::initConnection(Connection & conn)
|
||||||
conn.to << PROTOCOL_VERSION;
|
conn.to << PROTOCOL_VERSION;
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) {
|
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) {
|
||||||
int cpu = sameMachine() && settings.lockCPU ? lockToCurrentCPU() : -1;
|
// Obsolete CPU affinity.
|
||||||
if (cpu != -1)
|
conn.to << 0;
|
||||||
conn.to << 1 << cpu;
|
|
||||||
else
|
|
||||||
conn.to << 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11)
|
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11)
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
#include "types.hh"
|
|
||||||
#include "util.hh"
|
|
||||||
#include "affinity.hh"
|
|
||||||
|
|
||||||
#if __linux__
|
|
||||||
#include <sched.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
|
|
||||||
#if __linux__
|
|
||||||
static bool didSaveAffinity = false;
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
void setAffinityTo(int cpu)
|
|
||||||
{
|
|
||||||
#if __linux__
|
|
||||||
if (sched_getaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1) return;
|
|
||||||
didSaveAffinity = true;
|
|
||||||
debug(format("locking this thread to CPU %1%") % cpu);
|
|
||||||
cpu_set_t newAffinity;
|
|
||||||
CPU_ZERO(&newAffinity);
|
|
||||||
CPU_SET(cpu, &newAffinity);
|
|
||||||
if (sched_setaffinity(0, sizeof(cpu_set_t), &newAffinity) == -1)
|
|
||||||
printError("failed to lock thread to CPU %1%", cpu);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int lockToCurrentCPU()
|
|
||||||
{
|
|
||||||
#if __linux__
|
|
||||||
int cpu = sched_getcpu();
|
|
||||||
if (cpu != -1) setAffinityTo(cpu);
|
|
||||||
return cpu;
|
|
||||||
#else
|
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void restoreAffinity()
|
|
||||||
{
|
|
||||||
#if __linux__
|
|
||||||
if (!didSaveAffinity) return;
|
|
||||||
if (sched_setaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1)
|
|
||||||
{
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << savedAffinity;
|
|
||||||
printError("failed to restore CPU affinity %1%", oss.str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
void setAffinityTo(int cpu);
|
|
||||||
int lockToCurrentCPU();
|
|
||||||
void restoreAffinity();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,13 +1,10 @@
|
||||||
#include "thread-pool.hh"
|
#include "thread-pool.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
ThreadPool::ThreadPool(size_t _maxThreads)
|
ThreadPool::ThreadPool(size_t _maxThreads)
|
||||||
: maxThreads(_maxThreads)
|
: maxThreads(_maxThreads)
|
||||||
{
|
{
|
||||||
restoreAffinity(); // FIXME
|
|
||||||
|
|
||||||
if (!maxThreads) {
|
if (!maxThreads) {
|
||||||
maxThreads = std::thread::hardware_concurrency();
|
maxThreads = std::thread::hardware_concurrency();
|
||||||
if (!maxThreads) maxThreads = 1;
|
if (!maxThreads) maxThreads = 1;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
#include "sync.hh"
|
#include "sync.hh"
|
||||||
#include "finally.hh"
|
#include "finally.hh"
|
||||||
#include "serialise.hh"
|
#include "serialise.hh"
|
||||||
|
@ -1004,7 +1003,6 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
|
||||||
if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)
|
if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)
|
||||||
throw SysError("setting death signal");
|
throw SysError("setting death signal");
|
||||||
#endif
|
#endif
|
||||||
restoreAffinity();
|
|
||||||
fun();
|
fun();
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
try {
|
try {
|
||||||
|
@ -1675,8 +1673,6 @@ void restoreProcessContext(bool restoreMounts)
|
||||||
restoreMountNamespace();
|
restoreMountNamespace();
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreAffinity();
|
|
||||||
|
|
||||||
#if __linux__
|
#if __linux__
|
||||||
if (savedStackSize) {
|
if (savedStackSize) {
|
||||||
struct rlimit limit;
|
struct rlimit limit;
|
||||||
|
|
|
@ -300,7 +300,7 @@ void setStackSize(size_t stackSize);
|
||||||
|
|
||||||
|
|
||||||
/* Restore the original inherited Unix process context (such as signal
|
/* Restore the original inherited Unix process context (such as signal
|
||||||
masks, stack size, CPU affinity). */
|
masks, stack size). */
|
||||||
void restoreProcessContext(bool restoreMounts = true);
|
void restoreProcessContext(bool restoreMounts = true);
|
||||||
|
|
||||||
/* Save the current mount namespace. Ignored if called more than
|
/* Save the current mount namespace. Ignored if called more than
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include "local-fs-store.hh"
|
#include "local-fs-store.hh"
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "path-with-outputs.hh"
|
#include "path-with-outputs.hh"
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "path-with-outputs.hh"
|
#include "path-with-outputs.hh"
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
#include "progress-bar.hh"
|
#include "progress-bar.hh"
|
||||||
#include "run.hh"
|
#include "run.hh"
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ extern "C" {
|
||||||
#include "common-eval-args.hh"
|
#include "common-eval-args.hh"
|
||||||
#include "get-drvs.hh"
|
#include "get-drvs.hh"
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "command.hh"
|
#include "command.hh"
|
||||||
#include "finally.hh"
|
#include "finally.hh"
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include "finally.hh"
|
#include "finally.hh"
|
||||||
#include "fs-accessor.hh"
|
#include "fs-accessor.hh"
|
||||||
#include "progress-bar.hh"
|
#include "progress-bar.hh"
|
||||||
#include "affinity.hh"
|
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
|
|
||||||
#if __linux__
|
#if __linux__
|
||||||
|
|
Loading…
Reference in a new issue