Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions run_benchmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def os
end

# Checked system - error or return info if the command fails
def check_call(command, env: {}, raise_error: true)
puts(command)
def check_call(command, env: {}, raise_error: true, quiet: false)
puts("+ #{command}") unless quiet

result = {}

Expand All @@ -57,13 +57,21 @@ def have_yjit?(ruby)
ruby_version.downcase.include?("yjit")
end

# Disable Turbo Boost while running benchmarks. Maximize the CPU frequency.
def set_bench_config(turbo:)
# sudo requires the flag '-S' in order to take input from stdin
if File.exist?('/sys/devices/system/cpu/intel_pstate') # Intel
# sudo requires the flag '-S' in order to take input from stdin
check_call("sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'") unless turbo || intel_no_turbo?
unless intel_no_turbo? || turbo
check_call("sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'")
at_exit { check_call("sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'", quiet: true) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems better to not make it quiet here to let the user understand why e.g. the sudo password is asked again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair. Feel free to file a PR for it, but so far the 15-minute sudo timeout has been long enough for me to never encounter the situation when running benchmarks locally.

end
# Disabling Turbo Boost reduces the CPU frequency, so this should be run after that.
check_call("sudo -S sh -c 'echo 100 > /sys/devices/system/cpu/intel_pstate/min_perf_pct'") unless intel_perf_100pct?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and sudo -S cpupower frequency-set -g performance below should probably also be undone then, otherwise they might e.g. consume a lot more power.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean you've been fine with it so far, so it should be fine. I just kept the code simple by not introducing what I don't need. I'm personally not interested in lowering power consumption, but if you're, feel free to file a PR to change it.

elsif File.exist?('/sys/devices/system/cpu/cpufreq/boost') # AMD
check_call("sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'") unless turbo || amd_no_boost?
unless amd_no_boost? || turbo
check_call("sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'")
at_exit { check_call("sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'", quiet: true) }
end
check_call("sudo -S cpupower frequency-set -g performance") unless performance_governor?
end
end
Expand Down