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.

authored by

gnidorah and committed by
Joachim F
90deca3a 3c1ade7d

+16 -1
+1 -1
nixos/modules/config/power-management.nix
··· 69 69 70 70 config = mkIf cfg.enable { 71 71 72 - # FIXME: Implement powersave governor for sandy bridge or later Intel CPUs 72 + # Leftover for old setups, should be set by nixos-generate-config now 73 73 powerManagement.cpuFreqGovernor = mkDefault "ondemand"; 74 74 75 75 systemd.targets.post-resume = {
+15
nixos/modules/installer/tools/nixos-generate-config.pl
··· 94 94 my $cpus = scalar (grep {/^processor\s*:/} (split '\n', $cpuinfo)); 95 95 96 96 97 + # Determine CPU governor to use 98 + if (-e "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") { 99 + my $governors = read_file("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"); 100 + # ondemand governor is not available on sandy bridge or later Intel CPUs 101 + my @desired_governors = ("ondemand", "powersave"); 102 + my $e; 103 + 104 + foreach $e (@desired_governors) { 105 + if (index($governors, $e) != -1) { 106 + last if (push @attrs, "powerManagement.cpuFreqGovernor = \"$e\";"); 107 + } 108 + } 109 + } 110 + 111 + 97 112 # Virtualization support? 98 113 push @kernelModules, "kvm-intel" if hasCPUFeature "vmx"; 99 114 push @kernelModules, "kvm-amd" if hasCPUFeature "svm";