Skip to content

Commit

Permalink
nixos-generate-config: detect CPU governor
Browse files Browse the repository at this point in the history
* cpu-freq: Try powersave if ondemand is not available

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

This reverts commit 4dc56db.
Consult available scaling governors; for freshly generated configs, this provides a better experience than relying on a default that might not work everywhere.
  • Loading branch information
gnidorah authored and joachifm committed Jan 2, 2017
1 parent 3c1ade7 commit 90deca3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nixos/modules/config/power-management.nix
Expand Up @@ -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 = {
Expand Down
15 changes: 15 additions & 0 deletions nixos/modules/installer/tools/nixos-generate-config.pl
Expand Up @@ -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";
Expand Down

1 comment on commit 90deca3

@joachifm
Copy link
Contributor

@joachifm joachifm commented on 90deca3 Jan 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, the github interface obscured the fact that the original commit messages were included in the squashed one ... oh well.

Please sign in to comment.