aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPu Wen <puwen@hygon.cn>2018-10-03 21:21:43 -0400
committerBorislav Petkov <bp@suse.de>2018-10-04 03:57:25 -0400
commit995d5f64b62f20f05b8e0972f07ec4d6c23333c9 (patch)
tree807fdcca9114d04a4ca5c93e315bd06f41f56415
parentcc9690cfc7a36873b219d569049e10f073dd22e4 (diff)
tools/cpupower: Add Hygon Dhyana support
The tool cpupower is useful to get CPU frequency information and monitor power stats on the Hygon Dhyana platform. So add Hygon Dhyana support to it by checking vendor and family to share the code path of AMD family 17h. Signed-off-by: Pu Wen <puwen@hygon.cn> Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Shuah Khan (Samsung OSG) <shuah@kernel.org> CC: Prarit Bhargava <prarit@redhat.com> CC: Shuah Khan <shuah@kernel.org> CC: Thomas Gleixner <tglx@linutronix.de> CC: Thomas Renninger <trenn@suse.com> CC: linux-pm@vger.kernel.org Link: http://lkml.kernel.org/r/5ce86123a7b9dad925ac583d88d2f921040e859b.1538583282.git.puwen@hygon.cn
-rw-r--r--tools/power/cpupower/utils/cpufreq-info.c6
-rw-r--r--tools/power/cpupower/utils/helpers/amd.c4
-rw-r--r--tools/power/cpupower/utils/helpers/cpuid.c8
-rw-r--r--tools/power/cpupower/utils/helpers/helpers.h2
-rw-r--r--tools/power/cpupower/utils/helpers/misc.c2
-rw-r--r--tools/power/cpupower/utils/idle_monitor/mperf_monitor.c3
6 files changed, 15 insertions, 10 deletions
diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c
index df43cd45d810..56e54eabc65c 100644
--- a/tools/power/cpupower/utils/cpufreq-info.c
+++ b/tools/power/cpupower/utils/cpufreq-info.c
@@ -170,6 +170,7 @@ static int get_boost_mode(unsigned int cpu)
170 unsigned long pstates[MAX_HW_PSTATES] = {0,}; 170 unsigned long pstates[MAX_HW_PSTATES] = {0,};
171 171
172 if (cpupower_cpu_info.vendor != X86_VENDOR_AMD && 172 if (cpupower_cpu_info.vendor != X86_VENDOR_AMD &&
173 cpupower_cpu_info.vendor != X86_VENDOR_HYGON &&
173 cpupower_cpu_info.vendor != X86_VENDOR_INTEL) 174 cpupower_cpu_info.vendor != X86_VENDOR_INTEL)
174 return 0; 175 return 0;
175 176
@@ -190,8 +191,9 @@ static int get_boost_mode(unsigned int cpu)
190 printf(_(" Supported: %s\n"), support ? _("yes") : _("no")); 191 printf(_(" Supported: %s\n"), support ? _("yes") : _("no"));
191 printf(_(" Active: %s\n"), active ? _("yes") : _("no")); 192 printf(_(" Active: %s\n"), active ? _("yes") : _("no"));
192 193
193 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD && 194 if ((cpupower_cpu_info.vendor == X86_VENDOR_AMD &&
194 cpupower_cpu_info.family >= 0x10) { 195 cpupower_cpu_info.family >= 0x10) ||
196 cpupower_cpu_info.vendor == X86_VENDOR_HYGON) {
195 ret = decode_pstates(cpu, cpupower_cpu_info.family, b_states, 197 ret = decode_pstates(cpu, cpupower_cpu_info.family, b_states,
196 pstates, &pstate_no); 198 pstates, &pstate_no);
197 if (ret) 199 if (ret)
diff --git a/tools/power/cpupower/utils/helpers/amd.c b/tools/power/cpupower/utils/helpers/amd.c
index bb41cdd0df6b..65beaeefeef0 100644
--- a/tools/power/cpupower/utils/helpers/amd.c
+++ b/tools/power/cpupower/utils/helpers/amd.c
@@ -45,7 +45,7 @@ static int get_did(int family, union msr_pstate pstate)
45 45
46 if (family == 0x12) 46 if (family == 0x12)
47 t = pstate.val & 0xf; 47 t = pstate.val & 0xf;
48 else if (family == 0x17) 48 else if (family == 0x17 || family == 0x18)
49 t = pstate.fam17h_bits.did; 49 t = pstate.fam17h_bits.did;
50 else 50 else
51 t = pstate.bits.did; 51 t = pstate.bits.did;
@@ -59,7 +59,7 @@ static int get_cof(int family, union msr_pstate pstate)
59 int fid, did, cof; 59 int fid, did, cof;
60 60
61 did = get_did(family, pstate); 61 did = get_did(family, pstate);
62 if (family == 0x17) { 62 if (family == 0x17 || family == 0x18) {
63 fid = pstate.fam17h_bits.fid; 63 fid = pstate.fam17h_bits.fid;
64 cof = 200 * fid / did; 64 cof = 200 * fid / did;
65 } else { 65 } else {
diff --git a/tools/power/cpupower/utils/helpers/cpuid.c b/tools/power/cpupower/utils/helpers/cpuid.c
index 732b0b41ba26..5cc39d4e23ed 100644
--- a/tools/power/cpupower/utils/helpers/cpuid.c
+++ b/tools/power/cpupower/utils/helpers/cpuid.c
@@ -8,7 +8,7 @@
8#include "helpers/helpers.h" 8#include "helpers/helpers.h"
9 9
10static const char *cpu_vendor_table[X86_VENDOR_MAX] = { 10static const char *cpu_vendor_table[X86_VENDOR_MAX] = {
11 "Unknown", "GenuineIntel", "AuthenticAMD", 11 "Unknown", "GenuineIntel", "AuthenticAMD", "HygonGenuine",
12}; 12};
13 13
14#if defined(__i386__) || defined(__x86_64__) 14#if defined(__i386__) || defined(__x86_64__)
@@ -109,6 +109,7 @@ out:
109 fclose(fp); 109 fclose(fp);
110 /* Get some useful CPU capabilities from cpuid */ 110 /* Get some useful CPU capabilities from cpuid */
111 if (cpu_info->vendor != X86_VENDOR_AMD && 111 if (cpu_info->vendor != X86_VENDOR_AMD &&
112 cpu_info->vendor != X86_VENDOR_HYGON &&
112 cpu_info->vendor != X86_VENDOR_INTEL) 113 cpu_info->vendor != X86_VENDOR_INTEL)
113 return ret; 114 return ret;
114 115
@@ -124,8 +125,9 @@ out:
124 if (cpuid_level >= 6 && (cpuid_ecx(6) & 0x1)) 125 if (cpuid_level >= 6 && (cpuid_ecx(6) & 0x1))
125 cpu_info->caps |= CPUPOWER_CAP_APERF; 126 cpu_info->caps |= CPUPOWER_CAP_APERF;
126 127
127 /* AMD Boost state enable/disable register */ 128 /* AMD or Hygon Boost state enable/disable register */
128 if (cpu_info->vendor == X86_VENDOR_AMD) { 129 if (cpu_info->vendor == X86_VENDOR_AMD ||
130 cpu_info->vendor == X86_VENDOR_HYGON) {
129 if (ext_cpuid_level >= 0x80000007 && 131 if (ext_cpuid_level >= 0x80000007 &&
130 (cpuid_edx(0x80000007) & (1 << 9))) 132 (cpuid_edx(0x80000007) & (1 << 9)))
131 cpu_info->caps |= CPUPOWER_CAP_AMD_CBP; 133 cpu_info->caps |= CPUPOWER_CAP_AMD_CBP;
diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h
index 41da392be448..902139689315 100644
--- a/tools/power/cpupower/utils/helpers/helpers.h
+++ b/tools/power/cpupower/utils/helpers/helpers.h
@@ -61,7 +61,7 @@ extern int be_verbose;
61 61
62/* cpuid and cpuinfo helpers **************************/ 62/* cpuid and cpuinfo helpers **************************/
63enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL, 63enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
64 X86_VENDOR_AMD, X86_VENDOR_MAX}; 64 X86_VENDOR_AMD, X86_VENDOR_HYGON, X86_VENDOR_MAX};
65 65
66#define CPUPOWER_CAP_INV_TSC 0x00000001 66#define CPUPOWER_CAP_INV_TSC 0x00000001
67#define CPUPOWER_CAP_APERF 0x00000002 67#define CPUPOWER_CAP_APERF 0x00000002
diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
index 80fdf55f414d..f406adc40bad 100644
--- a/tools/power/cpupower/utils/helpers/misc.c
+++ b/tools/power/cpupower/utils/helpers/misc.c
@@ -26,7 +26,7 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,
26 * has Hardware determined variable increments instead. 26 * has Hardware determined variable increments instead.
27 */ 27 */
28 28
29 if (cpu_info.family == 0x17) { 29 if (cpu_info.family == 0x17 || cpu_info.family == 0x18) {
30 if (!read_msr(cpu, MSR_AMD_HWCR, &val)) { 30 if (!read_msr(cpu, MSR_AMD_HWCR, &val)) {
31 if (!(val & CPUPOWER_AMD_CPBDIS)) 31 if (!(val & CPUPOWER_AMD_CPBDIS))
32 *active = 1; 32 *active = 1;
diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
index d7c2a6d13dea..f2a7e9cfd577 100644
--- a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
@@ -241,7 +241,8 @@ static int init_maxfreq_mode(void)
241 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC)) 241 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC))
242 goto use_sysfs; 242 goto use_sysfs;
243 243
244 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { 244 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD ||
245 cpupower_cpu_info.vendor == X86_VENDOR_HYGON) {
245 /* MSR_AMD_HWCR tells us whether TSC runs at P0/mperf 246 /* MSR_AMD_HWCR tells us whether TSC runs at P0/mperf
246 * freq. 247 * freq.
247 * A test whether hwcr is accessable/available would be: 248 * A test whether hwcr is accessable/available would be: