From c7aa1af7b327bb9af163fbd7b83ade6ac07845fd Mon Sep 17 00:00:00 2001 From: Jinseok Kim Date: Mon, 6 Jul 2026 23:38:53 +0900 Subject: selftests/cpufreq: Remove unused local variables from switch_show_governor() switch_show_governor() assigns the current governor and frequency to local variables before switching governors. However, these variables are never referenced afterwards. The function does not restore the previous governor or use the saved frequency, as backup_governor() and restore_governor() already handle state preservation elsewhere. Signed-off-by: Jinseok Kim Acked-by: Viresh Kumar Link: https://patch.msgid.link/20260706143857.3306-1-always.starving0@gmail.com Signed-off-by: Rafael J. Wysocki --- tools/testing/selftests/cpufreq/governor.sh | 5 ----- 1 file changed, 5 deletions(-) (limited to 'tools/testing') diff --git a/tools/testing/selftests/cpufreq/governor.sh b/tools/testing/selftests/cpufreq/governor.sh index fe37df79c087..212ef1cf43d5 100755 --- a/tools/testing/selftests/cpufreq/governor.sh +++ b/tools/testing/selftests/cpufreq/governor.sh @@ -100,11 +100,6 @@ switch_governor() # $1: policy, $2: governor switch_show_governor() { - cur_gov=find_current_governor - if [ $cur_gov == "userspace" ]; then - cur_freq=find_current_freq - fi - # switch governor __switch_governor $1 $2 -- cgit From 60e32ff9ed850db22d16ff91a17e99a9efbca8cf Mon Sep 17 00:00:00 2001 From: Jinseok Kim Date: Mon, 6 Jul 2026 23:38:54 +0900 Subject: selftests/cpufreq: Remove unnecessary sudo from quick_shuffle() The cpufreq selftests are always executed through main.sh, which verifies that the test is run as root before dispatching any test case. Therefore, invoking sudo inside quick_shuffle() is redundant and may cause failures in environments where sudo is unavailable. Signed-off-by: Jinseok Kim Acked-by: Viresh Kumar Link: https://patch.msgid.link/20260706143857.3306-2-always.starving0@gmail.com Signed-off-by: Rafael J. Wysocki --- tools/testing/selftests/cpufreq/special-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/testing') diff --git a/tools/testing/selftests/cpufreq/special-tests.sh b/tools/testing/selftests/cpufreq/special-tests.sh index 8d40505dc468..f45eb525f3b1 100755 --- a/tools/testing/selftests/cpufreq/special-tests.sh +++ b/tools/testing/selftests/cpufreq/special-tests.sh @@ -65,8 +65,8 @@ quick_shuffle() # this is called concurrently from governor_race for I in `seq 1000` do - echo ondemand | sudo tee $CPUFREQROOT/policy*/scaling_governor & - echo userspace | sudo tee $CPUFREQROOT/policy*/scaling_governor & + echo ondemand | tee $CPUFREQROOT/policy*/scaling_governor & + echo userspace | tee $CPUFREQROOT/policy*/scaling_governor & done } -- cgit From 4763f0db60a538c29d882fb6ab9e9371fbeb697c Mon Sep 17 00:00:00 2001 From: Yiwei Lin Date: Wed, 8 Jul 2026 00:36:47 +0800 Subject: kselftest: cpufreq: Backup and restore governor for sptests After executing cpufreq sptest, the system governor will be overwritten with the governor switched during the test. Restore this setting to maintain consistency before and after the test. Signed-off-by: Yiwei Lin Acked-by: Viresh Kumar Link: https://patch.msgid.link/20260707163647.6646-1-s921975628@gmail.com Signed-off-by: Rafael J. Wysocki --- tools/testing/selftests/cpufreq/governor.sh | 21 +++++++++++++++++++++ tools/testing/selftests/cpufreq/special-tests.sh | 14 ++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'tools/testing') diff --git a/tools/testing/selftests/cpufreq/governor.sh b/tools/testing/selftests/cpufreq/governor.sh index 212ef1cf43d5..cf59e63f8e14 100755 --- a/tools/testing/selftests/cpufreq/governor.sh +++ b/tools/testing/selftests/cpufreq/governor.sh @@ -16,6 +16,12 @@ source cpufreq.sh CUR_GOV= CUR_FREQ= +# Per-policy backup, keyed by policy so multiple policies can be saved at once +# (backup_governor/restore_governor also keep CUR_GOV/CUR_FREQ for callers that +# read them directly). +declare -A SAVED_GOVERNORS +declare -A SAVED_FREQS + # Find governor's directory path # $1: policy, $2: governor find_gov_directory() @@ -39,11 +45,13 @@ find_current_governor() backup_governor() { CUR_GOV=$(find_current_governor $1) + SAVED_GOVERNORS[$1]=$CUR_GOV printf "Governor backup done for $1: $CUR_GOV\n" if [ $CUR_GOV == "userspace" ]; then CUR_FREQ=$(find_current_freq $1) + SAVED_FREQS[$1]=$CUR_FREQ printf "Governor frequency backup done for $1: $CUR_FREQ\n" fi @@ -53,11 +61,13 @@ backup_governor() # $1: policy restore_governor() { + CUR_GOV=${SAVED_GOVERNORS[$1]} __switch_governor $1 $CUR_GOV printf "Governor restored for $1 to $CUR_GOV\n" if [ $CUR_GOV == "userspace" ]; then + CUR_FREQ=${SAVED_FREQS[$1]} set_cpu_frequency $1 $CUR_FREQ printf "Governor frequency restored for $1: $CUR_FREQ\n" fi @@ -65,6 +75,17 @@ restore_governor() printf "\n" } +# Save/restore governors for every policy at once +save_all_governors() +{ + for_each_policy backup_governor +} + +restore_all_governors() +{ + for_each_policy restore_governor +} + # param: # $1: policy, $2: governor __switch_governor() diff --git a/tools/testing/selftests/cpufreq/special-tests.sh b/tools/testing/selftests/cpufreq/special-tests.sh index f45eb525f3b1..e87ed7c8e5e5 100755 --- a/tools/testing/selftests/cpufreq/special-tests.sh +++ b/tools/testing/selftests/cpufreq/special-tests.sh @@ -40,7 +40,9 @@ simple_lockdep() { printf "** Test: Running ${FUNCNAME[0]} **\n" + save_all_governors for_each_policy __simple_lockdep + restore_all_governors } # Test 2 @@ -56,7 +58,10 @@ concurrent_lockdep() { printf "** Test: Running ${FUNCNAME[0]} **\n" + save_all_governors for_each_policy_concurrent __concurrent_lockdep + wait + restore_all_governors } # Test 3 @@ -68,17 +73,23 @@ quick_shuffle() echo ondemand | tee $CPUFREQROOT/policy*/scaling_governor & echo userspace | tee $CPUFREQROOT/policy*/scaling_governor & done + wait } governor_race() { printf "** Test: Running ${FUNCNAME[0]} **\n" + save_all_governors + # run 8 concurrent instances for I in `seq 8` do quick_shuffle & done + wait + + restore_all_governors } # Test 4 @@ -112,5 +123,8 @@ hotplug_with_updates_cpu() hotplug_with_updates() { + save_all_governors for_each_non_boot_cpu hotplug_with_updates_cpu + wait + restore_all_governors } -- cgit