Search
j0ke.net Open Build Service
>
Projects
>
GFS
>
powersave
> cpufreq-test.pl
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File cpufreq-test.pl of Package powersave
#!/usr/bin/perl -w # # (C) Stefan Seyfried 2007, released under GPL v2. # # test script to test if the dynamic cpufreq scaling is working # needs the cpufrequtils package # # note that this is just a very simple and basic test if the cpu frequency # is changing at all, it does not test every aspect of freqency scaling. $cpufreq_info = "/usr/bin/cpufreq-info"; $|=1; $err = 0; if (! -e $cpufreq_info) { print "$cpufreq_info not found. Please make sure that the\n"; print "cpufrequtils package is installed.\n\n"; exit 1; } print "Examining the system:\n"; print "=====================\n"; $i = 0; while (1) { $limits = `$cpufreq_info -c $i -l`; last if ($limits eq ''); ($min[$i], $max[$i]) = split(/\s/,$limits); print "CPU$i Minimum frequency: $min[$i], maximum frequency: $max[$i]\n"; $i++; } $numcpus = $i; if ($numcpus == 0) { print "\n"; print "No freqency scaling capable CPUs found.\n"; print "This is what cpufreq-info tells about your machine:\n"; print "===================================================\n\n"; system("$cpufreq_info"); print "\n"; exit 1; } print "$numcpus CPU".(($numcpus == 1)?"":"s")." found.\n\n"; print "Starting the test:\n"; if (system("powersave -A") != 0) { print "\n"; print "WARNING: ==============================================================\n"; print "could not set powersave policy to 'dynamic'. Trying to continue anyway.\n"; print "=======================================================================\n\n"; $err++; } print "Waiting for cpu load to go down.\n"; $retry = 1; while ($retry) { $retry = 0; @cur = get_current_freqs(); for ($i = 0; $i < $numcpus; $i++) { if ($cur[$i] != $min[$i]) { print "info: cpu$i frequency is not at minimum, waiting"; while ($cur[$i] != $min[$i]) { print "."; sleep 1; $cur[$i] = get_current_freq($i); } print "\n"; $retry = 1; } } } $SIG{'CHLD'} = 'IGNORE'; print "Starting CPU load generation (one instance per CPU)\n"; for ($i = 0; $i < $numcpus; $i++) { if (($pid = fork()) == -1) { print "ERROR: could not fork. This must not happen.\n"; exit 1; } elsif ($pid == 0) { alarm (5); $SIG{'ALRM'} = sub { exit; }; print " ...instance $i"; while (1){}; exit; } } sleep 1; print " ...done.\n\n"; sleep 1; print "Getting current frequenc".(($numcpus == 1)?"y":"ies")." (under load):\n"; @full = get_current_freqs(); for ($i = 0; $i < $numcpus; $i++) { print " Current CPU$i frequency is: $full[$i]"; if ($full[$i] != $max[$i]) { print " WARNING! NOT FULL SPEED!"; $err++; } print "\n"; } print "\nWaiting for load generators to terminate..."; sleep 5; print "done.\n\n"; print "Getting current frequenc".(($numcpus == 1)?"y":"ies")." (no load):\n"; @cur = get_current_freqs(); for ($i = 0; $i < $numcpus; $i++) { print " Current CPU$i frequency is: $cur[$i]"; if ($cur[$i] != $min[$i]) { print " WARNING! NOT MINIMUM SPEED!"; $err++; } print "\n"; } print "\n\n"; print "Executive summary:\n"; print "==================\n\n"; if ($err == 0) { print "Everything looks OK.\n\n"; exit 0; } else { print "$err Warnings, please check the output above.\n\n"; } exit 1; sub get_current_freqs { my $i; my @ret; my $tmp; for ($i=0; $i < $numcpus; $i++) { $ret[$i] = get_current_freq($i); } return @ret; } sub get_current_freq { my $i = $_[0]; my $ret = `$cpufreq_info -c $i -f`; chomp $ret; return $ret + 0; }