Merge pull request #53041 from cdepillabout/add-nixos-cpufreq-max-min-options

Add nixos cpufreq max min options
This commit is contained in:
Silvan Mosberger
2019-01-02 09:11:53 +01:00
committed by GitHub
5 changed files with 69 additions and 21 deletions
@@ -408,6 +408,16 @@
from nixpkgs due to the lack of maintainers. from nixpkgs due to the lack of maintainers.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
The <option>powerManagement.cpuFreqGovernor</option> option has been
aliased to <option>powerManagement.cpufreq.governor</option>. On laptops,
<option>powerManagement.cpuFreqGovernor</option> is sometimes set in
<literal>/etc/nixos/hardware-configuration.nix</literal>, so you can
rename it to the new name, or run
<literal>nixos-generate-config</literal> again.
</para>
</listitem>
</itemizedlist> </itemizedlist>
</section> </section>
</section> </section>
@@ -104,7 +104,7 @@ if (-e "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") {
foreach $e (@desired_governors) { foreach $e (@desired_governors) {
if (index($governors, $e) != -1) { if (index($governors, $e) != -1) {
last if (push @attrs, "powerManagement.cpuFreqGovernor = lib.mkDefault \"$e\";"); last if (push @attrs, "powerManagement.cpufreq.governor = lib.mkDefault \"$e\";");
} }
} }
} }
+3
View File
@@ -286,6 +286,9 @@ with lib;
(mkRenamedOptionModule [ "hardware" "ckb" "enable" ] [ "hardware" "ckb-next" "enable" ]) (mkRenamedOptionModule [ "hardware" "ckb" "enable" ] [ "hardware" "ckb-next" "enable" ])
(mkRenamedOptionModule [ "hardware" "ckb" "package" ] [ "hardware" "ckb-next" "package" ]) (mkRenamedOptionModule [ "hardware" "ckb" "package" ] [ "hardware" "ckb-next" "package" ])
# cpufeq
(mkAliasOptionModule [ "powerManagement" "cpuFreqGovernor" ] [ "powerManagement" "cpufreq" "governor" ])
] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter" ] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter"
"jsonExporter" "minioExporter" "nginxExporter" "nodeExporter" "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter"
"snmpExporter" "unifiExporter" "varnishExporter" ] "snmpExporter" "unifiExporter" "varnishExporter" ]
+3 -1
View File
@@ -55,7 +55,9 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
powerManagement.scsiLinkPolicy = null; powerManagement.scsiLinkPolicy = null;
powerManagement.cpuFreqGovernor = null; powerManagement.cpufreq.governor = null;
powerManagement.cpufreq.max = null;
powerManagement.cpufreq.min = null;
systemd.sockets."systemd-rfkill".enable = false; systemd.sockets."systemd-rfkill".enable = false;
+52 -19
View File
@@ -4,22 +4,43 @@ with lib;
let let
cpupower = config.boot.kernelPackages.cpupower; cpupower = config.boot.kernelPackages.cpupower;
cfg = config.powerManagement; cfg = config.powerManagement.cpufreq;
in in
{ {
###### interface ###### interface
options = { options.powerManagement.cpufreq = {
powerManagement.cpuFreqGovernor = mkOption { governor = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
example = "ondemand"; example = "ondemand";
description = '' description = ''
Configure the governor used to regulate the frequence of the Configure the governor used to regulate the frequence of the
available CPUs. By default, the kernel configures the available CPUs. By default, the kernel configures the
performance governor. performance governor, although this may be overwriten in your
hardware-configuration.nix file.
Often used values: "ondemand", "powersave", "performance"
'';
};
max = mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
example = 2200000;
description = ''
The maximum frequency the CPU will use. Defaults to the maximum possible.
'';
};
min = mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
example = 800000;
description = ''
The minimum frequency the CPU will use.
''; '';
}; };
@@ -28,25 +49,37 @@ in
###### implementation ###### implementation
config = mkIf (!config.boot.isContainer && config.powerManagement.cpuFreqGovernor != null) { config =
let
governorEnable = cfg.governor != null;
maxEnable = cfg.max != null;
minEnable = cfg.min != null;
enable =
!config.boot.isContainer &&
(governorEnable || maxEnable || minEnable);
in
mkIf enable {
boot.kernelModules = [ "cpufreq_${cfg.cpuFreqGovernor}" ]; boot.kernelModules = optional governorEnable "cpufreq_${cfg.governor}";
environment.systemPackages = [ cpupower ]; environment.systemPackages = [ cpupower ];
systemd.services.cpufreq = { systemd.services.cpufreq = {
description = "CPU Frequency Governor Setup"; description = "CPU Frequency Setup";
after = [ "systemd-modules-load.service" ]; after = [ "systemd-modules-load.service" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = [ cpupower pkgs.kmod ]; path = [ cpupower pkgs.kmod ];
unitConfig.ConditionVirtualization = false; unitConfig.ConditionVirtualization = false;
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
RemainAfterExit = "yes"; RemainAfterExit = "yes";
ExecStart = "${cpupower}/bin/cpupower frequency-set -g ${cfg.cpuFreqGovernor}"; ExecStart = "${cpupower}/bin/cpupower frequency-set " +
SuccessExitStatus = "0 237"; optionalString governorEnable "--governor ${cfg.governor} " +
optionalString maxEnable "--max ${toString cfg.max} " +
optionalString minEnable "--min ${toString cfg.min} ";
SuccessExitStatus = "0 237";
};
}; };
};
}; };
} }