2011-12-16 23:44:37 +00:00
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
|
|
options = {
|
2012-08-23 17:12:25 +01:00
|
|
|
|
|
2011-12-20 22:44:58 +00:00
|
|
|
|
powerManagement.cpuFreqGovernor = mkOption {
|
2011-12-16 23:44:37 +00:00
|
|
|
|
default = "";
|
|
|
|
|
example = "ondemand";
|
2012-01-13 13:26:52 +00:00
|
|
|
|
type = types.uniq types.string;
|
2011-12-16 23:44:37 +00:00
|
|
|
|
description = ''
|
|
|
|
|
Configure the governor used to regulate the frequence of the
|
2013-01-24 12:55:59 +00:00
|
|
|
|
available CPUs. By default, the kernel configures the
|
|
|
|
|
on-demand governor.
|
2011-12-16 23:44:37 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-23 17:12:25 +01:00
|
|
|
|
|
2011-12-16 23:44:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
2011-12-20 22:44:58 +00:00
|
|
|
|
config = mkIf (config.powerManagement.cpuFreqGovernor != "") {
|
|
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.cpufrequtils ];
|
|
|
|
|
|
|
|
|
|
jobs.cpufreq =
|
2011-12-16 23:44:37 +00:00
|
|
|
|
{ description = "Initialize CPU frequency governor";
|
|
|
|
|
|
2012-08-23 17:12:25 +01:00
|
|
|
|
after = [ "systemd-modules-load.service" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
path = [ pkgs.cpufrequtils ];
|
2011-12-16 23:44:37 +00:00
|
|
|
|
|
2012-08-23 16:08:42 +01:00
|
|
|
|
preStart = ''
|
2011-12-16 23:44:37 +00:00
|
|
|
|
for i in $(seq 0 $(($(nproc) - 1))); do
|
2012-08-23 17:12:25 +01: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-16 23:44:37 +00:00
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
};
|
2011-12-20 22:44:58 +00:00
|
|
|
|
};
|
2011-12-16 23:44:37 +00:00
|
|
|
|
|
|
|
|
|
}
|