Skip to content

Commit d26d164

Browse files
SSapkalsuperm1
authored andcommitted
amd-pstate-ut: Reset amd-pstate driver mode after running selftests
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>
1 parent 608a76b commit d26d164

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

drivers/cpufreq/amd-pstate-ut.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ static int amd_pstate_set_mode(enum amd_pstate_mode mode)
242242
static int amd_pstate_ut_check_driver(u32 index)
243243
{
244244
enum amd_pstate_mode mode1, mode2 = AMD_PSTATE_DISABLE;
245+
enum amd_pstate_mode orig_mode = amd_pstate_get_status();
246+
int ret;
245247

246248
for (mode1 = AMD_PSTATE_DISABLE; mode1 < AMD_PSTATE_MAX; mode1++) {
247249
int ret = amd_pstate_set_mode(mode1);
@@ -251,16 +253,19 @@ static int amd_pstate_ut_check_driver(u32 index)
251253
if (mode1 == mode2)
252254
continue;
253255
ret = amd_pstate_set_mode(mode2);
254-
if (ret) {
255-
pr_err("%s: failed to update status for %s->%s\n", __func__,
256-
amd_pstate_get_mode_string(mode1),
257-
amd_pstate_get_mode_string(mode2));
258-
return ret;
259-
}
256+
if (ret)
257+
goto out;
260258
}
261259
}
262260

263-
return 0;
261+
out:
262+
if (ret)
263+
pr_warn("%s: failed to update status for %s->%s: %d\n", __func__,
264+
amd_pstate_get_mode_string(mode1),
265+
amd_pstate_get_mode_string(mode2), ret);
266+
267+
amd_pstate_set_mode(orig_mode);
268+
return ret;
264269
}
265270

266271
static int __init amd_pstate_ut_init(void)

drivers/cpufreq/amd-pstate.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,12 @@ static ssize_t amd_pstate_show_status(char *buf)
13321332
return sysfs_emit(buf, "%s\n", amd_pstate_mode_string[cppc_state]);
13331333
}
13341334

1335+
int amd_pstate_get_status(void)
1336+
{
1337+
return cppc_state;
1338+
}
1339+
EXPORT_SYMBOL_GPL(amd_pstate_get_status);
1340+
13351341
int amd_pstate_update_status(const char *buf, size_t size)
13361342
{
13371343
int mode_idx;

drivers/cpufreq/amd-pstate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ enum amd_pstate_mode {
121121
AMD_PSTATE_MAX,
122122
};
123123
const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode);
124+
int amd_pstate_get_status(void);
124125
int amd_pstate_update_status(const char *buf, size_t size);
125126

126127
#endif /* _LINUX_AMD_PSTATE_H */

0 commit comments

Comments
 (0)