summary refs log tree commit diff
diff options
context:
space:
mode:
authorgnidorah <gnidorah@users.noreply.github.com>2017-01-02 19:20:28 +0300
committerJoachim F <joachifm@users.noreply.github.com>2017-01-02 17:20:28 +0100
commit90deca3a0ce2144370277febca2c8d0870225433 (patch)
tree0e4156fd18b74ee5192eb430bc8010a8836b4e14
parent3c1ade7d15198c8af5cb1a4b04cc0e800afa3b80 (diff)
downloadnixpkgs-90deca3a0ce2144370277febca2c8d0870225433.tar
nixpkgs-90deca3a0ce2144370277febca2c8d0870225433.tar.gz
nixpkgs-90deca3a0ce2144370277febca2c8d0870225433.tar.bz2
nixpkgs-90deca3a0ce2144370277febca2c8d0870225433.tar.lz
nixpkgs-90deca3a0ce2144370277febca2c8d0870225433.tar.xz
nixpkgs-90deca3a0ce2144370277febca2c8d0870225433.tar.zst
nixpkgs-90deca3a0ce2144370277febca2c8d0870225433.zip
nixos-generate-config: detect CPU governor
* cpu-freq: Try powersave if ondemand is not available

* Revert "cpu-freq: Try powersave if ondemand is not available"

This reverts commit 4dc56db37e32dcfecd667ebbf88263e47b296097.
Consult available scaling governors; for freshly generated configs, this provides a better experience than relying on a default that might not work everywhere.

-rw-r--r--nixos/modules/config/power-management.nix2
-rw-r--r--nixos/modules/installer/tools/nixos-generate-config.pl15
2 files changed, 16 insertions, 1 deletions
diff --git a/nixos/modules/config/power-management.nix b/nixos/modules/config/power-management.nix
index fbd7867a095..a4a4d6e1a6a 100644
--- a/nixos/modules/config/power-management.nix
+++ b/nixos/modules/config/power-management.nix
@@ -69,7 +69,7 @@ in
 
   config = mkIf cfg.enable {
 
-    # FIXME: Implement powersave governor for sandy bridge or later Intel CPUs
+    # Leftover for old setups, should be set by nixos-generate-config now
     powerManagement.cpuFreqGovernor = mkDefault "ondemand";
 
     systemd.targets.post-resume = {
diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl
index f1874f23977..e17c02d1374 100644
--- a/nixos/modules/installer/tools/nixos-generate-config.pl
+++ b/nixos/modules/installer/tools/nixos-generate-config.pl
@@ -94,6 +94,21 @@ sub hasCPUFeature {
 my $cpus = scalar (grep {/^processor\s*:/} (split '\n', $cpuinfo));
 
 
+# Determine CPU governor to use
+if (-e "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") {
+    my $governors = read_file("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors");
+    # ondemand governor is not available on sandy bridge or later Intel CPUs
+    my @desired_governors = ("ondemand", "powersave");
+    my $e;
+
+    foreach $e (@desired_governors) {
+        if (index($governors, $e) != -1) {
+            last if (push @attrs, "powerManagement.cpuFreqGovernor = \"$e\";");
+        }
+    }
+}
+
+
 # Virtualization support?
 push @kernelModules, "kvm-intel" if hasCPUFeature "vmx";
 push @kernelModules, "kvm-amd" if hasCPUFeature "svm";