blob: befec4d48541e97af80d698909cd035d21c970f9 (
plain)
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
50
51
52
53
54
|
#!/usr/bin/perl
use Fcntl;
my $fifo = "/tmp/fixfreq";
system "mkfifo", $fifo;
chmod 0600, $fifo;
sysopen( READ_PIDS, $fifo, O_NONBLOCK|O_RDONLY) or die "Can't open modem: $!\n";
END {
set( 0 );
close READ_PIDS;
unlink $fifo;
}
sub bye { exit; }
$SIG{TERM} = \&bye;
$SIG{INT} = \&bye;
my $now_is = "";
sub set
{
my $num = shift;
my $set_to = $num ? "performance" : "ondemand";
return if $now_is eq $set_to;
$now_is = $set_to;
foreach my $gov ( glob "/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor" ) {
open GOV, ">", $gov;
print GOV $set_to;
close GOV;
}
}
my %pids;
while ( 1 ) {
foreach my $pid ( keys %pids ) {
unless ( -d "/proc/".$pid ) {
delete $pids{ $pid };
}
}
while ( my $pid = <READ_PIDS> ) {
chomp $pid;
if ( -d "/proc/$pid" ) {
$pids{ $pid } = 1;
}
}
set( keys %pids );
sleep 1;
}
|