This message generated a parse failure. Raw output follows here. Please use 'back' to navigate. From devnull@lkml.org Thu Apr 25 05:34:35 2024 >From mailfetcher Sun Apr 25 09:20:05 2021 Envelope-to: lkml@grols.ch Delivery-date: Sun, 25 Apr 2021 09:19:16 +0200 Received: from stout.grols.ch [195.201.141.146] by 72459556e3a9 with IMAP (fetchmail-6.3.26) for (single-drop); Sun, 25 Apr 2021 09:20:05 +0200 (CEST) Received: from vger.kernel.org ([23.128.96.18]) by stout.grols.ch with esmtp (Exim 4.89) (envelope-from ) id 1laZ2x-0004H6-DW for lkml@grols.ch; Sun, 25 Apr 2021 09:19:16 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229579AbhDYHTw (ORCPT ); Sun, 25 Apr 2021 03:19:52 -0400 Received: from mail-co1nam11on2068.outbound.protection.outlook.com ([40.107.220.68]:31585 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229480AbhDYHTv (ORCPT To: "Rafael J. Wysocki" Cc: Linux PM , Linux Kernel Mailing List , "Deucher, Alexander" , Jason Bagavatsingham , "Pierre-Loup A . Griff Subject: Re: [PATCH v2] x86, sched: Fix the AMD CPPC maximum perf on some specific generations Message-Id: <20210425071856.GB2175798@hr-amd> References: <20210421023807.1540290-1-ray.huang@amd.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Originating-IP: [58.247.170.245] X-ClientProxiedBy: HK2PR02CA0157.apcprd02.prod.outlook.com (2603:1096:201:1f::17) To MWHPR12MB1248.namprd12.prod.outlook.com (2603:10b6:300:12::21) Mime-Version: 1.0 x-ms-exchange-messagesentrepresentingtype: 1 Received: from hr-amd (58.247.170.245) by HK2PR02CA0157.apcprd02.prod.outlook.com (2603:1096:201:1f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Sun, 25 Apr 2021 07:19:03 +0 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4eacde6f-33bc-4d77-2865-08d907ba6932 x-ms-traffictypediagnostic: MWHPR1201MB2540: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-ms-exchange-senderadcheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kGp/uFdiG5lkXZjGHQe1uez0ntnm+XP+Wd/cZQgFvgfRGqjuHtPNmFK7mEktJIebxq4QtGSpiJdGwkiJZLcCHrfZLONLoq+iPUdcDJxjuUEpGji8XKmaYGX4uVXXizRLaXeaPnNG1BsAcCqx3UTtnsEHxAHYdQtfTyATqsmIZu3qcfAzPUdi7+/hSlpv2hHXNohWQtWhUiVYMm1o9lUCXr1Z1hReuSJALPv3vWpdI3e0Q7Lo3xg1hynzoVcIDd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR12MB1248.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(376002)(346002)(396003)(136003)(52116002)(6496006)(2906002)(86362001)(9686003)(316002)(33656002)(1076 x-ms-exchange-antispam-messagedata: =?us-ascii?Q?A9cAAGAgET4H6KDJOTWb5VkX2NYFHApkUStb2hu78FDlIqcKSljjf3vbgYjG?= =?us-ascii?Q?i6hvhVjPbvjYHVSyliuvMorVYZ3vk1bf8wY2IFdJfW8GwXZZvGHNOXL8WJ/z?= =?us-ascii?Q?u9xCIkTgWNnw2SPKd5xIBEIL6HokOp6IGDP1QTggg3eI4FJ3z1aQL7quVVJN?= =?us-ascii?Q?M3Zcc3p5w7g5A X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4eacde6f-33bc-4d77-2865-08d907ba6932 X-MS-Exchange-CrossTenant-AuthSource: MWHPR12MB1248.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2021 07:19:06.3260 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: iQtYCUfEHAUZ+jBoprzMNp22a3gMHjJKiZsRVMuOCwK0YbXmQyL2WIQkrJiIRD+gjBmQyfxj/HDyee1QKDcB/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB2540 Precedence: bulk List-Id: X-Mailing-List: linux-kernel@vger.kernel.org Received-SPF: pass client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org X-Spam-Score: -3.0 X-Spam-Score-Bar: --- X-Spam-Action: no action X-Spam-Report: Action: no action Symbol: HAS_XOIP(0.00) Symbol: R_SPF_ALLOW(-0.20) Symbol: TO_DN_ALL(0.00) Symbol: DKIM_TRACE(0.00) Symbol: DMARC_POLICY_ALLOW(-0.50) Symbol: RCPT_COUNT_SEVEN(0.00) Symbol: MAILLIST(-0.10) Symbol: RCVD_NO_TLS_LAST(0.10) Symbol: FORGED_RE On Fri, Apr 23, 2021 at 11:19:46PM +0800, Rafael J. Wysocki wrote: > On Wed, Apr 21, 2021 at 4:38 AM Huang Rui wrote: > > > > Some AMD Ryzen generations has different calculation method on maximum > > perf. 255 is not for all asics, some specific generations should use 166 > > as the maximum perf. Otherwise, it will report incorrect frequency value > > like below: > > > > ~ =1B$B"*=1B(B lscpu | grep MHz > > CPU MHz: 3400.000 > > CPU max MHz: 7228.3198 > > CPU min MHz: 2200.0000 > > > > Fixes: 41ea667227ba ("x86, sched: Calculate frequency invariance for AM= D systems") > > Fixes: 3c55e94c0ade ("cpufreq: ACPI: Extend frequency tables to cover b= oost frequencies") > > > > Reported-by: Jason Bagavatsingham > > Tested-by: Jason Bagavatsingham > > Bugzilla: https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3= A%2F%2Fbugzilla.kernel.org%2Fshow_bug.cgi%3Fid%3D211791&data=3D04%7C01%= 7Cray.huang%40amd.com%7C5069cfd46dfe4f0c504208d9066b41be%7C3dd8961fe4884e60= 8e11a82d994e183d%7C0%7C0%7C637547880005034494%7CUnknown%7CTWFpbGZsb3d8eyJWI= joiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sd= ata=3DYSgziLlmyJlAxMQceGlx%2FB1EgN50h512ai1F4ypXoD8%3D&reserved=3D0 > > Signed-off-by: Huang Rui > > Cc: Alex Deucher > > Cc: Nathan Fontenot > > Cc: Rafael J. Wysocki > > Cc: Borislav Petkov > > Cc: x86@kernel.org > > Cc: stable@vger.kernel.org > > --- > > > > Changes from V1 -> V2: > > - Enhance the commit message. > > - Move amd_get_highest_perf() into amd.c. > > - Refine the implementation of switch-case. > > - Cc stable mail list. > > > > --- > > arch/x86/include/asm/processor.h | 2 ++ > > arch/x86/kernel/cpu/amd.c | 22 ++++++++++++++++++++++ > > arch/x86/kernel/smpboot.c | 2 +- > > drivers/cpufreq/acpi-cpufreq.c | 19 +++++++++++++++++++ > > 4 files changed, 44 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/pr= ocessor.h > > index f1b9ed5efaa9..908bcaea1361 100644 > > --- a/arch/x86/include/asm/processor.h > > +++ b/arch/x86/include/asm/processor.h > > @@ -804,8 +804,10 @@ DECLARE_PER_CPU(u64, msr_misc_features_shadow); > > > > #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) > > diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c > > index 347a956f71ca..aadb691d9357 100644 > > --- a/arch/x86/kernel/cpu/amd.c > > +++ b/arch/x86/kernel/cpu/amd.c > > @@ -1170,3 +1170,25 @@ void set_dr_addr_mask(unsigned long mask, int dr) > > break; > > } > > } > > + > > +u32 amd_get_highest_perf(void) > > +{ > > + struct cpuinfo_x86 *c =3D &boot_cpu_data; > > + u32 cppc_max_perf =3D 225; >=20 > The extra local variable is redundant. >=20 > > + > > + switch (c->x86) { > > + case 0x17: > > + if ((c->x86_model >=3D 0x30 && c->x86_model < 0x40) || > > + (c->x86_model >=3D 0x70 && c->x86_model < 0x80)) > > + cppc_max_perf =3D 166; > > + break; >=20 > Also it would be cleaner to write this as >=20 > if (c->x86 =3D=3D 0x17 && ((c->x86_model >=3D 0x30 && c->x86_model < 0x40= ) || > (c->x86_model >=3D 0x70 && c->x86_model < 0x80)) > return 166; >=20 > And analogously below. >=20 > > + case 0x19: > > + if ((c->x86_model >=3D 0x20 && c->x86_model < 0x30) || > > + (c->x86_model >=3D 0x40 && c->x86_model < 0x70)) > > + cppc_max_perf =3D 166; > > + break; > > + } > > + > > + return cppc_max_perf; >=20 > And here >=20 > return 225; >=20 > > +} > > +EXPORT_SYMBOL_GPL(amd_get_highest_perf); > > diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c > > index 02813a7f3a7c..7bec57d04a87 100644 > > --- 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 =3D perf_caps.highest_perf; > > + highest_perf =3D amd_get_highest_perf(); > > nominal_perf =3D perf_caps.nominal_perf; > > > > if (!highest_perf || !nominal_perf) { > > diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpuf= req.c > > index d1bbc16fba4b..3f0a19dd658c 100644 > > --- a/drivers/cpufreq/acpi-cpufreq.c > > +++ b/drivers/cpufreq/acpi-cpufreq.c > > @@ -630,6 +630,22 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x= 86 *c) > > #endif > > > > #ifdef CONFIG_ACPI_CPPC_LIB > > + > > +static u64 get_amd_max_boost_ratio(unsigned int cpu, u64 nominal_perf) > > +{ > > + u64 boost_ratio, cppc_max_perf; > > + > > + if (!nominal_perf) > > + return 0; > > + > > + cppc_max_perf =3D amd_get_highest_perf(); > > + > > + boost_ratio =3D div_u64(cppc_max_perf << SCHED_CAPACITY_SHIFT, > > + nominal_perf); > > + > > + return boost_ratio; > > +} >=20 > The function above is not necessary if I'm not mistaken. >=20 Yes, right. > > + > > static u64 get_max_boost_ratio(unsigned int cpu) > > { > > struct cppc_perf_caps perf_caps; > > @@ -646,6 +662,9 @@ static u64 get_max_boost_ratio(unsigned int cpu) > > return 0; > > } > > > > + if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD) > > + return get_amd_max_boost_ratio(cpu, perf_caps.nominal_p= erf); > > + > > highest_perf =3D perf_caps.highest_perf; >=20 > The above can be written as >=20 > if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD) > highest_perf =3D amd_get_highest_perf(); > else > highest_perf =3D perf_caps.highest_perf; >=20 Thanks to simplify the implementation. Will update it in V4. Best Regards, Ray