From nobody Wed Oct 1 20:23:24 2025 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013058.outbound.protection.outlook.com [40.107.201.58]) (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 CEA5325DB1A; Wed, 1 Oct 2025 15:01:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330920; cv=fail; b=o4zbzPjpk/Yp5ZkFDqxmx9aWM56akxU9snR43bpzieScKsJ+20zysGH+rpYe9ES6zard/FtHJ6nd8IZHS/6GmXdJR2Cnx4zVFPoFSqhRPVpPpcIlUdSYkdM+ATbe+8Y73Wj8Bcu/zBt2jRRy1mh16cXS1r/HotQ0CbhdxxBmYFo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330920; c=relaxed/simple; bh=byEGQgda3vlPLeFJBc1dLmn7pJsL1vRoBQ1b+AGcWbY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BLai1LM4qdXgx56lxy7XLHpX7AQ+URqYGrlhLM7Jg7bw1hnf2u/yIj8q7Qtch8uZYlbDQmczOhLNBblREtECiERTzBM9evMZ4g5Zy1P2zl5+X5azhdaTGYJoZi5uyZgsFFsMiWDEmY+uhumQKrSXoLLHOIW2g9bIVHQcIngBlqA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=aUoukFYs; arc=fail smtp.client-ip=40.107.201.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="aUoukFYs" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xV6gMbf5XB6PoYJKXDrIFLlHvok9GWZBnP37M3NCKP2w98Nuo2zZTkyfCYGETuY4fnaNVwb/ADIz2fleq7fGgqeSxzCfM3x8lRGgTRED7+ps4uAzBXEpbmaI+q9USVo+6nQMacMjYGnyGQ9oo9mNFlfp7sPZuMPYeGgHsHNB306yfKZwS8t1VaVWvY9Whx0UycPUK/73TThDNbPgeq4Mp/afQ8IL8mprbfxnt9cJKE8doblDm+yeZ+7zeaSthOg+Kzs0IXlyOuBZrWUONMyuxgxMcbDlg4897c1RM9qbPJ5rv5VhMt6CNfvjtGl8EglDEacEj6+9H4SrZgkSCtLi+g== 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=QKiQlfKM1MsvrfoqoIXi5g9aTUfyXaP70QlfWL0N9Yw=; b=U1AaavOBHN4dnTUAVJzI2oRAerqf81HQdHNriPxEjKtCE45iBRUpy4ciYam169dhUVGeKybxpaDy2NIH2Sp3UPbFucuwQVd5FKnily3JDiWNrIZcyMhHrF5zN+BqaLKOn1KOoxedOiqDkgHDVW4zHRCHP8AN78t7fkU0XckymOCP2U1vVREhiDNcVDl8OEXoWxbis3Yr3yFjCWlQN2vihAlPzmkzQO4uGpyQwd6wbSkYOI4tgn6SH6VQHd/N36wI8qdzHwox4YgX+irCaKGdDWndT1wYzCKAcbW4Vu7DLogx9ZzMfzvfiK9jRm9/OuUV4+eYm7J+H8CSdwJQS87VhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QKiQlfKM1MsvrfoqoIXi5g9aTUfyXaP70QlfWL0N9Yw=; b=aUoukFYs2fIIkmtYX4jMk4WKZpYbwqUWCk0zP9Ul/8oN8aFwsTSgMd80cyunS+duvvZRBUEFG1cldUfM85LkIAJrxjsocyD1Y6DbI4u7WP23z+so6m4H5zYpfgMgYAxEbihMiVoRLz66quuKlg+gJq7qEdg1PULi0Q+wlIv177t8Vk8dkZKNpLRpPOrc2YPefmwGkmkR70p7vH8Yz+7B3n/lMdspCthJ5gqDjhopLXvcZmCSY/nMvmQ3LPzJyV8+e0OlYw5LgmMKxo2c4rsgdhdLY0fwdouxdJrPavNZ5zbSp2sQU4Af5pcNNlr2/JwhyoTi1Et86wvuBS1onOF4ZA== Received: from BL1P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::20) by DS0PR12MB7509.namprd12.prod.outlook.com (2603:10b6:8:137::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.18; Wed, 1 Oct 2025 15:01:56 +0000 Received: from BN2PEPF0000449E.namprd02.prod.outlook.com (2603:10b6:208:2c5:cafe::ef) by BL1P221CA0019.outlook.office365.com (2603:10b6:208:2c5::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9160.17 via Frontend Transport; Wed, 1 Oct 2025 15:01:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF0000449E.mail.protection.outlook.com (10.167.243.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:01:55 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 1 Oct 2025 08:01:25 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:01:25 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:01:18 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 1/8] cpufreq: CPPC: Add generic helpers for sysfs show/store Date: Wed, 1 Oct 2025 20:30:57 +0530 Message-ID: <20251001150104.1275188-2-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF0000449E:EE_|DS0PR12MB7509:EE_ X-MS-Office365-Filtering-Correlation-Id: e71b0798-d20e-49c8-489c-08de00fb7692 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ToXHLcwDotVCtVVTk5SG9Gi8sgzip49FEp72cMt1gUncvj8gOSXDCpPOC7LQ?= =?us-ascii?Q?Pm1VYAgNRc0WQyb5B3pGDsxwsTcqn+BD+IFAIpNiDdd01gnZHfsI9OAYUfb3?= =?us-ascii?Q?z+Whcn5xEhXcFyGM+ZxmUl3yuHXpAhxlVp2gq8lcA6libEGDQmjZo5xXkjdH?= =?us-ascii?Q?IEIyB1ZT1dVN7lqbw+iy7s/IxQ4h07oaYJS0JbwOA9oE73X89hWI/1+bzzV+?= =?us-ascii?Q?LGxuGY+DBX8gnQXd+87VRsZ1q5x7a9VopYZVDTHjNqFEl6YpOaH5CbOKHcNE?= =?us-ascii?Q?+LKQHOlEx+DiLSPzzPNOT854uv4sxXKqF4uxUofsNo8UIAhv51BMzkUTZehj?= =?us-ascii?Q?G39rdvOxpSvUM+4v3SzK/2peMs2PUTSbvUk5qHpTuPgyPhWKUX5x37NHMaHD?= =?us-ascii?Q?ZhAeXtQapAeZwh3Fq70VvhDc+Jd7OicJplB/sCaRiyLQDSD/92eEIbWZ4fZJ?= =?us-ascii?Q?KF4GvX0bY1NTClrp89amfvQyiwTzf71snoWnzzVu9fQowwTbLEQzbhplryMq?= =?us-ascii?Q?oR6xo4eV0RtzaAYtUIs6c4Gt3xO4rG++b8uMcwXib3tnoiZPBuAki2qJAxWQ?= =?us-ascii?Q?ePNTk9r762kqgFwYQ8gklJcwUX8/bqRg7vl0eCFzUDuNgNoleKTJaZkxANNI?= =?us-ascii?Q?cm8BwOjaXVRbGwMOppEKvdPDYWiV7WaBp5N8Eb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l0tO0c2B92vLHuo1URMXTyB/SNsZqXOPbvimMZr/?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(82310400026)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:01:55.7376 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e71b0798-d20e-49c8-489c-08de00fb7692 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF0000449E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7509 Content-Type: text/plain; charset="utf-8" Add generic show/store helper functions for u64 sysfs attributes: - cppc_cpufreq_sysfs_show_u64() - cppc_cpufreq_sysfs_store_u64() Refactor auto_act_window and energy_performance_preference_val attributes to use these helpers, eliminating code duplication. No functional changes. Signed-off-by: Sumit Gupta --- drivers/cpufreq/cppc_cpufreq.c | 87 ++++++++++++++-------------------- 1 file changed, 35 insertions(+), 52 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 12de0ac7bbaf..732f35096991 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -781,6 +781,36 @@ static int cppc_cpufreq_set_boost(struct cpufreq_polic= y *policy, int state) return 0; } =20 +static ssize_t cppc_cpufreq_sysfs_show_u64(unsigned int cpu, int (*get_fun= c)(int, u64 *), char *buf) +{ + u64 val; + int ret =3D get_func(cpu, &val); + + if (ret =3D=3D -EOPNOTSUPP) + return sysfs_emit(buf, "\n"); + if (ret) + return ret; + + return sysfs_emit(buf, "%llu\n", val); +} + +static ssize_t cppc_cpufreq_sysfs_store_u64(const char *buf, size_t count, + int (*set_func)(int, u64), unsigned int cpu) +{ + u64 val; + int ret; + + if (!buf || !set_func) + return -EINVAL; + + ret =3D kstrtou64(buf, 0, &val); + if (ret) + return ret; + + ret =3D set_func((int)cpu, val); + return ret ? ret : count; +} + static ssize_t show_freqdomain_cpus(struct cpufreq_policy *policy, char *b= uf) { struct cppc_cpudata *cpu_data =3D policy->driver_data; @@ -824,70 +854,23 @@ static ssize_t store_auto_select(struct cpufreq_polic= y *policy, =20 static ssize_t show_auto_act_window(struct cpufreq_policy *policy, char *b= uf) { - u64 val; - int ret; - - ret =3D cppc_get_auto_act_window(policy->cpu, &val); - - /* show "" when this register is not supported by cpc */ - if (ret =3D=3D -EOPNOTSUPP) - return sysfs_emit(buf, "\n"); - - if (ret) - return ret; - - return sysfs_emit(buf, "%llu\n", val); + return cppc_cpufreq_sysfs_show_u64(policy->cpu, cppc_get_auto_act_window,= buf); } =20 -static ssize_t store_auto_act_window(struct cpufreq_policy *policy, - const char *buf, size_t count) +static ssize_t store_auto_act_window(struct cpufreq_policy *policy, const = char *buf, size_t count) { - u64 usec; - int ret; - - ret =3D kstrtou64(buf, 0, &usec); - if (ret) - return ret; - - ret =3D cppc_set_auto_act_window(policy->cpu, usec); - if (ret) - return ret; - - return count; + return cppc_cpufreq_sysfs_store_u64(buf, count, cppc_set_auto_act_window,= policy->cpu); } =20 static ssize_t show_energy_performance_preference_val(struct cpufreq_polic= y *policy, char *buf) { - u64 val; - int ret; - - ret =3D cppc_get_epp_perf(policy->cpu, &val); - - /* show "" when this register is not supported by cpc */ - if (ret =3D=3D -EOPNOTSUPP) - return sysfs_emit(buf, "\n"); - - if (ret) - return ret; - - return sysfs_emit(buf, "%llu\n", val); + return cppc_cpufreq_sysfs_show_u64(policy->cpu, cppc_get_epp_perf, buf); } =20 static ssize_t store_energy_performance_preference_val(struct cpufreq_poli= cy *policy, const char *buf, size_t count) { - u64 val; - int ret; - - ret =3D kstrtou64(buf, 0, &val); - if (ret) - return ret; - - ret =3D cppc_set_epp(policy->cpu, val); - if (ret) - return ret; - - return count; + return cppc_cpufreq_sysfs_store_u64(buf, count, cppc_set_epp, policy->cpu= ); } =20 cpufreq_freq_attr_ro(freqdomain_cpus); --=20 2.34.1 From nobody Wed Oct 1 20:23:24 2025 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012046.outbound.protection.outlook.com [52.101.43.46]) (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 DB33B3081D0; Wed, 1 Oct 2025 15:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759331004; cv=fail; b=cxrfunVhNrokeyzrKSzaCBP1tsjig99fXlLJdktZPn6PL/hGAVdzupiAX0UQBk3ZB2rVwGedxBUTnyP6hA3CkZm1PI9n5IBQh3qM1hjttj/zdhqVi3j9VBiSpjSFTD+vGEsthbkLIYQtwdj4zFqsmrdA4XF1K0DpWkj1zTULMv0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759331004; c=relaxed/simple; bh=lufpOUJXWvaXbvydJhhn0TdF/nF0R8B4S1qupX8CDXU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Dr9sTmV7SFg+YhCWJC5LcKRltnq/S1swvwHtuznI23Ewl58uEQ69u3g6MSs8lG/jF8ATQu0cZ/PZOG0w0Kdc/85uOhGDxIoUTqf+5Ywj0e8T20b0CLaI26y9E6WE1t/RtDlRq3tC6NE+XHfJ2gO89t9k4Diu93gKX36/PKLoiW0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=fLn6TB+d; arc=fail smtp.client-ip=52.101.43.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="fLn6TB+d" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ilSTgY3YfwJCfTl+2jQ8ywK5gu1f+JL680o3nUdoyEiYNMcROAaUki0LJ0t/QLsC6Pc+HZFlYK5cq20Gii6Te5gO5Gb7WZkIivgbpTjBFei94PEuA0wCoevojmAxrRvxQcxPwMU5wS9VLLelEvza6Jp/C21+6yvxvgJs7vkiwy0RS2xsbzyK5wY6ZcKRf4b9v+a4RyPvc4dXnPqUPPeJLkw5U729hGTOZveMqC2FIammvIcSZu4gyftGvGlD2TxYNDxnet9hOdd294sOP9hf4cb85A62/NPxdERgX4EOOmi+ld4XwLIF2y+lJs15ibxaGkSskzY8sT/SpkKWEfFamw== 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=svO4lhV5TCA2tVmRgEKBzTMP58G5wZUue61MV76cVzw=; b=JG/xY+Su+xIBwwkyrZCkNvcSiWMvRGMnymZmMT8sdYVxUef8r39jT+47Dr6JbmzGHbMcdXopuemoWyq8oYc09Ucv1bdeQjf8mrZa92ALIc3rHy6flK0uuIAqt6BoPo9Yq+7LTqiqVliwFLLLNEGBusuW7fK3lVse7g8oueD1BuUOMi2bR7zn3RC+D7Q68rrMUVwFVPy3bQ9AgBelSH+wCJ9B/QmBGQ0jadU7OBlvbM5pYzPkh7Glkf60BuJxMiO0Fg1iI5C9U2i/W4TvKLpEohFKjMRAjTY9CD/NsQL7yqKCOVfDa0rE3eKGnvkk4ookGzdpFOfAlVB/IW0vOFXMgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=svO4lhV5TCA2tVmRgEKBzTMP58G5wZUue61MV76cVzw=; b=fLn6TB+dGnGtJ+rjcrkZBf6wjsclUb82Xj4xZAHu4jY5gYSvsvWeMMJBZpNaHTEkA/hKY00J28M1Vs5MGgMEfRxDtZ4JhqJX1BZpObnpov7HVnEzrp8lUtBs75GCXh3MT0BAboF6R5YLzj+hz11ykTRvbsPAC9p1C+6WIrkUPUk9G/dYAysjjzCAvepESg9xYJRjwweU/RSo4hheVpJQ4Tm29Ssj8Lw+nlsnxXDE+Sy7e+jNiGpgG9npguecNDupJxjyvH8xX0+sejf4cwstVbiccJQfflEoOVmJjsWJD3fDUilwHBz3xJ38ILWdK8/NLh/F9Akidhp/1P8/ke/nyg== Received: from BN8PR15CA0024.namprd15.prod.outlook.com (2603:10b6:408:c0::37) by IA0PPF64A94D5DF.namprd12.prod.outlook.com (2603:10b6:20f:fc04::bd0) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.19; Wed, 1 Oct 2025 15:02:00 +0000 Received: from BN1PEPF0000468D.namprd05.prod.outlook.com (2603:10b6:408:c0:cafe::91) by BN8PR15CA0024.outlook.office365.com (2603:10b6:408:c0::37) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:01:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF0000468D.mail.protection.outlook.com (10.167.243.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:01:59 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.34; Wed, 1 Oct 2025 08:01:35 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:01:35 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:01:28 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 2/8] ACPI: CPPC: Add cppc_get_perf() API to read performance controls Date: Wed, 1 Oct 2025 20:30:58 +0530 Message-ID: <20251001150104.1275188-3-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468D:EE_|IA0PPF64A94D5DF:EE_ X-MS-Office365-Filtering-Correlation-Id: b2d495fa-ba96-4070-51bc-08de00fb78d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mysiRG7T5LWck6a1ndomuvZeHHoMN/q9auz409rjCAAIItz+T1QUhQWY7cUa?= =?us-ascii?Q?uxkDvSqpn5wEiE2ZpiEZW4Bu60gi/AWHqNcVGhBpOzZtWbn1JqugFsK8L4UI?= =?us-ascii?Q?nho8JfWydR9qU6pizEruoska0Zo7GNw0AAUQ9zaTtRuOk//wpFssfxDPlGHp?= =?us-ascii?Q?ALV2SOdl5/5/bC+7qvZIdQYFlo+3w5PpFdWa+Pm3H6sOJh3efY7xHMFvyWMC?= =?us-ascii?Q?G/gcT3z5fXyu8J/6hG1g+6wsmGRViLGSmIxfyQIi/1PJFYeh7hJ6PbQclxoc?= =?us-ascii?Q?/5xY0Oe6DXAQrgfbVxzQKWREbSudgHMgcUuKOdHRxfrWi40bHXubnKhlGd0c?= =?us-ascii?Q?qnrWprFZlUk1+fb1cXr3WzqGNrpRA6EIhKD8yqOyZWrCiVXyiGMmHYS0hVcA?= =?us-ascii?Q?LBamyM+OlewVqJbLrapjdy15qUJUlAcyOX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PCWWR5tMb46iizimoIVIKoxuHM8oTvOO5cD2Xn0rFIxKOxyc8d?= =?us-ascii?Q?jTxWjv1H7qnQpsWJsKGYDqN7Lta7MBl1nuI9lUHP2xvaIQC6jcyZEer43vvq?= =?us-ascii?Q?KWG9CE8CIf+I26S/Dyg/QI+jyPbvXrUdUtTMAQwDVwiA6VwDy/OweKLz6KpF?= =?us-ascii?Q?MqxbwAhCG2hNjHViJOLf0rb8zBgGbmf+nd9agNUZarqLz0zgTXWLrFP9sdya?= =?us-ascii?Q?9SwVtaqSPgWWnS0Gp2lf1y1SOCiGEbLPIl6r1pCM?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:01:59.5548 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2d495fa-ba96-4070-51bc-08de00fb78d9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PPF64A94D5DF Content-Type: text/plain; charset="utf-8" Add cppc_get_perf() function to read values of performance control registers including desired_perf, min_perf, max_perf, and energy_perf. This provides a read interface to complement the existing cppc_set_perf() write interface for performance control registers. Signed-off-by: Sumit Gupta --- drivers/acpi/cppc_acpi.c | 73 ++++++++++++++++++++++++++++++++++++++++ include/acpi/cppc_acpi.h | 5 +++ 2 files changed, 78 insertions(+) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 6b649031808f..ab8dd5cdb13b 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1731,6 +1731,79 @@ int cppc_set_enable(int cpu, bool enable) return cppc_set_reg_val(cpu, ENABLE, enable); } EXPORT_SYMBOL_GPL(cppc_set_enable); +/** + * cppc_get_perf - Get a CPU's performance controls. + * @cpu: CPU for which to get performance controls. + * @perf_ctrls: ptr to cppc_perf_ctrls. See cppc_acpi.h + * + * Return: 0 for success with perf_ctrls, -ERRNO otherwise. + */ +int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) +{ + struct cpc_desc *cpc_desc =3D per_cpu(cpc_desc_ptr, cpu); + struct cpc_register_resource *desired_perf_reg, *min_perf_reg, *max_perf_= reg, + *energy_perf_reg; + u64 desired_perf =3D 0, min =3D 0, max =3D 0, energy_perf =3D 0; + int pcc_ss_id =3D per_cpu(cpu_pcc_subspace_idx, cpu); + struct cppc_pcc_data *pcc_ss_data =3D NULL; + int ret =3D 0, regs_in_pcc =3D 0; + + if (!cpc_desc) { + pr_debug("No CPC descriptor for CPU:%d\n", cpu); + return -ENODEV; + } + + if (!perf_ctrls) { + pr_debug("Invalid perf_ctrls pointer\n"); + return -EINVAL; + } + + desired_perf_reg =3D &cpc_desc->cpc_regs[DESIRED_PERF]; + min_perf_reg =3D &cpc_desc->cpc_regs[MIN_PERF]; + max_perf_reg =3D &cpc_desc->cpc_regs[MAX_PERF]; + energy_perf_reg =3D &cpc_desc->cpc_regs[ENERGY_PERF]; + + /* Are any of the regs PCC ?*/ + if (CPC_IN_PCC(desired_perf_reg) || CPC_IN_PCC(min_perf_reg) || + CPC_IN_PCC(max_perf_reg) || CPC_IN_PCC(energy_perf_reg)) { + if (pcc_ss_id < 0) { + pr_debug("Invalid pcc_ss_id for CPU:%d\n", cpu); + return -ENODEV; + } + pcc_ss_data =3D pcc_data[pcc_ss_id]; + regs_in_pcc =3D 1; + down_write(&pcc_ss_data->pcc_lock); + /* Ring doorbell once to update PCC subspace */ + if (send_pcc_cmd(pcc_ss_id, CMD_READ) < 0) { + pr_debug("Failed to send PCC command for CPU:%d, ret:%d\n", cpu, ret); + ret =3D -EIO; + goto out_err; + } + } + + /* Read optional elements if present */ + if (CPC_SUPPORTED(max_perf_reg)) + cpc_read(cpu, max_perf_reg, &max); + perf_ctrls->max_perf =3D max; + + if (CPC_SUPPORTED(min_perf_reg)) + cpc_read(cpu, min_perf_reg, &min); + perf_ctrls->min_perf =3D min; + + if (CPC_SUPPORTED(desired_perf_reg)) + cpc_read(cpu, desired_perf_reg, &desired_perf); + perf_ctrls->desired_perf =3D desired_perf; + + if (CPC_SUPPORTED(energy_perf_reg)) + cpc_read(cpu, energy_perf_reg, &energy_perf); + perf_ctrls->energy_perf =3D energy_perf; + +out_err: + if (regs_in_pcc) + up_write(&pcc_ss_data->pcc_lock); + return ret; +} +EXPORT_SYMBOL_GPL(cppc_get_perf); =20 /** * cppc_set_perf - Set a CPU's performance controls. diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 20f3d62e7a16..213bd389ec57 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -151,6 +151,7 @@ extern int cppc_get_desired_perf(int cpunum, u64 *desir= ed_perf); extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf); extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf); extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_c= trs); +extern int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls); extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls); extern int cppc_set_enable(int cpu, bool enable); extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps); @@ -192,6 +193,10 @@ static inline int cppc_get_perf_ctrs(int cpu, struct c= ppc_perf_fb_ctrs *perf_fb_ { return -EOPNOTSUPP; } +static inline int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrl= s) +{ + return -EOPNOTSUPP; +} static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrl= s) { return -EOPNOTSUPP; --=20 2.34.1 From nobody Wed Oct 1 20:23:25 2025 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010053.outbound.protection.outlook.com [52.101.85.53]) (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 D0CED2765EA; Wed, 1 Oct 2025 15:02:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330950; cv=fail; b=ppDeUEA75PBLSJT7yyQ1r1aWHUnQW0VIp724oMqfop6FUdk+2exnfe/q0yTOGbaNTZGfX8RRGR1tdluiXOgAWyRT685uXo+MqytALYhRKoa69NAFlUVN7e7NUI9O+cVzAP52mFdncwuuOwVf+P9b1ckz0XkBCNTlLrArlO83bT4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330950; c=relaxed/simple; bh=kyb94L8u2/ZLMgXVCeBDYv2Yqhtb9TLGwOzPwSl2ejg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eMWWGyuiq7GPgZzPj4Zm49bnhe0LgK5+czD1DIoVakf8/MHuB59GpBivcRRJJJx5ojRrDZ67F+m4N/cD8BUYiryBMVqz06pHdz/gZm0UJjR9jTATQOE5aETAh76a6AcD9/OhN3Oy5NzyAEbAitNGir0ZcqUTDuUbkH+fpOxwyzs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=dAry4pFD; arc=fail smtp.client-ip=52.101.85.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="dAry4pFD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qCbbR5DTbd5w7nkNVfwR94HoUL8k6RuD8WBTIwrQ3hRc2M+GRJbXt+wrZo8zb5/HqentxITdBbeR/Y5+mLsWLNTJLT8GbI9vuWT+tglTwUnY2gkZB5Q7VGbiPYlpqphIWwdftu5OZFx/6C7rcyqabZ/xwxw5sYDEK3qJVEMJ4nBLoERZbAaVtiWSCWWhLf39Xp6gKE+2EME1WGNkZWgn/Q1+smRb7R4OcgpTpwMH0lHag13xow91SLfeCdjakuX6dpF1CbyTLCbfw0Y8Y9DpjEK2qVRrFEhUme2uBhbv952l7glxHMuKgnLFTkjEoNUd92fQ2voYExh5FRlvE445mw== 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=k10XumIXl8XGtEvPU8QcvMiIzkrvFhG18hLdNilnd8M=; b=Fsg7DkJhefo6WqMQUOKj6Sawxf5Sqh6vFCfbJS8Z40fWiXJo6d/bNDtP8ERztewXbEbRgfXXM18brTudFC9uhqq0F7WRkQawlQGl6Kvm45SXOA69GnCpY5lWfsVvpDZEZdOKV3+qlRHVC+sXLHPMiz3uotqNbyqcFoI0sqW+l9kPT3XXRPO7b5bfAN7HwGWFh644FWs6zmHtg+MhC8AxycfaVYOej+kKprqqvLQv2kQ+8g8YnsIcBq4wlkWi4gAg3BEXdfihZFs4t0kGFVynYdHIQz3KkQyz6421Mfn9r0VX4ERlGbt4nx6uMD1mbVZY68ZRNkWWsUb+xudJ9GRshg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k10XumIXl8XGtEvPU8QcvMiIzkrvFhG18hLdNilnd8M=; b=dAry4pFDJBXdaX9zR9fiNys8GGPKxes5Jg6xj1yuNOxHBzJ6L2Y1y2qKJUoWZDo9DiI5yMJatVVk0F4CrK43rBzSHpR5dsNq01f4mgUMZJcTtcQLfjEINne1/qrxjiYqzfjFp5n0zJf7pkgyHsGgC5b6NVRO3C6wEPiQS6HsTqfOMouvWDR2gIL/pGKpB4CHb6rVv/prrZ0tc0h//9lU1wpX7DI1f2u6mWIftADeafL6cTSbATp1O1mgn4etHCS8WHa5zUfQrVMDeCHSt75pTZ1Z4kXr+wrANS8Sg/I7ZpLyEKdsIPp8NJxEghuTr8kYyjhZRW7Syu+75P6UfsToaQ== Received: from BL1PR13CA0233.namprd13.prod.outlook.com (2603:10b6:208:2bf::28) by MN2PR12MB4176.namprd12.prod.outlook.com (2603:10b6:208:1d5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.16; Wed, 1 Oct 2025 15:02:24 +0000 Received: from BN1PEPF0000468E.namprd05.prod.outlook.com (2603:10b6:208:2bf:cafe::5b) by BL1PR13CA0233.outlook.office365.com (2603:10b6:208:2bf::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9182.14 via Frontend Transport; Wed, 1 Oct 2025 15:02:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF0000468E.mail.protection.outlook.com (10.167.243.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:02:24 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.34; Wed, 1 Oct 2025 08:02:00 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:01:49 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:01:42 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 3/8] ACPI: CPPC: extend APIs to support auto_sel and epp Date: Wed, 1 Oct 2025 20:30:59 +0530 Message-ID: <20251001150104.1275188-4-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468E:EE_|MN2PR12MB4176:EE_ X-MS-Office365-Filtering-Correlation-Id: a6bddc3f-c7fc-49cf-bb18-08de00fb877e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?XQpZU2qbFMjlgS6QKozgjXA/cdiz5x7oHsSjuY60A9c6VUW0t2AEaV3wVNQs?= =?us-ascii?Q?RatxpPC0RV5Z7/oE/7RvdFL/qhzhvPZtlc12PCWVj+3apAFih91U7nWlxd5t?= =?us-ascii?Q?9jZcUVxoSpyd/QMiQrhblCfku6O1ey14oFVbRXoIslE+ky/i53IH9xl2T2fw?= =?us-ascii?Q?BrjcS3iBll04qqPru11V71KLMW8/RiJ3mxNCO+paalqKCzLslIUJ3+dN17AO?= =?us-ascii?Q?P+GxzY3uctBfJIVIRBXqsqT2kAWFUCFAUYo7jfuurWy6Akn8wFwf74Luzn5p?= =?us-ascii?Q?4DvnvBbXu0P5QgP/ZVox0ubB973ECBf4QtJ6dPAGe02rberOXXHKLLBrd09c?= =?us-ascii?Q?hcs0LV+wpp7gi9dtCCZbb8+Wsq/kZ0RUQ6I9uoqWht6Q3IxWwRMWHJdCEXwr?= =?us-ascii?Q?iSM7Z5/dQIuHecGNvxNUkNu8Gs0jgLP8z9wqYn5/5VFeSH5tXb7xhjJMNBt2?= =?us-ascii?Q?Qzd9/dQsVmfSaQNdEOiOMYIeZ1DyLkCl+1yNG3CCdUCHXa9OD///Mw+QfRSX?= =?us-ascii?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KfImYHuAdpL3LrlXGql?= =?us-ascii?Q?JEULcohG/xww4yJqqkAAVLeLzWiguRYHVjckuleIezmtqXIys3CGksi/wjhI?= =?us-ascii?Q?b4lXJo6gtVhGlNFJk2zRwDh1I1GmewMlSVE0RIJT74bsvFZ0ZTLBTK+lq62E?= =?us-ascii?Q?I/fc7M3tUR2xtZ8KHGZ5MfzGzLfw7qmw/HC1T0h/?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:02:24.1286 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6bddc3f-c7fc-49cf-bb18-08de00fb877e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4176 Content-Type: text/plain; charset="utf-8" - Add auto_sel read support in cppc_get_perf_caps(). - Add write of both auto_sel and energy_perf in cppc_set_epp_perf(). - Remove redundant energy_perf field from 'struct cppc_perf_caps' as the same is available in 'struct cppc_perf_ctrls' which is used. Signed-off-by: Sumit Gupta --- drivers/acpi/cppc_acpi.c | 30 ++++++++++++++++++++++++++---- include/acpi/cppc_acpi.h | 1 - 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index ab8dd5cdb13b..12b2516b971c 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1344,8 +1344,8 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_c= aps *perf_caps) struct cpc_desc *cpc_desc =3D per_cpu(cpc_desc_ptr, cpunum); struct cpc_register_resource *highest_reg, *lowest_reg, *lowest_non_linear_reg, *nominal_reg, *guaranteed_reg, - *low_freq_reg =3D NULL, *nom_freq_reg =3D NULL; - u64 high, low, guaranteed, nom, min_nonlinear, low_f =3D 0, nom_f =3D 0; + *low_freq_reg =3D NULL, *nom_freq_reg =3D NULL, *auto_sel_reg =3D NULL; + u64 high, low, guaranteed, nom, min_nonlinear, low_f =3D 0, nom_f =3D 0, = auto_sel =3D 0; int pcc_ss_id =3D per_cpu(cpu_pcc_subspace_idx, cpunum); struct cppc_pcc_data *pcc_ss_data =3D NULL; int ret =3D 0, regs_in_pcc =3D 0; @@ -1362,11 +1362,12 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf= _caps *perf_caps) low_freq_reg =3D &cpc_desc->cpc_regs[LOWEST_FREQ]; nom_freq_reg =3D &cpc_desc->cpc_regs[NOMINAL_FREQ]; guaranteed_reg =3D &cpc_desc->cpc_regs[GUARANTEED_PERF]; + auto_sel_reg =3D &cpc_desc->cpc_regs[AUTO_SEL_ENABLE]; =20 /* Are any of the regs PCC ?*/ if (CPC_IN_PCC(highest_reg) || CPC_IN_PCC(lowest_reg) || CPC_IN_PCC(lowest_non_linear_reg) || CPC_IN_PCC(nominal_reg) || - CPC_IN_PCC(low_freq_reg) || CPC_IN_PCC(nom_freq_reg)) { + CPC_IN_PCC(low_freq_reg) || CPC_IN_PCC(nom_freq_reg) || CPC_IN_PCC(auto_= sel_reg)) { if (pcc_ss_id < 0) { pr_debug("Invalid pcc_ss_id\n"); return -ENODEV; @@ -1414,6 +1415,9 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_c= aps *perf_caps) perf_caps->lowest_freq =3D low_f; perf_caps->nominal_freq =3D nom_f; =20 + if (CPC_SUPPORTED(auto_sel_reg)) + cpc_read(cpunum, auto_sel_reg, &auto_sel); + perf_caps->auto_sel =3D (bool)auto_sel; =20 out_err: if (regs_in_pcc) @@ -1555,6 +1559,8 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls= *perf_ctrls, bool enable) struct cpc_register_resource *auto_sel_reg; struct cpc_desc *cpc_desc =3D per_cpu(cpc_desc_ptr, cpu); struct cppc_pcc_data *pcc_ss_data =3D NULL; + bool autosel_support_in_ffh_or_sysmem; + bool epp_support_in_ffh_or_sysmem; int ret; =20 if (!cpc_desc) { @@ -1565,6 +1571,11 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrl= s *perf_ctrls, bool enable) auto_sel_reg =3D &cpc_desc->cpc_regs[AUTO_SEL_ENABLE]; epp_set_reg =3D &cpc_desc->cpc_regs[ENERGY_PERF]; =20 + epp_support_in_ffh_or_sysmem =3D CPC_SUPPORTED(epp_set_reg) && + (CPC_IN_FFH(epp_set_reg) || CPC_IN_SYSTEM_MEMORY(epp_set_reg)); + autosel_support_in_ffh_or_sysmem =3D CPC_SUPPORTED(auto_sel_reg) && + (CPC_IN_FFH(auto_sel_reg) || CPC_IN_SYSTEM_MEMORY(auto_sel_reg)); + if (CPC_IN_PCC(epp_set_reg) || CPC_IN_PCC(auto_sel_reg)) { if (pcc_ss_id < 0) { pr_debug("Invalid pcc_ss_id for CPU:%d\n", cpu); @@ -1590,8 +1601,19 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrl= s *perf_ctrls, bool enable) ret =3D send_pcc_cmd(pcc_ss_id, CMD_WRITE); up_write(&pcc_ss_data->pcc_lock); } else if (osc_cpc_flexible_adr_space_confirmed && - CPC_SUPPORTED(epp_set_reg) && CPC_IN_FFH(epp_set_reg)) { + epp_support_in_ffh_or_sysmem && autosel_support_in_ffh_or_sysmem) { + ret =3D cpc_write(cpu, auto_sel_reg, enable); + if (ret) { + pr_debug("Failed to write auto_sel=3D%d for CPU:%d\n", enable, cpu); + return ret; + } + ret =3D cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf); + if (ret) { + pr_debug("Failed to write energy_perf=3D%u for CPU:%d\n", + perf_ctrls->energy_perf, cpu); + return ret; + } } else { ret =3D -ENOTSUPP; pr_debug("_CPC in PCC and _CPC in FFH are not supported\n"); diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 213bd389ec57..3babc6d6e70a 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -119,7 +119,6 @@ struct cppc_perf_caps { u32 lowest_nonlinear_perf; u32 lowest_freq; u32 nominal_freq; - u32 energy_perf; bool auto_sel; }; =20 --=20 2.34.1 From nobody Wed Oct 1 20:23:25 2025 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010033.outbound.protection.outlook.com [52.101.56.33]) (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 56C85304BB2; Wed, 1 Oct 2025 15:02:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.33 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330964; cv=fail; b=PyOnZg8Lw3lZ8cAcJLcDNuVnEQS8DR5pT9t9GXkERlazb4kM1jAzvsOjch5XWhtVGNgJYQqjFmxD/PmcmlQ6q0gmfSBFf9xAZW71F/x+WY+KE7vQruWkmzF3QwwYqQo1AUzXgHJrZPSgBYLWyppEpeDtIMTm+5zxq2VXqVlze/A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330964; c=relaxed/simple; bh=YNETxuSbbGlJHC8WVMv5YrEGu1yI5Y1+aZgXjXgeqoc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y8dXYx+n/Y0hGxuXGgCAjiD/Q537KPbizoyiQjrlWueEDAnp2JOMJjD+5d7s/hVIb+X4Og9f/hrFrSL7QlV9b6XCbb06N6wc/7D0laq+bECmsLjYsacZ12xImB0igUA+zikyHMRMUP9WXUYTuCv0lgH04ZAaU9YFczftga0aurk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ciK9xGGs; arc=fail smtp.client-ip=52.101.56.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ciK9xGGs" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MNJJZVrryKghfvOGM9Qgnt/gtJoUmwltUeR5Q7lK1+6HYF1Hv5O/mZyxDY7tTfLiC/xt1GzEEUklQ038gsy9DkOk+TDru/jN8kJY9l8U8Js2jQ4/6Am9e7vWx4heQ9KIRlDCy+w2S4D7iOt3/EYKrtgJWLgr+V0mtT5EZMm/jXczmP6/dqmMTCG6hLvGYH/SGnMG9gQigbgmhA7YxQgX6mKQrZDji9DIURorKKbGUFt/Boy6qiVsP+zqVDSybwPuCvXLB+gwDSk5uKm83nMxrmco1vTCynlZF9Vz6EWCUZCITCa5jgCavORYBs/bCiA813M7kG3PlCiZ1v/WPV5E0w== 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=HpOpbH3erulXBksZv9dDNnoOh5tyiZ88/zhwRPq74sY=; b=w+RYwcC9iuuabEat68ydCQ/K/hrRzPzvfu80m37YaFP2Xk4lyoyHUccLUm24dze/m1nbKJMtrZv5GE/l7r/BOTyA+ovEkMbDeL87yo41aoIhNJn/4DJtffcfnolwyOsDEXn9WHEv2alnXyv6PLU5V9LfBjowm/V3JMZ66+MmF5O+Pk090F9qYJAhL7Y2jVz1BOhYE4d6aiWHl/Uu0GOHcRDDs0xG7PTeiW1NR/tt1XnlJAsAw2eBG0FSz9kEB2pEh4jNX9eELSTkUKiCt2NaFXLqJdGtd6Nh9lYPlGDmMv6Nzzu9HYDUYM6ZLftVZO1QEa4NWT3DTvYQxp5yWPA/9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HpOpbH3erulXBksZv9dDNnoOh5tyiZ88/zhwRPq74sY=; b=ciK9xGGsNT2gF57MdtNNEJNTiP8b2jCCbN4bwbKs5cg8ABnFVkBymTJ6YuFnOwoTIqH11pXwnhV82KKLG06zIOOWpowdYOVoPn+ZEU8oNUIQMsPqVuPqpdyKBMJmsp2nnL/k9CCKW0hX9H/GhvLer0ayYxsZRpCOMMt9OAcM4Ye3TQ8h8CgoSHHPziJ03I8IkAMUWhtH59fGVnk1kvhz8ftaegU6Y/PY6W391VmZcYRfJux0Z2G84uV7D8G1eiV9fEZ97Fec7G3Xdlx7ihubdvK/yKPbom+VTYqUmfEPRPtbasO1PUdk2cjQmCsc3iYfPwWjz42TqXMaK+Dr4ddbSg== Received: from MN2PR20CA0066.namprd20.prod.outlook.com (2603:10b6:208:235::35) by CY5PR12MB6621.namprd12.prod.outlook.com (2603:10b6:930:43::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.11; Wed, 1 Oct 2025 15:02:27 +0000 Received: from BN2PEPF000044A1.namprd02.prod.outlook.com (2603:10b6:208:235:cafe::98) by MN2PR20CA0066.outlook.office365.com (2603:10b6:208:235::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9160.18 via Frontend Transport; Wed, 1 Oct 2025 15:02:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF000044A1.mail.protection.outlook.com (10.167.243.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:02:25 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 1 Oct 2025 08:01:59 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:01:59 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:01:52 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 4/8] ACPI: CPPC: add APIs and sysfs interface for min/max_perf Date: Wed, 1 Oct 2025 20:31:00 +0530 Message-ID: <20251001150104.1275188-5-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A1:EE_|CY5PR12MB6621:EE_ X-MS-Office365-Filtering-Correlation-Id: adc3413c-82c0-41a9-9e11-08de00fb8823 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|7416014|376014|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?meWcb29jOXGUnDQvYOwiU+PYBLw0s7VoPwkzOKRkesF2Tb8eCwYnF0Qau+dr?= =?us-ascii?Q?0f+o+DlZNdEi7O2YZ7Em38rFKCyRz6pfajS1rpOIayW/nedN+j/NaRK4GZye?= =?us-ascii?Q?veWUApAv8uLqK/dSTps1+FGZqrTLzsjL165vmALcM9J2PckZgt6z0fPdAIgB?= =?us-ascii?Q?AxUQVpGmnEbOMIpnJTLv0metRWovnNDfwxXCs8MVjurKrmBH+wNHHgIEBCEk?= =?us-ascii?Q?qM9IjKEevB3HuDMJywfrkjf2n/ozCkgaKc/7q7JHekrWdf3NAo7hYmyTWT9O?= =?us-ascii?Q?jXDlNFArLmGcq2WoLSCJfW+81tjTVxSat8x6kOWrihRBQ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/AbeC1nuIWwUoSyPnJM2bPCNjKzB8pGMTGPQ?= =?us-ascii?Q?YByi00MIVJCoCYJFRTkGCP69HBcaT/tBBejNAYvVy9G69r4qpr5O80kGMJwN?= =?us-ascii?Q?50vmwktXe0NwBpgNSeG1+56O1x9xljHJJGPJbQE7OuPwwQGWetujmlfB2zpw?= =?us-ascii?Q?naPOXokoCHCWrIsBKq6kJ1NaapnU5JcWp8cghA7Hmtak/wiWHKNbvp2c3O9l?= =?us-ascii?Q?pt+k3EQHfbYzzGzKdipjEi1Ku3BGQ3yJgsVHlsvLJELt6DJ3INwlJn/rP5U8?= =?us-ascii?Q?r921Fa7vMHJt+QB5IrQCP82j7i4tV7p2gvqogUuIsSy21m946Dv9nSTpm04o?= =?us-ascii?Q?2QPCDbNR5/Z7qOY0j5M7YsTctQTm/u7j3flVRfaJ?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(7416014)(376014)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:02:25.2055 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adc3413c-82c0-41a9-9e11-08de00fb8823 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A1.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6621 Content-Type: text/plain; charset="utf-8" CPPC allows platforms to specify minimum and maximum performance limits that constrain the operating range for CPU performance scaling when Autonomous Selection is enabled. These limits can be dynamically adjusted to implement power management policies or workload-specific optimizations. Add cppc_get_min_perf() and cppc_set_min_perf() functions to read and write the MIN_PERF register, allowing dynamic adjustment of the minimum performance floor. Add cppc_get_max_perf() and cppc_set_max_perf() functions to read and write the MAX_PERF register, enabling dynamic ceiling control for maximum performance. Expose these capabilities through cpufreq sysfs attributes: - /sys/.../cpufreq/policy*/min_perf: Read/write min performance limit - /sys/.../cpufreq/policy*/max_perf: Read/write max performance limit Also update EPP constants for better clarity: - Rename CPPC_ENERGY_PERF_MAX to CPPC_EPP_ENERGY_EFFICIENCY_PREF - Add CPPC_EPP_PERFORMANCE_PREF for the performance-oriented setting Signed-off-by: Sumit Gupta --- drivers/acpi/cppc_acpi.c | 55 +++++++++++++++- drivers/cpufreq/cppc_cpufreq.c | 115 +++++++++++++++++++++++++++++++++ include/acpi/cppc_acpi.h | 23 ++++++- 3 files changed, 191 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 12b2516b971c..d47aec2aed13 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1630,7 +1630,7 @@ EXPORT_SYMBOL_GPL(cppc_set_epp_perf); */ int cppc_set_epp(int cpu, u64 epp_val) { - if (epp_val > CPPC_ENERGY_PERF_MAX) + if (epp_val > CPPC_EPP_ENERGY_EFFICIENCY_PREF) return -EINVAL; =20 return cppc_set_reg_val(cpu, ENERGY_PERF, epp_val); @@ -1753,6 +1753,59 @@ int cppc_set_enable(int cpu, bool enable) return cppc_set_reg_val(cpu, ENABLE, enable); } EXPORT_SYMBOL_GPL(cppc_set_enable); + +/** + * cppc_get_min_perf - Get the min performance register value. + * @cpu: CPU from which to get min performance. + * @min_perf: Return address. + * + * Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if = not supported. + */ +int cppc_get_min_perf(int cpu, u64 *min_perf) +{ + return cppc_get_reg_val(cpu, MIN_PERF, min_perf); +} +EXPORT_SYMBOL_GPL(cppc_get_min_perf); + +/** + * cppc_set_min_perf() - Write the min performance register. + * @cpu: CPU on which to write register. + * @min_perf: Value to write to the MIN_PERF register. + * + * Return: 0 for success, -EIO otherwise. + */ +int cppc_set_min_perf(int cpu, u64 min_perf) +{ + return cppc_set_reg_val(cpu, MIN_PERF, min_perf); +} +EXPORT_SYMBOL_GPL(cppc_set_min_perf); + +/** + * cppc_get_max_perf - Get the max performance register value. + * @cpu: CPU from which to get max performance. + * @max_perf: Return address. + * + * Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if = not supported. + */ +int cppc_get_max_perf(int cpu, u64 *max_perf) +{ + return cppc_get_reg_val(cpu, MAX_PERF, max_perf); +} +EXPORT_SYMBOL_GPL(cppc_get_max_perf); + +/** + * cppc_set_max_perf() - Write the max performance register. + * @cpu: CPU on which to write register. + * @max_perf: Value to write to the MAX_PERF register. + * + * Return: 0 for success, -EIO otherwise. + */ +int cppc_set_max_perf(int cpu, u64 max_perf) +{ + return cppc_set_reg_val(cpu, MAX_PERF, max_perf); +} +EXPORT_SYMBOL_GPL(cppc_set_max_perf); + /** * cppc_get_perf - Get a CPU's performance controls. * @cpu: CPU for which to get performance controls. diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 732f35096991..864978674efc 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -23,6 +23,7 @@ #include =20 #include +#include =20 #include =20 @@ -38,6 +39,8 @@ static enum { module_param(fie_disabled, int, 0444); MODULE_PARM_DESC(fie_disabled, "Disable Frequency Invariance Engine (FIE)"= ); =20 +static DEFINE_MUTEX(cppc_cpufreq_update_autosel_config_lock); + /* Frequency invariance support */ struct cppc_freq_invariance { int cpu; @@ -572,6 +575,70 @@ static void cppc_cpufreq_put_cpu_data(struct cpufreq_p= olicy *policy) policy->driver_data =3D NULL; } =20 +/** + * cppc_cpufreq_set_mperf_limit - Generic function to set min/max performa= nce limit + * @policy: cpufreq policy + * @val: performance value to set + * @update_reg: whether to update hardware register + * @update_policy: whether to update policy constraints + * @is_min: true for min_perf, false for max_perf + */ +static int cppc_cpufreq_set_mperf_limit(struct cpufreq_policy *policy, u64= val, + bool update_reg, bool update_policy, bool is_min) +{ + struct cppc_cpudata *cpu_data =3D policy->driver_data; + struct cppc_perf_caps *caps =3D &cpu_data->perf_caps; + unsigned int cpu =3D policy->cpu; + struct freq_qos_request *req; + unsigned int freq; + u32 perf; + int ret; + + perf =3D clamp(val, caps->lowest_perf, caps->highest_perf); + freq =3D cppc_perf_to_khz(caps, perf); + + pr_debug("cpu%d, %s_perf:%llu, update_reg:%d, update_policy:%d\n", cpu, + is_min ? "min" : "max", (u64)perf, update_reg, update_policy); + + guard(mutex)(&cppc_cpufreq_update_autosel_config_lock); + + if (update_reg) { + ret =3D is_min ? cppc_set_min_perf(cpu, perf) : cppc_set_max_perf(cpu, p= erf); + if (ret =3D=3D -EOPNOTSUPP) + return 0; + if (ret) { + pr_warn("Failed to set %s_perf (%llu) on CPU%d (%d)\n", + is_min ? "min" : "max", (u64)perf, cpu, ret); + return ret; + } + + /* Update cached value only on success */ + if (is_min) + cpu_data->perf_ctrls.min_perf =3D perf; + else + cpu_data->perf_ctrls.max_perf =3D perf; + } + + if (update_policy) { + req =3D is_min ? policy->min_freq_req : policy->max_freq_req; + + ret =3D freq_qos_update_request(req, freq); + if (ret < 0) { + pr_warn("Failed to update %s_freq constraint for CPU%d: %d\n", + is_min ? "min" : "max", cpu, ret); + return ret; + } + } + + return 0; +} + +#define cppc_cpufreq_set_min_perf(policy, val, update_reg, update_policy) \ + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, true) + +#define cppc_cpufreq_set_max_perf(policy, val, update_reg, update_policy) \ + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, fals= e) + static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) { unsigned int cpu =3D policy->cpu; @@ -873,16 +940,64 @@ static ssize_t store_energy_performance_preference_va= l(struct cpufreq_policy *po return cppc_cpufreq_sysfs_store_u64(buf, count, cppc_set_epp, policy->cpu= ); } =20 +static ssize_t show_min_perf(struct cpufreq_policy *policy, char *buf) +{ + return cppc_cpufreq_sysfs_show_u64(policy->cpu, cppc_get_min_perf, buf); +} + +static ssize_t store_min_perf(struct cpufreq_policy *policy, const char *b= uf, size_t count) +{ + struct cppc_cpudata *cpu_data =3D policy->driver_data; + u64 val; + int ret; + + ret =3D kstrtou64(buf, 0, &val); + if (ret) + return ret; + + ret =3D cppc_cpufreq_set_min_perf(policy, val, true, cpu_data->perf_caps.= auto_sel); + if (ret) + return ret; + + return count; +} + +static ssize_t show_max_perf(struct cpufreq_policy *policy, char *buf) +{ + return cppc_cpufreq_sysfs_show_u64(policy->cpu, cppc_get_max_perf, buf); +} + +static ssize_t store_max_perf(struct cpufreq_policy *policy, const char *b= uf, size_t count) +{ + struct cppc_cpudata *cpu_data =3D policy->driver_data; + u64 val; + int ret; + + ret =3D kstrtou64(buf, 0, &val); + if (ret) + return ret; + + ret =3D cppc_cpufreq_set_max_perf(policy, val, true, cpu_data->perf_caps.= auto_sel); + if (ret) + return ret; + + return count; +} + cpufreq_freq_attr_ro(freqdomain_cpus); cpufreq_freq_attr_rw(auto_select); cpufreq_freq_attr_rw(auto_act_window); cpufreq_freq_attr_rw(energy_performance_preference_val); +cpufreq_freq_attr_rw(min_perf); +cpufreq_freq_attr_rw(max_perf); =20 static struct freq_attr *cppc_cpufreq_attr[] =3D { &freqdomain_cpus, &auto_select, &auto_act_window, &energy_performance_preference_val, + &min_perf, + &max_perf, NULL, }; =20 diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 3babc6d6e70a..fc7614eb9dcb 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -39,7 +39,8 @@ /* CPPC_AUTO_ACT_WINDOW_MAX_SIG is 127, so 128 and 129 will decay to 127 w= hen writing */ #define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129 =20 -#define CPPC_ENERGY_PERF_MAX (0xFF) +#define CPPC_EPP_PERFORMANCE_PREF 0x00 +#define CPPC_EPP_ENERGY_EFFICIENCY_PREF 0xFF =20 /* Each register has the folowing format. */ struct cpc_reg { @@ -172,6 +173,10 @@ extern int cppc_get_auto_act_window(int cpu, u64 *auto= _act_window); extern int cppc_set_auto_act_window(int cpu, u64 auto_act_window); extern int cppc_get_auto_sel(int cpu, bool *enable); extern int cppc_set_auto_sel(int cpu, bool enable); +extern int cppc_get_min_perf(int cpu, u64 *min_perf); +extern int cppc_set_min_perf(int cpu, u64 min_perf); +extern int cppc_get_max_perf(int cpu, u64 *max_perf); +extern int cppc_set_max_perf(int cpu, u64 max_perf); extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf); extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator); extern int amd_detect_prefcore(bool *detected); @@ -264,6 +269,22 @@ static inline int cppc_set_auto_sel(int cpu, bool enab= le) { return -EOPNOTSUPP; } +static inline int cppc_get_min_perf(int cpu, u64 *min_perf) +{ + return -EOPNOTSUPP; +} +static inline int cppc_set_min_perf(int cpu, u64 min_perf) +{ + return -EOPNOTSUPP; +} +static inline int cppc_get_max_perf(int cpu, u64 *max_perf) +{ + return -EOPNOTSUPP; +} +static inline int cppc_set_max_perf(int cpu, u64 max_perf) +{ + return -EOPNOTSUPP; +} static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) { return -ENODEV; --=20 2.34.1 From nobody Wed Oct 1 20:23:25 2025 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012009.outbound.protection.outlook.com [52.101.48.9]) (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 26112306D54; Wed, 1 Oct 2025 15:03:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.48.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330982; cv=fail; b=EPiwsP7/j3zrcA+PzHglnZcwfxyQ7DEcEwDXfmT+lNNjptG9PC1OLPFsRfUPnVBDfprdA9l8Vl382QRCNRCJAhpxnRlSX2a4rJ7pEnCtNTgc8fTQPxvB/9BMbM9liFusWof1nmE4yvohlVPm8jpJFAu3PePbx6Ih2XOEUeOgGAY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330982; c=relaxed/simple; bh=LRTyGRKYlbLZ+OMrfMzOP7otqb/W/Ovf1/IdK+XdNXw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iwvHuH1mxovHyxsisx/Nu0G1qr6yTviTc+GzwYiYKsOYK5o9vmPPQVTbCN+jN58bkCVWdbGjQLPLskBDX6O5kcx1cJZ0wBBxiyeIwdzr1PkS85V4dHL1UMDkJ0rSMpItbed64+6ZYURrwpb3TzWFVXK355KIAdOLBAn7MZ3/wzo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RLm0DxKB; arc=fail smtp.client-ip=52.101.48.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RLm0DxKB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HfUQJnc65r5wJn2K70kjHlmRr8WkDlIKY6RXANUQ7x38kh5W4/a/4aHbFp1tERIc6qzHpW/HeVO4bntIYpcEAHRDBQNp9X30kPf0Ad3afsDxSWmYA98oc/OUPQNyKFbHQchqNry6/fcSWXgFVFfGnF1aotUHgz5QqITI0UCFBf4y7xEGexLbXfQa+O3ErZJSwVIZ/JRUWPzbC/6UHwfleImcj0tCT7s5PhDslMsNVVGMG034lWK9poZk+lTeU5ObanB2RUJY3KOGj0+rfzmQtAVntTJvH3aqM5NpNmi/i1SAuFhsmQ7BZOnrlGoIVTcyskrE8fAhlznkYBFCN5fo0g== 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=cG9NZRBBs7Wou3cFVnB2ubD8+FHVk0nwEykCqTRz+e0=; b=U3KcfUyTMEvGF4w45+sBqXtBULcuZmcxruoHENI2W11A1Ykgji6t8r3/fNGWlDjg/C+U9wgvu8HuIyF/6WkotmwSfI9XAN8rbSiR4MPwhpvqs4bLd/lvqI68ULYmS+bd8nZOZqWLAn+fthU5tua1yrmPKPtrJIYgPRf0zknICgZTToYNaXfXxtjUGSr2qLyBBdvz/f05luVP7U7rDPvx5eI7GCTG6lrhQVOsEkQx0QvpZttu8nYDHQNMqt/Jk0Gak/6YXC7pcaibGs71067QmgkXwuRIH6S6+v6UuOwjQxu5VJWQ5RDfXtpA3/wmpRgIU8oOTCRtTEXIpzUfnlD6bA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cG9NZRBBs7Wou3cFVnB2ubD8+FHVk0nwEykCqTRz+e0=; b=RLm0DxKBqMiZu6wIHGJRAgEvwrHJ/MZEZ4Yrd+zyM9jtO+vKBXzGsRC3DPca/HhBRdWIEgwoK6FPB0NfDbUE+NsHT0dFdhEwov/RgGgvxF1+LzPUkkpsQaXJ04iTnScgxPp8y4JsO3mBvvii7RgTQPlOh3CXRxwl3q1bp6C0bZXACIE2T3d9QK4Iwen4ZoFec32M4Eqcc30ToX/PomysKNJjEM8bzvRKtr8N5bcxvfz42CtrEgd1WrdtvvA7KZk5NqAGi9YU9cIWdciW4tE0KSSqCumI7m5yf86y0+uqYoCx+PgAu/8isVW4x7au8IQGxdJnmbNW9O5uDS+5s6u6Uw== Received: from BN9PR03CA0871.namprd03.prod.outlook.com (2603:10b6:408:13c::6) by CH1PPF2C6B99E0C.namprd12.prod.outlook.com (2603:10b6:61f:fc00::609) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.10; Wed, 1 Oct 2025 15:02:36 +0000 Received: from BN2PEPF0000449F.namprd02.prod.outlook.com (2603:10b6:408:13c:cafe::d0) by BN9PR03CA0871.outlook.office365.com (2603:10b6:408:13c::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:02:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF0000449F.mail.protection.outlook.com (10.167.243.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:02:33 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 1 Oct 2025 08:02:10 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:02:09 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:02:03 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 5/8] ACPI: CPPC: add APIs and sysfs interface for perf_limited register Date: Wed, 1 Oct 2025 20:31:01 +0530 Message-ID: <20251001150104.1275188-6-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF0000449F:EE_|CH1PPF2C6B99E0C:EE_ X-MS-Office365-Filtering-Correlation-Id: ce839b5e-6588-4654-72d1-08de00fb8d5a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|36860700013|1800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?hmFlaP/HRfXKO/Eo2U0FXz3t8anHZCzQBVby9EWPbqI95OZaY3/n/zvYqq+O?= =?us-ascii?Q?3IQHljQKRX8RYrFtKDfFzD5eDclQD/e5OdT7rA+h58O/ppPa6NxbBd0fnQ7L?= =?us-ascii?Q?r+34dlvtd+yV6S+T33qR5+deQpMptrQSgPpT1hHGlpAPL/rihVLEq4bouhvH?= =?us-ascii?Q?rzxaxF4xhnHAiFYuSLjDYuGPWQTOz+WX8SPreAnKF4+BCKumR9vPUW1rI9xh?= =?us-ascii?Q?cgbN9VUmquVst1QblpSK5CGPjzinFpi6xhKRBTeieJq8Y+JvX7zi9dy+CnhQ?= =?us-ascii?Q?o2Ohzcb4L9b4HK9oojYDpdhlXq+ZV0YG6RkZRolEAw/N4OplmvgCfGDy+nit?= =?us-ascii?Q?gcHW4mTfZEY4NP/BffTHqOwSEJO4q/+ONXRekaSaiWmJlEx+ygYvL0mn2usx?= =?us-ascii?Q?MHbwa06iiDoR4K945FpjB4fLcZJcnDOHDIlttI9Bix3MiTulURsHK36WBHJH?= =?us-ascii?Q?xMDQKLGZm6F8YKkFfrE8YkQtL9SUH8rHNCzvRcOzplAFqApmSaK7aFIKHQjW?= =?us-ascii?Q?pQKdWaNmnI1vgUmhU6G1hDWHizx1Yla4S4Ccre5eKe8J2kiYmKoEWNyZZgDj?= =?us-ascii?Q?13ThE6VXqZ2akcbU6enbxNd/Ys8SKz/tGZMl4Tp/OfZfROX3ix6+dfHS6LaN?= =?us-ascii?Q?6ldkD1DxJ7WVcCJUTA4SR1xZ/1uvRLclur0cEvDOQhDTcEPNCnAFBrnuZidI?= =?us-ascii?Q?++YcSYsrbJ/9i1L12DiyasQCjeysRVLusyGwWOnC?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:02:33.9474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ce839b5e-6588-4654-72d1-08de00fb8d5a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF0000449F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH1PPF2C6B99E0C Content-Type: text/plain; charset="utf-8" Add sysfs interface to read/write the Performance Limited register. The Performance Limited register indicates to the OS that an unpredictable event (like thermal throttling) has limited processor performance. This register is sticky and remains set until reset or OS clears it by writing 0. The interface is exposed as: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited Signed-off-by: Sumit Gupta --- drivers/acpi/cppc_acpi.c | 26 ++++++++++++++++++++++++++ drivers/cpufreq/cppc_cpufreq.c | 12 ++++++++++++ include/acpi/cppc_acpi.h | 10 ++++++++++ 3 files changed, 48 insertions(+) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index d47aec2aed13..ce99c3f3ae85 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1806,6 +1806,32 @@ int cppc_set_max_perf(int cpu, u64 max_perf) } EXPORT_SYMBOL_GPL(cppc_set_max_perf); =20 +/** + * cppc_get_perf_limited - Get the Performance Limited register value. + * @cpu: CPU from which to get Performance Limited register. + * @perf_limited: Pointer to store the Performance Limited value. + * + * Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if = not supported. + */ +int cppc_get_perf_limited(int cpu, u64 *perf_limited) +{ + return cppc_get_reg_val(cpu, PERF_LIMITED, perf_limited); +} +EXPORT_SYMBOL_GPL(cppc_get_perf_limited); + +/** + * cppc_set_perf_limited() - Write the Performance Limited register. + * @cpu: CPU on which to write register. + * @perf_limited: Value to write to the perf_limited register. + * + * Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if = not supported. + */ +int cppc_set_perf_limited(int cpu, u64 perf_limited) +{ + return cppc_set_reg_val(cpu, PERF_LIMITED, perf_limited); +} +EXPORT_SYMBOL_GPL(cppc_set_perf_limited); + /** * cppc_get_perf - Get a CPU's performance controls. * @cpu: CPU for which to get performance controls. diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 864978674efc..9946adfeeee4 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -984,12 +984,23 @@ static ssize_t store_max_perf(struct cpufreq_policy *= policy, const char *buf, si return count; } =20 +static ssize_t show_perf_limited(struct cpufreq_policy *policy, char *buf) +{ + return cppc_cpufreq_sysfs_show_u64(policy->cpu, cppc_get_perf_limited, bu= f); +} + +static ssize_t store_perf_limited(struct cpufreq_policy *policy, const cha= r *buf, size_t count) +{ + return cppc_cpufreq_sysfs_store_u64(buf, count, cppc_set_perf_limited, po= licy->cpu); +} + cpufreq_freq_attr_ro(freqdomain_cpus); cpufreq_freq_attr_rw(auto_select); cpufreq_freq_attr_rw(auto_act_window); cpufreq_freq_attr_rw(energy_performance_preference_val); cpufreq_freq_attr_rw(min_perf); cpufreq_freq_attr_rw(max_perf); +cpufreq_freq_attr_rw(perf_limited); =20 static struct freq_attr *cppc_cpufreq_attr[] =3D { &freqdomain_cpus, @@ -998,6 +1009,7 @@ static struct freq_attr *cppc_cpufreq_attr[] =3D { &energy_performance_preference_val, &min_perf, &max_perf, + &perf_limited, NULL, }; =20 diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index fc7614eb9dcb..9fc28fb1890b 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -177,6 +177,8 @@ extern int cppc_get_min_perf(int cpu, u64 *min_perf); extern int cppc_set_min_perf(int cpu, u64 min_perf); extern int cppc_get_max_perf(int cpu, u64 *max_perf); extern int cppc_set_max_perf(int cpu, u64 max_perf); +extern int cppc_get_perf_limited(int cpu, u64 *perf_limited); +extern int cppc_set_perf_limited(int cpu, u64 perf_limited); extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf); extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator); extern int amd_detect_prefcore(bool *detected); @@ -285,6 +287,14 @@ static inline int cppc_set_max_perf(int cpu, u64 max_p= erf) { return -EOPNOTSUPP; } +static inline int cppc_get_perf_limited(int cpu, u64 *perf_limited) +{ + return -EOPNOTSUPP; +} +static inline int cppc_set_perf_limited(int cpu, u64 perf_limited) +{ + return -EOPNOTSUPP; +} static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) { return -ENODEV; --=20 2.34.1 From nobody Wed Oct 1 20:23:25 2025 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013018.outbound.protection.outlook.com [40.93.201.18]) (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 D23AA305070; Wed, 1 Oct 2025 15:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330971; cv=fail; b=GsBTss9mcaUbJAFD/hIwgIG1PjODDsu3Bkjegwz4rNfVx11Gd9JV/S8rsfuqcPyt6ATxC89yfq2PdQ76hU9j4PMMakEqoiVSpTmUGECWiW0Sn1kav1xMrB38ewEC3Mv5K5prRjjFtqaWXw87+Bko1F3do8CxkUxwSBj3d11UQfk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330971; c=relaxed/simple; bh=zzi0eqrnn+qj/X7BWZlOeT0f6dVVkCSWvXazwtlErig=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RqiPsfCzhdfvXZiCOYs8xhCTs3IBoTnXkNJxuKIUW8uSD+iSoCQU9Rtr3w9wbmIkdiRkWIytmoZTNuCbAiC97ICTSzkyKTk6+GPulI/BPUELDiV2xnp/DkNiVwi8gtcxSIH1kvGpj9SHWUMbjlKkeWLfxv03Z3Pp4qrOqNDKCpE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=OBLXemv2; arc=fail smtp.client-ip=40.93.201.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="OBLXemv2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tznret9nmcUpS39aUlpnMR/io7+DCR9hrULnnQrDM4wdf1ygxs2651YYMIaJwP+LPzh+9iJbbocrkvl7h+APxFKaTcDf9szjZFJZgxNfmKuJ831crQ0hG1gX59VDFvHN0SAXzR/sallqsQOCpvJZ0RapYyKMjeqOXTC1qkTXvjZqrZYnb9MeE9UZWl0AWc3tqb5oHziwVH6EnTIIQesP5hgjv9u97DyQamVRvJiH5Su8Ma+RbcVIXK65UFqicrsr3u91uOx6n2w+gS2uJ0M7UozmZTf1A1mrRbGJ+qKAFYyrQb57LpJ+9GniWsA4tov3q3dKAXWnCLgRBoIhGI5yTA== 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=VCW6f4S+l52ghuNRtCnhyfpRAezEa8UA1R2rN1JucWo=; b=DdDtgU2m+kv1rM9sw8hWYCI0SwkSIYOL3Q88amcc2e32bUaz/NcHSpAl4H5etPjxQuEF0H21svQOV9D/8/gNGW3MqHkgYnyV434QVASmG2PckLMVKkd0qn5qvb/w39HdLwKjRz1uYZZ5la9/5UVlOL9SC+vO6i2PnXlGCTRtuHQfD7beih236DUg/e3VO7rT6/15lOPRmBLXBxtYEnukfKq5TfvvwYXE52CRSdUDUUQUHpk+fN8nBTPaeNwORCqP7BTZAyp3RibaJpTMjWsVuNYlGXZtD20IR7KkEbZqboo/yzKBLAEugFHSBS5iFNQQoxKcg4UkqynfoPT5RntVuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VCW6f4S+l52ghuNRtCnhyfpRAezEa8UA1R2rN1JucWo=; b=OBLXemv2cNmjswMwY3VhX8u8metiK0DcfNIskMRE8KoZXbbQ27QeRe4Xbrt2mtJhTgIQkPzHu/PNr4+M7C3V99IFj0EKZ4PjOkFWcoAPqivf6P+3AcL7fz15TGmhOwync4WahRNL6mSbChxfS6WFODSUTuwDHIfeGwfJmoGB1dWBOpYyesuzopfOVIfXEEoUZ29tmbx2ZJH02diL/AcshRX4115onFncMyN3Z8zknwIPPJMakJQQPadISkrp9TzpMXyZWRByQUfH2plTrHL8xvd3HSIyKVtetmXENZaImyFt+Zqi9nZxmDtxLnjN1hRwgmOYkhRjzOe+afyQmi13qg== Received: from BL1P221CA0036.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:5b5::6) by CY5PR12MB6622.namprd12.prod.outlook.com (2603:10b6:930:42::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.17; Wed, 1 Oct 2025 15:02:44 +0000 Received: from BN1PEPF00004688.namprd05.prod.outlook.com (2603:10b6:208:5b5:cafe::28) by BL1P221CA0036.outlook.office365.com (2603:10b6:208:5b5::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9182.14 via Frontend Transport; Wed, 1 Oct 2025 15:02:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF00004688.mail.protection.outlook.com (10.167.243.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:02:42 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.34; Wed, 1 Oct 2025 08:02:23 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:02:22 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:02:16 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 6/8] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited Date: Wed, 1 Oct 2025 20:31:02 +0530 Message-ID: <20251001150104.1275188-7-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004688:EE_|CY5PR12MB6622:EE_ X-MS-Office365-Filtering-Correlation-Id: 75909f09-fe5d-444f-e673-08de00fb9271 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?tNBhlKg1lmmiW8LkS6aUSLSJdPZ2/2dhbDf113HFel7HNzXbFrcM04o+QJ4O?= =?us-ascii?Q?yS2ib+kIpBBKYgcPwzkLuuvFAsMs8t/tmmLEyoS3mEAY1GkwdAl3s+1yvgcM?= =?us-ascii?Q?aDcy8TMnbGSmsmDyVaAcNPDKLR5emBhnlr55VzH/h3sTCos36+lj8XF604Kt?= =?us-ascii?Q?cSP8MvbI9eGcWQGBOoEZ3oYViKXaTWNJRJZjvJFq55oRIgO56y6wM+ERNens?= =?us-ascii?Q?yyAR9D3AXLjTQ+Xng9pphz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ii?Q?oB4Gbok78lR7fe52VcIENWfHOvVOduLdxrkpUy8vRw59LdARual7gA7yoxvV?= =?us-ascii?Q?C+9k4N28jzzDsKFTajkFcd8er6ak2Z6QYlFAo2w5VYoF+D1+c8Nw09Pxgkfr?= =?us-ascii?Q?yCOj+lf8Ki+GZtDthxYcoSDiM886ySCcAJdo55rxTbCzv7TZHBkOJjt8pXy8?= =?us-ascii?Q?fsXNOxFNgRB+5GeK4fdtvrKl5usaNqwxN+do34gtl2z9PUFRycs6z4xL11fi?= =?us-ascii?Q?Fzd49KQIxr7si5WQrFsK8ABi8dU2i3Lflu7APsjQcyJ8PIyuJDi/Jyg6hfmp?= =?us-ascii?Q?3xnoBHQ9j0JeaED9+egOSUa8TpMHnPa9gniMkr8ZViGQ4apoJLt+4Zxod97E?= =?us-ascii?Q?jcCrP4d4vKkxDlbucRe+MsCETj7Y7mVpwd//j3HU1EhF3UP0j5lmVlVJrZp8?= =?us-ascii?Q?ibY7cN2nDK7GwXZjxeeiIC5dbpfdPLsWINft4Bh/?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:02:42.4766 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75909f09-fe5d-444f-e673-08de00fb9271 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004688.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6622 Content-Type: text/plain; charset="utf-8" Add sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the cppc_cpufreq driver. Reviewed-by: Randy Dunlap Signed-off-by: Sumit Gupta --- .../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documenta= tion/ABI/testing/sysfs-devices-system-cpu index ab8cd337f43a..82141b45d58c 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -327,6 +327,49 @@ Description: Energy performance preference =20 This file is only present if the cppc-cpufreq driver is in use. =20 +What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025 +Contact: linux-pm@vger.kernel.org +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which the platform + may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance], + inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register. + + Writing to this file only has meaning when Autonomous Selection + is enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: linux-pm@vger.kernel.org +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file conveys + the maximum performance level at which the platform may run. + Maximum performance may be set to any performance value in the + range [Lowest Performance, Highest Performance], inclusive. + + Writing to this file only has meaning when Autonomous Selection is + enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: linux-pm@vger.kernel.org +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file indicates + to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than + desired/minimum performance. + + This file is only present if the cppc-cpufreq driver is in use. =20 What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} Date: August 2008 --=20 2.34.1 From nobody Wed Oct 1 20:23:25 2025 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010055.outbound.protection.outlook.com [52.101.201.55]) (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 D232B306B18; Wed, 1 Oct 2025 15:02:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330980; cv=fail; b=YguTTjplB6AbYCxnVo252OIJHBN5amTKc2MK/3HTuqj1K3gTZ23nbpjggmsNctAlIpqo6d6yrzYfj/WaK0MNP2EJAOetrXc0Cz0jCJHVvSqwkzUk8N4clrHawkRmDHb/iqDGDz9/M2TY4pG0/qh/AYlqUVUAu8LE20DZNmBBiko= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330980; c=relaxed/simple; bh=3vPZuFusBJhAGDS/bJ6j5uwiPqlTX+matI0/zfnG9dg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dkSpA8pmh50QcNjpVdRUgXv0AEY4gRpC/fw4PaReU6FQglgv5yflFbA3V8nB1izQiPdXMDSR86oyKyZpn8O5ZHGQYoqv8t+K7PqggF9k9SPH0GsfkoliTXcmeqvNvGGNWKr4Ly4B+KjF9qoL4/M/JFYZ+qFV/odQB9rvHoDDLTg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=EReUeRWy; arc=fail smtp.client-ip=52.101.201.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="EReUeRWy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sMbvJM2GjQDcc+GCGfUgpJNdsnx3C7o+KlI/FKJZhtFCllppwT/sk72f9woJvExQ6aRj7kTkg57mw4trZjbSRQRMbzaGIWrhmvPZg1TScc11kQJiddgYcCSG6Y2T3IWMKhw95Nmfl3wvN8xCBNlZyrqjvlMIyNyK5vSPSEeDCt80zCy4JH4dfCfF1e4FxlX3clAOO4kv5a3n5SSjane5E174co70FS924crChMZiiDqFq7M/A+Hcu9wkZ3njVRDVATFfODCfF/GOaFqe2C8AXKWh4gCf+jk3aD72t+Jfs8d9j3ZQ/4I+N+eeD2rvGPqqgrS9U20tOoatA8HUZf0gjA== 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=umytqkzZlESBFLaNtS0b9DPwhwcRoqPe/Jqvc6fjskI=; b=N9IxyKoyBBjcshAzN1ynJsZVhW80rKwqI5m4Z1RCMz5/n+4IJcppivYyZy2WJ+V9NhF161nF5+GIpJZQoXxjYnZ3L0rnVqs/+BcZfH4QFYEaCBPw7ANjCmmUWClfQ9lvM4gCKsW/WybWDZzhG+UFkLoycBR2RAhwivPJDkxBgn7FhkRkVG7cJk6a6I7ittrS4pFp+I4ZReQT+mdNtkgSynXFtHewx/BFuk2AHOlpT7i6G+HUE7Q8LlEHMNepnwSbJUy8B7jyCqIfwINYfGs82fm07GoeIeEddJNCvzMypCp7STo8i2WUAMleEQzbEeDR79s43Gtm3Qq91Vb8wHlKhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=umytqkzZlESBFLaNtS0b9DPwhwcRoqPe/Jqvc6fjskI=; b=EReUeRWywucSaSmml+lTGwm9eAZzBLSrU0f+q2IFUhYoKKQSepSXgFJgqUFqta/Z/1wlKsCaXQVr95brp2uu3mijOiHp69DY+Rn4JuEuAokFqP4YqNI8oVnfnkHtsb14aWxVneTDbxgIS0EL6eov7DiK5TNvG7ZpZ9Evf3mp9v/8QdLh3jdcTZkeJzmthxOEyLe/ad5VzM9YruF9x+xx5UtHXbYFgxrOg6v0LbooH/dEi3lHh8yZqoBLX/4QE6X6tBNXVJDNCBx1jJcSU2zyyYHSes+XBtmVw6/nGF8z8ypVbUQjmTZErm9Uu2SdheT+YepKmn10P208j+vcX3b0eg== Received: from BL1PR13CA0212.namprd13.prod.outlook.com (2603:10b6:208:2bf::7) by CH3PR12MB9170.namprd12.prod.outlook.com (2603:10b6:610:199::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.18; Wed, 1 Oct 2025 15:02:54 +0000 Received: from BN1PEPF0000468E.namprd05.prod.outlook.com (2603:10b6:208:2bf:cafe::9d) by BL1PR13CA0212.outlook.office365.com (2603:10b6:208:2bf::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9182.14 via Frontend Transport; Wed, 1 Oct 2025 15:02:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF0000468E.mail.protection.outlook.com (10.167.243.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:02:53 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.34; Wed, 1 Oct 2025 08:02:32 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:02:31 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:02:25 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 7/8] cpufreq: CPPC: update policy min/max when toggling auto_select Date: Wed, 1 Oct 2025 20:31:03 +0530 Message-ID: <20251001150104.1275188-8-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468E:EE_|CH3PR12MB9170:EE_ X-MS-Office365-Filtering-Correlation-Id: 5cb7c61f-6e28-419a-e307-08de00fb9902 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?wENb2GhM8Oae89dKwsQAwh99XX2wzoZI3Nxou9z2wdqG53CDP1BCfTlKs+a3?= =?us-ascii?Q?8e2FTPi/3AMBk9r9779xFtqbGubLa6IhggGLDo0uLLdbQljn/nl1mwj/p9p+?= =?us-ascii?Q?J1oYiliNJtvQyIYA2Qqu0xbbSUZwbwTHpn8WheaRNjVT3QMipGMZ/VdKVx8h?= =?us-ascii?Q?kap/e7mqv7GNfESMt9AIKq4dmE/YUX41YsliyFcKivYuTAnQtC3d4xQ5AAoG?= =?us-ascii?Q?VIYG4TmFyvP6HIIEZr+hVj//LCm6mueYwTGKztuwXf3hAUpfoR8pQVQM2RKy?= =?us-ascii?Q?txyc4torDSfY3Dxml4V+5WvoJTUOSrtYC2F7kynBvUpFO92NHnyUXDdQpGLu?= =?us-ascii?Q?4g/+gIDyNPa89Bbo08Rf0mzhW6IzNIA/fdoeEDlvWu5M/iS9fPA8gNTD3kow?= =?us-ascii?Q?fcdJTPVR5gyIz9mo+6gAAf4WSV77ApA9eFP59DU/hypeALb5y1mxNsTbu2JB?= =?us-ascii?Q?ZdeNZahc9OW5q3xWBQtFlxh4OWLJohjj9FQQ+dAqUTP9NpxSXux9xcuqNnx7?= =?us-ascii?Q?TfzxMxIlb8z9AxZEyXyUDeuAvHq7ehyPEd6br+sO51rEnDTdyn8fKLyU+wn0?= =?us-ascii?Q?BpHSgFegEbr43HdVzAmJQMW2U3RXjQDYxAirV4xVy+w7gfJG+xANAnM7OwEI?= =?us-ascii?Q?SEaX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qY5Te9guvYuus/RrYT0PqLDQ?= =?us-ascii?Q?XwrXEXcMz6gJ/cp24EP0itPhDfij79+lUWnJXEDk?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(1800799024)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:02:53.5118 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5cb7c61f-6e28-419a-e307-08de00fb9902 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9170 Content-Type: text/plain; charset="utf-8" When CPPC autonomous selection (auto_select) is enabled or disabled, the policy min/max frequency limits should be updated appropriately to reflect the new operating mode. Currently, toggling auto_select only changes the hardware register but doesn't update the cpufreq policy constraints, which can lead to inconsistent behavior between the hardware state and the policy limits visible to userspace and other kernel components. When auto_select is enabled, preserve the current min/max performance values to maintain user-configured limits. When disabled, the hardware operates in a default mode where the OS directly controls performance, so update the policy limits accordingly. Signed-off-by: Sumit Gupta --- drivers/cpufreq/cppc_cpufreq.c | 65 ++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 9946adfeeee4..c888733ce5da 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -639,6 +639,26 @@ static int cppc_cpufreq_set_mperf_limit(struct cpufreq= _policy *policy, u64 val, #define cppc_cpufreq_set_max_perf(policy, val, update_reg, update_policy) \ cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, fals= e) =20 +static int cppc_cpufreq_update_autosel_val(struct cpufreq_policy *policy, = bool auto_sel) +{ + struct cppc_cpudata *cpu_data =3D policy->driver_data; + unsigned int cpu =3D policy->cpu; + int ret; + + pr_debug("cpu%d, auto_sel curr:%u, new:%d\n", cpu, cpu_data->perf_caps.au= to_sel, auto_sel); + + guard(mutex)(&cppc_cpufreq_update_autosel_config_lock); + + ret =3D cppc_set_auto_sel(cpu, auto_sel); + if (ret) { + pr_warn("Failed to set auto_sel=3D%d for CPU%d (%d)\n", auto_sel, cpu, r= et); + return ret; + } + cpu_data->perf_caps.auto_sel =3D auto_sel; + + return 0; +} + static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) { unsigned int cpu =3D policy->cpu; @@ -902,8 +922,47 @@ static ssize_t show_auto_select(struct cpufreq_policy = *policy, char *buf) return sysfs_emit(buf, "%d\n", val); } =20 -static ssize_t store_auto_select(struct cpufreq_policy *policy, - const char *buf, size_t count) +/** + * cppc_cpufreq_update_auto_select - Update autonomous selection config fo= r policy->cpu + * @policy: cpufreq policy + * @enable: enable/disable autonomous selection + */ +static int cppc_cpufreq_update_auto_select(struct cpufreq_policy *policy, = bool enable) +{ + struct cppc_cpudata *cpu_data =3D policy->driver_data; + struct cppc_perf_caps *caps =3D &cpu_data->perf_caps; + u64 min_perf =3D caps->lowest_nonlinear_perf; + u64 max_perf =3D caps->nominal_perf; + int ret; + + if (enable) { + if (cpu_data->perf_ctrls.min_perf) + min_perf =3D cpu_data->perf_ctrls.min_perf; + if (cpu_data->perf_ctrls.max_perf) + max_perf =3D cpu_data->perf_ctrls.max_perf; + } + + /* + * Set min/max performance registers and update policy constraints. + * When enabling: update both registers and policy. + * When disabling: update policy only. + */ + ret =3D cppc_cpufreq_set_min_perf(policy, min_perf, enable, true); + if (ret) + return ret; + + ret =3D cppc_cpufreq_set_max_perf(policy, max_perf, enable, true); + if (ret) + return ret; + + ret =3D cppc_cpufreq_update_autosel_val(policy, enable); + if (ret) + return ret; + + return 0; +} + +static ssize_t store_auto_select(struct cpufreq_policy *policy, const char= *buf, size_t count) { bool val; int ret; @@ -912,7 +971,7 @@ static ssize_t store_auto_select(struct cpufreq_policy = *policy, if (ret) return ret; =20 - ret =3D cppc_set_auto_sel(policy->cpu, val); + ret =3D cppc_cpufreq_update_auto_select(policy, val); if (ret) return ret; =20 --=20 2.34.1 From nobody Wed Oct 1 20:23:25 2025 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012048.outbound.protection.outlook.com [52.101.53.48]) (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 333723081BF; Wed, 1 Oct 2025 15:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759331005; cv=fail; b=SGAMWZBFXB9d4ENSHjvLhU1D0B+AsgMpPkyV45iK+ceW/ENPSZ1amu752VTd55QAj2PcXiNLqkVU6eTI1XflZ0DzR57AdxdzLpyE2H8LApYVsJB76EF/mXxrq0q37Uk9964HTEmBfNrU6kpsJDFqBgI/MkF8jgm7m7obo7F8BJE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759331005; c=relaxed/simple; bh=RZBfNAP5PxpzsjhNd6Vo3+74uKc0LhOW5yhmKbmp+Ps=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IRkX3x9Cg32YmKIH+jm/gc6u0UlRp2xatDwwV5IrNqhrsgRmIxp0wwzql5mtYx/4tmYJwDQSqfqQj3mN+sbEx63spW9yK8Fb4RG17m0tCW9a7c7h0k11wGHpKk0ec7grAkvT8z7c0f0cvHvd8L1enYBRzecsD1vQkoMSyWWkELw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=p/VMc1TX; arc=fail smtp.client-ip=52.101.53.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="p/VMc1TX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lYA+0Dyv/O8oTEf6zY5UEyb0Do5/dS+GpWPJ1pL5Mo/dtU/ZNRw57y2NAHEMehDrwxTe/HeKZb+RP7nz/0Swt+xmCnTEK1a0QJS3AphAG53fC+KXnAcF6VCB7UIclxwXyQmUnLYiHf2gIBe1AtORuUIUmzlKWnykk3o/yupVBzeMjRQGODnXao28sllmQ/j7Ay5sFd8jB3g5kD0o56YM/axRzuDMYoHXCokrLLZvUi9xnFTQ8E7eXOrjyrtsTS6TINmWbQjyh2CRN4OxgeYJ8lTVMfloTFE8gxY/zdD7q5I3Zfvxg4KT1D9TQIXW5ADaiISy6eGYSI42UEUa/JKWVw== 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=sY7/zH9uaici0RmxLrCLn4hHMhc22Jp3a9xHvklFHFY=; b=A1iWRR+ryum/KS70QkbmpmPjh6ThKNVxE8bDu4ny879L17AazzkcAI2QVOrGz++hGS/AszJ6UOFzVsqwBZK/IzY9386CHVeClblCKdY+FhsQfVY29fROKcl9bjtA+eL0FphcMYRq75/xGDVkC32hlokjWSvLHtNtQyeBO7s4yadA30oHwtOer6NVK/TSXb8Fe0SvQqQAjXkOEFa3gWGi9dugCHssOxczoMLWBOstc6JlBqWcAB5cxjzVPmkG5COH2SdsWt7qQFJghyeDx2ba19SRscZfUALgXA5iqHuCRpX9zcZ6fXb/uzNWAgDk/q+IlSvol7HyhjWG/MBvsocZFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sY7/zH9uaici0RmxLrCLn4hHMhc22Jp3a9xHvklFHFY=; b=p/VMc1TXdYSErfoOK2t2PnHYmeFR610yStl5G8HZCagI8Znic7dHrPvfPtsrH0iOn5ofXDLg51UUVn8iJJc408pE1NdPDr3NjqSBREmfYsH9xCvIIVgQYlGcc30KeplHiKD10v+rxSUwZY7Sh5ANqCAf1bhqk2gbFsxV1lcziJvGjdvEE9k41JiexQwyqby9JzvDNV33DE9wZBr01E797tQ766ZgpUuWfAxC66nfVdAm/vXOmawiyU3dyVxOZ/sFqBkGqiZr6jSU+JnOY8GwJPRGLgm67K7XA8Dvx8aoTirxzjiaP2s4NDodLlB7rsqmr+WLc68MkhpjOpRKznMg+A== Received: from MN2PR15CA0005.namprd15.prod.outlook.com (2603:10b6:208:1b4::18) by LV3PR12MB9404.namprd12.prod.outlook.com (2603:10b6:408:219::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.18; Wed, 1 Oct 2025 15:03:15 +0000 Received: from BN1PEPF0000468B.namprd05.prod.outlook.com (2603:10b6:208:1b4:cafe::f6) by MN2PR15CA0005.outlook.office365.com (2603:10b6:208:1b4::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9160.17 via Frontend Transport; Wed, 1 Oct 2025 15:03:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF0000468B.mail.protection.outlook.com (10.167.243.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.15 via Frontend Transport; Wed, 1 Oct 2025 15:03:15 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.34; Wed, 1 Oct 2025 08:02:52 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Oct 2025 08:02:51 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Oct 2025 08:02:44 -0700 From: Sumit Gupta To: , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 8/8] cpufreq: CPPC: add autonomous mode boot parameter support Date: Wed, 1 Oct 2025 20:31:04 +0530 Message-ID: <20251001150104.1275188-9-sumitg@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251001150104.1275188-1-sumitg@nvidia.com> References: <20251001150104.1275188-1-sumitg@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468B:EE_|LV3PR12MB9404:EE_ X-MS-Office365-Filtering-Correlation-Id: 04df0b47-98bd-4a7e-2866-08de00fba5f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|7416014|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Gj/kRK9JLN6KfmhtiHr0cuiJxSUDUaak1/nU+rk9xyNIcD3EyZQmnq0CaZfp?= =?us-ascii?Q?P9G0UNOudYSXul7q/yUO1kMvS0QqVLDzkToPLz4MRiixmZWr6XHXW81lCanC?= =?us-ascii?Q?G+nX06qSpn5Wvwraz2kNsluMBPVwSuywLl2EsOIjbsMl6rhplLussDWsr3Js?= =?us-ascii?Q?EMEZAYxMJCrhG6Wc8BgRe9oj+7BlXOaUuuSVtykG4mNeGW8gsznxclbkM3Ke?= =?us-ascii?Q?46D+ccAbT7x10s6zf6cbzuAnpSKiSC0KhqARHlNUXUsb7CuZ0yoqwUAh6cKq?= =?us-ascii?Q?7EY3UWGRdfBoeOinCNms72ozSRsRHywwdYtOvWxyA0f81pX5y3T01zs0s+H2?= =?us-ascii?Q?CWF4m3iusEmquiLDaGdOxOyEaz6ivK4BpNF/xCaV3cja1R0Tmo/vd6C/9iGW?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jJQgEzezMyT/Ut4BqvfbC83z?= =?us-ascii?Q?dfYgenAOT4aEKPkhryJQHPyWhRzl9C3TiwAokH1/n0RqvDxXMo7Bo4sbX4ZU?= =?us-ascii?Q?m+ah0hXvVo/8Sj+miJEXItsxMNHrEdSiqdKkDH/vvLg5TZBVFDl+a2ZjrfPk?= =?us-ascii?Q?NGCzjIW3lt+AXNjuc9Er8PDSppPq2gIHHu0XffGoLQORBYwy3uG/AWyNVmqY?= =?us-ascii?Q?tilPX9PPIDpTeGJkVkKW57AtsRgB3O0swz3uS44UWGo4yJaL2FF45w6Kjji+?= =?us-ascii?Q?ez8YBydUgRsKNVPCauW6/W5L/nkGBp7iPhcL1IUj?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(82310400026)(7416014)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2025 15:03:15.2450 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04df0b47-98bd-4a7e-2866-08de00fba5f6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468B.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9404 Content-Type: text/plain; charset="utf-8" Add kernel boot parameter 'cppc_cpufreq.auto_sel_mode' to enable CPPC autonomous performance selection at system startup. When autonomous mode is enabled, the hardware automatically adjusts CPU performance based on workload demands using Energy Performance Preference (EPP) hints. This parameter allows to configure the autonomous mode on all CPUs without requiring runtime sysfs manipulation if the 'auto_sel' register is present. When auto_sel_mode=3D1: - All CPUs are configured for autonomous operation during module init - EPP is set to performance preference (0x0) by default - Min/max performance bounds use defaults - CPU frequency scaling is handled by hardware instead of OS governor For Documentation/: Reviewed-by: Randy Dunlap Signed-off-by: Sumit Gupta --- .../admin-guide/kernel-parameters.txt | 12 + drivers/cpufreq/cppc_cpufreq.c | 205 +++++++++++++++--- 2 files changed, 192 insertions(+), 25 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 1b2131d003ce..94950340851e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -911,6 +911,18 @@ Format: ,,,[,] =20 + cppc_cpufreq.auto_sel_mode=3D + [CPU_FREQ] Enable ACPI CPPC autonomous performance selection. + When enabled, hardware automatically adjusts CPU frequency + on all CPUs based on workload demands. In Autonomous mode, + Energy Performance Preference(EPP) hints guide hardware + toward performance(0x0) or energy efficiency (0xff). + Requires ACPI CPPC autonomous selection register support. + Format: + Default: 0 (disabled) + 0: use cpufreq governors + 1: enable if supoorted by hardware + cpuidle.off=3D1 [CPU_IDLE] disable the cpuidle sub-system =20 diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index c888733ce5da..8deb51d6bc2c 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -28,6 +28,8 @@ #include =20 static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection */ +static bool auto_sel_mode; =20 #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { @@ -273,6 +275,14 @@ static int cppc_cpufreq_set_target(struct cpufreq_poli= cy *policy, freqs.old =3D policy->cur; freqs.new =3D target_freq; =20 + /* + * In autonomous mode, hardware handles frequency scaling directly + * based on workload demands and EPP hints, so OS frequency requests + * are not needed. + */ + if (cpu_data->perf_caps.auto_sel) + return 0; + cpufreq_freq_transition_begin(policy, &freqs); ret =3D cppc_set_perf(cpu, &cpu_data->perf_ctrls); cpufreq_freq_transition_end(policy, &freqs, ret !=3D 0); @@ -556,6 +566,12 @@ static struct cppc_cpudata *cppc_cpufreq_get_cpu_data(= unsigned int cpu) goto free_mask; } =20 + ret =3D cppc_get_perf(cpu, &cpu_data->perf_ctrls); + if (ret) { + pr_debug("Err reading CPU%d perf ctrls: ret:%d\n", cpu, ret); + goto free_mask; + } + return cpu_data; =20 free_mask: @@ -659,11 +675,79 @@ static int cppc_cpufreq_update_autosel_val(struct cpu= freq_policy *policy, bool a return 0; } =20 +static int cppc_cpufreq_update_epp_val(struct cpufreq_policy *policy, u32 = epp) +{ + struct cppc_cpudata *cpu_data =3D policy->driver_data; + unsigned int cpu =3D policy->cpu; + int ret; + + pr_debug("cpu%d, epp curr:%u, new:%u\n", cpu, cpu_data->perf_ctrls.energy= _perf, epp); + + guard(mutex)(&cppc_cpufreq_update_autosel_config_lock); + + ret =3D cppc_set_epp(cpu, epp); + if (ret) { + pr_warn("failed to set energy_perf for cpu:%d (%d)\n", cpu, ret); + return ret; + } + cpu_data->perf_ctrls.energy_perf =3D epp; + + return 0; +} + +/** + * cppc_cpufreq_update_autosel_config - Update Autonomous selection config= uration + * @policy: cpufreq policy for the CPU + * @min_perf: minimum performance value to set + * @max_perf: maximum performance value to set + * @auto_sel: autonomous selection mode enable/disable (also controls min/= max perf reg updates) + * @epp_val: energy performance preference value + * @update_epp: whether to update EPP register + * @update_policy: whether to update policy constraints + * + * Return: 0 on success, negative error code on failure + */ +static int cppc_cpufreq_update_autosel_config(struct cpufreq_policy *polic= y, + u64 min_perf, u64 max_perf, bool auto_sel, + u32 epp_val, bool update_epp, bool update_policy) +{ + const unsigned int cpu =3D policy->cpu; + int ret; + + /* + * Set min/max performance registers and update policy constraints. + * When enabling: update both registers and policy. + * When disabling: update policy only. + */ + ret =3D cppc_cpufreq_set_min_perf(policy, min_perf, auto_sel, update_poli= cy); + if (ret) + return ret; + + ret =3D cppc_cpufreq_set_max_perf(policy, max_perf, auto_sel, update_poli= cy); + if (ret) + return ret; + + if (update_epp) { + ret =3D cppc_cpufreq_update_epp_val(policy, epp_val); + if (ret) + return ret; + } + + ret =3D cppc_cpufreq_update_autosel_val(policy, auto_sel); + if (ret) + return ret; + + pr_debug("Updated autonomous config [%llu-%llu] for CPU%d\n", min_perf, m= ax_perf, cpu); + + return 0; +} + static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) { unsigned int cpu =3D policy->cpu; struct cppc_cpudata *cpu_data; struct cppc_perf_caps *caps; + u64 min_perf, max_perf; int ret; =20 cpu_data =3D cppc_cpufreq_get_cpu_data(cpu); @@ -727,11 +811,31 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_polic= y *policy) policy->cur =3D cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf =3D caps->highest_perf; =20 - ret =3D cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) { - pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", - caps->highest_perf, cpu, ret); - goto out; + if (cpu_data->perf_caps.auto_sel) { + ret =3D cppc_set_enable(cpu, true); + if (ret) { + pr_err("Failed to enable CPPC on cpu%d (%d)\n", cpu, ret); + goto out; + } + + min_perf =3D cpu_data->perf_ctrls.min_perf ? + cpu_data->perf_ctrls.min_perf : caps->lowest_nonlinear_perf; + max_perf =3D cpu_data->perf_ctrls.max_perf ? + cpu_data->perf_ctrls.max_perf : caps->nominal_perf; + + ret =3D cppc_cpufreq_update_autosel_config(policy, min_perf, max_perf, t= rue, + CPPC_EPP_PERFORMANCE_PREF, true, false); + if (ret) { + cppc_set_enable(cpu, false); + goto out; + } + } else { + ret =3D cppc_set_perf(cpu, &cpu_data->perf_ctrls); + if (ret) { + pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", + caps->highest_perf, cpu, ret); + goto out; + } } =20 cppc_cpufreq_cpu_fie_init(policy); @@ -933,7 +1037,6 @@ static int cppc_cpufreq_update_auto_select(struct cpuf= req_policy *policy, bool e struct cppc_perf_caps *caps =3D &cpu_data->perf_caps; u64 min_perf =3D caps->lowest_nonlinear_perf; u64 max_perf =3D caps->nominal_perf; - int ret; =20 if (enable) { if (cpu_data->perf_ctrls.min_perf) @@ -942,24 +1045,8 @@ static int cppc_cpufreq_update_auto_select(struct cpu= freq_policy *policy, bool e max_perf =3D cpu_data->perf_ctrls.max_perf; } =20 - /* - * Set min/max performance registers and update policy constraints. - * When enabling: update both registers and policy. - * When disabling: update policy only. - */ - ret =3D cppc_cpufreq_set_min_perf(policy, min_perf, enable, true); - if (ret) - return ret; - - ret =3D cppc_cpufreq_set_max_perf(policy, max_perf, enable, true); - if (ret) - return ret; - - ret =3D cppc_cpufreq_update_autosel_val(policy, enable); - if (ret) - return ret; - - return 0; + return cppc_cpufreq_update_autosel_config(policy, min_perf, max_perf, ena= ble, + 0, false, true); } =20 static ssize_t store_auto_select(struct cpufreq_policy *policy, const char= *buf, size_t count) @@ -996,7 +1083,18 @@ static ssize_t show_energy_performance_preference_val= (struct cpufreq_policy *pol static ssize_t store_energy_performance_preference_val(struct cpufreq_poli= cy *policy, const char *buf, size_t count) { - return cppc_cpufreq_sysfs_store_u64(buf, count, cppc_set_epp, policy->cpu= ); + u64 val; + int ret; + + ret =3D kstrtou64(buf, 0, &val); + if (ret) + return ret; + + ret =3D cppc_cpufreq_update_epp_val(policy, (u32)val); + if (ret) + return ret; + + return count; } =20 static ssize_t show_min_perf(struct cpufreq_policy *policy, char *buf) @@ -1085,13 +1183,61 @@ static struct cpufreq_driver cppc_cpufreq_driver = =3D { .name =3D "cppc_cpufreq", }; =20 +static int cppc_cpufreq_set_epp_autosel_allcpus(bool auto_sel, u64 epp) +{ + int cpu, ret; + + for_each_present_cpu(cpu) { + ret =3D cppc_set_epp(cpu, epp); + if (ret) { + pr_warn("Failed to set EPP on CPU%d (%d)\n", cpu, ret); + goto disable_all; + } + + ret =3D cppc_set_auto_sel(cpu, auto_sel); + if (ret) { + pr_warn("Failed to set auto_sel on CPU%d (%d)\n", cpu, ret); + goto disable_all; + } + } + + return 0; + +disable_all: + pr_warn("Disabling auto_sel for all CPUs\n"); + for_each_present_cpu(cpu) + cppc_set_auto_sel(cpu, false); + + return -EIO; +} + static int __init cppc_cpufreq_init(void) { + bool auto_sel; int ret; =20 if (!acpi_cpc_valid()) return -ENODEV; =20 + if (auto_sel_mode) { + /* + * Check if autonomous selection is supported by testing CPU 0. + * If supported, enable autonomous mode on all CPUs. + */ + ret =3D cppc_get_auto_sel(0, &auto_sel); + if (!ret) { + pr_info("Enabling auto_sel_mode (autonomous selection mode)\n"); + ret =3D cppc_cpufreq_set_epp_autosel_allcpus(true, CPPC_EPP_PERFORMANCE= _PREF); + if (ret) { + pr_warn("Disabling auto_sel_mode, fallback to standard\n"); + auto_sel_mode =3D false; + } + } else { + pr_warn("Disabling auto_sel_mode as not supported by hardware\n"); + auto_sel_mode =3D false; + } + } + cppc_freq_invariance_init(); populate_efficiency_class(); =20 @@ -1104,10 +1250,19 @@ static int __init cppc_cpufreq_init(void) =20 static void __exit cppc_cpufreq_exit(void) { + int cpu; + + for_each_present_cpu(cpu) + cppc_set_auto_sel(cpu, false); + auto_sel_mode =3D false; + cpufreq_unregister_driver(&cppc_cpufreq_driver); cppc_freq_invariance_exit(); } =20 +module_param(auto_sel_mode, bool, 0000); +MODULE_PARM_DESC(auto_sel_mode, "Enable Autonomous Performance Level Selec= tion"); + module_exit(cppc_cpufreq_exit); MODULE_AUTHOR("Ashwin Chaugule"); MODULE_DESCRIPTION("CPUFreq driver based on the ACPI CPPC v5.0+ spec"); --=20 2.34.1