From nobody Thu Apr 9 18:41:02 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011047.outbound.protection.outlook.com [40.93.194.47]) (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 195D434DB71; Fri, 6 Mar 2026 09:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772791111; cv=fail; b=D3TZ1+95BfNWs7yc2uQWENEokYjcszX06IissBEXqCvh2ri1AzCFv02RhsmamYWvK/imPSzL6hqahV1LViP8k2A0/WC7Nb0FnIiYS3+3Z2swUKo3bLBzmLjgq0ESBUVBPcpuvtSrGr6/udfH0CsKS2Jxp1iiY+znELxNlGhyGok= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772791111; c=relaxed/simple; bh=ERDLP2yDIE+LbCEpbvCi04ACdHnp9GqSEDVmw4qbRGE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nuZoAbDkJOkUq1krNPJQHfGRgI43EuzaTN7D/WMf+jYrZkr9ZsULo1y0Wb3m16MQXdIOs15rHPOdrTwzNLUdzqUNYGcAkXnCtmc68mSBBRvxuiCdbQIsZFeiot93o1kj0wcs1Ep9gB0yIeTCg83Sveoir66MX3IlPvWaVkLpAjk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=lRLEPeav; arc=fail smtp.client-ip=40.93.194.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="lRLEPeav" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cYlgr873P7ILRuyyaAlb/4JMn2lP9wsK2aqOrCPs5y1kaatd2x4imH5A9/fyvOhEQz0iWmS7d7xBzdxy9M6Nljw/v0mH/rBDRTNSCK/vnmRDbq6xDDj9QYRHhzh2IjqITuWURiKvR67f11S7BL1my54sIZMPrxEcqSng2fYU1hDfPB82wI08Xq0cUfDRgwQeon8IvG2GS+iBipBTvZqsvVURt2LJX1bp+WrrrO2vTJbKllcSAXJNNDMSqv1+ip+Hc2ucQnNzQux8Zai4A7bUWTn995FzZxU7UlqL+e9Zx2pcBOEVHyAWRBXm39LYge2jSI2+ey4HjvTYdW7v/yU9HQ== 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=nIklXVIqMNnvTwvkJUffYmhLZc1doDN22kT9oQnfjOQ=; b=wUrfdFaTDql3onumg+IXXZAoO2g4zyIBYpsnhu+tPYrK0uY2sb/QLqDCVQ6jSTsigrib9Cu4fICPZ8p5+OnH0iLghUToVy1iYyKr5YSxPx3Eo8k2xTrkMrW7hTBon+fADVtb/freu4rwXh/PNkvPrppqUnwTuBUKYoIiJe7kSKphJ3YoqHzzC4T+tu7Ai6OnDxnLA3p39MJV3M3xgYlqojVZBV4Djdvy72WKPI/YL62P3J9gAAMKo6iKXOzmPi+su873L0wJ7vQMB5V6+Mzu3OWqtdaX+ZXPNfhEp0bN5plUXEWeg2wFCYY/VEHclbEwqqRvNAIdDn7jaHLgwSVfKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nIklXVIqMNnvTwvkJUffYmhLZc1doDN22kT9oQnfjOQ=; b=lRLEPeavScI8MTcXCPXvkW1ibelMX1jKPbYg1LPuvEEFT6NTZd8IQUrbVY8h4HYkgkmF2F7x2wXXMkqw+sJB5DupF6SCvVTDVFoDMsD3WXRo4wHyIjV+Y08Ts16HLE19BrEv3gjickEB7VIXjGsOgugKnkatRCAxygcI4Z/XxhY= Received: from BN9PR03CA0580.namprd03.prod.outlook.com (2603:10b6:408:10d::15) by SA1PR12MB9545.namprd12.prod.outlook.com (2603:10b6:806:45b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9678.18; Fri, 6 Mar 2026 09:58:25 +0000 Received: from BN2PEPF000044A1.namprd02.prod.outlook.com (2603:10b6:408:10d:cafe::e5) by BN9PR03CA0580.outlook.office365.com (2603:10b6:408:10d::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9678.18 via Frontend Transport; Fri, 6 Mar 2026 09:58:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by 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.9678.18 via Frontend Transport; Fri, 6 Mar 2026 09:58:25 +0000 Received: from BLRRASHENOY1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Fri, 6 Mar 2026 03:58:23 -0600 From: "Gautham R. Shenoy" To: Mario Limonciello , "Rafael J . Wysocki" , Viresh Kumar , K Prateek Nayak CC: , , "Gautham R. Shenoy" Subject: [PATCH 3/9] amd-pstate: Make certain freq_attrs conditionally visible Date: Fri, 6 Mar 2026 15:27:47 +0530 Message-ID: <20260306095753.17155-4-gautham.shenoy@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260306095753.17155-1-gautham.shenoy@amd.com> References: <20260306095753.17155-1-gautham.shenoy@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A1:EE_|SA1PR12MB9545:EE_ X-MS-Office365-Filtering-Correlation-Id: e890b786-a6b4-418e-6774-08de7b66e8c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: 4IKcUJgIuTGUEG/OkoaxoCUVzDKHGRZ2cAFMda1zCvtuZ4Ej73MFiyH7r+I74XS9z6ohbHA6jkTl7TBUNG38BVW/lFo+6Kg2Pt7wI/og157NhYxYnLgpEeyxMwHWjZKJxuaqwZKdJ3FeTKTX/LJLyYsQkmxU2/O8/yDkdjP0MCdlvN+Yxissf9QzE7xYR6aCFQy3p+PnkJ6bs/R941cOS7o9K2AiQ2eZ1qydXBzkFHOaEnsWqHpPHbKK/3naoYl1MYfENFT1qaTffQX48Xe0OcPW7ZbZZB/Dj38u4bTXKU7BNk3KUefLYmSQJPVCbbokf2POv+Tn08uBaUNa5Hx/K2Dk0iMOhR01fgxHAtIVoTjnA+JdeiOXZmU2sFQRNJ0PP+lMrryQGw4gr/r9Av9Bt9JXi+MoBL7dl8hmd9WrZRNxfD2xrLBJqZ+qYRar81uR+7NfW2y300qoYthdevRBXdzivlvjl4aAnlGHtoCji9y3cCPyTGBKHBIwMLauwn2zIWmKPljDFfwvNoU+69iKEUB+vRhs7z8Kvy9hU06PBeJId/5zmfbo7nJ7oCCII7XZfJqztzD1VdGU17rD+Ad0xgpYFEJk9Fzjm4zuXwusKgWlOkb27kW43ODgm5S4TvV1T0JHJXo9epHUaNckqdVOJpVyRNCxidkZriZNbDud+elwoxm2gbnrUuBODL8El4hCea9PZQ/xbyknF3tQuXSJMLcuqeuFWBLiHpB//ypnj3SBKKyN1n9t5YHgh7gD+wkpbpsa2lpedaHw9WLRZU4fMw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sLz6CXIWSoby8u8srVVSOHNvdq37aVoorzzrg348m++g5qdSZTAHuVZepG6NwkhYHlYb+3ywx/H03Wfa+RjOQM8cPLkP9rNg39Z0EpqlSWA9E21CnPZ2IbCZhRnWSEcVaHdhiJB41FlyuFUNVyws7TN/b5FH712dv8KLAKyG15U8vGBFzJldZJLkMzLGnl9Nhs3Yro4aizPZOh6hh711+RJsO034QNcLD7h5dexjrDO3kfIWXhWnFyj/fNG8MaGz7ooAj1TKz8FObr3VIe3YCnzmLVCWEmASR3UoVlz9IQVHZTLc5VxVnv+e9lNBRkgTTAuxRgMPIdz1I99LQgLEzyCekcNXCKvu2voc/xc3zn/UR/08Pt4EMmbhmNtNoIoU2XX//Zm23QK77LtIOXrmZfve2kTzBq+NAWSt07YBQSLyjNopPbyoMRI3GYjQzZgy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2026 09:58:25.4693 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e890b786-a6b4-418e-6774-08de7b66e8c2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A1.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB9545 Content-Type: text/plain; charset="utf-8" Certain amd_pstate freq_attrs such as amd_pstate_hw_prefcore and amd_pstate_prefcore_ranking are enabled even when preferred core is not supported on the platform. Similarly there are common freq_attrs between the amd-pstate and the amd-pstate-epp drivers (eg: amd_pstate_max_freq, amd_pstate_lowest_non_linear_freq, etc.) but are duplicated in two different freq_attr structs. Unify all the attributes in a single place and associate each of them with a visibility function that determines whether the attribute should be visible based on the underlying platform support and the current amd_pstate mode. Signed-off-by: Gautham R. Shenoy --- drivers/cpufreq/amd-pstate.c | 123 ++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 31 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 24cdeffbcd40e..fb5d7bb320c15 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1220,12 +1220,86 @@ static ssize_t show_energy_performance_preference( return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]); } =20 +cpufreq_freq_attr_ro(amd_pstate_max_freq); +cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq); + +cpufreq_freq_attr_ro(amd_pstate_highest_perf); +cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking); +cpufreq_freq_attr_ro(amd_pstate_hw_prefcore); +cpufreq_freq_attr_rw(energy_performance_preference); +cpufreq_freq_attr_ro(energy_performance_available_preferences); + +struct freq_attr_visibility { + struct freq_attr *attr; + bool (*visibility_fn)(void); +}; + +/* For attributes which are always visible */ +static bool always_visible(void) +{ + return true; +} + +/* Determines whether prefcore related attributes should be visible */ +static bool prefcore_visibility(void) +{ + return amd_pstate_prefcore; +} + +/* Determines whether energy performance preference should be visible */ +static bool epp_visibility(void) +{ + return cppc_state =3D=3D AMD_PSTATE_ACTIVE; +} + +static struct freq_attr_visibility amd_pstate_attr_visibility[] =3D { + {&amd_pstate_max_freq, always_visible}, + {&amd_pstate_lowest_nonlinear_freq, always_visible}, + {&amd_pstate_highest_perf, always_visible}, + {&amd_pstate_prefcore_ranking, prefcore_visibility}, + {&amd_pstate_hw_prefcore, prefcore_visibility}, + {&energy_performance_preference, epp_visibility}, + {&energy_performance_available_preferences, epp_visibility}, +}; + +static struct freq_attr **get_freq_attrs(void) +{ + bool attr_visible[ARRAY_SIZE(amd_pstate_attr_visibility)]; + struct freq_attr **attrs; + int i, j, count; + + for (i =3D 0, count =3D 0; i < ARRAY_SIZE(amd_pstate_attr_visibility); i+= +) { + struct freq_attr_visibility *v =3D &amd_pstate_attr_visibility[i]; + + attr_visible[i] =3D v->visibility_fn(); + if (attr_visible[i]) + count++; + } + + /* amd_pstate_{max_freq, lowest_nonlinear_freq, highest_freq} should alwa= ys be visible */ + BUG_ON(!count); + + attrs =3D kcalloc(count + 1, sizeof(struct freq_attr *), GFP_KERNEL); + if (!attrs) + return ERR_PTR(-ENOMEM); + + for (i =3D 0, j =3D 0; i < ARRAY_SIZE(amd_pstate_attr_visibility); i++) { + if (!attr_visible[i]) + continue; + + attrs[j++] =3D amd_pstate_attr_visibility[i].attr; + } + + return attrs; +} + static void amd_pstate_driver_cleanup(void) { if (amd_pstate_prefcore) sched_clear_itmt_support(); =20 cppc_state =3D AMD_PSTATE_DISABLE; + kfree(current_pstate_driver->attr); current_pstate_driver =3D NULL; } =20 @@ -1250,6 +1324,7 @@ static int amd_pstate_set_driver(int mode_idx) =20 static int amd_pstate_register_driver(int mode) { + struct freq_attr **attr =3D NULL; int ret; =20 ret =3D amd_pstate_set_driver(mode); @@ -1258,6 +1333,22 @@ static int amd_pstate_register_driver(int mode) =20 cppc_state =3D mode; =20 + /* + * Note: It is important to compute the attrs _after_ + * re-initializing the cppc_state. Some attributes become + * visible only when cppc_state is AMD_PSTATE_ACTIVE. + */ + attr =3D get_freq_attrs(); + if (IS_ERR(attr)) { + ret =3D (int) PTR_ERR(attr); + pr_err("Couldn't compute freq_attrs for current mode %s [%d]\n", + amd_pstate_get_mode_string(cppc_state), ret); + amd_pstate_driver_cleanup(); + return ret; + } + + current_pstate_driver->attr =3D attr; + /* at least one CPU supports CPB */ current_pstate_driver->boost_enabled =3D cpu_feature_enabled(X86_FEATURE_= CPB); =20 @@ -1399,37 +1490,9 @@ static ssize_t prefcore_show(struct device *dev, return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_prefcore)); } =20 -cpufreq_freq_attr_ro(amd_pstate_max_freq); -cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq); - -cpufreq_freq_attr_ro(amd_pstate_highest_perf); -cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking); -cpufreq_freq_attr_ro(amd_pstate_hw_prefcore); -cpufreq_freq_attr_rw(energy_performance_preference); -cpufreq_freq_attr_ro(energy_performance_available_preferences); static DEVICE_ATTR_RW(status); static DEVICE_ATTR_RO(prefcore); =20 -static struct freq_attr *amd_pstate_attr[] =3D { - &amd_pstate_max_freq, - &amd_pstate_lowest_nonlinear_freq, - &amd_pstate_highest_perf, - &amd_pstate_prefcore_ranking, - &amd_pstate_hw_prefcore, - NULL, -}; - -static struct freq_attr *amd_pstate_epp_attr[] =3D { - &amd_pstate_max_freq, - &amd_pstate_lowest_nonlinear_freq, - &amd_pstate_highest_perf, - &amd_pstate_prefcore_ranking, - &amd_pstate_hw_prefcore, - &energy_performance_preference, - &energy_performance_available_preferences, - NULL, -}; - static struct attribute *pstate_global_attributes[] =3D { &dev_attr_status.attr, &dev_attr_prefcore.attr, @@ -1696,7 +1759,6 @@ static struct cpufreq_driver amd_pstate_driver =3D { .set_boost =3D amd_pstate_set_boost, .update_limits =3D amd_pstate_update_limits, .name =3D "amd-pstate", - .attr =3D amd_pstate_attr, }; =20 static struct cpufreq_driver amd_pstate_epp_driver =3D { @@ -1712,7 +1774,6 @@ static struct cpufreq_driver amd_pstate_epp_driver = =3D { .update_limits =3D amd_pstate_update_limits, .set_boost =3D amd_pstate_set_boost, .name =3D "amd-pstate-epp", - .attr =3D amd_pstate_epp_attr, }; =20 /* @@ -1858,7 +1919,7 @@ static int __init amd_pstate_init(void) return ret; =20 global_attr_free: - cpufreq_unregister_driver(current_pstate_driver); + amd_pstate_unregister_driver(0); return ret; } device_initcall(amd_pstate_init); --=20 2.34.1