From f53d4f1da6b9ad24c1c3581638cabf8e6500541a Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 27 May 2026 16:08:50 -0400 Subject: [PATCH] Use `sudo --non-interactive` in at_exit to not hang I noticed that ruby-bench hangs after a long enough benchmarking session. Turns out it was sudo trying to ask for with `quiet: true`. Since it may hang trying to ask for input during exit, let's use `--non-interactive` to opportunistically re-enable turbo boost. --- lib/cpu_config.rb | 4 ++-- test/cpu_config_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cpu_config.rb b/lib/cpu_config.rb index 0ac01688..68c9dc6a 100644 --- a/lib/cpu_config.rb +++ b/lib/cpu_config.rb @@ -67,7 +67,7 @@ class IntelCPUConfig < CPUConfig def disable_turbo_boost # sudo requires the flag '-S' in order to take input from stdin BenchmarkRunner.check_call("sudo -S sh -c 'echo #{TURBO_DISABLED_VALUE} > #{NO_TURBO_PATH}'") - at_exit { BenchmarkRunner.check_call("sudo -S sh -c 'echo 0 > #{NO_TURBO_PATH}'", quiet: true) } + at_exit { BenchmarkRunner.check_call("sudo --non-interactive sh -c 'echo 0 > #{NO_TURBO_PATH}'", quiet: true) } end def maximize_frequency @@ -114,7 +114,7 @@ class AMDCPUConfig < CPUConfig def disable_turbo_boost # sudo requires the flag '-S' in order to take input from stdin BenchmarkRunner.check_call("sudo -S sh -c 'echo #{TURBO_DISABLED_VALUE} > #{BOOST_PATH}'") - at_exit { BenchmarkRunner.check_call("sudo -S sh -c 'echo #{TURBO_ENABLED_VALUE} > #{BOOST_PATH}'", quiet: true) } + at_exit { BenchmarkRunner.check_call("sudo --non-interactive sh -c 'echo #{TURBO_ENABLED_VALUE} > #{BOOST_PATH}'", quiet: true) } end def maximize_frequency diff --git a/test/cpu_config_test.rb b/test/cpu_config_test.rb index f59a28e9..406a42c2 100644 --- a/test/cpu_config_test.rb +++ b/test/cpu_config_test.rb @@ -159,7 +159,7 @@ end assert_equal 1, cleanup_commands.length, "at_exit block should call check_call once" - assert_equal "sudo -S sh -c 'echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'", cleanup_commands[0][:cmd] + assert_equal "sudo --non-interactive sh -c 'echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'", cleanup_commands[0][:cmd] assert_equal({ quiet: true }, cleanup_commands[0][:opts]) end @@ -298,7 +298,7 @@ end assert_equal 1, cleanup_commands.length, "at_exit block should call check_call once" - assert_equal "sudo -S sh -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'", cleanup_commands[0][:cmd] + assert_equal "sudo --non-interactive sh -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'", cleanup_commands[0][:cmd] assert_equal({ quiet: true }, cleanup_commands[0][:opts]) end