diff mbox series

[13/19] cpupower: add the function to check amd-pstate enabled

Message ID 20210908150001.3702552-14-ray.huang@amd.com
State New
Headers show
Series [01/19] x86/cpufreatures: add AMD CPPC extension feature flag | expand

Commit Message

Huang Rui Sept. 8, 2021, 2:59 p.m. UTC
Introduce the cpupower_amd_pstate_enabled() to check whether the kernel
mode enables amd-pstate.

Signed-off-by: Huang Rui <ray.huang@amd.com>
---
 tools/power/cpupower/utils/helpers/helpers.h |  5 +++++
 tools/power/cpupower/utils/helpers/misc.c    | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+)

Comments

Shuah Khan Sept. 9, 2021, 10:16 p.m. UTC | #1
On 9/8/21 8:59 AM, Huang Rui wrote:
> Introduce the cpupower_amd_pstate_enabled() to check whether the kernel

> mode enables amd-pstate.

> 


What does "kernel mode" mean? Are you referring to kernel vs.
firmware mode?

> Signed-off-by: Huang Rui <ray.huang@amd.com>

> ---

>   tools/power/cpupower/utils/helpers/helpers.h |  5 +++++

>   tools/power/cpupower/utils/helpers/misc.c    | 20 ++++++++++++++++++++

>   2 files changed, 25 insertions(+)

> 

> diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h

> index b4813efdfb00..eb43c14d1728 100644

> --- a/tools/power/cpupower/utils/helpers/helpers.h

> +++ b/tools/power/cpupower/utils/helpers/helpers.h

> @@ -136,6 +136,11 @@ extern int decode_pstates(unsigned int cpu, int boost_states,

>   

>   extern int cpufreq_has_boost_support(unsigned int cpu, int *support,

>   				     int *active, int * states);

> +

> +/* AMD PSTATE enabling **************************/

> +

> +extern unsigned long cpupower_amd_pstate_enabled(unsigned int cpu);

> +

>   /*

>    * CPUID functions returning a single datum

>    */

> diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c

> index fc6e34511721..07d80775fb68 100644

> --- a/tools/power/cpupower/utils/helpers/misc.c

> +++ b/tools/power/cpupower/utils/helpers/misc.c

> @@ -83,6 +83,26 @@ int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)

>   	return 0;

>   }

>   

> +unsigned long cpupower_amd_pstate_enabled(unsigned int cpu)

> +{

> +	char linebuf[MAX_LINE_LEN];

> +	char path[SYSFS_PATH_MAX];

> +	unsigned long val;

> +	char *endp;

> +

> +	snprintf(path, sizeof(path),

> +		 PATH_TO_CPU "cpu%u/cpufreq/is_amd_pstate_enabled", cpu);

> +

> +	if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)

> +		return 0;

> +

> +	val = strtoul(linebuf, &endp, 0);

> +	if (endp == linebuf || errno == ERANGE)

> +		return 0;

> +

> +	return val;

> +}

> +

>   #endif /* #if defined(__i386__) || defined(__x86_64__) */

>   

>   /* get_cpustate

>
Huang Rui Sept. 13, 2021, 11:29 a.m. UTC | #2
On Fri, Sep 10, 2021 at 06:16:21AM +0800, Shuah Khan wrote:
> On 9/8/21 8:59 AM, Huang Rui wrote:

> > Introduce the cpupower_amd_pstate_enabled() to check whether the kernel

> > mode enables amd-pstate.

> > 

> 

> What does "kernel mode" mean? Are you referring to kernel vs.

> firmware mode?


I am referring kernel. In fact, the proccessor which supports the AMD
P-States also supports the legacy ACPI P-States as well. So this API is to
check whether the kernel driver is using amd-pstate or acpi-cpufreq.

I would have explained this, sorry to make you confused, I will explain the
details in the commit log at V2.

Thanks,
Ray

> 

> > Signed-off-by: Huang Rui <ray.huang@amd.com>

> > ---

> >   tools/power/cpupower/utils/helpers/helpers.h |  5 +++++

> >   tools/power/cpupower/utils/helpers/misc.c    | 20 ++++++++++++++++++++

> >   2 files changed, 25 insertions(+)

> > 

> > diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h

> > index b4813efdfb00..eb43c14d1728 100644

> > --- a/tools/power/cpupower/utils/helpers/helpers.h

> > +++ b/tools/power/cpupower/utils/helpers/helpers.h

> > @@ -136,6 +136,11 @@ extern int decode_pstates(unsigned int cpu, int boost_states,

> >   

> >   extern int cpufreq_has_boost_support(unsigned int cpu, int *support,

> >   				     int *active, int * states);

> > +

> > +/* AMD PSTATE enabling **************************/

> > +

> > +extern unsigned long cpupower_amd_pstate_enabled(unsigned int cpu);

> > +

> >   /*

> >    * CPUID functions returning a single datum

> >    */

> > diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c

> > index fc6e34511721..07d80775fb68 100644

> > --- a/tools/power/cpupower/utils/helpers/misc.c

> > +++ b/tools/power/cpupower/utils/helpers/misc.c

> > @@ -83,6 +83,26 @@ int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)

> >   	return 0;

> >   }

> >   

> > +unsigned long cpupower_amd_pstate_enabled(unsigned int cpu)

> > +{

> > +	char linebuf[MAX_LINE_LEN];

> > +	char path[SYSFS_PATH_MAX];

> > +	unsigned long val;

> > +	char *endp;

> > +

> > +	snprintf(path, sizeof(path),

> > +		 PATH_TO_CPU "cpu%u/cpufreq/is_amd_pstate_enabled", cpu);

> > +

> > +	if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)

> > +		return 0;

> > +

> > +	val = strtoul(linebuf, &endp, 0);

> > +	if (endp == linebuf || errno == ERANGE)

> > +		return 0;

> > +

> > +	return val;

> > +}

> > +

> >   #endif /* #if defined(__i386__) || defined(__x86_64__) */

> >   

> >   /* get_cpustate

> > 

>
diff mbox series

Patch

diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h
index b4813efdfb00..eb43c14d1728 100644
--- a/tools/power/cpupower/utils/helpers/helpers.h
+++ b/tools/power/cpupower/utils/helpers/helpers.h
@@ -136,6 +136,11 @@  extern int decode_pstates(unsigned int cpu, int boost_states,
 
 extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
 				     int *active, int * states);
+
+/* AMD PSTATE enabling **************************/
+
+extern unsigned long cpupower_amd_pstate_enabled(unsigned int cpu);
+
 /*
  * CPUID functions returning a single datum
  */
diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
index fc6e34511721..07d80775fb68 100644
--- a/tools/power/cpupower/utils/helpers/misc.c
+++ b/tools/power/cpupower/utils/helpers/misc.c
@@ -83,6 +83,26 @@  int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)
 	return 0;
 }
 
+unsigned long cpupower_amd_pstate_enabled(unsigned int cpu)
+{
+	char linebuf[MAX_LINE_LEN];
+	char path[SYSFS_PATH_MAX];
+	unsigned long val;
+	char *endp;
+
+	snprintf(path, sizeof(path),
+		 PATH_TO_CPU "cpu%u/cpufreq/is_amd_pstate_enabled", cpu);
+
+	if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)
+		return 0;
+
+	val = strtoul(linebuf, &endp, 0);
+	if (endp == linebuf || errno == ERANGE)
+		return 0;
+
+	return val;
+}
+
 #endif /* #if defined(__i386__) || defined(__x86_64__) */
 
 /* get_cpustate