From nobody Tue Apr 7 05:43:51 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013023.outbound.protection.outlook.com [40.93.196.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C8D518787A; Mon, 16 Mar 2026 08:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.23 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773649178; cv=fail; b=iupTl2ly4pQsj4RaSY9I9UoX4xqVqfzhA46wU6Yz3hHDq9vz9sxMuWUPzLsLEI9xfIB1lt23gnZ/T31/Td82nKbWbS4z0CrBaTYgEv5rf24L/FAWKkVfejaqASvMTNi4rIppwq5/44SVQxLEqJz0n0Zc1fknU0xJwc9pxaZpxJE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773649178; c=relaxed/simple; bh=51S7Dqrl5vrpNM6zmwdZHWuWCgdGOWGy8eryEwqu8D0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f7cTrZUEIbwEW16Ew2QprOGkgXujg4l+quIZA4d6zA6ezN9aHonAc+xDtomL6D8JuTytzkJhwjlrL+DGceffpEh/IMZpUHF3KIDooT+HUq7TxfN4zOwtIyOnZGpFQfqPI6hG3zFaI3YLEoov+u4LXdnY6UhzVlVxbhl+02hQ+Ps= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=3h5Q2XPg; arc=fail smtp.client-ip=40.93.196.23 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) header.d=amd.com header.i=@amd.com header.b="3h5Q2XPg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S4U+bbT8sduAPhCRXtswPL5ZOQ495rgo9t/VIx4SrSW0EYHj4MXgoHTHpDk8kKXLVuPLHgxNdqskc591LUYPXNNlUu6CQNr6q+Y7HemEphTNzSVyzbD0bmWGJ6mKo+FdV+OHcnYuVxT9sVWvHgYUyvHraT8DFr+qwEa3hmGU9WKZjTheJFEppp893ibdj4c8Q0VMlJw+svdvNufaMfuod7JjxcYoAXo6M7wcqXJ+WXVZaah8Xl3AmvteZ5N+9YrIA51zMOqgqGTC+gINIE1EDqUhOImTHpYwrQD/dhBt5i9Bk5d6rrIvIyeHtrwQi8Y4qhvT122HYanzuEGhgp854A== 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=Jtcy468dngoNlmtfB1Ai30TS9xYCuck9oPa5VF4EX78=; b=BGHS7Yn480OpIil8z0AaFB4SusiSrAHii8HeWaRbonnJaX6Ky8uEZewGM3oCF8mXVDNlpPjE601GTvWS59MHcGIzkD5fON8KMetaXCmAuyacXKmmJBhLSvJDUglzq1h2h7yZzqthX98L0vtBBwU0PsPyBK3SOA0whc7q3MX7L1L4YEMsLgawwgxfSFZYk/FauTvf8IUls6lHXB7TSmnj97jsJMX+wPW8QSdSZ8DyIk9BFokxtR/U8AEotyFB0R7hAf1dL2RBmrKhnf/wCzNjHIE+hlBtZRknhUQ5d4no8qgDbMFoGb9L9tqBzY84RCL0gzq2Rfeact172XOfl+/Isw== 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=Jtcy468dngoNlmtfB1Ai30TS9xYCuck9oPa5VF4EX78=; b=3h5Q2XPg8izS/nwKpihbDBhoWC8klxk4kGi0Iv42t/+bYflGd/stsxkPmtea0Knoh3b8w+vIN+ecIBqoy7G0pglu70AiAmN3yEtn5Dp/MXntxZIwvS03IvgMRYtEr9HlE6N37OOA1xq9SHODS7626k2zoTglHbLpmuOxWfRqTqA= Received: from CH5P221CA0005.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:1f2::29) by PH7PR12MB6393.namprd12.prod.outlook.com (2603:10b6:510:1ff::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.16; Mon, 16 Mar 2026 08:19:33 +0000 Received: from CH1PEPF0000AD81.namprd04.prod.outlook.com (2603:10b6:610:1f2:cafe::9e) by CH5P221CA0005.outlook.office365.com (2603:10b6:610:1f2::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9700.25 via Frontend Transport; Mon, 16 Mar 2026 08:19:29 +0000 X-MS-Exchange-Authentication-Results: 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 CH1PEPF0000AD81.mail.protection.outlook.com (10.167.244.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9700.17 via Frontend Transport; Mon, 16 Mar 2026 08:19:32 +0000 Received: from BLRKPRNAYAK.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.17; Mon, 16 Mar 2026 03:19:28 -0500 From: K Prateek Nayak To: "Rafael J. Wysocki" , Viresh Kumar , Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt CC: Perry Yuan , , , , , K Prateek Nayak , Mario Limonciello Subject: [PATCH v4 1/2] cpufreq/amd-pstate: Pass the policy to amd_pstate_update() Date: Mon, 16 Mar 2026 08:18:48 +0000 Message-ID: <20260316081849.19368-2-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316081849.19368-1-kprateek.nayak@amd.com> References: <20260316081849.19368-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CH1PEPF0000AD81:EE_|PH7PR12MB6393:EE_ X-MS-Office365-Filtering-Correlation-Id: 42185ed4-ce1e-4a5d-94e1-08de8334c0a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|82310400026|1800799024|376014|7416014|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: 8sDDziQdMpAQK5nhEkCJbpL/mft7NBEMKmTPFpjXzpR54J3qZJgadPzF/kmFBc9xTay20U0Bi8eHf5xzTig7pAZrcesMe1NlkIHUo7u6//9xWD1B2iKEesC5cSXBksOS/8+pUEB2zb7xYreE6jN46AQ4/g0u4YRI6SyDWJRXTTFAAozdiGdfIR1RLIMGBz6t0lGPiluTsE4Cf2m81Lxa7CWU1yZrnyiSklp64O/ce9kEqQz1hwEvmdGmSEDMO7YdgD9irsbOYA8GVd55oXP+x5Pm+2GY93gbQvl9Lvx4VO9QXFnCRUFRGQL0fC0edH8X34e9ioKP6G1fwT6R223PNfcZtXciSmG+MxOKaGV1Sb6UT2hpClcyCiWpSsQ2HU/rpDJQIBTCg6tHRamI+dU7ZPGPEZo3UxpETIGxh7T67LVxSzLjj1eR9Naqs7khm3GNEeow1eujJGRpYAym4xjLJx1TlU+wBtKx55tJzV9pgxg9MM+wF7Ll1YeWgCWJ2FmHNFQcIHAUujCXu5NBHBLMaeb69Is8Qm89nmko8q8ySWmNuvZIHgVnRd2lcad6f3IX3zwSecwzHxRkLSKzChTF0Kw6HEK0Cw6A+5THK/csoTR3I64WlxdLw8L+pDZstpVeXx7tUqlQjU89F6ck84jc9RRl3r9Lr9LM2yEOgL6U2wtto70IShT2jU1mOUGN8iEuiR/NXGG4J5gnFN3ztn+3W5+0w6WJ8CRW5EnLXYB3gK1FOeqWPk6dzPv9D1gXKo2m2iaGUFzfscz+fMHi1h1ODQ== 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)(36860700016)(82310400026)(1800799024)(376014)(7416014)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hWacUxCD3Hb5MnuGA80xnGXplm8UIjlzlTUSTvhEBAY5fRcArMODv/13l9rdduytrTgy/NoBh5IaidQebkZTXFhYlVeW1h3WXZ5QKTFjC4ZYLkrx+u7hkY2ukvKSFc7IRT0u+lGz4epH/g5UDoNmteqXSsGwQMKWhXsbHbkCHyB69sXcdyxdKeA2Bk+YLwwLqpjSV2um/+hAlANYyCLElSRywDbWizCpCcChfhgyXbWpOlLNdg5X9ov7LzQEA/EH4jWCekRQQTd/gMX9Fch2Z4FkPdt1PIgVO8QREml9z4XwWj9i6vTvyGmlhtre6QpGAyJTsAi7INvlmW0OUPemaIa4uoQoj6koBQqhsEQlQ9pBvLOOe8kPdBNUQaoQasw0+Xk/lv35PRwNbwIwmPbRhmhy+AmL4wcI+BhFmKf5j7lAJ+9OSqN6yEbZnW/33626 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2026 08:19:32.6198 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42185ed4-ce1e-4a5d-94e1-08de8334c0a4 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: CH1PEPF0000AD81.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6393 Content-Type: text/plain; charset="utf-8" All callers of amd_pstate_update() already have a reference to the cpufreq_policy object. Pass the entire policy object and grab the cpudata using "policy->driver_data" instead of passing the cpudata and unnecessarily grabbing another read-side reference to the cpufreq policy object when it is already available in the caller. No functional changes intended. Reviewed-by: Mario Limonciello (AMD) Acked-by: Viresh Kumar Signed-off-by: K Prateek Nayak Reviewed-by: Gautham R. Shenoy --- changelog v3..v4: o No changes. --- drivers/cpufreq/amd-pstate.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 5aa9fcd80cf5..5faccb3d6b14 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -565,15 +565,12 @@ static inline bool amd_pstate_sample(struct amd_cpuda= ta *cpudata) return true; } =20 -static void amd_pstate_update(struct amd_cpudata *cpudata, u8 min_perf, +static void amd_pstate_update(struct cpufreq_policy *policy, u8 min_perf, u8 des_perf, u8 max_perf, bool fast_switch, int gov_flags) { - struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D cpufreq_cpu_= get(cpudata->cpu); + struct amd_cpudata *cpudata =3D policy->driver_data; union perf_cached perf =3D READ_ONCE(cpudata->perf); =20 - if (!policy) - return; - /* limit the max perf when core performance boost feature is disabled */ if (!cpudata->boost_supported) max_perf =3D min_t(u8, perf.nominal_perf, max_perf); @@ -688,7 +685,7 @@ static int amd_pstate_update_freq(struct cpufreq_policy= *policy, if (!fast_switch) cpufreq_freq_transition_begin(policy, &freqs); =20 - amd_pstate_update(cpudata, perf.min_limit_perf, des_perf, + amd_pstate_update(policy, perf.min_limit_perf, des_perf, perf.max_limit_perf, fast_switch, policy->governor->flags); =20 @@ -750,7 +747,7 @@ static void amd_pstate_adjust_perf(unsigned int cpu, if (max_perf < min_perf) max_perf =3D min_perf; =20 - amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true, + amd_pstate_update(policy, min_perf, des_perf, max_perf, true, policy->governor->flags); } =20 --=20 2.34.1 From nobody Tue Apr 7 05:43:51 2026 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010008.outbound.protection.outlook.com [52.101.56.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D32A3502AC; Mon, 16 Mar 2026 08:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.8 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773649204; cv=fail; b=kTDE7eXiV97NciwC5oG7S8FNsR009VcxsHnTuJvczVDas+FVO9Kq9y1S/lom/DaiqSdLgA2Sf9QwKgq2Y14ISBOc0TjKwrl0ndL2Q6A/qV/pwod+aGrrGAVdgoOt2wI+HTjqHNLLlutUJ3FP7NnucA64eR5LNKIXzfKBllA928c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773649204; c=relaxed/simple; bh=piezncCOp+g+r/eFQIEey25yymdGdj5I+X/Mb5yOWF0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aCJXstt1GWeLnGRVBQ9NDhj5GyNlvWsdyDyrms4OPnryyPqbjE+tBmxroTh9aNXUo+3SuU4/Xmr5/+F1Gb0XNhs70rIEBInvKoZYTEj9kyq4FbCHhWC+lL4eQA2fHlRRAjQVgNa1IkAagtRdYgdXOvPA3z3Yo3yp8+Ph0CtDFBE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=5kpxAYzG; arc=fail smtp.client-ip=52.101.56.8 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) header.d=amd.com header.i=@amd.com header.b="5kpxAYzG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H1WBNXag/zLYC38cl6xjNTF9l5fX8B/5bRZD69ww6WSonSs0zgOI3OxvtwgWXyn1LC1KKDtLtkoPrGkwq9kHPkXYmz4VkrtLE2keLnhrqFTZwh1fNz4ZO8k14CitAAhKzDaVpVa1fShmWAAhOhl0AmSAHg2VtOfYPuEQuHVgDfhPgeo3zpYtKeF65HI/MQ6wR5VQdLg2UuNP5igKxyZccJGVcYDrqDNScsRfArJTgR2hTBFkvIvsJor2wI/QLro0F9d6eP1jLU6DWYQufwgMK00BGW7h83WfaGr7KyT44jbHXSIwKuMawnDSANtbKBmsvN5eue37EQ4LPWnArhVBAw== 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=WCPogLwmME3roSPsfqdhRE/Wt6K3AkD3g7YPPknEuGY=; b=ITG8tcbmtGJRFF/CYXUwJbiaA91Hb+nAItKuuA/qejOlAPJ+HsKNeBKGh3tMPsOmucSpnAwui24ywSDvGtm4ouf8wxF7Ah6NCWHwX60p5ZKKTH0GWxMsm4CKCXjfoltWE0tXKu//AbdcWIc7PO4Ry3JMCizd+dskGABIGRLMT+RhKrrjoOjpe6tsIRi2pWfv2VRT31zb/q8zlOVPkzNd1xP+g5BWIZjEBwdLyhhD2B/0JjCg7uWDYYbxU/Id4S4rWlFSVhxg+oK/Xo1PT1536QSZxCN2WMwGnb9quPAHiUSpVYKjypg+N/sEzyJPysuZAUBsfAeTO0pM3CjCM70P+A== 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=WCPogLwmME3roSPsfqdhRE/Wt6K3AkD3g7YPPknEuGY=; b=5kpxAYzGUYODzZJkd2XEU8QVNR8Pu7SnBT0ZJGlPQPWPOuF038SRj33CGl5LAcee9hBoBrDLrnp2OyywyW0srg4P04vU7Ld/CFF+0K1r+IzNIFMJHfp8+usJWdz1YyPa1I43j6HxcbOtZGFPTTsxpRhsa8CbAX/O+0ncM3UDWsM= Received: from CH2PR11CA0015.namprd11.prod.outlook.com (2603:10b6:610:54::25) by DS4PR12MB9634.namprd12.prod.outlook.com (2603:10b6:8:280::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.16; Mon, 16 Mar 2026 08:19:54 +0000 Received: from CH1PEPF0000AD82.namprd04.prod.outlook.com (2603:10b6:610:54:cafe::f1) by CH2PR11CA0015.outlook.office365.com (2603:10b6:610:54::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9700.24 via Frontend Transport; Mon, 16 Mar 2026 08:19:49 +0000 X-MS-Exchange-Authentication-Results: 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 CH1PEPF0000AD82.mail.protection.outlook.com (10.167.244.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9700.17 via Frontend Transport; Mon, 16 Mar 2026 08:19:53 +0000 Received: from BLRKPRNAYAK.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.17; Mon, 16 Mar 2026 03:19:45 -0500 From: K Prateek Nayak To: "Rafael J. Wysocki" , Viresh Kumar , Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , "Srinivas Pandruvada" , Len Brown , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Miguel Ojeda CC: Perry Yuan , , , , , K Prateek Nayak , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , "Boqun Feng" , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bert Karwatzki Subject: [PATCH v4 2/2] cpufreq: Pass the policy to cpufreq_driver->adjust_perf() Date: Mon, 16 Mar 2026 08:18:49 +0000 Message-ID: <20260316081849.19368-3-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316081849.19368-1-kprateek.nayak@amd.com> References: <20260316081849.19368-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CH1PEPF0000AD82:EE_|DS4PR12MB9634:EE_ X-MS-Office365-Filtering-Correlation-Id: 80b3184c-35c7-4676-2187-08de8334cd43 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700016|82310400026|1800799024|921020|13003099007|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: eYRan3LGXijtOt8BvfiUK1sklkYGKX1W6cojtyBhOFYnlSW2k/OUlz3IE9eov5x/mU+RqdfYxIuBsF4z1w+UQYPHDns/vzEtU5KFicsYi4T1UhHB8cf5yTIAj0+8IvOuWKaBqtAx2KeHbmQ1UrRYdhht9JoLXXUUkj4S8zEQgAUd8+hKGEjAMsxjppB9g2dGPEzOE1M1GML/AMTO6j9CfUssHm0/bYseAKbbs1t7JyrkzC0uyPsqwyZwTxxo7Gs8hoYIN0T0PBLvYyrN6HBI8+v8+iNAWWgMrSFnbFRpNNbicL1iCpRlAPKjw28Jla0SEEJ15rkKHf/MXa84tsS1PDyvBMOJzN94UScSacwy7xnhSp7nicC6PoFd2MvNiR5cHrjZ+6Cs6dtouWafmkThVeTI/OpLVvVb+inMB2RKUStm4Rj0UDEIDjYqqrCd0Ua9FCLxR1/3rGRnK3hF65/WK3Y2OL8q9I1LZbMUj0SgktOuZJpogUEtQk4c+WnPzrhwXqhwaNYR8XYDYkIGsVyGYKbB1udNwJgC9djxAr1UdyhIxbfTi/ECQwT20VM/kjgfAZss3Zbb/r/imXLKzhYffIonLwFnCIW3QCW08plU/KEzgERE73tyvnf4gU7jfTZdOwBTqRaJUThVE+HX1L19d4j6KzhZxdMDU3tluMKjOALuW2B0aMApYb/mRu7qRVt//As1LIX7g/eF+X/B3qSBy358roLNtw7CCXFw8U0ruTsjWSnZ8ggUV7DQ0QrOhajxyfGLEQ8gW1zLL2Wbj/V5NZK10uyb6i7t144/DBvHjR5Z0f7GuGhXY/wyarZ3JPCG 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)(376014)(7416014)(36860700016)(82310400026)(1800799024)(921020)(13003099007)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7by5fJLAzybWJL1K4/MupY3HzCMhen/NreD8mJ5bWeUHJduwJ74FdkXB8AD9+2yptlNQfoOYCar1BUxVIgYrueuyIv377PPQ2etJJH1Vs/WfYTXVdxl0Onp6BmJkN6QXAWIdikiWgv67Ch831yWboXuvzdMI8jkS8Efen14y7scgro7FqvhYua/OZRkw5wlh/yXGADGgwe3tNEMMAqdLoC8aBMswctnx3beIIUC0i2ZUIiHGSHLUjJ+yzcgqe3aZRg7/VrBHK4FR7WEr8ivJgqYaiqVXRafjy6ojP9vRbDHYZ5qU7OAsgU5ZtptcGM2SprNxJIuZfMiQu5vBMX8z3280XVbbdvukL15Wt/iPCvsGzxKMdEifQQRpX3nJs8o+nehFdgP+GA+jdubtTReAZNYkZeeHWwYDxPCU13cgBio0O3Z+mIgt9oTU/N3CstvE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2026 08:19:53.7917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 80b3184c-35c7-4676-2187-08de8334cd43 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: CH1PEPF0000AD82.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS4PR12MB9634 Content-Type: text/plain; charset="utf-8" cpufreq_cpu_get() can sleep on PREEMPT_RT in presence of concurrent writer(s), however amd-pstate depends on fetching the cpudata via the policy's driver data which necessitates grabbing the reference. Since schedutil governor can call "cpufreq_driver->update_perf()" during sched_tick/enqueue/dequeue with rq_lock held and IRQs disabled, fetching the policy object using the cpufreq_cpu_get() helper in the scheduler fast-path leads to "BUG: scheduling while atomic" on PREEMPT_RT [1]. Pass the cached cpufreq policy object in sg_policy to the update_perf() instead of just the CPU. The CPU can be inferred using "policy->cpu". The lifetime of cpufreq_policy object outlasts that of the governor and the cpufreq driver (allocated when the CPU is onlined and only reclaimed when the CPU is offlined / the CPU device is removed) which makes it safe to be referenced throughout the governor's lifetime. Fixes: 1d215f0319c2 ("cpufreq: amd-pstate: Add fast switch function for AMD= P-State") Reported-by: Bert Karwatzki Closes:https://lore.kernel.org/all/20250731092316.3191-1-spasswolf@web.de/ = [1] Acked-by: Viresh Kumar Signed-off-by: K Prateek Nayak Acked-by: Gary Guo # Rust Reviewed-by: Gautham R. Shenoy Reviewed-by: Zhongqiu Han --- changelog v3..v4: o Added the Fixes tag. (Gautham, Chris Mason's review-prompts) --- drivers/cpufreq/amd-pstate.c | 3 +-- drivers/cpufreq/cpufreq.c | 6 +++--- drivers/cpufreq/intel_pstate.c | 4 ++-- include/linux/cpufreq.h | 4 ++-- kernel/sched/cpufreq_schedutil.c | 5 +++-- rust/kernel/cpufreq.rs | 13 ++++++------- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 5faccb3d6b14..ad4b5f84773a 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -710,13 +710,12 @@ static unsigned int amd_pstate_fast_switch(struct cpu= freq_policy *policy, return policy->cur; } =20 -static void amd_pstate_adjust_perf(unsigned int cpu, +static void amd_pstate_adjust_perf(struct cpufreq_policy *policy, unsigned long _min_perf, unsigned long target_perf, unsigned long capacity) { u8 max_perf, min_perf, des_perf, cap_perf; - struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D cpufreq_cpu_= get(cpu); struct amd_cpudata *cpudata; union perf_cached perf; =20 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2082a9e4384f..17a5b8e0ea1e 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2231,7 +2231,7 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); =20 /** * cpufreq_driver_adjust_perf - Adjust CPU performance level in one go. - * @cpu: Target CPU. + * @policy: cpufreq policy object of the target CPU. * @min_perf: Minimum (required) performance level (units of @capacity). * @target_perf: Target (desired) performance level (units of @capacity). * @capacity: Capacity of the target CPU. @@ -2250,12 +2250,12 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); * parallel with either ->target() or ->target_index() or ->fast_switch() = for * the same CPU. */ -void cpufreq_driver_adjust_perf(unsigned int cpu, +void cpufreq_driver_adjust_perf(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity) { - cpufreq_driver->adjust_perf(cpu, min_perf, target_perf, capacity); + cpufreq_driver->adjust_perf(policy, min_perf, target_perf, capacity); } =20 /** diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 51938c5a47ca..1552b2d32a34 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -3239,12 +3239,12 @@ static unsigned int intel_cpufreq_fast_switch(struc= t cpufreq_policy *policy, return target_pstate * cpu->pstate.scaling; } =20 -static void intel_cpufreq_adjust_perf(unsigned int cpunum, +static void intel_cpufreq_adjust_perf(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity) { - struct cpudata *cpu =3D all_cpu_data[cpunum]; + struct cpudata *cpu =3D all_cpu_data[policy->cpu]; u64 hwp_cap =3D READ_ONCE(cpu->hwp_cap_cached); int old_pstate =3D cpu->pstate.current_pstate; int cap_pstate, min_pstate, max_pstate, target_pstate; diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index cc894fc38971..4317c5a312bd 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -372,7 +372,7 @@ struct cpufreq_driver { * conditions) scale invariance can be disabled, which causes the * schedutil governor to fall back to the latter. */ - void (*adjust_perf)(unsigned int cpu, + void (*adjust_perf)(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity); @@ -617,7 +617,7 @@ struct cpufreq_governor { /* Pass a target to the cpufreq driver */ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq); -void cpufreq_driver_adjust_perf(unsigned int cpu, +void cpufreq_driver_adjust_perf(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity); diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedu= til.c index 153232dd8276..ae9fd211cec1 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -461,6 +461,7 @@ static void sugov_update_single_perf(struct update_util= _data *hook, u64 time, unsigned int flags) { struct sugov_cpu *sg_cpu =3D container_of(hook, struct sugov_cpu, update_= util); + struct sugov_policy *sg_policy =3D sg_cpu->sg_policy; unsigned long prev_util =3D sg_cpu->util; unsigned long max_cap; =20 @@ -482,10 +483,10 @@ static void sugov_update_single_perf(struct update_ut= il_data *hook, u64 time, if (sugov_hold_freq(sg_cpu) && sg_cpu->util < prev_util) sg_cpu->util =3D prev_util; =20 - cpufreq_driver_adjust_perf(sg_cpu->cpu, sg_cpu->bw_min, + cpufreq_driver_adjust_perf(sg_policy->policy, sg_cpu->bw_min, sg_cpu->util, max_cap); =20 - sg_cpu->sg_policy->last_freq_update_time =3D time; + sg_policy->last_freq_update_time =3D time; } =20 static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 t= ime) diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs index 76faa1ac8501..a83aec198336 100644 --- a/rust/kernel/cpufreq.rs +++ b/rust/kernel/cpufreq.rs @@ -1256,18 +1256,17 @@ impl Registration { /// # Safety /// /// - This function may only be called from the cpufreq C infrastructu= re. + /// - The pointer arguments must be valid pointers. unsafe extern "C" fn adjust_perf_callback( - cpu: c_uint, + ptr: *mut bindings::cpufreq_policy, min_perf: c_ulong, target_perf: c_ulong, capacity: c_ulong, ) { - // SAFETY: The C API guarantees that `cpu` refers to a valid CPU n= umber. - let cpu_id =3D unsafe { CpuId::from_u32_unchecked(cpu) }; - - if let Ok(mut policy) =3D PolicyCpu::from_cpu(cpu_id) { - T::adjust_perf(&mut policy, min_perf, target_perf, capacity); - } + // SAFETY: The `ptr` is guaranteed to be valid by the contract wit= h the C code for the + // lifetime of `policy`. + let policy =3D unsafe { Policy::from_raw_mut(ptr) }; + T::adjust_perf(policy, min_perf, target_perf, capacity); } =20 /// Driver's `get_intermediate` callback. --=20 2.34.1