#!/usr/bin/perl use Fcntl; # Are we forcing dual IDA?; if the FID below is IDA, this must be true $ida=0; # FID and VID to set $fidvid=0x915; # save existing governor $governor = `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`; chomp $governor; # save existing MSRs $cpu0_config = `rdmsr -p0 -d 0x1a0`; $cpu1_config = `rdmsr -p1 -d 0x1a0`; $cpu0_fidvid = `rdmsr -p0 -d 0x199`; $cpu1_fidvid = `rdmsr -p1 -d 0x199`; # is second core running? $core1=1; local $SIG{INT} = sub { exit(); }; # set userspace governor `echo "userspace" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`; `echo "userspace" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor`; # force set the clock frequency and voltage if($ida){ my $trying=1; $ret = `rdmsr -d 0x1a0`; $ret &= 0x100000; if($ret){ print STDERR "Cannot set IDA; bit locked by BIOS\n"; exit(1); } # turn off speedstep and IDA `wrmsr 0x1a0 0x1364862489`; # request ida `wrmsr 0x199 $fidvid`; # disable second core `echo 0 > /sys/devices/system/cpu/cpu1/online`; $core1=0; # toggle speedstep until the request sticks while($trying){ `wrmsr 0x1a0 0x1364872489`; `wrmsr 0x1a0 0x1364862489`; $trying=0; $ret = `rdmsr -d 0x198`; $ret &= 0xffff; if( ($ret+0) != ($fidvid+0) ){ $trying=1; } if($trying){ print STDERR "retrying IDA request\n"; sleep 1; }else{ print STDERR "IDA request successful\n"; } } # reenable second core `echo 1 > /sys/devices/system/cpu/cpu1/online`; $core1=1; }else{ # turn off speedstep and IDA `wrmsr -p0 0x1a0 0x1364862489`; `wrmsr -p1 0x1a0 0x1364862489`; # request vid/fid on both processors `wrmsr -p0 0x199 $fidvid`; `wrmsr -p1 0x199 $fidvid`; # turn on speedstep `wrmsr -p0 0x1a0 0x1364872489`; `wrmsr -p1 0x1a0 0x1364872489`; # verify they set $ret = `rdmsr -p0 -d 0x198`; $ret &= 0xffff; if( ($ret+0) != ($fidvid+0) ){ print STDERR "could not set fid/vid on CPU0\n"; exit(1); } $ret = `rdmsr -p1 -d 0x198`; $ret &= 0xffff; if( ($ret+0) != ($fidvid+0) ){ print STDERR "could not set fid/vid on CPU1\n"; exit(1); } # turn off speedstep # `wrmsr -p0 0x1a0 0x1364862489`; # `wrmsr -p1 0x1a0 0x1364862489`; } while(1){ sleep; } END { if($core1==0){ `echo 1 > /sys/devices/system/cpu/cpu1/online`; sleep 1; } `wrmsr -p0 0x199 $cpu0_fidvid`; `wrmsr -p1 0x199 $cpu1_fidvid`; `wrmsr -p0 0x1a0 $cpu0_config`; `wrmsr -p1 0x1a0 $cpu1_config`; `echo $governor > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`; `echo $governor > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor`; };