Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp35376pxy; Tue, 20 Apr 2021 19:39:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1FneEqpDyq/ct3Qz5j39rBYrHBpTuRZzz0gEjyzW9reBJs8388vUh8krZp1mnHdF/lIrr X-Received: by 2002:a17:90a:db4b:: with SMTP id u11mr8268820pjx.154.1618972757221; Tue, 20 Apr 2021 19:39:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1618972757; cv=pass; d=google.com; s=arc-20160816; b=UfAwNi3z17j7i8smZqZdJ/LbFE3fN4HjJdkLNPMN8H/yelAJeJPkvmS/KPeGB9OEMP AwBbsx2Zn7H+bsmT/QLXaIXEu0EHWFn08ioduU7AnMfuBYznLIv9R3+xNpuXCAYFRUpg lwkVgR7cHw9hvt9VBoRx9pGRIgK8/azpjMfvzpsFh1dZ1LfazpybJF3YX3IxAYWb4y++ Q+3uL2aQEFJI+EwUh3mWXF/vVwzaNedO63q4yS9YgNrhTiTupK1+/RE7K5dBMlHRPHm7 Z65NLBsJYRwTa7JuwTwIXcheHXn9fcb04T6FXyosCRWeE3MmMx7zBkPLwppmD0qg1DXG gGKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=kOJEuwiCa0aZEKGIWBNfLSQkXqIfPkaOdeHSIxCn5zI=; b=BaWm6HOiL35j1mQHY63+0sryCkApNOm10w5UDWTjP2kgrtdvcmqzFwrjjQQUI4Fn7N RVOOgklVvUGDJMK0Mj3EYJ8Vc4qsFDkVpQMKdTRDdLKS0bg/soggi43IVjmmvt0rv75s s4a89AYwOV25E9rb8wvDr3zIg+T9rWy8lj8+Fa8TbpONn88eRwwSwfi1Stq1oeWUIOLF FPv7iEtVkPkwur24zNgLtpT+lrKA/iNjKGrxZSU2+YsYRNWC2Kwudi1jyb/47GfJ6c2n rSZvEWb3od0Yg7oqFud/jsL7ieMyOthl5bpjDPepnE+cTumZMB9fLnsE6S98Uh2w4WMB 7fQQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=ttA2aA4O; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m14si1017067pjr.8.2021.04.20.19.39.05; Tue, 20 Apr 2021 19:39:17 -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=@amd.com header.s=selector1 header.b=ttA2aA4O; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233824AbhDUCi6 (ORCPT + 99 others); Tue, 20 Apr 2021 22:38:58 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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?B?ZDBYT0RpcG5UVVQwMWRMNzF6dURqenhyVk1IL0RjVm9iRkFuRHQ2U2dEdjRs?= =?utf-8?B?TEFBSmJnSzNkU0JwVHVSbE9wN0VvTDBlTEN0MWlJcExVdUsyeGZ4SVBNbURl?= =?utf-8?B?d3k2SXZsc0pIdll6aS9hMzZWa296Y1NaLzgvVDdUbGJaaFE3L2dHSGgyNTl0?= =?utf-8?B?NU5BQkxLS2dQSjZmV1pZRWxLVzVEOHZnUzN3bDlSM0t3b3BwK1lLWGxRWHlm?= =?utf-8?B?N3lLdXh5TUZxN0V3NGtFYitRcHRmYkhmRGQwN3JIUjE4dHRVcXdhNi90eU9T?= =?utf-8?B?N2RpQ3A1bmt4Y0kxZEp3NHpqY09xNCtHTFkzdnVmQitLM1dvWXd6ZTJoYnc5?= =?utf-8?B?cnJvTjZpcE9MVERLR0V4THR1eDBsMktWSU5SZ3dZeW51TGthMzc0SDlhZDNJ?= =?utf-8?B?ZHRHVHJqNzBTN04raitpRURTdXBwaVp2Sy8yUEhrakhrMnI2anNObDcxVys4?= =?utf-8?B?aXRYbXdWMVBCMEdGeUd4U2kzN2Nra3J2UDE4TTdlS2VoS0ViTUVSbWNLS1hy?= =?utf-8?B?TW1saXJQRFBJeDlNSWZ3cXlHOGtubmZ4TGU5djM5VWRQUWVMd0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kZTM4MzAyOGty?= =?utf-8?B?VS80U1A2Zlk2K1lQU0NPamdCTjlscXgrbHdiSm1tVzlpa0NPSFpLWWM5SWVo?= =?utf-8?B?Mm9SR2FIUWMzb0hqbXNWY0JPdjJYVkhkZ3VUUlFrSWcvM3ozRXgvV0NkM2Ux?= =?utf-8?B?Z2FDbUZLenpHT0tsLy9xOUJNejJLWWJWcVhua01PRDc0cjhZME10eE5wSkNM?= =?utf-8?B?ZUlZdWtFUHRFckhaTmtNdVM3RGZUSTk0azFGT1ZRa2VsajNoTUxHTWhNTEdR?= =?utf-8?Q?AvMgbAm/xS7sdal9OLQnbDPIQW9bnz9UV7GSxWd?= 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-kernel@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; -- 2.25.1