2014-04-14 16:26:48 +02:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
2011-12-17 00:44:37 +01:00
|
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
|
with lib;
|
2011-12-17 00:44:37 +01:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
|
|
options = {
|
2012-08-23 18:12:25 +02:00
|
|
|
|
|
2011-12-20 23:44:58 +01:00
|
|
|
|
powerManagement.cpuFreqGovernor = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2011-12-17 00:44:37 +01:00
|
|
|
|
example = "ondemand";
|
|
|
|
|
description = ''
|
|
|
|
|
Configure the governor used to regulate the frequence of the
|
2013-01-24 13:55:59 +01:00
|
|
|
|
available CPUs. By default, the kernel configures the
|
|
|
|
|
on-demand governor.
|
2011-12-17 00:44:37 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-23 18:12:25 +02:00
|
|
|
|
|
2011-12-17 00:44:37 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
2013-10-30 17:37:45 +01:00
|
|
|
|
config = mkIf (config.powerManagement.cpuFreqGovernor != null) {
|
2011-12-20 23:44:58 +01:00
|
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.cpufrequtils ];
|
|
|
|
|
|
|
|
|
|
jobs.cpufreq =
|
2013-09-22 20:49:01 +02:00
|
|
|
|
{ description = "CPU Frequency Governor Setup";
|
2011-12-17 00:44:37 +01:00
|
|
|
|
|
2012-08-23 18:12:25 +02:00
|
|
|
|
after = [ "systemd-modules-load.service" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
2013-11-26 18:17:12 +01:00
|
|
|
|
unitConfig.ConditionPathIsReadWrite = "/sys/devices/";
|
|
|
|
|
|
2012-08-23 18:12:25 +02:00
|
|
|
|
path = [ pkgs.cpufrequtils ];
|
2011-12-17 00:44:37 +01:00
|
|
|
|
|
2012-08-23 17:08:42 +02:00
|
|
|
|
preStart = ''
|
2011-12-17 00:44:37 +01:00
|
|
|
|
for i in $(seq 0 $(($(nproc) - 1))); do
|
2012-08-23 18:12:25 +02:00
|
|
|
|
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
|
2011-12-17 00:44:37 +01:00
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
};
|
2011-12-20 23:44:58 +01:00
|
|
|
|
};
|
2011-12-17 00:44:37 +01:00
|
|
|
|
|
|
|
|
|
}
|