From dd209e901cfbac8e68949b4871d6aece935b6215 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Mon, 17 Mar 2014 18:07:46 -0500 Subject: [PATCH] cpu-freq: Use cpupower instead of cpufrequtils Additionally, put the powersave utility in charge of loading the cpufrequency modules based on the governor specified in the configuration. --- nixos/modules/config/power-management.nix | 6 +--- nixos/modules/tasks/cpu-freq.nix | 43 ++++++++++++----------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/nixos/modules/config/power-management.nix b/nixos/modules/config/power-management.nix index 4984c0cd826d..17f3ed00b9be 100644 --- a/nixos/modules/config/power-management.nix +++ b/nixos/modules/config/power-management.nix @@ -65,11 +65,7 @@ in config = mkIf cfg.enable { - boot.kernelModules = - [ "acpi_cpufreq" "powernow-k8" "cpufreq_performance" "cpufreq_powersave" "cpufreq_ondemand" - "cpufreq_conservative" - ]; - + # FIXME: Implement powersave governor for sandy bridge or later Intel CPUs powerManagement.cpuFreqGovernor = mkDefault "ondemand"; powerManagement.scsiLinkPolicy = mkDefault "min_power"; diff --git a/nixos/modules/tasks/cpu-freq.nix b/nixos/modules/tasks/cpu-freq.nix index 3df9b58c524c..02f269f28f9d 100644 --- a/nixos/modules/tasks/cpu-freq.nix +++ b/nixos/modules/tasks/cpu-freq.nix @@ -2,6 +2,11 @@ with lib; +let + cpupower = config.boot.kernelPackages.cpupower; + cfg = config.powerManagement; +in + { ###### interface @@ -25,29 +30,25 @@ with lib; config = mkIf (config.powerManagement.cpuFreqGovernor != null) { - environment.systemPackages = [ pkgs.cpufrequtils ]; + boot.kernelModules = [ "acpi-cpufreq" "speedstep-lib" "pcc-cpufreq" + "cpufreq_${cfg.cpuFreqGovernor}" + ]; - jobs.cpufreq = - { description = "CPU Frequency Governor Setup"; + environment.systemPackages = [ cpupower ]; - after = [ "systemd-modules-load.service" ]; - wantedBy = [ "multi-user.target" ]; - - unitConfig.ConditionPathIsReadWrite = "/sys/devices/"; - - path = [ pkgs.cpufrequtils ]; - - preStart = '' - for i in $(seq 0 $(($(nproc) - 1))); do - for gov in $(cpufreq-info -c $i -g); do - if [ "$gov" = ${config.powerManagement.cpuFreqGovernor} ]; then - echo "<6>setting governor on CPU $i to ‘$gov’" - cpufreq-set -c $i -g $gov - fi - done - done - ''; + systemd.services.cpufreq = { + description = "CPU Frequency Governor Setup"; + after = [ "systemd-modules-load.service" ]; + wantedBy = [ "multi-user.target" ]; + path = [ cpupower ]; + script = '' + cpupower frequency-set -g ${cfg.cpuFreqGovernor} + ''; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = "yes"; }; - }; + }; + }; }