From patchwork Sun Sep 1 02:49:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13786223 X-Patchwork-Delegate: mario.limonciello@amd.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FEE12AD13; Sun, 1 Sep 2024 02:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725158975; cv=none; b=pckt+abNviC3pqsnnwTn/NYGfrOx9BvHjNJVWMpc/4ZjkVS7F3jZjShu94UT41kOBorgwbNuvTGaa7KvmBCN7+OIOAoZBqUnQh1gd1ZAYregVZs4tfq8hukRtEipsF6Wyk+vr2vEieVWQ3eg+d3FisZOo2yswzeB20Z/2pGoT60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725158975; c=relaxed/simple; bh=57Pfzhf5HI0arp2bkDqGJxs6bko+iFrqX0x2e0coG9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c3AZPkPRvHbz6E4tEaM+vvsZjPvdLGPSZQFtbc9eDCk6Sid75iXWM39YwP6qge69yzUTh+gFwynD/3602gt4XPm3dTlfA70jj4+uAeNGb5wmjvVEkfT9UTaxZEfxJKHTqPoh65vrV6wHQmwNX4kevQDOmzeaNs4QIzNjJdt79S8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aCcZrREp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aCcZrREp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA6B9C4CEC5; Sun, 1 Sep 2024 02:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725158974; bh=57Pfzhf5HI0arp2bkDqGJxs6bko+iFrqX0x2e0coG9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCcZrREpQIa/ITh66+o2YIlCvPMgw6CAHmBXXa5Wmg/UGApyYXdRakHZQnnjiYAVu EX/ztdCuMCCixfl436NTiFnT6aazaecCY02yergBmG1+lNRbdonAGTwoDlk9LfFnSg MyRiAO4vKHn2BYp1QZBr3kCiIOyrQhxT3f2pbCRnE0nHpoCcJ/Jqjltpj1ZuIklbMS gVlRgBxqOlgO7uUL+WEdnS0T+zbb8bZFio11b8hR/Ivl1pwDaVcrDrH/YUI6vGFHPe Zxg7L6l6FLAOAY8o02axX7R+iCkizqt67VRGgkqHg17Uijvpl8YH0o1dEXVSU6l3bY F6CVEUqCy6d0g== From: Mario Limonciello To: Meng Li , "Gautham R . Shenoy" , Perry Yuan Cc: linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), ptr1337@cachyos.org, Mario Limonciello Subject: [PATCH 1/2] cpufreq/amd-pstate: Export symbols for changing modes Date: Sat, 31 Aug 2024 21:49:11 -0500 Message-ID: <20240901024912.1217014-2-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240901024912.1217014-1-superm1@kernel.org> References: <20240901024912.1217014-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello In order to effectively test all mode switch combinations export everything necessarily for amd-pstate-ut to trigger a mode switch. Signed-off-by: Mario Limonciello Reviewed-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 23 ++++++++++------------- drivers/cpufreq/amd-pstate.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 073ca9caf52ac..93adde45bebce 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -60,18 +60,6 @@ #define AMD_CPPC_EPP_BALANCE_POWERSAVE 0xBF #define AMD_CPPC_EPP_POWERSAVE 0xFF -/* - * enum amd_pstate_mode - driver working mode of amd pstate - */ -enum amd_pstate_mode { - AMD_PSTATE_UNDEFINED = 0, - AMD_PSTATE_DISABLE, - AMD_PSTATE_PASSIVE, - AMD_PSTATE_ACTIVE, - AMD_PSTATE_GUIDED, - AMD_PSTATE_MAX, -}; - static const char * const amd_pstate_mode_string[] = { [AMD_PSTATE_UNDEFINED] = "undefined", [AMD_PSTATE_DISABLE] = "disable", @@ -81,6 +69,14 @@ static const char * const amd_pstate_mode_string[] = { NULL, }; +const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode) +{ + if (mode < 0 || mode >= AMD_PSTATE_MAX) + return NULL; + return amd_pstate_mode_string[mode]; +} +EXPORT_SYMBOL_GPL(amd_pstate_get_mode_string); + struct quirk_entry { u32 nominal_freq; u32 lowest_freq; @@ -1352,7 +1348,7 @@ static ssize_t amd_pstate_show_status(char *buf) return sysfs_emit(buf, "%s\n", amd_pstate_mode_string[cppc_state]); } -static int amd_pstate_update_status(const char *buf, size_t size) +int amd_pstate_update_status(const char *buf, size_t size) { int mode_idx; @@ -1369,6 +1365,7 @@ static int amd_pstate_update_status(const char *buf, size_t size) return 0; } +EXPORT_SYMBOL_GPL(amd_pstate_update_status); static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h index cc8bb2bc325aa..cd573bc6b6db8 100644 --- a/drivers/cpufreq/amd-pstate.h +++ b/drivers/cpufreq/amd-pstate.h @@ -103,4 +103,18 @@ struct amd_cpudata { bool boost_state; }; +/* + * enum amd_pstate_mode - driver working mode of amd pstate + */ +enum amd_pstate_mode { + AMD_PSTATE_UNDEFINED = 0, + AMD_PSTATE_DISABLE, + AMD_PSTATE_PASSIVE, + AMD_PSTATE_ACTIVE, + AMD_PSTATE_GUIDED, + AMD_PSTATE_MAX, +}; +const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode); +int amd_pstate_update_status(const char *buf, size_t size); + #endif /* _LINUX_AMD_PSTATE_H */ From patchwork Sun Sep 1 02:49:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13786224 X-Patchwork-Delegate: mario.limonciello@amd.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E873364AB; Sun, 1 Sep 2024 02:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725158976; cv=none; b=rd32hiI6yv4aCNuj+rD6wdF4EhgUl5V3iufa5XLUE/qKC0IxySseM6dz9qExPSCzXrpQsG5yf9rfh5o9o6hR5+d036HXJJALosGJqy6C+vx0/bm7cyIuE+ZflJVu+JPRkfZj00tKw3NitvS9Wkz8M7HaV1c+I6FTV3LuQ8AZqh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725158976; c=relaxed/simple; bh=lmiZoFRv3RC9NTR0pOBpjFGmZGtJhe2ymb6X495LMqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C68BQ+aKjpBLA1eSHuaeK6wwdcQKj8BUyUtc7vCHwaraXFT117X+KsrcFmkqwLIrJb+rkV14wtKmP9Cyxxxt2wlBJgs/whZ4fXgmVYxL9pj1eVFWbSknvAfDFAbYEzbk4ZB1BpESrXJ6RFE5dqde8t3NnnZ1pG3obIGHyr5RCtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cwn/LY5X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cwn/LY5X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E848CC4CED0; Sun, 1 Sep 2024 02:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725158975; bh=lmiZoFRv3RC9NTR0pOBpjFGmZGtJhe2ymb6X495LMqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cwn/LY5XU5e0Ey7LoR/osnHgb8U/0bSZADGOgRyJQ01G/XYJIZdvIjKkS/o+U7tVb 4ygqrQCwlqr67GA+BA9GLNm3Q+mLBbUHxj7ZXXWpOeCckpbLDAov0LYdpem5odzGeM zFD8a2uUe9T2CFgfFl+sintRzGvQ/g+bMvDKkIUYrPaX6SzpdEwcB6yndGooKa096U /UafOzROviPOH8xJExIAdVDOiy/7Xsc8QdslDjw3gXtC/tiHaZXeAKS88Y1zPJB10j fdG89ZxpPdzCsW4zh8lfjGgqRYNfpDZxeQN9Dgv5cr7xm5MtmQbbwxudKtl9ebKFlF inEqXWplZ+nAg== From: Mario Limonciello To: Meng Li , "Gautham R . Shenoy" , Perry Yuan Cc: linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), ptr1337@cachyos.org, Mario Limonciello Subject: [PATCH 2/2] cpufreq/amd-pstate-ut: Add test case for mode switches Date: Sat, 31 Aug 2024 21:49:12 -0500 Message-ID: <20240901024912.1217014-3-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240901024912.1217014-1-superm1@kernel.org> References: <20240901024912.1217014-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello There is a state machine in the amd-pstate driver utilized for switches for all modes. To make sure that cleanup and setup works properly for each mode add a unit test case that tries all combinations. Signed-off-by: Mario Limonciello Reviewed-by: Perry Yuan --- drivers/cpufreq/amd-pstate-ut.c | 41 ++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/amd-pstate-ut.c b/drivers/cpufreq/amd-pstate-ut.c index b7318669485e4..c291b3dbec381 100644 --- a/drivers/cpufreq/amd-pstate-ut.c +++ b/drivers/cpufreq/amd-pstate-ut.c @@ -54,12 +54,14 @@ static void amd_pstate_ut_acpi_cpc_valid(u32 index); static void amd_pstate_ut_check_enabled(u32 index); static void amd_pstate_ut_check_perf(u32 index); static void amd_pstate_ut_check_freq(u32 index); +static void amd_pstate_ut_check_driver(u32 index); static struct amd_pstate_ut_struct amd_pstate_ut_cases[] = { {"amd_pstate_ut_acpi_cpc_valid", amd_pstate_ut_acpi_cpc_valid }, {"amd_pstate_ut_check_enabled", amd_pstate_ut_check_enabled }, {"amd_pstate_ut_check_perf", amd_pstate_ut_check_perf }, - {"amd_pstate_ut_check_freq", amd_pstate_ut_check_freq } + {"amd_pstate_ut_check_freq", amd_pstate_ut_check_freq }, + {"amd_pstate_ut_check_driver", amd_pstate_ut_check_driver } }; static bool get_shared_mem(void) @@ -257,6 +259,43 @@ static void amd_pstate_ut_check_freq(u32 index) cpufreq_cpu_put(policy); } +static int amd_pstate_set_mode(enum amd_pstate_mode mode) +{ + const char *mode_str = amd_pstate_get_mode_string(mode); + + pr_debug("->setting mode to %s\n", mode_str); + + return amd_pstate_update_status(mode_str, strlen(mode_str)); +} + +static void amd_pstate_ut_check_driver(u32 index) +{ + enum amd_pstate_mode mode1, mode2; + int ret; + + for (mode1 = AMD_PSTATE_DISABLE; mode1 < AMD_PSTATE_MAX; mode1++) { + ret = amd_pstate_set_mode(mode1); + if (ret) + goto out; + for (mode2 = AMD_PSTATE_DISABLE; mode2 < AMD_PSTATE_MAX; mode2++) { + if (mode1 == mode2) + continue; + ret = amd_pstate_set_mode(mode2); + if (ret) + goto out; + } + } +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_ut_cases[index].result = ret ? + AMD_PSTATE_UT_RESULT_FAIL : + AMD_PSTATE_UT_RESULT_PASS; +} + static int __init amd_pstate_ut_init(void) { u32 i = 0, arr_size = ARRAY_SIZE(amd_pstate_ut_cases);