1111require 'etc'
1212require 'yaml'
1313require_relative 'misc/stats'
14+ require_relative 'lib/cpu_config'
1415require_relative 'lib/benchmark_runner'
1516require_relative 'lib/table_formatter'
1617require_relative 'lib/benchmark_filter'
@@ -20,71 +21,6 @@ def have_yjit?(ruby)
2021 ruby_version . downcase . include? ( "yjit" )
2122end
2223
23- # Disable Turbo Boost while running benchmarks. Maximize the CPU frequency.
24- def set_bench_config ( turbo :)
25- # sudo requires the flag '-S' in order to take input from stdin
26- if File . exist? ( '/sys/devices/system/cpu/intel_pstate' ) # Intel
27- unless intel_no_turbo? || turbo
28- BenchmarkRunner . check_call ( "sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'" )
29- at_exit { BenchmarkRunner . check_call ( "sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'" , quiet : true ) }
30- end
31- # Disabling Turbo Boost reduces the CPU frequency, so this should be run after that.
32- BenchmarkRunner . check_call ( "sudo -S sh -c 'echo 100 > /sys/devices/system/cpu/intel_pstate/min_perf_pct'" ) unless intel_perf_100pct?
33- elsif File . exist? ( '/sys/devices/system/cpu/cpufreq/boost' ) # AMD
34- unless amd_no_boost? || turbo
35- BenchmarkRunner . check_call ( "sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'" )
36- at_exit { BenchmarkRunner . check_call ( "sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'" , quiet : true ) }
37- end
38- BenchmarkRunner . check_call ( "sudo -S cpupower frequency-set -g performance" ) unless performance_governor?
39- end
40- end
41-
42- def check_pstate ( turbo :)
43- if File . exist? ( '/sys/devices/system/cpu/intel_pstate' ) # Intel
44- unless turbo || intel_no_turbo?
45- puts ( "You forgot to disable turbo:" )
46- puts ( " sudo sh -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'" )
47- exit ( -1 )
48- end
49-
50- unless intel_perf_100pct?
51- puts ( "You forgot to set the min perf percentage to 100:" )
52- puts ( " sudo sh -c 'echo 100 > /sys/devices/system/cpu/intel_pstate/min_perf_pct'" )
53- exit ( -1 )
54- end
55- elsif File . exist? ( '/sys/devices/system/cpu/cpufreq/boost' ) # AMD
56- unless turbo || amd_no_boost?
57- puts ( "You forgot to disable boost:" )
58- puts ( " sudo sh -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'" )
59- exit ( -1 )
60- end
61-
62- unless performance_governor?
63- puts ( "You forgot to set the performance governor:" )
64- puts ( " sudo cpupower frequency-set -g performance" )
65- exit ( -1 )
66- end
67- end
68- end
69-
70- def intel_no_turbo?
71- File . read ( '/sys/devices/system/cpu/intel_pstate/no_turbo' ) . strip == '1'
72- end
73-
74- def intel_perf_100pct?
75- File . read ( '/sys/devices/system/cpu/intel_pstate/min_perf_pct' ) . strip == '100'
76- end
77-
78- def amd_no_boost?
79- File . read ( '/sys/devices/system/cpu/cpufreq/boost' ) . strip == '0'
80- end
81-
82- def performance_governor?
83- Dir . glob ( '/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor' ) . all? do |governor |
84- File . read ( governor ) . strip == 'performance'
85- end
86- end
87-
8824def mean ( values )
8925 Stats . new ( values ) . mean
9026end
@@ -366,11 +302,7 @@ def run_benchmarks(ruby:, ruby_description:, categories:, name_filters:, out_pat
366302 end
367303end
368304
369- # Disable CPU frequency scaling
370- set_bench_config ( turbo : args . turbo )
371-
372- # Check pstate status
373- check_pstate ( turbo : args . turbo )
305+ CPUConfig . configure_for_benchmarking ( turbo : args . turbo )
374306
375307# Create the output directory
376308FileUtils . mkdir_p ( args . out_path )
0 commit comments