Skip to content

Commit f2b3c35

Browse files
authored
Re-enable Turbo Boost after running benchmarks (#327)
1 parent 5f019c2 commit f2b3c35

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

run_benchmarks.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def os
3232
end
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")
5858
end
5959

60+
# Disable Turbo Boost while running benchmarks. Maximize the CPU frequency.
6061
def 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
6977
end

0 commit comments

Comments
 (0)