forked from dbb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcpu-gov.pl
executable file
·50 lines (40 loc) · 1.04 KB
/
cpu-gov.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
use autodie;
use strict;
use warnings;
# github.com/dbbolton
unless ( `which acpi` && `which cpufreq-set` ) {
print "'acpi' or 'cpufrequtils' is not installed, exiting.\n";
exit 1;
}
open(my $in, '<', '/proc/cpuinfo');
my $cores;
while ( <$in> ) {
if ( /cpu\ cores.*(\d+)/ ) {
$cores = $1;
}
}
my $ac_status = `acpi -a`;
my $battery_status = `acpi -b`;
my $gov;
if ( $ac_status =~ /on-line/i ) {
print "Running on AC power... using the performance governor\n";
&set_gov( 'performance' );
}
elsif ($battery_status =~ /Discharging/ || $ac_status =~ /off-line/ ) {
print "Running on Battery power... using the powersave governor\n";
&set_gov( 'powersave' );
}
else {
print "Power source unknown... using the ondemand governor\n";
&set_gov( 'ondemand' );
}
sub set_gov {
my ($gov) = @_;
for my $core ( 0..($cores - 1) ) {
print "Setting '$gov' for core '$core'...\n";
system "cpufreq-set --cpu $core --governor $gov";
}
}
print "cpu-gov is finished.\n";
exit 0;