From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C87A63EB81E for ; Tue, 7 Jul 2026 16:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783442214; cv=none; b=LHQhvCA6oyht3359FrQTVKntGkLYGkimfmcgSgknY6tSXFtm8YSs3N6adCkBuftf9Z/cFc+0f+0mYlX5TgNv8Cun2Rc2a+8tNVsmM4DNCufQgACW++QrgpaWiZtPQT1SNXHwFzG8iuchBYQREH7q162FXGYhYjbrYb2/qaPcdP0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783442214; c=relaxed/simple; bh=ke8OFstbdA/XHRGMxrbiN265g4oaheYPg0LqgQ63z+k=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uBXvT0/vBaqW1sFPWxPGx/AyK4UBkrwJnJJVbkYO5Ev6w9yVTSOddPsZF+O1buotPwDkRwlqaSp/44KP/k6GY+rp03phpWA8eClOGwnXPS0sPDmlgJyZIfuBcQiKaS1BN12hTP5QbFBfvH3YjjeVn0uKqtqoq5xmtb8QoWF11sE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zs5R3tWC; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zs5R3tWC" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-847a69ba83dso3555885b3a.2 for ; Tue, 07 Jul 2026 09:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783442212; x=1784047012; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=59KAfUy7DDwnSuMBWSJQPVmdDSAgriDADemJejGadBs=; b=Zs5R3tWCRWpcZxE2HEFClpoqwv1zl9s8uzD7f2LEwocxMOmQmqmLVOpc/LT4JEQDFh k2X8trvhGYVXNXQu3sqradmOemSMCksrpl00Hc7NKC4/VA3122GeQ5ahQ/IYsEpPvXLz b/nwmuJB10O9LZdjuW74H26bM5nE06njXR+Ig8s8440/Bq/DlePCbez4nBNa3uWDPnKE gWyzzO0ekR4W9WX1bDfkFO4Je/rUFsU7Tv5Gb9icN4u3KTKseSOXUg3pGB4RaHjaO8d1 VHrQ43hGJF86vefU0fgumlQX9jaotvUkgLaIOWVyudeHPrmR4umbIfKCKY5n6dYltXd8 7smA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783442212; x=1784047012; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=59KAfUy7DDwnSuMBWSJQPVmdDSAgriDADemJejGadBs=; b=IDNSorfTOzJFFDmPLuQ0CeI7v0caIZXzLPBrDYM4hkajSFby/1YNhsJlDuBl94ETd2 y8hOIooh3e+TpGqTETKFpdcti640LE6VOokRpsyOCkWExO2osWyMfDmRTKAkbZip+3jT u52NEGNp8QDtJL+UUuDWgLSzFyWHYtITd7O52xUfBAVpKE+gVPCgKqrlJHTosV7pkUbf 84PI39/OE3chTPc1Me7yj6Hg+hJhkBausO/jFovXyNNH51zI3EPGUfLdYqaM68/rXcSm /ygloMsomOL6/KoBii28ZlRMygCBNlPYF4hwVUgVIzj7zupsWBF08Kbdo1xLn2k0dEfz UMlg== X-Forwarded-Encrypted: i=1; AHgh+Roumz6F3bDU4GIkFJqDE6yHxvGUaCd3vZMSM+M7ohCSA9+76T2UMFoXx3hWuy026+C//cw+9ypXYc313U9Gj14=@vger.kernel.org X-Gm-Message-State: AOJu0YzMIOO/efWaymddxEPNayFVPBcEn5iqFuwuzOZSymtqxXKpFc3s 33vOyIcy7H4XYOVBz7epk4mQj35EkAsN/f0NoqfBk2RpYhg5OSLBfW2jZH2La/e1 X-Gm-Gg: AfdE7cnkyGbeohuh933MsJ3zjeJIp2WjXJIi9/4guzCGy5lhTBMpitWxWBP9j0xHH2h tzs2+XHWFLPoxRrPy+FFnsy3ywuqjs8VWea3wCiSRYbYA9D93F2RUmPbNEqbs5mMY5Iae9fvo68 bUKop8E/nkXjS/xhTrd2jIdSJc7U0lXlzImH3cP0bUswCFUCWjCBHJCkJnvITm3BO4EDQ4HC64V 2DrIy4wdA0QqOlCu2o7drnJXAUX32z8eCG8o0FVpTRS2lZtPZl3HhOBBO5C5jCHaflQaCYj9eSt oPIMUogd3JZKYXEpt7tS6Jrl9moQIokwCq3PaXLU31EDrEnh64fUtU92iLc2oa2PezXDTTlcGoi tvT7xJrt1nAFm5aREtQl2y8nkQmsh799bdAhwJ8Q7piJrbJ+37qXxIJLAyl9MxsuYdergeOMPjl g98MoaIZUoxm4UvJK6E/MB/g2ulyr1ZLyDuvPoyZyszdUF+XSTgiULNapZss2+Iz7u4912g8upC fa7jeOfTEMXfkbK5z7StOY8rwr8ci0= X-Received: by 2002:a05:6a00:2d19:b0:848:2f6e:e52c with SMTP id d2e1a72fcca58-8482f6f0336mr3163662b3a.64.1783442211806; Tue, 07 Jul 2026 09:36:51 -0700 (PDT) Received: from NV-9MNJ414.nvidia.com (2001-b011-2005-986c-7892-641c-1789-73b1.dynamic-ip6.hinet.net. [2001:b011:2005:986c:7892:641c:1789:73b1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847f6d4dbdesm5721700b3a.31.2026.07.07.09.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 09:36:51 -0700 (PDT) From: Yiwei Lin To: rafael@kernel.org, viresh.kumar@linaro.org, shuah@kernel.org Cc: linux-pm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Yiwei Lin Subject: [PATCH v2] kselftest: cpufreq: Backup and restore governor for sptests Date: Wed, 8 Jul 2026 00:36:47 +0800 Message-Id: <20260707163647.6646-1-s921975628@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- Change-Logs in V2: - Wait for all background processes to finish before restoring governors in sptest4 --- tools/testing/selftests/cpufreq/governor.sh | 21 +++++++++++++++++++ .../selftests/cpufreq/special-tests.sh | 14 +++++++++++++ 2 files changed, 35 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..954c5fddf4d3f 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,8 @@ hotplug_with_updates_cpu() hotplug_with_updates() { + save_all_governors for_each_non_boot_cpu hotplug_with_updates_cpu + wait + restore_all_governors } -- 2.34.1