]> git.pld-linux.org Git - projects/cleanbuild.git/blob - fixfreq
make cleanbuild wrapper symlinkable
[projects/cleanbuild.git] / fixfreq
1 #!/usr/bin/perl
2
3 use Fcntl;
4 my $fifo = "/tmp/fixfreq";
5
6 system "mkfifo", $fifo;
7 chmod 0600, $fifo;
8
9 sysopen( READ_PIDS, $fifo, O_NONBLOCK|O_RDONLY) or die "Can't open modem: $!\n";
10
11
12 END {
13         set( 0 );
14         close READ_PIDS;
15         unlink $fifo;
16 }
17
18 sub bye { exit; }
19
20 $SIG{TERM} = \&bye;
21 $SIG{INT} = \&bye;
22
23 my $now_is = "";
24 sub set
25 {
26         my $num = shift;
27         my $set_to = $num ? "performance" : "ondemand";
28         return if $now_is eq $set_to;
29         $now_is = $set_to;
30         foreach my $gov ( glob "/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor" ) {
31                 open GOV, ">", $gov;
32                 print GOV $set_to;
33                 close GOV;
34         }
35 }
36
37 my %pids;
38
39 while ( 1 ) {
40         foreach my $pid ( keys %pids ) {
41                 unless ( -d "/proc/".$pid ) {
42                         delete $pids{ $pid };
43                 }
44         }
45         while ( my $pid = <READ_PIDS> ) {
46                 chomp $pid;
47                 if ( -d "/proc/$pid" ) {
48                         $pids{ $pid } = 1;
49                 }
50         }
51         set( keys %pids );
52         sleep 1;
53 }
54
This page took 0.066466 seconds and 3 git commands to generate.