@@ -19,16 +19,17 @@ class BenchmarkSuite
1919 RACTOR_CATEGORY = [ "ractor" ] . freeze
2020 RACTOR_HARNESS = "harness-ractor"
2121
22- attr_reader :categories , :name_filters , :excludes , :out_path , :harness , :pre_init , :no_pinning , :bench_dir , :ractor_bench_dir
22+ attr_reader :categories , :name_filters , :excludes , :out_path , :harness , :pre_init , :no_pinning , :force_pinning , : bench_dir, :ractor_bench_dir
2323
24- def initialize ( categories :, name_filters :, excludes : [ ] , out_path :, harness :, pre_init : nil , no_pinning : false )
24+ def initialize ( categories :, name_filters :, excludes : [ ] , out_path :, harness :, pre_init : nil , no_pinning : false , force_pinning : false )
2525 @categories = categories
2626 @name_filters = name_filters
2727 @excludes = excludes
2828 @out_path = out_path
2929 @harness = harness
3030 @pre_init = pre_init ? expand_pre_init ( pre_init ) : nil
3131 @no_pinning = no_pinning
32+ @force_pinning = force_pinning
3233 @ractor_only = ( categories == RACTOR_ONLY_CATEGORY )
3334
3435 setup_benchmark_directories
@@ -41,13 +42,13 @@ def run(ruby:, ruby_description:)
4142 bench_failures = { }
4243
4344 benchmark_entries = discover_benchmarks
44- cmd_prefix = base_cmd ( ruby_description )
4545 env = benchmark_env ( ruby )
4646
4747 benchmark_entries . each_with_index do |entry , idx |
4848 puts ( "Running benchmark \" #{ entry . name } \" (#{ idx +1 } /#{ benchmark_entries . length } )" )
4949
5050 result_json_path = File . join ( out_path , "temp#{ Process . pid } .json" )
51+ cmd_prefix = base_cmd ( ruby_description , entry . name )
5152 result = run_single_benchmark ( entry . script_path , result_json_path , ruby , cmd_prefix , env )
5253
5354 if result [ :success ]
@@ -197,13 +198,13 @@ def linux?
197198 end
198199
199200 # Set up the base command with CPU pinning if needed
200- def base_cmd ( ruby_description )
201+ def base_cmd ( ruby_description , benchmark_name )
201202 if linux?
202203 cmd = setarch_prefix
203204
204205 # Pin the process to one given core to improve caching and reduce variance on CRuby
205206 # Other Rubies need to use multiple cores, e.g., for JIT threads
206- if ruby_description . start_with? ( 'ruby ' ) && ! no_pinning
207+ if ruby_description . start_with? ( 'ruby ' ) && should_pin? ( benchmark_name )
207208 # The last few cores of Intel CPU may be slow E-Cores, so avoid using the last one.
208209 cpu = [ ( Etc . nprocessors / 2 ) - 1 , 0 ] . max
209210 cmd . concat ( [ "taskset" , "-c" , "#{ cpu } " ] )
@@ -215,6 +216,14 @@ def base_cmd(ruby_description)
215216 end
216217 end
217218
219+ def should_pin? ( benchmark_name )
220+ return false if no_pinning
221+ return true if force_pinning
222+
223+ benchmark_meta = benchmarks_metadata [ benchmark_name ] || { }
224+ !benchmark_meta [ "no_pinning" ]
225+ end
226+
218227 # Generate setarch prefix for Linux
219228 def setarch_prefix
220229 # Disable address space randomization (for determinism)
0 commit comments