about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--perl/lib/Nix/Store.xs1
-rw-r--r--src/libstore/globals.cc1
-rw-r--r--src/libstore/globals.hh3
-rw-r--r--src/libstore/remote-store.cc2
-rw-r--r--src/libutil/affinity.cc11
5 files changed, 11 insertions, 7 deletions
diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs
index 8154bcbb0f4b..c449ed5241e8 100644
--- a/perl/lib/Nix/Store.xs
+++ b/perl/lib/Nix/Store.xs
@@ -20,6 +20,7 @@ void doInit()
     if (!store) {
         try {
             settings.processEnvironment();
+            settings.lockCPU = false;
             store = openStore();
         } catch (Error & e) {
             croak(e.what());
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index aeb52e1a8696..7e0157cd365a 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -54,6 +54,7 @@ Settings::Settings()
     gcKeepDerivations = true;
     autoOptimiseStore = false;
     envKeepDerivations = false;
+    lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
 }
 
 
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 50b61725c742..cbc6d4e9848e 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -183,6 +183,9 @@ struct Settings {
        (to prevent them from being GCed). */
     bool envKeepDerivations;
 
+    /* Whether to lock the Nix client and worker to the same CPU. */
+    bool lockCPU;
+
 private:
     SettingsMap settings, overrides;
 
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 3764b4813a4e..3017254baf3b 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -73,7 +73,7 @@ void RemoteStore::openConnection(bool reserveSpace)
         writeInt(PROTOCOL_VERSION, to);
 
         if (GET_PROTOCOL_MINOR(daemonVersion) >= 14) {
-            int cpu = lockToCurrentCPU();
+            int cpu = settings.lockCPU ? lockToCurrentCPU() : -1;
             if (cpu != -1) {
                 writeInt(1, to);
                 writeInt(cpu, to);
diff --git a/src/libutil/affinity.cc b/src/libutil/affinity.cc
index 7a6310cadb00..3e21f43a2e9d 100644
--- a/src/libutil/affinity.cc
+++ b/src/libutil/affinity.cc
@@ -33,13 +33,12 @@ void setAffinityTo(int cpu)
 int lockToCurrentCPU()
 {
 #if HAVE_SCHED_SETAFFINITY
-    if (getEnv("NIX_AFFINITY_HACK", "1") == "1") {
-        int cpu = sched_getcpu();
-        if (cpu != -1) setAffinityTo(cpu);
-        return cpu;
-    }
-#endif
+    int cpu = sched_getcpu();
+    if (cpu != -1) setAffinityTo(cpu);
+    return cpu;
+#else
     return -1;
+#endif
 }