Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp515332imm; Wed, 29 Aug 2018 05:48:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ3BIZjKYibmDSfeEuSpVRqSeBLXb8gTeVEuMJ5co5mFNUcdB37nIerfe5V1T54E1pj3BT1 X-Received: by 2002:a17:902:7798:: with SMTP id o24-v6mr5843791pll.93.1535546895413; Wed, 29 Aug 2018 05:48:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535546895; cv=none; d=google.com; s=arc-20160816; b=ke9gKMH0KQ6ASZqzLrBOJOJu4pRKJXu/7+ILQfc3gE+odIsrwAdI0gIkaSP/6Y3dhW F2QI1m1mHf8bjh+d2SM9TOOu7T4nDyg70iMQKX3lRyJE3tG43PmwJGX9LkyatJZ85oSr c45JLd8Lm6lP+EVT06zI7zE63S7mr9o/aRqn4HFzt3PtNEIB5rF27PFqWHz/EBlafMlh 8mB1aR8auTteMjFvAoA0KWuE98eA0VhVuO3KLEHNTeZS3+D6JmAW+1nREUfnnp6580x0 EgLxpowNuUB7vioKW+bYVaxME3dx3/PPkEG4XtmyrtAPfVQhQ8fPAuqd8Ld6uEa5OnXb c4CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=59VDzxjseVDvRsLJf/YRK3LHhQbf9iAT5GdK5eFuC80=; b=BYiRCV2HvTR0rJQQTORvPnWHwybl16qvPd/hjpOh5qGX9U9hNSY1Fiiy1/cuy8zxZ/ AV2WgOFNxEhYpFpK7ed5w824KCtT1sMQcakKdlFaCqVnXtR0asHpIAKkHCzL+UN82IZ6 0WBCosUKAuw/3FabbMAOH5Vk5QBpivgbaTOIXHaUvgduU58+WlHQJj2sz/W4KU4bPyRO 62WVswP8eaIk/GV3wnVQU03fWM5l1oYbya+GMG8HZAjYcuZe7BL88SM5leqYXdL8PT7i p2SnBBb2XSjtl/jM3r5yEjaIiEDMWUZf6Da/Gam8UhHviCGMwPrCRzIXdmtm7FUe//E3 aoLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si3727544pfb.280.2018.08.29.05.48.00; Wed, 29 Aug 2018 05:48:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728824AbeH2QnD (ORCPT + 99 others); Wed, 29 Aug 2018 12:43:03 -0400 Received: from smtp17.cstnet.cn ([159.226.251.17]:51056 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727684AbeH2QnD (ORCPT ); Wed, 29 Aug 2018 12:43:03 -0400 Received: from pw-vbox.higon.com (unknown [182.150.46.145]) by APP-09 (Coremail) with SMTP id swCowADXt+yFlYZb36z_BA--.6S2; Wed, 29 Aug 2018 20:46:02 +0800 (CST) From: Pu Wen To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, thomas.lendacky@amd.com, bp@alien8.de, pbonzini@redhat.com, trenn@suse.com, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-pm@vger.kernel.org, Pu Wen Subject: [PATCH v5 16/16] tools/cpupower: enable Hygon support to cpupower tool Date: Wed, 29 Aug 2018 20:45:56 +0800 Message-Id: <30d0bae54fd0255a5a51d5578d69bcbaf915dcae.1535459013.git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I42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43 ZEXa7VUbKLvtUUUUU== X-Originating-IP: [182.150.46.145] X-CM-SenderInfo: psxzv046klw03qof0z/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tool cpupower is useful to get CPU frequency information and monitor power stats on Hygon platforms. So enable platform support to cpupower for Hygon Dhyana Family 0x18 processors by checking vendor ID & family and vendor string by using the code path of AMD family 0x17. Signed-off-by: Pu Wen --- tools/power/cpupower/utils/cpufreq-info.c | 6 ++++-- tools/power/cpupower/utils/helpers/amd.c | 6 ++++-- tools/power/cpupower/utils/helpers/cpuid.c | 8 +++++--- tools/power/cpupower/utils/helpers/helpers.h | 2 +- tools/power/cpupower/utils/helpers/misc.c | 3 ++- tools/power/cpupower/utils/idle_monitor/mperf_monitor.c | 3 ++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c index df43cd4..56e54ea 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) unsigned long pstates[MAX_HW_PSTATES] = {0,}; if (cpupower_cpu_info.vendor != X86_VENDOR_AMD && + cpupower_cpu_info.vendor != X86_VENDOR_HYGON && cpupower_cpu_info.vendor != X86_VENDOR_INTEL) return 0; @@ -190,8 +191,9 @@ static int get_boost_mode(unsigned int cpu) printf(_(" Supported: %s\n"), support ? _("yes") : _("no")); printf(_(" Active: %s\n"), active ? _("yes") : _("no")); - if (cpupower_cpu_info.vendor == X86_VENDOR_AMD && - cpupower_cpu_info.family >= 0x10) { + if ((cpupower_cpu_info.vendor == X86_VENDOR_AMD && + cpupower_cpu_info.family >= 0x10) || + cpupower_cpu_info.vendor == X86_VENDOR_HYGON) { ret = decode_pstates(cpu, cpupower_cpu_info.family, b_states, pstates, &pstate_no); if (ret) diff --git a/tools/power/cpupower/utils/helpers/amd.c b/tools/power/cpupower/utils/helpers/amd.c index bb41cdd..dbce56c 100644 --- a/tools/power/cpupower/utils/helpers/amd.c +++ b/tools/power/cpupower/utils/helpers/amd.c @@ -45,7 +45,8 @@ static int get_did(int family, union msr_pstate pstate) if (family == 0x12) t = pstate.val & 0xf; - else if (family == 0x17) + else if (family == 0x17 || + (family == 0x18 && cpupower_cpu_info.vendor == X86_VENDOR_HYGON)) t = pstate.fam17h_bits.did; else t = pstate.bits.did; @@ -59,7 +60,8 @@ static int get_cof(int family, union msr_pstate pstate) int fid, did, cof; did = get_did(family, pstate); - if (family == 0x17) { + if (family == 0x17 || + (family == 0x18 && cpupower_cpu_info.vendor == X86_VENDOR_HYGON)) { fid = pstate.fam17h_bits.fid; cof = 200 * fid / did; } else { diff --git a/tools/power/cpupower/utils/helpers/cpuid.c b/tools/power/cpupower/utils/helpers/cpuid.c index 732b0b4..5cc39d4 100644 --- a/tools/power/cpupower/utils/helpers/cpuid.c +++ b/tools/power/cpupower/utils/helpers/cpuid.c @@ -8,7 +8,7 @@ #include "helpers/helpers.h" static const char *cpu_vendor_table[X86_VENDOR_MAX] = { - "Unknown", "GenuineIntel", "AuthenticAMD", + "Unknown", "GenuineIntel", "AuthenticAMD", "HygonGenuine", }; #if defined(__i386__) || defined(__x86_64__) @@ -109,6 +109,7 @@ int get_cpu_info(struct cpupower_cpu_info *cpu_info) fclose(fp); /* Get some useful CPU capabilities from cpuid */ if (cpu_info->vendor != X86_VENDOR_AMD && + cpu_info->vendor != X86_VENDOR_HYGON && cpu_info->vendor != X86_VENDOR_INTEL) return ret; @@ -124,8 +125,9 @@ int get_cpu_info(struct cpupower_cpu_info *cpu_info) if (cpuid_level >= 6 && (cpuid_ecx(6) & 0x1)) cpu_info->caps |= CPUPOWER_CAP_APERF; - /* AMD Boost state enable/disable register */ - if (cpu_info->vendor == X86_VENDOR_AMD) { + /* AMD or Hygon Boost state enable/disable register */ + if (cpu_info->vendor == X86_VENDOR_AMD || + cpu_info->vendor == X86_VENDOR_HYGON) { if (ext_cpuid_level >= 0x80000007 && (cpuid_edx(0x80000007) & (1 << 9))) 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 41da392..9021396 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; /* cpuid and cpuinfo helpers **************************/ enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL, - X86_VENDOR_AMD, X86_VENDOR_MAX}; + X86_VENDOR_AMD, X86_VENDOR_HYGON, X86_VENDOR_MAX}; #define CPUPOWER_CAP_INV_TSC 0x00000001 #define CPUPOWER_CAP_APERF 0x00000002 diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index 80fdf55..0be93ee 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -26,7 +26,8 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, * has Hardware determined variable increments instead. */ - if (cpu_info.family == 0x17) { + if (cpu_info.family == 0x17 || + (cpu_info.family == 0x18 && cpu_info.vendor == X86_VENDOR_HYGON)) { if (!read_msr(cpu, MSR_AMD_HWCR, &val)) { if (!(val & CPUPOWER_AMD_CPBDIS)) *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 d7c2a6d..f2a7e9c 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) if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC)) goto use_sysfs; - if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { + if (cpupower_cpu_info.vendor == X86_VENDOR_AMD || + cpupower_cpu_info.vendor == X86_VENDOR_HYGON) { /* MSR_AMD_HWCR tells us whether TSC runs at P0/mperf * freq. * A test whether hwcr is accessable/available would be: -- 2.7.4