]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
amd-pstate-ut: Reset amd-pstate driver mode after running selftests
authorSwapnil Sapkal <swapnil.sapkal@amd.com>
Wed, 30 Apr 2025 06:42:06 +0000 (06:42 +0000)
committerMario Limonciello <mario.limonciello@amd.com>
Mon, 5 May 2025 17:07:42 +0000 (12:07 -0500)
In amd-pstate-ut, one of the basic test is to switch between all
possible mode combinations. After running this test the mode of the
amd-pstate driver is active mode. Store and reset the mode to its original
state.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20250430064206.7402-1-swapnil.sapkal@amd.com
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
drivers/cpufreq/amd-pstate-ut.c
drivers/cpufreq/amd-pstate.c
drivers/cpufreq/amd-pstate.h

index e671bc7d155082a8c04a5faa743b64a858c58146..30835d0e499403a75b2a19b5a5b8d9bf91dd5f86 100644 (file)
@@ -242,6 +242,8 @@ static int amd_pstate_set_mode(enum amd_pstate_mode mode)
 static int amd_pstate_ut_check_driver(u32 index)
 {
        enum amd_pstate_mode mode1, mode2 = AMD_PSTATE_DISABLE;
+       enum amd_pstate_mode orig_mode = amd_pstate_get_status();
+       int ret;
 
        for (mode1 = AMD_PSTATE_DISABLE; mode1 < AMD_PSTATE_MAX; mode1++) {
                int ret = amd_pstate_set_mode(mode1);
@@ -251,16 +253,19 @@ static int amd_pstate_ut_check_driver(u32 index)
                        if (mode1 == mode2)
                                continue;
                        ret = amd_pstate_set_mode(mode2);
-                       if (ret) {
-                               pr_err("%s: failed to update status for %s->%s\n", __func__,
-                                       amd_pstate_get_mode_string(mode1),
-                                       amd_pstate_get_mode_string(mode2));
-                               return ret;
-                       }
+                       if (ret)
+                               goto out;
                }
        }
 
-       return 0;
+out:
+       if (ret)
+               pr_warn("%s: failed to update status for %s->%s: %d\n", __func__,
+                       amd_pstate_get_mode_string(mode1),
+                       amd_pstate_get_mode_string(mode2), ret);
+
+       amd_pstate_set_mode(orig_mode);
+       return ret;
 }
 
 static int __init amd_pstate_ut_init(void)
index fa4eb5a0a443603bba8834a95bbcf5f8e05850a1..dee9d84e9f998f1e968e43c8597e3cb42f785332 100644 (file)
@@ -1332,6 +1332,12 @@ static ssize_t amd_pstate_show_status(char *buf)
        return sysfs_emit(buf, "%s\n", amd_pstate_mode_string[cppc_state]);
 }
 
+int amd_pstate_get_status(void)
+{
+       return cppc_state;
+}
+EXPORT_SYMBOL_GPL(amd_pstate_get_status);
+
 int amd_pstate_update_status(const char *buf, size_t size)
 {
        int mode_idx;
index 2f7ae364d3313393c2ca853f911f0b9aa26a5a09..cb45fdca27a6c75606e5a5e152a3d53f075ec44a 100644 (file)
@@ -121,6 +121,7 @@ enum amd_pstate_mode {
        AMD_PSTATE_MAX,
 };
 const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode);
+int amd_pstate_get_status(void);
 int amd_pstate_update_status(const char *buf, size_t size);
 
 #endif /* _LINUX_AMD_PSTATE_H */