All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yiwei Lin <s921975628@gmail.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: rafael@kernel.org, shuah@kernel.org, linux-pm@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kselftest: cpufreq: Backup and restore governor for sptests
Date: Wed, 8 Jul 2026 00:28:58 +0800	[thread overview]
Message-ID: <e51399ad-c604-47db-bee4-fa61302f59dd@gmail.com> (raw)
In-Reply-To: <qtcyti7hqhr5sgzkhp2rt6h4kh3lfxmgjx5spi4nn7il63ckvl@woiclsimqqqh>


On 7/7/2026 1:19 PM, Viresh Kumar wrote:
> On 07-07-26, 00:14, Yiwei Lin wrote:
>> 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 <s921975628@gmail.com>
>> ---
>>   tools/testing/selftests/cpufreq/governor.sh   | 21 +++++++++++++++++++
>>   .../selftests/cpufreq/special-tests.sh        | 13 ++++++++++++
>>   2 files changed, 34 insertions(+)
>>
>> diff --git a/tools/testing/selftests/cpufreq/governor.sh b/tools/testing/selftests/cpufreq/governor.sh
>> index fe37df79c0871..5d105ab9c9222 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 8d40505dc4682..c7eddadd047d1 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 | sudo tee $CPUFREQROOT/policy*/scaling_governor &
>>   		echo userspace | sudo 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,7 @@ hotplug_with_updates_cpu()
>>   
>>   hotplug_with_updates()
>>   {
>> +	save_all_governors
>>   	for_each_non_boot_cpu hotplug_with_updates_cpu
> Don't you need wait here too ?
Right. Sorry for missing that there are processes running in the 
background for sptest4. I'll submit the fix for this.
>> +	restore_all_governors
>>   }
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

      reply	other threads:[~2026-07-07 16:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 16:14 [PATCH] kselftest: cpufreq: Backup and restore governor for sptests Yiwei Lin
2026-07-07  5:19 ` Viresh Kumar
2026-07-07 16:28   ` Yiwei Lin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e51399ad-c604-47db-bee4-fa61302f59dd@gmail.com \
    --to=s921975628@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=shuah@kernel.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.