From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 270CD41613B for ; Mon, 6 Jul 2026 16:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783354520; cv=none; b=rCG/S7dCHkSnkiB+skmhQg/it5Bg6+Ab9Ze9on/T/yiW5afqIYx6vxEuHjc4aVQH3NkLm0u/hmc9Q1I+MizDW3U4B0j3ASIxZYYU6BnXLigUjuxoSj29sD2/D3z8pWfDQ6AONeYrxlVtOWQ5MIOaXBgzDpZe8UT/CMVVialX7lg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783354520; c=relaxed/simple; bh=5G5FB9kOtpFLC9ywyKU/WqUp5GOuGEuJ4zI7XGzDU/w=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=I633dqx65HpCy5nU4lQMOkAoaDZeBUxU8al0+KP8TlCa5RbgXtEz4wmHHwEldtt2B7YFfJAA+FVkaTFcccjGFRGK2UGDgJAF9hQmoq5JnAxfTyIjTwOMerIqoINjw/pq/9h/Ut3ocC3vr521QYjro17URfnsZO0Cv5FuvgbWO0c= 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=Dsf6MDyX; arc=none smtp.client-ip=209.85.214.181 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="Dsf6MDyX" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2cc73e322dbso17670575ad.1 for ; Mon, 06 Jul 2026 09:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783354518; x=1783959318; 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=S/3RgXCA9XKT4PqM3Zw2JPstafRKCR+nS+crMfKpAcE=; b=Dsf6MDyXItcjWn9QJIcv5EzfidGxocrrA7mt65C0Rpsf3CECAM0+kMW2UryOaySVtH HY7B2hOkvyy7vX6MZqSEEwcY0tFjhG5v+YPiZHiLYpTyHvYk5mZ8oL+Jof2aPolBb7oX vxTFesMrDGFsVxx2qbqlNZGUKkQwhoMKA1r4CElWLlkbCKWgtx4AUu5QfV58yjbUoYBL jE5qjwVVkeeTfJ4hCXDhBOWqchfxSV51XazD9Abk0jqHEo33FxtIG28YbbMTlUhFOHvq zPW5WE2TFZtc1wc8Ckn89C5QnQFa4Ow3nMs7G60Yl4wfsBiQXRDjb+L+o4ukoYoImAiS 7TcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783354518; x=1783959318; 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=S/3RgXCA9XKT4PqM3Zw2JPstafRKCR+nS+crMfKpAcE=; b=b7D+G7EHeBPOVVrPzIKOfJ/f6h+5kHbzo0Ngd1NqCO9g8L2MzIy3Ay6Qymg1P0SV4t eL21k3P8w8fU6YnWcEqgXQqovEKFfiyZyxeqe8seH2/NjoySZCZrgaWHbsQ9Go1nI9Sy D/Bol1CkAw8ZW8poNc11GzHs8Lyh1+ofejsxqcy+RlUzZppnDEEsXnJQIZ+KQ6xXDBx5 Sq1KJzBNmgTMoTuyywqzA34ZCVngtellj+MObAEu4qoTYql+tbxy+eS22uXLJJ1b8Kh9 0sKEvtSyBjLVSrSpHaK2ppJU/XAOhvJZQXA4IJ72KXfE+KQvbDQKZYkyyiIWE4h8lZyx 64sg== X-Forwarded-Encrypted: i=1; AHgh+RrhjmlfO34EDxBIDZHt2oRLTZT3hTdb+h4ttK6JnKLOQqDosQW2AEF7nLADo+PmNy9AiXgfwJFVa/Knguc=@vger.kernel.org X-Gm-Message-State: AOJu0YxuBuL/uGN/MjCnmmR578AbxEUk2VPhiqJYQWE27PD9sXsY8GN8 /JrQUDyI676be8BPocpIGlyarIAOW1GZ7du3nGjfp34e5TViPeTXGBTA X-Gm-Gg: AfdE7clDkZznZPks2rSp9mxmEnQxYjYViw1r4lpXmCOn6k+1hqataLGfoDj/rUqxkND 3wI1NpRONIDmQxW5LoMpHKHoxUGmOZS5ZOnOMNKqf7eV8U+8NCw0pPL5NyaQ5oxAgZGAwVJ5oWK keZvYF2YrOkkFtAIOGsdzsFxYMnrtbY7wgDuqY4FcThpyqmdcHq/jzC0j30KWQ2s1kIDkJwghvX bfwbp1gwGprk6bbkLi6e6tlotCNh88OseegIC+bKaRRkVv1u2hawfqmJbFF6g4CzyHlV7BuluH2 D5eCPcPmQfk8HBJwh5mrARDSiaU1wBcrwdtWlVaLxxm92SoTF4LqarnwABTyDgF3HaWJFGB+1li XvWy2JpZyPPVQDKWH6hjszHXrKxNIjnnfvUUcb2etp6IU4AlgQr7+ilizR1wPKYN4nFzblmh6rx QfxXPMW4+VODqud6UwVDGU19h5pUWHwpwU3GY1w+UI67RRPD34MbLVVT+PNkslf1aOfy1ftFdWN p5cPU+LMAy5IcMpt0L9VWLPXVtnexw= X-Received: by 2002:a17:902:d2ca:b0:2c9:da58:17dd with SMTP id d9443c01a7336-2ccbf02ea30mr12245295ad.34.1783354518316; Mon, 06 Jul 2026 09:15:18 -0700 (PDT) Received: from NV-9MNJ414.nvidia.com (2001-b011-2005-72fc-7da4-215b-b67f-50ea.dynamic-ip6.hinet.net. [2001:b011:2005:72fc:7da4:215b:b67f:50ea]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cad6f260a1sm53394545ad.11.2026.07.06.09.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 09:15:17 -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] kselftest: cpufreq: Backup and restore governor for sptests Date: Tue, 7 Jul 2026 00:14:30 +0800 Message-Id: <20260706161430.16949-1-s921975628@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@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 --- 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 + restore_all_governors } -- 2.34.1