Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp460064pxj; Tue, 18 May 2021 07:14:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHgurjQu4TCwS3cf3lCZxGDDdd3qcS83/KIgpRuKQly8S7/d/9v1huV1c9IcPGWJ9y5ras X-Received: by 2002:a17:906:56d1:: with SMTP id an17mr3987260ejc.6.1621347284046; Tue, 18 May 2021 07:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621347284; cv=none; d=google.com; s=arc-20160816; b=gTXFvYVt+I1ulPTOKfy2UscvLqS9sSI8Nhpi9aMuclBfZ3dklcuWTDi/FN6l1N3NpH 15r0T/AmIJMZ9tecijJp+z9KLT5a+3hBVY6TF28fe9aOcoPdW7l5NI6QDol6pRITxCu0 NbbPtgGZaqWoZAymR15T/cIOWQS3ALaIloZ662Z/zjgbXvoQQSLhtBtvXihGa3Qi0WKG j+mVElTj7j0wKCKg0vGd5vZjMFmY/kdlWEC4Q2oWCoGsRQV80fci4To12LiLhKuVxDyx sSoJqLuhDitAhtu12J//k5gTq1QbkoFKoWKDE9oNy5rdayJOEBZXJ7oxfEnzIHConXXg yNFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1HjaxWY2TNeUos5G9hvdPYXPZGJK262fdwBXvfv9+/w=; b=AnrsrnSLvMyA0ylFCQCmidu1d/lSFMqRGzutP9QDJa5fwwd/NyrlEVFSkTLIsjkuX9 8ZGqRMbpwyNFig4xUDj+VvGWvmLqw5or1MnwQkc8OoRsk9WXHZt1jHKU3DzmE3FW51AU 2TO2L3J/qEaccnFo+yFFB7DQMjJLWcBXL7KPb1Wu418lscJarxxK/ZTVxCtqK1a5oINa RQeLBdYYjTtsWE+GzVP0BZvbu0jYVkC20nqsarcRJx3A9kTlU8cypFTOgyWcvkz/eLLx qiOVmexjQGbLiBSCprL98WpPfK0drPNzp7a5ZkZxveVOltfNpoNKxtk8n5eo4/YrWX60 TSDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XAuqK6zO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y18si14517813edu.32.2021.05.18.07.14.20; Tue, 18 May 2021 07:14:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XAuqK6zO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238797AbhEQPnH (ORCPT + 99 others); Mon, 17 May 2021 11:43:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:44806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244524AbhEQP2E (ORCPT ); Mon, 17 May 2021 11:28:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B9AFB61400; Mon, 17 May 2021 14:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262219; bh=bLbd3KllPc+nb1HSgkE8C2q+J5Spfs4xjxOr+sJZ6kw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XAuqK6zOYh6CUSWDBK4iFwUZnVY81GSRyDviLQD+OmXkuOBsv/fDxQ4/h4/GoHfbL ePYwSc30G2pOkkLOIrYB8xQ0BcekkWqyig752FqjQGgujjURmex8yoKAJGErCNt1w7 /MMo12mzZdAOi0ChI3HqjVbgHOe0qLldDfdSkmPg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Bagavatsingham , "Rafael J. Wysocki" , Huang Rui , Ingo Molnar , Alexander Monakov Subject: [PATCH 5.11 241/329] x86, sched: Fix the AMD CPPC maximum performance value on certain AMD Ryzen generations Date: Mon, 17 May 2021 16:02:32 +0200 Message-Id: <20210517140310.264877828@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huang Rui commit 3743d55b289c203d8f77b7cd47c24926b9d186ae upstream. Some AMD Ryzen generations has different calculation method on maximum performance. 255 is not for all ASICs, some specific generations should use 166 as the maximum performance. Otherwise, it will report incorrect frequency value like below: ~ → lscpu | grep MHz CPU MHz: 3400.000 CPU max MHz: 7228.3198 CPU min MHz: 2200.0000 [ mingo: Tidied up whitespace use. ] [ Alexander Monakov : fix 225 -> 255 typo. ] Fixes: 41ea667227ba ("x86, sched: Calculate frequency invariance for AMD systems") Fixes: 3c55e94c0ade ("cpufreq: ACPI: Extend frequency tables to cover boost frequencies") Reported-by: Jason Bagavatsingham Fixed-by: Alexander Monakov Reviewed-by: Rafael J. Wysocki Signed-off-by: Huang Rui Signed-off-by: Ingo Molnar Tested-by: Jason Bagavatsingham Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210425073451.2557394-1-ray.huang@amd.com Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=211791 Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/processor.h | 2 ++ arch/x86/kernel/cpu/amd.c | 16 ++++++++++++++++ arch/x86/kernel/smpboot.c | 2 +- drivers/cpufreq/acpi-cpufreq.c | 6 +++++- 4 files changed, 24 insertions(+), 2 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -805,8 +805,10 @@ DECLARE_PER_CPU(u64, msr_misc_features_s #ifdef CONFIG_CPU_SUP_AMD extern u32 amd_get_nodes_per_socket(void); +extern u32 amd_get_highest_perf(void); #else static inline u32 amd_get_nodes_per_socket(void) { return 0; } +static inline u32 amd_get_highest_perf(void) { return 0; } #endif static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves) --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1170,3 +1170,19 @@ void set_dr_addr_mask(unsigned long mask break; } } + +u32 amd_get_highest_perf(void) +{ + struct cpuinfo_x86 *c = &boot_cpu_data; + + if (c->x86 == 0x17 && ((c->x86_model >= 0x30 && c->x86_model < 0x40) || + (c->x86_model >= 0x70 && c->x86_model < 0x80))) + return 166; + + if (c->x86 == 0x19 && ((c->x86_model >= 0x20 && c->x86_model < 0x30) || + (c->x86_model >= 0x40 && c->x86_model < 0x70))) + return 166; + + return 255; +} +EXPORT_SYMBOL_GPL(amd_get_highest_perf); --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -2046,7 +2046,7 @@ static bool amd_set_max_freq_ratio(void) return false; } - highest_perf = perf_caps.highest_perf; + highest_perf = amd_get_highest_perf(); nominal_perf = perf_caps.nominal_perf; if (!highest_perf || !nominal_perf) { --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c @@ -646,7 +646,11 @@ static u64 get_max_boost_ratio(unsigned return 0; } - highest_perf = perf_caps.highest_perf; + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) + highest_perf = amd_get_highest_perf(); + else + highest_perf = perf_caps.highest_perf; + nominal_perf = perf_caps.nominal_perf; if (!highest_perf || !nominal_perf) {