linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] amd-pstate optimizations
@ 2025-10-09 16:17 Mario Limonciello (AMD)
  2025-10-09 16:17 ` [PATCH v2 1/6] cpufreq/amd-pstate: Use sysfs_match_string() for epp Mario Limonciello (AMD)
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Mario Limonciello (AMD) @ 2025-10-09 16:17 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK,
	Mario Limonciello (AMD)

Some optimizations for EPP sysfs files and then various other small
things that I noticed while looking at the code again.

Mario Limonciello (AMD) (6):
  cpufreq/amd-pstate: Use sysfs_match_string() for epp
  cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string
  cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return
    NULL
  cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status()
  cpufreq/amd-pstate: Fix some whitespace issues
  cpufreq/amd-pstate: Add static asserts for EPP indices

 drivers/cpufreq/amd-pstate.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/6] cpufreq/amd-pstate: Use sysfs_match_string() for epp
  2025-10-09 16:17 [PATCH v2 0/6] amd-pstate optimizations Mario Limonciello (AMD)
@ 2025-10-09 16:17 ` Mario Limonciello (AMD)
  2025-10-15  8:46   ` Gautham R. Shenoy
  2025-10-09 16:17 ` [PATCH v2 2/6] cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string Mario Limonciello (AMD)
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Mario Limonciello (AMD) @ 2025-10-09 16:17 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK,
	Mario Limonciello (AMD)

Rather than scanning the buffer and manually matching the string
use the sysfs macros.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
v2:
 * Drop NULL from energy_perf_strings too (Gautham)
---
 drivers/cpufreq/amd-pstate.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index b44f0f7a5ba1c..0bc5013448873 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -118,7 +118,6 @@ static const char * const energy_perf_strings[] = {
 	[EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance",
 	[EPP_INDEX_BALANCE_POWERSAVE] = "balance_power",
 	[EPP_INDEX_POWERSAVE] = "power",
-	NULL
 };
 
 static unsigned int epp_values[] = {
@@ -1137,16 +1136,15 @@ static ssize_t show_amd_pstate_hw_prefcore(struct cpufreq_policy *policy,
 static ssize_t show_energy_performance_available_preferences(
 				struct cpufreq_policy *policy, char *buf)
 {
-	int i = 0;
-	int offset = 0;
+	int offset = 0, i;
 	struct amd_cpudata *cpudata = policy->driver_data;
 
 	if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
 		return sysfs_emit_at(buf, offset, "%s\n",
 				energy_perf_strings[EPP_INDEX_PERFORMANCE]);
 
-	while (energy_perf_strings[i] != NULL)
-		offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i++]);
+	for (i = 0; i < ARRAY_SIZE(energy_perf_strings); i++)
+		offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i]);
 
 	offset += sysfs_emit_at(buf, offset, "\n");
 
@@ -1157,15 +1155,10 @@ static ssize_t store_energy_performance_preference(
 		struct cpufreq_policy *policy, const char *buf, size_t count)
 {
 	struct amd_cpudata *cpudata = policy->driver_data;
-	char str_preference[21];
 	ssize_t ret;
 	u8 epp;
 
-	ret = sscanf(buf, "%20s", str_preference);
-	if (ret != 1)
-		return -EINVAL;
-
-	ret = match_string(energy_perf_strings, -1, str_preference);
+	ret = sysfs_match_string(energy_perf_strings, buf);
 	if (ret < 0)
 		return -EINVAL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/6] cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string
  2025-10-09 16:17 [PATCH v2 0/6] amd-pstate optimizations Mario Limonciello (AMD)
  2025-10-09 16:17 ` [PATCH v2 1/6] cpufreq/amd-pstate: Use sysfs_match_string() for epp Mario Limonciello (AMD)
@ 2025-10-09 16:17 ` Mario Limonciello (AMD)
  2025-10-15  8:47   ` Gautham R. Shenoy
  2025-10-09 16:17 ` [PATCH v2 3/6] cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return NULL Mario Limonciello (AMD)
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Mario Limonciello (AMD) @ 2025-10-09 16:17 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK,
	Mario Limonciello (AMD)

None of the users actually look for the NULL value.  To avoid risk
of regression introducing a new value but forgetting to add a string
add a static assert to test AMD_PSTATE_MAX matches the array size.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/cpufreq/amd-pstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 0bc5013448873..a5b9e5baf4234 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -65,8 +65,8 @@ static const char * const amd_pstate_mode_string[] = {
 	[AMD_PSTATE_PASSIVE]     = "passive",
 	[AMD_PSTATE_ACTIVE]      = "active",
 	[AMD_PSTATE_GUIDED]      = "guided",
-	NULL,
 };
+static_assert(ARRAY_SIZE(amd_pstate_mode_string) == AMD_PSTATE_MAX);
 
 const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode)
 {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/6] cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return NULL
  2025-10-09 16:17 [PATCH v2 0/6] amd-pstate optimizations Mario Limonciello (AMD)
  2025-10-09 16:17 ` [PATCH v2 1/6] cpufreq/amd-pstate: Use sysfs_match_string() for epp Mario Limonciello (AMD)
  2025-10-09 16:17 ` [PATCH v2 2/6] cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string Mario Limonciello (AMD)
@ 2025-10-09 16:17 ` Mario Limonciello (AMD)
  2025-10-15  8:51   ` Gautham R. Shenoy
  2025-10-09 16:17 ` [PATCH v2 4/6] cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status() Mario Limonciello (AMD)
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Mario Limonciello (AMD) @ 2025-10-09 16:17 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK,
	Mario Limonciello (AMD)

amd_pstate_get_mode_string() is only used by amd-pstate-ut.  Set the
failure path to use AMD_PSTATE_UNDEFINED ("undefined") to avoid showing
"(null)" as a string when running test suite.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/cpufreq/amd-pstate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index a5b9e5baf4234..5feb9f5e3a491 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -70,8 +70,8 @@ static_assert(ARRAY_SIZE(amd_pstate_mode_string) == AMD_PSTATE_MAX);
 
 const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode)
 {
-	if (mode < 0 || mode >= AMD_PSTATE_MAX)
-		return NULL;
+	if (mode < AMD_PSTATE_UNDEFINED || mode >= AMD_PSTATE_MAX)
+		mode = AMD_PSTATE_UNDEFINED;
 	return amd_pstate_mode_string[mode];
 }
 EXPORT_SYMBOL_GPL(amd_pstate_get_mode_string);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/6] cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status()
  2025-10-09 16:17 [PATCH v2 0/6] amd-pstate optimizations Mario Limonciello (AMD)
                   ` (2 preceding siblings ...)
  2025-10-09 16:17 ` [PATCH v2 3/6] cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return NULL Mario Limonciello (AMD)
@ 2025-10-09 16:17 ` Mario Limonciello (AMD)
  2025-10-15  9:02   ` Gautham R. Shenoy
  2025-10-09 16:17 ` [PATCH v2 5/6] cpufreq/amd-pstate: Fix some whitespace issues Mario Limonciello (AMD)
  2025-10-09 16:17 ` [PATCH v2 6/6] cpufreq/amd-pstate: Add static asserts for EPP indices Mario Limonciello (AMD)
  5 siblings, 1 reply; 13+ messages in thread
From: Mario Limonciello (AMD) @ 2025-10-09 16:17 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK,
	Mario Limonciello (AMD)

get_mode_idx_from_str() already checks the upper boundary for a string
sent.  Drop the extra check in amd_pstate_update_status() and pass
the return code if there is a failure.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/cpufreq/amd-pstate.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 5feb9f5e3a491..2d2ef53d12447 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1346,9 +1346,8 @@ int amd_pstate_update_status(const char *buf, size_t size)
 		return -EINVAL;
 
 	mode_idx = get_mode_idx_from_str(buf, size);
-
-	if (mode_idx < 0 || mode_idx >= AMD_PSTATE_MAX)
-		return -EINVAL;
+	if (mode_idx < 0)
+		return mode_idx;
 
 	if (mode_state_machine[cppc_state][mode_idx]) {
 		guard(mutex)(&amd_pstate_driver_lock);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 5/6] cpufreq/amd-pstate: Fix some whitespace issues
  2025-10-09 16:17 [PATCH v2 0/6] amd-pstate optimizations Mario Limonciello (AMD)
                   ` (3 preceding siblings ...)
  2025-10-09 16:17 ` [PATCH v2 4/6] cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status() Mario Limonciello (AMD)
@ 2025-10-09 16:17 ` Mario Limonciello (AMD)
  2025-10-15  9:04   ` Gautham R. Shenoy
  2025-10-09 16:17 ` [PATCH v2 6/6] cpufreq/amd-pstate: Add static asserts for EPP indices Mario Limonciello (AMD)
  5 siblings, 1 reply; 13+ messages in thread
From: Mario Limonciello (AMD) @ 2025-10-09 16:17 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK,
	Mario Limonciello (AMD)

Add whitespace around the equals and remove leading space.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/cpufreq/amd-pstate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 2d2ef53d12447..a0f21ac1205af 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -126,7 +126,7 @@ static unsigned int epp_values[] = {
 	[EPP_INDEX_BALANCE_PERFORMANCE] = AMD_CPPC_EPP_BALANCE_PERFORMANCE,
 	[EPP_INDEX_BALANCE_POWERSAVE] = AMD_CPPC_EPP_BALANCE_POWERSAVE,
 	[EPP_INDEX_POWERSAVE] = AMD_CPPC_EPP_POWERSAVE,
- };
+};
 
 typedef int (*cppc_mode_transition_fn)(int);
 
@@ -182,7 +182,7 @@ static inline int get_mode_idx_from_str(const char *str, size_t size)
 {
 	int i;
 
-	for (i=0; i < AMD_PSTATE_MAX; i++) {
+	for (i = 0; i < AMD_PSTATE_MAX; i++) {
 		if (!strncmp(str, amd_pstate_mode_string[i], size))
 			return i;
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 6/6] cpufreq/amd-pstate: Add static asserts for EPP indices
  2025-10-09 16:17 [PATCH v2 0/6] amd-pstate optimizations Mario Limonciello (AMD)
                   ` (4 preceding siblings ...)
  2025-10-09 16:17 ` [PATCH v2 5/6] cpufreq/amd-pstate: Fix some whitespace issues Mario Limonciello (AMD)
@ 2025-10-09 16:17 ` Mario Limonciello (AMD)
  2025-10-15  9:11   ` Gautham R. Shenoy
  5 siblings, 1 reply; 13+ messages in thread
From: Mario Limonciello (AMD) @ 2025-10-09 16:17 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK,
	Mario Limonciello (AMD)

In case a new index is introduced add a static assert to make sure
that strings and values are updated.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/cpufreq/amd-pstate.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index a0f21ac1205af..b3dad7cde46f0 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -110,6 +110,7 @@ enum energy_perf_value_index {
 	EPP_INDEX_BALANCE_PERFORMANCE,
 	EPP_INDEX_BALANCE_POWERSAVE,
 	EPP_INDEX_POWERSAVE,
+	EPP_INDEX_MAX,
 };
 
 static const char * const energy_perf_strings[] = {
@@ -119,6 +120,7 @@ static const char * const energy_perf_strings[] = {
 	[EPP_INDEX_BALANCE_POWERSAVE] = "balance_power",
 	[EPP_INDEX_POWERSAVE] = "power",
 };
+static_assert(ARRAY_SIZE(energy_perf_strings) == EPP_INDEX_MAX);
 
 static unsigned int epp_values[] = {
 	[EPP_INDEX_DEFAULT] = 0,
@@ -127,6 +129,7 @@ static unsigned int epp_values[] = {
 	[EPP_INDEX_BALANCE_POWERSAVE] = AMD_CPPC_EPP_BALANCE_POWERSAVE,
 	[EPP_INDEX_POWERSAVE] = AMD_CPPC_EPP_POWERSAVE,
 };
+static_assert(ARRAY_SIZE(epp_values) == EPP_INDEX_MAX);
 
 typedef int (*cppc_mode_transition_fn)(int);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/6] cpufreq/amd-pstate: Use sysfs_match_string() for epp
  2025-10-09 16:17 ` [PATCH v2 1/6] cpufreq/amd-pstate: Use sysfs_match_string() for epp Mario Limonciello (AMD)
@ 2025-10-15  8:46   ` Gautham R. Shenoy
  0 siblings, 0 replies; 13+ messages in thread
From: Gautham R. Shenoy @ 2025-10-15  8:46 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK

On Thu, Oct 09, 2025 at 11:17:51AM -0500, Mario Limonciello (AMD) wrote:
> Rather than scanning the buffer and manually matching the string
> use the sysfs macros.
> 
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>

The patch looks good to me.
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>

> ---
> v2:
>  * Drop NULL from energy_perf_strings too (Gautham)
> ---
>  drivers/cpufreq/amd-pstate.c | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index b44f0f7a5ba1c..0bc5013448873 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -118,7 +118,6 @@ static const char * const energy_perf_strings[] = {
>  	[EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance",
>  	[EPP_INDEX_BALANCE_POWERSAVE] = "balance_power",
>  	[EPP_INDEX_POWERSAVE] = "power",
> -	NULL
>  };
>  
>  static unsigned int epp_values[] = {
> @@ -1137,16 +1136,15 @@ static ssize_t show_amd_pstate_hw_prefcore(struct cpufreq_policy *policy,
>  static ssize_t show_energy_performance_available_preferences(
>  				struct cpufreq_policy *policy, char *buf)
>  {
> -	int i = 0;
> -	int offset = 0;
> +	int offset = 0, i;
>  	struct amd_cpudata *cpudata = policy->driver_data;
>  
>  	if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
>  		return sysfs_emit_at(buf, offset, "%s\n",
>  				energy_perf_strings[EPP_INDEX_PERFORMANCE]);
>  
> -	while (energy_perf_strings[i] != NULL)
> -		offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i++]);
> +	for (i = 0; i < ARRAY_SIZE(energy_perf_strings); i++)
> +		offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i]);
>  
>  	offset += sysfs_emit_at(buf, offset, "\n");
>  
> @@ -1157,15 +1155,10 @@ static ssize_t store_energy_performance_preference(
>  		struct cpufreq_policy *policy, const char *buf, size_t count)
>  {
>  	struct amd_cpudata *cpudata = policy->driver_data;
> -	char str_preference[21];
>  	ssize_t ret;
>  	u8 epp;
>  
> -	ret = sscanf(buf, "%20s", str_preference);
> -	if (ret != 1)
> -		return -EINVAL;
> -
> -	ret = match_string(energy_perf_strings, -1, str_preference);
> +	ret = sysfs_match_string(energy_perf_strings, buf);
>  	if (ret < 0)
>  		return -EINVAL;
>  
> -- 
> 2.43.0
> 

-- 
Thanks and Regards
gautham.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/6] cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string
  2025-10-09 16:17 ` [PATCH v2 2/6] cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string Mario Limonciello (AMD)
@ 2025-10-15  8:47   ` Gautham R. Shenoy
  0 siblings, 0 replies; 13+ messages in thread
From: Gautham R. Shenoy @ 2025-10-15  8:47 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK

On Thu, Oct 09, 2025 at 11:17:52AM -0500, Mario Limonciello (AMD) wrote:
> None of the users actually look for the NULL value.  To avoid risk
> of regression introducing a new value but forgetting to add a string
> add a static assert to test AMD_PSTATE_MAX matches the array size.
> 
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>

Thanks for getting rid of the NULL entry.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> ---
>  drivers/cpufreq/amd-pstate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 0bc5013448873..a5b9e5baf4234 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -65,8 +65,8 @@ static const char * const amd_pstate_mode_string[] = {
>  	[AMD_PSTATE_PASSIVE]     = "passive",
>  	[AMD_PSTATE_ACTIVE]      = "active",
>  	[AMD_PSTATE_GUIDED]      = "guided",
> -	NULL,
>  };
> +static_assert(ARRAY_SIZE(amd_pstate_mode_string) == AMD_PSTATE_MAX);
>  
>  const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode)
>  {
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 3/6] cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return NULL
  2025-10-09 16:17 ` [PATCH v2 3/6] cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return NULL Mario Limonciello (AMD)
@ 2025-10-15  8:51   ` Gautham R. Shenoy
  0 siblings, 0 replies; 13+ messages in thread
From: Gautham R. Shenoy @ 2025-10-15  8:51 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK

On Thu, Oct 09, 2025 at 11:17:53AM -0500, Mario Limonciello (AMD) wrote:
> amd_pstate_get_mode_string() is only used by amd-pstate-ut.  Set the
> failure path to use AMD_PSTATE_UNDEFINED ("undefined") to avoid showing
> "(null)" as a string when running test suite.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>

> 
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
>  drivers/cpufreq/amd-pstate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index a5b9e5baf4234..5feb9f5e3a491 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -70,8 +70,8 @@ static_assert(ARRAY_SIZE(amd_pstate_mode_string) == AMD_PSTATE_MAX);
>  
>  const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode)
>  {
> -	if (mode < 0 || mode >= AMD_PSTATE_MAX)
> -		return NULL;
> +	if (mode < AMD_PSTATE_UNDEFINED || mode >= AMD_PSTATE_MAX)
> +		mode = AMD_PSTATE_UNDEFINED;
>  	return amd_pstate_mode_string[mode];
>  }
>  EXPORT_SYMBOL_GPL(amd_pstate_get_mode_string);
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/6] cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status()
  2025-10-09 16:17 ` [PATCH v2 4/6] cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status() Mario Limonciello (AMD)
@ 2025-10-15  9:02   ` Gautham R. Shenoy
  0 siblings, 0 replies; 13+ messages in thread
From: Gautham R. Shenoy @ 2025-10-15  9:02 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK

Hello Mario,

On Thu, Oct 09, 2025 at 11:17:54AM -0500, Mario Limonciello (AMD) wrote:
> get_mode_idx_from_str() already checks the upper boundary for a string
> sent.  Drop the extra check in amd_pstate_update_status() and pass
> the return code if there is a failure.

Looks good to me. This patch doesn't introduce any behavioural change
since in the absence of a match, get_mode_idx_from_str() returns
-EINVAL, which is what was being returned by
amd_pstate_update_status() previously when @buf contains an invalid
string.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>

> 
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
>  drivers/cpufreq/amd-pstate.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 5feb9f5e3a491..2d2ef53d12447 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1346,9 +1346,8 @@ int amd_pstate_update_status(const char *buf, size_t size)
>  		return -EINVAL;
>  
>  	mode_idx = get_mode_idx_from_str(buf, size);
> -
> -	if (mode_idx < 0 || mode_idx >= AMD_PSTATE_MAX)
> -		return -EINVAL;
> +	if (mode_idx < 0)
> +		return mode_idx;
>  
>  	if (mode_state_machine[cppc_state][mode_idx]) {
>  		guard(mutex)(&amd_pstate_driver_lock);
> -- 
> 2.43.0
> 

-- 
Thanks and Regards
gautham.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 5/6] cpufreq/amd-pstate: Fix some whitespace issues
  2025-10-09 16:17 ` [PATCH v2 5/6] cpufreq/amd-pstate: Fix some whitespace issues Mario Limonciello (AMD)
@ 2025-10-15  9:04   ` Gautham R. Shenoy
  0 siblings, 0 replies; 13+ messages in thread
From: Gautham R. Shenoy @ 2025-10-15  9:04 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK

On Thu, Oct 09, 2025 at 11:17:55AM -0500, Mario Limonciello (AMD) wrote:
> Add whitespace around the equals and remove leading space.
>
Thanks for cleaning this up.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>

> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
>  drivers/cpufreq/amd-pstate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 2d2ef53d12447..a0f21ac1205af 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -126,7 +126,7 @@ static unsigned int epp_values[] = {
>  	[EPP_INDEX_BALANCE_PERFORMANCE] = AMD_CPPC_EPP_BALANCE_PERFORMANCE,
>  	[EPP_INDEX_BALANCE_POWERSAVE] = AMD_CPPC_EPP_BALANCE_POWERSAVE,
>  	[EPP_INDEX_POWERSAVE] = AMD_CPPC_EPP_POWERSAVE,
> - };
> +};
>  
>  typedef int (*cppc_mode_transition_fn)(int);
>  
> @@ -182,7 +182,7 @@ static inline int get_mode_idx_from_str(const char *str, size_t size)
>  {
>  	int i;
>  
> -	for (i=0; i < AMD_PSTATE_MAX; i++) {
> +	for (i = 0; i < AMD_PSTATE_MAX; i++) {
>  		if (!strncmp(str, amd_pstate_mode_string[i], size))
>  			return i;
>  	}
> -- 
> 2.43.0
> 

-- 
Thanks and Regards
gautham.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 6/6] cpufreq/amd-pstate: Add static asserts for EPP indices
  2025-10-09 16:17 ` [PATCH v2 6/6] cpufreq/amd-pstate: Add static asserts for EPP indices Mario Limonciello (AMD)
@ 2025-10-15  9:11   ` Gautham R. Shenoy
  0 siblings, 0 replies; 13+ messages in thread
From: Gautham R. Shenoy @ 2025-10-15  9:11 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK

Hello Mario,

On Thu, Oct 09, 2025 at 11:17:56AM -0500, Mario Limonciello (AMD) wrote:
> In case a new index is introduced add a static assert to make sure
> that strings and values are updated.
>

Thanks for hardening this part of the code.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>

> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
>  drivers/cpufreq/amd-pstate.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index a0f21ac1205af..b3dad7cde46f0 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -110,6 +110,7 @@ enum energy_perf_value_index {
>  	EPP_INDEX_BALANCE_PERFORMANCE,
>  	EPP_INDEX_BALANCE_POWERSAVE,
>  	EPP_INDEX_POWERSAVE,
> +	EPP_INDEX_MAX,
>  };
>  
>  static const char * const energy_perf_strings[] = {
> @@ -119,6 +120,7 @@ static const char * const energy_perf_strings[] = {
>  	[EPP_INDEX_BALANCE_POWERSAVE] = "balance_power",
>  	[EPP_INDEX_POWERSAVE] = "power",
>  };
> +static_assert(ARRAY_SIZE(energy_perf_strings) == EPP_INDEX_MAX);
>  
>  static unsigned int epp_values[] = {
>  	[EPP_INDEX_DEFAULT] = 0,
> @@ -127,6 +129,7 @@ static unsigned int epp_values[] = {
>  	[EPP_INDEX_BALANCE_POWERSAVE] = AMD_CPPC_EPP_BALANCE_POWERSAVE,
>  	[EPP_INDEX_POWERSAVE] = AMD_CPPC_EPP_POWERSAVE,
>  };
> +static_assert(ARRAY_SIZE(epp_values) == EPP_INDEX_MAX);
>  
>  typedef int (*cppc_mode_transition_fn)(int);
>  
> -- 
> 2.43.0
> 

-- 
Thanks and Regards
gautham.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-10-15  9:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-09 16:17 [PATCH v2 0/6] amd-pstate optimizations Mario Limonciello (AMD)
2025-10-09 16:17 ` [PATCH v2 1/6] cpufreq/amd-pstate: Use sysfs_match_string() for epp Mario Limonciello (AMD)
2025-10-15  8:46   ` Gautham R. Shenoy
2025-10-09 16:17 ` [PATCH v2 2/6] cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string Mario Limonciello (AMD)
2025-10-15  8:47   ` Gautham R. Shenoy
2025-10-09 16:17 ` [PATCH v2 3/6] cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return NULL Mario Limonciello (AMD)
2025-10-15  8:51   ` Gautham R. Shenoy
2025-10-09 16:17 ` [PATCH v2 4/6] cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status() Mario Limonciello (AMD)
2025-10-15  9:02   ` Gautham R. Shenoy
2025-10-09 16:17 ` [PATCH v2 5/6] cpufreq/amd-pstate: Fix some whitespace issues Mario Limonciello (AMD)
2025-10-15  9:04   ` Gautham R. Shenoy
2025-10-09 16:17 ` [PATCH v2 6/6] cpufreq/amd-pstate: Add static asserts for EPP indices Mario Limonciello (AMD)
2025-10-15  9:11   ` Gautham R. Shenoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).