#!/usr/bin/perl -w $cpu_path = '/sys/devices/system/cpu/cpu0/cpufreq/'; $all_cpu = '/sys/devices/system/cpu/cpu[0-9]/cpufreq/'; chomp ($avl_governors = `cat $cpu_path/scaling_available_governors`); chomp ($avl_frequencies = `cat $cpu_path/scaling_available_frequencies`); # Only current status desired if (! @ARGV) { @cpus = `cat $all_cpu/cpuinfo_cur_freq`; print map { "Current frequency : $_" } @cpus; chomp ($cur_governor = `cat $cpu_path/scaling_governor`); print <<_END_OF_INFO_; Current governor : $cur_governor Avail. governors : $avl_governors _END_OF_INFO_ } # Set current frequency or scaling governor else { if ($ARGV[0] =~ /^\d+$/) { $req_speed = $ARGV[0]; if ($avl_frequencies !~ /\b$req_speed\b/) { die("Requested frequency $req_speed is not valid\n", "Available frequencies are: $avl_frequencies\n\n"); } @cpus = `ls $all_cpu/scaling_max_freq`; foreach $cpu (@cpus) { system("echo $req_speed >> $cpu"); } } else { $req_governor = $ARGV[0]; if ($avl_governors !~ /$req_governor/) { die("Requested governor $req_governor is not valid\n", "Available governors are: $avl_governors\n\n"); } @cpus = `ls $all_cpu/scaling_governor`; foreach $cpu (@cpus) { system("echo $req_governor >> $cpu"); } } }