Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp669271imm; Thu, 4 Oct 2018 01:05:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV62vdFFvFoJsNLVSOw67wYjGijt61k35dhgXqM3Sa8ibS9fehxJMQKHKC1KgIqoyMrmSJyav X-Received: by 2002:a63:3308:: with SMTP id z8-v6mr1089579pgz.220.1538640306919; Thu, 04 Oct 2018 01:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538640306; cv=none; d=google.com; s=arc-20160816; b=KZPUAOF2rS/JNqcx0vHp3x2OeCXmE1Y1gm5CyVWv30Lxyt8gEukx0kUirW34yHCD31 k+rCH0GmU0e/HSAaVcarwUXWHw/zt3grTzTLEKiL1wkanWV7dnXe8WlSLvN6t15HarGQ RpWaxAp/bF2fVIV1ahLAO5zjDHRht6PoDc9cb5wV1FZwf0Am5B7ouVJVTD5wDoCYvfDd Tgmtt4o2rqCJDl5ZH0QHGyBEWn2jGKU8mTzboaGs1PFV9O87//3ASBtkqA3PvTv01Oxs 3MZArFbbPcBr1i09coZNoW+SGquR3g2iPi7mQKCD2dnsUjdXcTW3hwQvE5ilNs1FjyR2 DpyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=Nu/hTzWw86E8egZWz38Acdb49PYkvRBr7nc8shtdTtM=; b=ydDJJ/CM/O2z5fLCp0u7msT9ir0Kg855YMxJz0vnuEnKhqxewrBOhk0kGqonKInv/O xf4IhTTxDoxkOV/2Sag4jheP8GAPpOzG+7Vb75d+omDp0S9Ur2fWZotu2d3DD3kZluDx svZQoj6nd5ozvqWONoR6OozVyfiQNjJsVvMEk6n73Y/HbgAq3+n0iZ63cpZinbYLxt5f Nnn9xtsBGE7tnbEtLeGY1E3vW1FKurMMpQFn3DUvroTXa8tyIogCA3gL7VRHSQAJ+ZyW u0GxN7Q3euPva42eqeqP7WFE/G5zeAqk2ovGS2S5EFmQVqC8542uTeFiErXghYg/sPk3 Ttgw== 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 17-v6si342076pgz.577.2018.10.04.01.04.50; Thu, 04 Oct 2018 01:05:06 -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 S1727771AbeJDO41 (ORCPT + 99 others); Thu, 4 Oct 2018 10:56:27 -0400 Received: from terminus.zytor.com ([198.137.202.136]:48691 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727533AbeJDO41 (ORCPT ); Thu, 4 Oct 2018 10:56:27 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w9483ruY2668272 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 4 Oct 2018 01:03:53 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w9483qUA2668269; Thu, 4 Oct 2018 01:03:52 -0700 Date: Thu, 4 Oct 2018 01:03:52 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Pu Wen Message-ID: Cc: puwen@hygon.cn, hpa@zytor.com, shuah@kernel.org, prarit@redhat.com, trenn@suse.com, bp@suse.de, linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de Reply-To: linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, prarit@redhat.com, hpa@zytor.com, shuah@kernel.org, puwen@hygon.cn, bp@suse.de, trenn@suse.com In-Reply-To: <5ce86123a7b9dad925ac583d88d2f921040e859b.1538583282.git.puwen@hygon.cn> References: <5ce86123a7b9dad925ac583d88d2f921040e859b.1538583282.git.puwen@hygon.cn> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cpu] tools/cpupower: Add Hygon Dhyana support Git-Commit-ID: 995d5f64b62f20f05b8e0972f07ec4d6c23333c9 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 995d5f64b62f20f05b8e0972f07ec4d6c23333c9 Gitweb: https://git.kernel.org/tip/995d5f64b62f20f05b8e0972f07ec4d6c23333c9 Author: Pu Wen AuthorDate: Thu, 4 Oct 2018 09:21:43 +0800 Committer: Borislav Petkov CommitDate: Thu, 4 Oct 2018 09:57:25 +0200 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 Signed-off-by: Borislav Petkov Acked-by: Shuah Khan (Samsung OSG) CC: Prarit Bhargava CC: Shuah Khan CC: Thomas Gleixner CC: Thomas Renninger CC: linux-pm@vger.kernel.org Link: http://lkml.kernel.org/r/5ce86123a7b9dad925ac583d88d2f921040e859b.1538583282.git.puwen@hygon.cn --- tools/power/cpupower/utils/cpufreq-info.c | 6 ++++-- tools/power/cpupower/utils/helpers/amd.c | 4 ++-- tools/power/cpupower/utils/helpers/cpuid.c | 8 +++++--- tools/power/cpupower/utils/helpers/helpers.h | 2 +- tools/power/cpupower/utils/helpers/misc.c | 2 +- tools/power/cpupower/utils/idle_monitor/mperf_monitor.c | 3 ++- 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) 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 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) if (family == 0x12) t = pstate.val & 0xf; - else if (family == 0x17) + else if (family == 0x17 || family == 0x18) t = pstate.fam17h_bits.did; else t = pstate.bits.did; @@ -59,7 +59,7 @@ 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) { 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 732b0b41ba26..5cc39d4e23ed 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 @@ out: 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 @@ out: 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 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; /* 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 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, * has Hardware determined variable increments instead. */ - if (cpu_info.family == 0x17) { + if (cpu_info.family == 0x17 || cpu_info.family == 0x18) { 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 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) 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: