From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.196.16 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796390881; b=lBTZVYA1aSgbk27eAGdK/rY6dWFHFytvZO1bWMaF5ZKpQaEankNR/thSrZHh//w4oCG8 3nRary0pApThiOPYvpSIkpXOp2bIET6hOPzlexGmmyHpcXsgwT5FdE1InPRe+jNMXhU02 wj6vmQsM/aSqAnFCWmUIID7KlgCCpuqe5GRFEm6YyvGIIoxfguU43k5+9qcwBfXob36F+ sp3auarpgMYO5dmzfrFoDkKemyhZm4OKG3BKSHenMYuCvIfP5fewZUHsHYIH5c6joja3J 9OOzU4L556i1DRE9pEUyehSrdToI1n646UFO1UWVE5NezVkkrUASTRkJYT5OC4RCPdA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390881; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=xZq5aRLFPMQDW80BOhQM0VIzmJYEdfT5XVkeo3bkZmc=; b=TPkP01kQkMeRuiL/qOnuZVdrdvUyHTMfrbTG64HTQBTF6CijCL0rM0muW47uWzLNNVZh 1PMapX/W8iccSLr1EXDgfBhaf2S0X2v+n1w8EuFFB8EBWynAmt2alK+15CNyt2r1GAppn +H/CRSKNBR7erjitJheDVa9KvDACucTuBsR7szFHlkd5mp26UJggySoAwLe8b968kEU6O KvoYop3R/opm7t1axNuFcGEdW5rI7SDepeT9OMwKsOymWqK1Sy1tN8zm17SC8l1P7GemX hRmd+3pJTBHDgcG4NbcvFPhn0Ol9f0/SC0EDPEVGFi7A3QFCoSWkehEnOqr2AYOGJeQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b="oh2nJEL/"; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.196.16 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013016.outbound.protection.outlook.com [40.93.196.16]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FF99606A322; Fri, 4 Dec 2026 13:28:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7FF99606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=oh2nJEL/ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ffpDf4h3SAGzgv1aZuK8NjYCLYlWEMYEJsZo23EtZMeYHZcuUe0yQyPZj2/1XDKdO47x+Jck8o4Y71lto9UkuPpT5H3E/6vXS9Wi0Sk/yE4d57Untp7B3rcM+cYwmKrnMI1zMH1d0NLOKwCPB3sWJlAzVLbixAvc7Tqqt/SoqLGmgcSCjMniHh+itAR7XFfHGmEOmIJwS6iGd+nmXbvhjgS8Xrv85C5iCIUznYUTljJipfRGFbKVEXWI7zWZf0wFUSl62OHB5TEO+8I3BZaOhfWVmGl2SgkOYfpL6LgRQNAy0B7emAgb/RF8QGm2cFdqcRObKHTqnMTkMEG/D6RRKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xZq5aRLFPMQDW80BOhQM0VIzmJYEdfT5XVkeo3bkZmc=; b=AENLvJjFX5EgI5YDdsvy8otV9iGL7b9VL+Yca4+19fhWMg8KR0s7m6ZIJSKnnostmhBkxvRSVZ2Ts3Sawmb0JDWkqWCRUtDboNGQ8Xe7OpCdmfjp6ZBq8qey8BdDvl1nWMLgE/0SgbjGEWxStdPBRlvBr/u3gedobMc+ewkYUQghi7qy4RY01pPTbBSkxOdRmSGKDCFAW2cJw/Nk8eVNHGyFfN79T5MJKX3GAnvHoLAk/6DVpMi4yCAKlMM0u9HnKpx5gL3iWg3PLOU2sVGt/Po3GT1AAEp6Ipi1aQHJx8yVpnEsDMlH85zlzDuulckvBzBWJLCr0/RzogEX3OtNxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=xZq5aRLFPMQDW80BOhQM0VIzmJYEdfT5XVkeo3bkZmc=; b=oh2nJEL/aDQjWbt3Mr7UUvRJFS1TZSQI0bl81h7NDRYSQXx7EYCl8NPW2TrTLKqOKcqNbNIugBqan96Ki77K5LXgdcP87wH2kKtJ67hp4QMJLIam8B0hIYTbIt4OQG4PCVtW2E+sWFY9NbXzRKD/8CiZIH5fkr2Xsh2TAW+cpcE= Received: from BN8PR04CA0038.namprd04.prod.outlook.com (2603:10b6:408:d4::12) by LV2PR12MB5920.namprd12.prod.outlook.com (2603:10b6:408:172::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Fri, 4 Dec 2026 13:27:54 +0000 Received: from BN3PEPF00022BC7.namprd05.prod.outlook.com (2603:10b6:408:d4:cafe::8d) by BN8PR04CA0038.outlook.office365.com (2603:10b6:408:d4::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.13 via Frontend Transport; Fri, 4 Dec 2026 13:27:54 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN3PEPF00022BC7.mail.protection.outlook.com (10.167.248.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Fri, 4 Dec 2026 13:27:54 +0000 Received: from airavat.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 07:27:49 -0600 From: Vishal Badole To: , , , , , , , , , , , , , , , , , , , , CC: Vishal Badole Subject: [PATCH v3 2/3] cpufreq: amd-pstate: Set asymmetric CPU capacity on hybrid platforms Date: Fri, 4 Dec 2026 18:57:14 +0530 Message-ID: <20261204132715.1668516-3-Vishal.Badole@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261204132715.1668516-1-Vishal.Badole@amd.com> References: <20261204132715.1668516-1-Vishal.Badole@amd.com> X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF00022BC7:EE_|LV2PR12MB5920:EE_ X-MS-Office365-Filtering-Correlation-Id: 95f57693-d247-4117-0ebc-08df520a677c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700016|23010399003|1800799024|11063799006|6133799003|261009221227099003|261009223027099003|18002099003|22082099003|921020|261021123027099003|261022075727099003|10067099003|261022105027099003|261102123227099003|56012099006|261102130727099003|261028144727099003|261026140227099003|261021121427099003|261026121527099003; X-Microsoft-Antispam-Message-Info: 8XaQcsyFxsiMuNHeIaxXlA9re2XVPmePFJlU+GdXd3O3ZMVfZVWbNkjVqCyBIav0OVl0rApbRCuzkvdFtTmFzR/WC9CXaoT0pLKWWp0IBy2rk+uP8H1Km0oxfM5FQFIHjjakBASm7R9TcgN5Uhw+0HzJeAQaaizMkUpDKOVK7wgUgqH2B3Hxm8lTEQKLQPAL5x4bSmN6od90WVsduXWNA50tl3phny44HB5R9jRNF5HiqtNe43wga6WvN75MMtX0oNqaVn1i/gQ2FbB/09HY0+NnSLC/ImmeBzW8Y6UkuQhMjOVqFIsecqfknnc9M6XnzFNvkMwLePyqK2jZkwddqxDtOTJtNBz889RJz/2QMTVv30eR4wS0MpxzDdtzo0PuV/SEenX74JAtGLodCLij62GspIJbFjA2YkNU94m0sVXO32RXMf0YwWs4f8g3v/Tl2UuLjiZsbNYs4WRSOw9UxgqhBHTsAWYOhCFKcmYXHrpxfJ3VUFr+snAqT6RDJik09vE/nYzekrfkHwlhHvp6InC6iWSTQy5MCVMSSimQezlfHvbCw1aPg+HbcMoG65GHtjz3UENFxR249tr+xtwlr+De6fK1PThC58aAtdiI47leYjWyiTbZVtkqsCyt3BBXNhsijk4U1IC7+OztoNyz76vOGG8f0lVrWcUaXfCvGn5abcgg8YYKCKBwMpdLoXsssK5OyoRkGTs5ESi0B/bz2uMhP2wqHLEIyg69qhz9/rkXxVF8z2b9wgx8w0Zb8jzh X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700016)(23010399003)(1800799024)(11063799006)(6133799003)(261009221227099003)(261009223027099003)(18002099003)(22082099003)(921020)(261021123027099003)(261022075727099003)(10067099003)(261022105027099003)(261102123227099003)(56012099006)(261102130727099003)(261028144727099003)(261026140227099003)(261021121427099003)(261026121527099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ngHacQW/0hmzZ3v93tf1EZWG4XwUzvdbPFI5m3NWNzCO4biHY2k9hjwu1pQLO5JeRGwJjah3ysmWHM7BLBwslgGWI3MKvRyM5xwnrtC985YJuj37v+BUxR/oUIQ+O2Cc0U2Vg6yeMURPMABVDmRcYQdiZ4vm9VY3oJ3YTwQIMgjxOmQtr1QXlOGkUgAwMBITdilFeV8qtOyS2pkCiICmC7UtWdoARlqL7JQKA1X2HQLi5IKVTEmKCUix1tJf1MaGFTMUp2lULWpSRBbFtDRoQ60+w6JyVUV77cicKMYI10T/R+1/AmIVEWCxjr26vBqj/y1klekch1pN7Y4JF9Ldwb65aSHKdfwMEBngvNrYkSo22tYIhqXBfPPPcX9TWCFzGKeISRCZ0M2EVDOf5HPR/UfjJFEyz4SiVGfvnAw7AuGE6BRhy0yVAYbU3uTiVE6R X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 13:27:54.8809 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95f57693-d247-4117-0ebc-08df520a677c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF00022BC7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5920 AMD heterogeneous processors combine multiple core types (e.g. performance and efficiency cores) whose maximum sustained performance and frequency differ. On such platforms the Linux scheduler relies on per-CPU capacity values to place and balance tasks across cores. Today amd-pstate does not export any per-CPU capacity information. As a result the scheduler sees every CPU as having identical capacity and treats performance and efficiency cores as interchangeable. Tasks are therefore placed and balanced without regard to core strength, which hurts both throughput and energy efficiency on hybrid systems. This happens because the scheduler defaults to a uniform SCHED_CAPACITY_SCALE when no arch- or driver-supplied capacity exists, and amd-pstate never feeds the asymmetry it knows (via CPPC highest frequency or the effective highest performance register) into the arch hybrid capacity scaling interface. Enable capacity aware scheduling by scaling each CPU's capacity relative to a reference CPU. Use the maximum attainable frequencies when available for both CPUs, or their effective highest performance values otherwise. If reference setup fails, keep CAS disabled and continue normal CPUFreq registration. Capacity aware scheduling is enabled by default on supported hardware and can be turned off with the "amd_cas=disable" boot parameter. Its effective state is exposed through the "cas" sysfs attribute, and also exported via amd_pstate_cas_active() so amd-hfi can stand down when capacity aware scheduling owns the heterogeneous cores. Signed-off-by: Vishal Badole --- MAINTAINERS | 1 + arch/x86/include/asm/amd/amd-pstate.h | 16 +++ arch/x86/include/asm/topology.h | 6 + arch/x86/kernel/acpi/cppc.c | 4 +- drivers/cpufreq/amd-pstate.c | 184 +++++++++++++++++++++++++- 5 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 arch/x86/include/asm/amd/amd-pstate.h diff --git a/MAINTAINERS b/MAINTAINERS index 44540a1eb2b80..300dce181c1c4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1322,6 +1322,7 @@ R: K Prateek Nayak L: linux-pm@vger.kernel.org S: Supported F: Documentation/admin-guide/pm/amd-pstate.rst +F: arch/x86/include/asm/amd/amd-pstate.h F: drivers/cpufreq/amd-pstate* F: tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py diff --git a/arch/x86/include/asm/amd/amd-pstate.h b/arch/x86/include/asm/amd/amd-pstate.h new file mode 100644 index 0000000000000..1c0eb56c8f867 --- /dev/null +++ b/arch/x86/include/asm/amd/amd-pstate.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Public interface for the AMD P-state driver. + */ +#ifndef _ASM_X86_AMD_PSTATE_H_ +#define _ASM_X86_AMD_PSTATE_H_ + +#include + +#if IS_ENABLED(CONFIG_X86_AMD_PSTATE) +bool amd_pstate_cas_active(void); +#else +static inline bool amd_pstate_cas_active(void) { return false; } +#endif + +#endif /* _ASM_X86_AMD_PSTATE_H_ */ diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 1825691af9410..ddcd550e25846 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -264,6 +264,12 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources); extern bool x86_topology_update; +static inline void arch_mark_cpu_topology_changed(void) +{ + if (IS_ENABLED(CONFIG_SMP)) + x86_topology_update = true; +} + #ifdef CONFIG_SCHED_MC_PRIO #include #include diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index 1c6bf56c3215b..15590e9da2dca 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -248,8 +248,8 @@ int amd_get_effective_highest_perf(unsigned int cpu) if (ret < 0) return ret; - /* without preferred cores, return the highest perf register value */ - if (!prefcore) + /* Reuse the cached value for homogeneous CPUs without preferred cores. */ + if (!prefcore && !cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES)) return boost_numerator; /* diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 3e0308f644778..366ba3802f3c8 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -39,10 +39,12 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -86,6 +88,9 @@ static struct cpufreq_driver amd_pstate_driver; static struct cpufreq_driver amd_pstate_epp_driver; static int cppc_state = AMD_PSTATE_UNDEFINED; static bool amd_pstate_prefcore = true; +static bool amd_pstate_cas = true; +static bool amd_pstate_cas_initialized; +static u32 amd_pstate_ref_freq_khz; static struct quirk_entry *quirks; /* @@ -962,6 +967,142 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) sched_set_itmt_core_prio((int)READ_ONCE(cpudata->prefcore_ranking), cpudata->cpu); } +bool amd_pstate_cas_active(void) +{ + return READ_ONCE(amd_pstate_cas_initialized); +} +EXPORT_SYMBOL_GPL(amd_pstate_cas_active); + +static bool amd_pstate_update_ref(int offline_cpu) +{ + u32 ref_max_freq = 0, max_freq, nominal_freq; + struct cppc_perf_caps perf_caps; + int cpu, ret, highest_perf; + + for_each_online_cpu(cpu) { + if (cpu == offline_cpu) + continue; + + ret = amd_get_max_frequency(cpu); + if (ret < 0) { + pr_warn("Invalid maximum frequency (%d) on CPU%d\n", ret, cpu); + return false; + } + + max_freq = (u32)ret * 1000; + if (!max_freq) { + ret = cppc_get_perf_caps(cpu, &perf_caps); + if (ret) + return false; + + if (!perf_caps.nominal_freq) { + pr_warn("Missing nominal frequency on CPU%d\n", cpu); + return false; + } + + highest_perf = amd_get_effective_highest_perf(cpu); + if (highest_perf <= 0) { + pr_warn("Invalid highest performance (%d) on CPU%d\n", + highest_perf, cpu); + return false; + } + + nominal_freq = perf_caps.nominal_freq * 1000; + max_freq = DIV_ROUND_UP_ULL((u64)nominal_freq * highest_perf, + perf_caps.nominal_perf); + } + + if (max_freq <= ref_max_freq) + continue; + + ref_max_freq = max_freq; + } + + if (!ref_max_freq) { + pr_warn("No reference CPU available for capacity scaling\n"); + return false; + } + + amd_pstate_ref_freq_khz = ref_max_freq; + + return true; +} + +static void __init amd_pstate_init_cas(void) +{ + if (!amd_pstate_cas) + return; + + amd_pstate_cas = false; + if (!cpu_feature_enabled(X86_FEATURE_AMD_HTR_CORES)) + return; + + if (!amd_pstate_update_ref(nr_cpu_ids)) + return; + + amd_pstate_cas = arch_enable_hybrid_capacity_scale(); +} + +static void amd_pstate_update_cpu_capacity(struct amd_cpudata *data) +{ + unsigned long max_freq = READ_ONCE(data->max_freq); + int cpu = data->cpu; + + arch_set_cpu_capacity(cpu, max_freq, amd_pstate_ref_freq_khz, + max_freq, amd_pstate_ref_freq_khz); + topology_set_cpu_scale(cpu, arch_scale_cpu_capacity(cpu)); +} + +static void __amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata, bool refresh) +{ + int cpu; + + lockdep_assert_cpus_held(); + lockdep_assert_held(&sched_domains_mutex); + + if (cpudata) { + u32 max_freq = READ_ONCE(cpudata->max_freq); + + if (max_freq > amd_pstate_ref_freq_khz) { + amd_pstate_ref_freq_khz = max_freq; + refresh = true; + } + } + + if (refresh) { + for_each_online_cpu(cpu) { + struct cpufreq_policy *policy; + + if (cpudata && cpu == cpudata->cpu) + continue; + + policy = cpufreq_cpu_get_raw(cpu); + if (policy && policy->driver_data) + amd_pstate_update_cpu_capacity(policy->driver_data); + } + } + + if (cpudata) + amd_pstate_update_cpu_capacity(cpudata); + WRITE_ONCE(amd_pstate_cas_initialized, true); +} + +static void amd_pstate_refresh_cpu_capacity(struct amd_cpudata *cpudata, int offline_cpu) +{ + guard(mutex)(&sched_domains_mutex); + + if (amd_pstate_update_ref(offline_cpu)) + __amd_pstate_set_cpu_capacity(cpudata, true); +} + +static void amd_pstate_set_cpu_capacity(struct amd_cpudata *cpudata) +{ + guard(mutex)(&sched_domains_mutex); + + __amd_pstate_set_cpu_capacity(cpudata, false); + arch_mark_cpu_topology_changed(); +} + static void amd_pstate_update_limits(struct cpufreq_policy *policy) { struct amd_cpudata *cpudata; @@ -1093,6 +1234,9 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata) bios_min_freq, cpudata->cpu); } + if (amd_pstate_cas) + amd_pstate_set_cpu_capacity(cpudata); + return 0; } @@ -1203,6 +1347,7 @@ static void amd_pstate_cpu_exit(struct cpufreq_policy *policy) freq_qos_remove_request(&cpudata->req[0]); policy->fast_switch_possible = false; kfree(cpudata); + policy->driver_data = NULL; } static int amd_pstate_get_balanced_epp(struct cpufreq_policy *policy) @@ -1916,12 +2061,20 @@ static ssize_t prefcore_show(struct device *dev, return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_prefcore)); } +static ssize_t cas_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_cas_active())); +} + static DEVICE_ATTR_RW(status); static DEVICE_ATTR_RO(prefcore); +static DEVICE_ATTR_RO(cas); static struct attribute *pstate_global_attributes[] = { &dev_attr_status.attr, &dev_attr_prefcore.attr, + &dev_attr_cas.attr, NULL }; @@ -2142,7 +2295,14 @@ static int amd_pstate_cpu_online(struct cpufreq_policy *policy) return ret; cached_floor_perf = freq_to_perf(perf, cpudata->nominal_freq, cpudata->floor_freq); - return amd_pstate_set_floor_perf(policy, cached_floor_perf); + ret = amd_pstate_set_floor_perf(policy, cached_floor_perf); + if (ret) + return ret; + + if (amd_pstate_cas) + amd_pstate_refresh_cpu_capacity(cpudata, nr_cpu_ids); + + return 0; } static int amd_pstate_cpu_offline(struct cpufreq_policy *policy) @@ -2151,6 +2311,9 @@ static int amd_pstate_cpu_offline(struct cpufreq_policy *policy) union perf_cached perf = READ_ONCE(cpudata->perf); int ret; + if (amd_pstate_cas) + amd_pstate_refresh_cpu_capacity(NULL, cpudata->cpu); + /* * Reset CPPC_REQ MSR to the BIOS value, this will allow us to retain the BIOS specified * min_perf value across kexec reboots. If this CPU is just onlined normally after this, the @@ -2431,8 +2594,10 @@ static int __init amd_pstate_init(void) return ret; } - if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) && - IS_ENABLED(CONFIG_AMD_HFI)) + amd_pstate_init_cas(); + + if ((cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS) && + IS_ENABLED(CONFIG_AMD_HFI)) || amd_pstate_cas) amd_pstate_prefcore = false; ret = amd_pstate_register_driver(cppc_state); @@ -2441,6 +2606,10 @@ static int __init amd_pstate_init(void) return ret; } + /* Per-CPU capacities are set during registration; rebuild domains once. */ + if (amd_pstate_cas) + rebuild_sched_domains(); + dev_root = bus_get_dev_root(&cpu_subsys); if (dev_root) { ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group); @@ -2481,8 +2650,17 @@ static int __init amd_prefcore_param(char *str) return 0; } +static int __init amd_cas_param(char *str) +{ + if (!strcmp(str, "disable")) + amd_pstate_cas = false; + + return 0; +} + early_param("amd_pstate", amd_pstate_param); early_param("amd_prefcore", amd_prefcore_param); +early_param("amd_cas", amd_cas_param); MODULE_AUTHOR("Huang Rui "); MODULE_DESCRIPTION("AMD Processor P-state Frequency Driver"); -- 2.34.1