Skip to content

Commit 46c273a

Browse files
huangruishuahkh
authored andcommitted
cpupower: Add the function to check AMD P-State enabled
The processor with AMD P-State function also supports legacy ACPI hardware P-States feature as well. Once driver sets AMD P-State eanbled, the processor will respond the finer grain AMD P-State feature instead of legacy ACPI P-States. So it introduces the cpupower_amd_pstate_enabled() to check whether the current kernel enables AMD P-State or AMD CPUFreq module. Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Huang Rui <ray.huang@amd.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent c8be60c commit 46c273a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

tools/power/cpupower/utils/helpers/helpers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <libintl.h>
1313
#include <locale.h>
14+
#include <stdbool.h>
1415

1516
#include "helpers/bitmask.h"
1617
#include <cpupower.h>
@@ -136,6 +137,12 @@ extern int decode_pstates(unsigned int cpu, int boost_states,
136137

137138
extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
138139
int *active, int * states);
140+
141+
/* AMD P-State stuff **************************/
142+
bool cpupower_amd_pstate_enabled(void);
143+
144+
/* AMD P-State stuff **************************/
145+
139146
/*
140147
* CPUID functions returning a single datum
141148
*/
@@ -168,6 +175,9 @@ static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
168175
int *active, int * states)
169176
{ return -1; }
170177

178+
static inline bool cpupower_amd_pstate_enabled(void)
179+
{ return false; }
180+
171181
/* cpuid and cpuinfo helpers **************************/
172182

173183
static inline unsigned int cpuid_eax(unsigned int op) { return 0; };

tools/power/cpupower/utils/helpers/misc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#include <stdio.h>
44
#include <errno.h>
55
#include <stdlib.h>
6+
#include <string.h>
67

78
#include "helpers/helpers.h"
89
#include "helpers/sysfs.h"
10+
#include "cpufreq.h"
911

1012
#if defined(__i386__) || defined(__x86_64__)
1113

@@ -83,6 +85,22 @@ int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)
8385
return 0;
8486
}
8587

88+
bool cpupower_amd_pstate_enabled(void)
89+
{
90+
char *driver = cpufreq_get_driver(0);
91+
bool ret = false;
92+
93+
if (!driver)
94+
return ret;
95+
96+
if (!strcmp(driver, "amd-pstate"))
97+
ret = true;
98+
99+
cpufreq_put_driver(driver);
100+
101+
return ret;
102+
}
103+
86104
#endif /* #if defined(__i386__) || defined(__x86_64__) */
87105

88106
/* get_cpustate

0 commit comments

Comments
 (0)