From patchwork Wed Apr 21 02:38:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 426071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBCCBC433ED for ; Wed, 21 Apr 2021 02:38:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 823F861414 for ; Wed, 21 Apr 2021 02:38:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234539AbhDUCi5 (ORCPT ); Tue, 20 Apr 2021 22:38:57 -0400 Received: from mail-eopbgr760078.outbound.protection.outlook.com ([40.107.76.78]:38516 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234004AbhDUCi4 (ORCPT ); Tue, 20 Apr 2021 22:38:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mXDLPrjjLnAbWYKd/oPdYsrFocDTK5zypBfCesc/QyohHe58JJgYHkxvIb5KgBFVOZjO1G9hIhoYpZ9ZzV/YfV602fzo9wMm2O1SifGmoKfJPIv9OE8ehtmoam5IL8ODB/VDRkqhtHCCP8Gqc1nEHOrU0SCjIofho3QCl3xLc1iZmp+MmR6BwkwXqZNA0qAV1XT+twt5flbL4kUfwA1mc00rRa6Y+MbujurHiELV8dVkTcfCa1nSYwTBdhWu6OjmpU+Ijofeb/iCbB67swhxebVKiwYxV/mbp++I15+GST4YC+as953qfz/faQUYrwJ2EcalqfhCbs+DrOh0V6wZ6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kOJEuwiCa0aZEKGIWBNfLSQkXqIfPkaOdeHSIxCn5zI=; b=ZBnmgH1CQ10E4lqr8aMc1+DUklebQzq3L68MeJrVtBIr8bGf68E9khMxo3iZGCo11h8BrAyZptJVjmaS7QQnk3n883Wkbx8vS8chX4R3fsh9wALqjfk8yWpdQi/Q0SrCu9WU3/J7RpWFDLTCp0YWQScZReHzumyutvgerhnVWepwV0OYLOxOTcKNeT0AmE63HxM6vSC2wMluQOaXF4hfRyeW38i3WmSodwCu6/s2ucaB+PqzFoWf/HXskbxXmgSnyd9HDDzHnCd1PgTpFYVoYFQuRPHKEk7zSV2VclHJmUxoLXwwvvGyO0L1cbC1cReDD3bHB7k6Bx8BEMN4rr3gZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kOJEuwiCa0aZEKGIWBNfLSQkXqIfPkaOdeHSIxCn5zI=; b=ttA2aA4OEtVSIfX9lzYoESj/64Bvc8QZXAMXWG5iyxc/Mua/QWQnVPQGx0f7Tr1ngLz5JkVdhy5Z/8gRp/UMBBsKpF6g7srhQHgC9H5VwTxlnZ8exFXlcc0b+IgSRw5lf4ZNZ/gY4CQP5jNqeW+8+uVK54vPMHW+btnbS8l7GEw= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from MWHPR12MB1248.namprd12.prod.outlook.com (2603:10b6:300:12::21) by MWHPR12MB1375.namprd12.prod.outlook.com (2603:10b6:300:10::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Wed, 21 Apr 2021 02:38:22 +0000 Received: from MWHPR12MB1248.namprd12.prod.outlook.com ([fe80::f07c:dc0f:e7e8:416c]) by MWHPR12MB1248.namprd12.prod.outlook.com ([fe80::f07c:dc0f:e7e8:416c%4]) with mapi id 15.20.4065.020; Wed, 21 Apr 2021 02:38:22 +0000 From: Huang Rui To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alex Deucher , Jason Bagavatsingham , "Pierre-Loup A . Griffais" , Huang Rui , Nathan Fontenot , "Rafael J . Wysocki" , Borislav Petkov , x86@kernel.org, stable@vger.kernel.org Subject: [PATCH v2] x86, sched: Fix the AMD CPPC maximum perf on some specific generations Date: Wed, 21 Apr 2021 10:38:06 +0800 Message-Id: <20210421023807.1540290-1-ray.huang@amd.com> X-Mailer: git-send-email 2.25.1 X-Originating-IP: [58.247.170.245] X-ClientProxiedBy: HK2PR04CA0046.apcprd04.prod.outlook.com (2603:1096:202:14::14) To MWHPR12MB1248.namprd12.prod.outlook.com (2603:10b6:300:12::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from hr-amd.amd.com (58.247.170.245) by HK2PR04CA0046.apcprd04.prod.outlook.com (2603:1096:202:14::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Wed, 21 Apr 2021 02:38:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d41bd1d-a823-4974-098d-08d9046e8802 X-MS-TrafficTypeDiagnostic: MWHPR12MB1375: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:843; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h6qFUgVUw7ZNxZEkwvhXezKp4s1T2RVyCS3CHhnEX1Pkt99UG22G2U0KT+O90BII5q53CEeOp2Sq8yydJACj+/0LKOns5LVJVXyuG6UOztcUq0yVu5J1ZAYNyy6IjaNbnXv8Uqi6WHPTnRjTEthu0Q2BjRyZ6dwSKGjR/HzXYehJJzF/dNVoJ3qrwdG2M+J2Axc9ti/LrcIKYSl+s+LZClb2Kbs0VumnRqWe8RTRyoVQYDO3AvMmDh1BR9LZnI3pcGELSauAAXvFpI6xhGK7nzvHVuGHxFwDf+H/hT+/5H2IlaXw/l/EmiRyzwjQj8SG5kYR2lh7oSspsVcxPfrZ0q9bsw+KIh/FZLyWUYlBrIJvBjhhQhRShUXlDnbdTbte0fOZHe59x9Sp4ma9Y0IdW2oDjTVvZlC+z8fpg6GHAdc5UjZ1AOdPlQrzfFjFLigdBKRbqZfyBzxslAlR5Bd1jbWt3Mf1Y51G2oqVBHATU5y7Gupc+NtsE+PwzruBTrCQwCTpggosjjtlmD6c/bqUaLPBcgPmpouDK0DPt6iuOxt7qJme5sA3ksuF4QEqh5WuuemN05gVx/9m+WbwdtSZnn4+CF0lSPzrbzO5xZKth/aoaiZkWbfKkBkK4FWWYgaA3sLNbMQFLFf3lORWCCKFgaAY/cXbE+33rkfWUESC+RyfAUMJZIep4JO2yUJhB7b/wWl0Qcsyjs0dl6jKBX9yZsdTjEWKQxDcU5VEty4L6lxJOUgKIa73Yi2uKhoh2MS0 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)(346002)(366004)(396003)(39860400002)(136003)(376002)(54906003)(7696005)(956004)(83380400001)(186003)(38100700002)(16526019)(66476007)(316002)(8936002)(5660300002)(1076003)(66556008)(8676002)(86362001)(38350700002)(2906002)(2616005)(26005)(36756003)(478600001)(66946007)(6486002)(52116002)(4326008)(966005)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?d0XODipnTUT01dL71zuDjzxrVMH?= =?utf-8?q?/DcVobFAnDt6SgDv4lLAAJbgK3dSBpTuRlOp7EoL0eLCt1iIpLUuK2xf?= =?utf-8?q?xIPMmDewy6IvlsJHvYzi/a36VkozcSZ/8/T7TlbZhQ7/gGHh259t5NAB?= =?utf-8?q?LKKgPJ6fWZYElKW5D8vgS3wl9R3Kwopp+YKXlQXyf7yKuxyMFq7Ew4kE?= =?utf-8?q?b+QptfbHfDd07rHR18ttUqwa6/tyOS7diCp5nkxcI1dJw4zjcOq4+GLY?= =?utf-8?q?3vufB+K3WoYwze2hbw9rroN6ipOLTDKGExLtux0l2KVINRgwYynuLka3?= =?utf-8?q?74H9ad3IdtGTrj70S7N+j+iEDSuppiZvK/2PHkjHk2r6jsNl71W+8itX?= =?utf-8?q?mwV1PB0GFyGxSi37ckkrvP18M7eKehKEbMERmcKKXrMmlirPDPIx9MIf?= =?utf-8?q?wqyG8knnfxLe9v39UdPQeLwLGLHuQyqC+sFvCOUTPMZltFVsH76QEDpo?= =?utf-8?q?ie+qiUApGWEcOW7yPHQEHpYbwdFFUsQvOg26wWZSBl0VTZNwxVJOJ1F1?= =?utf-8?q?x9V91XpgRaAjV3XIezSQkqcQhaqiyYD3pNyAGLoGZ2++ejCQ8PLOzj8Z?= =?utf-8?q?UkYN3/9QPEQ8uFClwGp63+p00LmD1PgAp6OXOJt1VU4D9q242VokINXM?= =?utf-8?q?BTY6l25/4qcHCxQLSw9TJwHz2ZmbctZ9Q5h72+mxI1fuJ92JH8a5Im9W?= =?utf-8?q?IKa+Ple++/Vu1vgTOUz7Sp+peG5kMRss+xYso6Iv0q1uBVFJkTAeSsnU?= =?utf-8?q?HFU507GHpuaSEDVkiyyn0ayRR/AlCHijFSna+8ACKoi7w7NpP0hIv/Q7?= =?utf-8?q?why+ZuJ9bLyHwWHQKoO2LM5QRLkK2a6EVxNKLQ133gkP8yciJtMya6n+?= =?utf-8?q?EDVXZlCoFi6s6DNhH+3X6icnN3pSYgVhdzwK3k5Q8ejAKZGaGRilt03b?= =?utf-8?q?jjqV8L5M0EbKn54KTrruDzycpsGNl3uEsesWEtPb3LRjZlywCniQiW/b?= =?utf-8?q?5YJg+o4IGcqUOcsUtaSaxnCUoTvuBfbc7Uxgn+Fclvof2T+3lc+3kMrm?= =?utf-8?q?eRRZCK4JamlVyFBOJpfuBYOGSEtlx1mi23fXY2AgtuNdb97a1oZltl3d?= =?utf-8?q?L81Zo48GgiLrfGSh1tJXiaUAde383028krU/4SP6fY6+YPSCOjgBN9lq?= =?utf-8?q?x+lwbJmmW9ikCOHZKYc9Ieh2oRGaHQc3oHjmsVcBOv2XVHdguTRQkIg/?= =?utf-8?q?3z3Ex/WCd3e1gaCmFKzzGOKl//q9BMz2KYbVqXnkMOD74r8Y0MtxNpJC?= =?utf-8?q?LeIYukEPtErHZNkMuS7DfTI94k1FOVQkelj3hMLGMhMLGQAvMgbAm/xS?= =?utf-8?q?7sdal9OLQnbDPIQW9bnz9UV7GSxWd?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d41bd1d-a823-4974-098d-08d9046e8802 X-MS-Exchange-CrossTenant-AuthSource: MWHPR12MB1248.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 02:38:22.6813 (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: RDN6usyJvtu/YCPH5KBo2kNYbolywknNBNMqKDSmlBKJYnnekeSpzyBuyB6e6tEfyl0BOqab3BLIlpwaeuhjnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1375 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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: ~ → 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 AMD systems") Fixes: 3c55e94c0ade ("cpufreq: ACPI: Extend frequency tables to cover boost frequencies") Reported-by: Jason Bagavatsingham Tested-by: Jason Bagavatsingham Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=211791 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/processor.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 = &boot_cpu_data; + u32 cppc_max_perf = 225; + + switch (c->x86) { + case 0x17: + if ((c->x86_model >= 0x30 && c->x86_model < 0x40) || + (c->x86_model >= 0x70 && c->x86_model < 0x80)) + cppc_max_perf = 166; + break; + case 0x19: + if ((c->x86_model >= 0x20 && c->x86_model < 0x30) || + (c->x86_model >= 0x40 && c->x86_model < 0x70)) + cppc_max_perf = 166; + break; + } + + return cppc_max_perf; +} +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 = perf_caps.highest_perf; + highest_perf = amd_get_highest_perf(); nominal_perf = perf_caps.nominal_perf; if (!highest_perf || !nominal_perf) { diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.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_x86 *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 = amd_get_highest_perf(); + + boost_ratio = div_u64(cppc_max_perf << SCHED_CAPACITY_SHIFT, + nominal_perf); + + return boost_ratio; +} + 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 == X86_VENDOR_AMD) + return get_amd_max_boost_ratio(cpu, perf_caps.nominal_perf); + highest_perf = perf_caps.highest_perf; nominal_perf = perf_caps.nominal_perf;