3232end 
3333
3434# Checked system - error or return info if the command fails 
35- def  check_call ( command ,  env : { } ,  raise_error : true ) 
36-   puts ( command ) 
35+ def  check_call ( command ,  env : { } ,  raise_error : true ,   quiet :  false ) 
36+   puts ( "+  #{ command } " )   unless   quiet 
3737
3838  result  =  { } 
3939
@@ -57,13 +57,21 @@ def have_yjit?(ruby)
5757  ruby_version . downcase . include? ( "yjit" ) 
5858end 
5959
60+ # Disable Turbo Boost while running benchmarks. Maximize the CPU frequency. 
6061def  set_bench_config ( turbo :) 
62+   # sudo requires the flag '-S' in order to take input from stdin 
6163  if  File . exist? ( '/sys/devices/system/cpu/intel_pstate' )  # Intel 
62-     # sudo requires the flag '-S' in order to take input from stdin 
63-     check_call ( "sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'" )  unless  turbo  || intel_no_turbo? 
64+     unless  intel_no_turbo?  || turbo 
65+       check_call ( "sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'" ) 
66+       at_exit  {  check_call ( "sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'" ,  quiet : true )  } 
67+     end 
68+     # Disabling Turbo Boost reduces the CPU frequency, so this should be run after that. 
6469    check_call ( "sudo -S sh -c 'echo 100 > /sys/devices/system/cpu/intel_pstate/min_perf_pct'" )  unless  intel_perf_100pct? 
6570  elsif  File . exist? ( '/sys/devices/system/cpu/cpufreq/boost' )  # AMD 
66-     check_call ( "sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'" )  unless  turbo  || amd_no_boost? 
71+     unless  amd_no_boost?  || turbo 
72+       check_call ( "sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'" ) 
73+       at_exit  {  check_call ( "sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'" ,  quiet : true )  } 
74+     end 
6775    check_call ( "sudo -S cpupower frequency-set -g performance" )  unless  performance_governor? 
6876  end 
6977end 
0 commit comments