forked from lix-project/lix
Don't apply the CPU affinity hack to nix-shell (and other Perl programs)
As discovered by Todd Veldhuizen, the shell started by nix-shell has its affinity set to a single CPU. This is because nix-shell connects to the Nix daemon, which causes the affinity hack to be applied. So we turn this off for Perl programs.
This commit is contained in:
parent
4b83830d0c
commit
936f9d45ba
|
@ -20,6 +20,7 @@ void doInit()
|
||||||
if (!store) {
|
if (!store) {
|
||||||
try {
|
try {
|
||||||
settings.processEnvironment();
|
settings.processEnvironment();
|
||||||
|
settings.lockCPU = false;
|
||||||
store = openStore();
|
store = openStore();
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
croak(e.what());
|
croak(e.what());
|
||||||
|
|
|
@ -54,6 +54,7 @@ Settings::Settings()
|
||||||
gcKeepDerivations = true;
|
gcKeepDerivations = true;
|
||||||
autoOptimiseStore = false;
|
autoOptimiseStore = false;
|
||||||
envKeepDerivations = false;
|
envKeepDerivations = false;
|
||||||
|
lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,9 @@ struct Settings {
|
||||||
(to prevent them from being GCed). */
|
(to prevent them from being GCed). */
|
||||||
bool envKeepDerivations;
|
bool envKeepDerivations;
|
||||||
|
|
||||||
|
/* Whether to lock the Nix client and worker to the same CPU. */
|
||||||
|
bool lockCPU;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SettingsMap settings, overrides;
|
SettingsMap settings, overrides;
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ void RemoteStore::openConnection(bool reserveSpace)
|
||||||
writeInt(PROTOCOL_VERSION, to);
|
writeInt(PROTOCOL_VERSION, to);
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 14) {
|
if (GET_PROTOCOL_MINOR(daemonVersion) >= 14) {
|
||||||
int cpu = lockToCurrentCPU();
|
int cpu = settings.lockCPU ? lockToCurrentCPU() : -1;
|
||||||
if (cpu != -1) {
|
if (cpu != -1) {
|
||||||
writeInt(1, to);
|
writeInt(1, to);
|
||||||
writeInt(cpu, to);
|
writeInt(cpu, to);
|
||||||
|
|
|
@ -33,13 +33,12 @@ void setAffinityTo(int cpu)
|
||||||
int lockToCurrentCPU()
|
int lockToCurrentCPU()
|
||||||
{
|
{
|
||||||
#if HAVE_SCHED_SETAFFINITY
|
#if HAVE_SCHED_SETAFFINITY
|
||||||
if (getEnv("NIX_AFFINITY_HACK", "1") == "1") {
|
|
||||||
int cpu = sched_getcpu();
|
int cpu = sched_getcpu();
|
||||||
if (cpu != -1) setAffinityTo(cpu);
|
if (cpu != -1) setAffinityTo(cpu);
|
||||||
return cpu;
|
return cpu;
|
||||||
}
|
#else
|
||||||
#endif
|
|
||||||
return -1;
|
return -1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue