From nobody Fri Sep 19 01:05:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08866C4332F for ; Fri, 2 Dec 2022 07:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232552AbiLBHv4 (ORCPT ); Fri, 2 Dec 2022 02:51:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232460AbiLBHv3 (ORCPT ); Fri, 2 Dec 2022 02:51:29 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2057.outbound.protection.outlook.com [40.107.243.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0BDFAC6E1; Thu, 1 Dec 2022 23:51:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ir1/nBfXcG6opj7+KjfRkUiKNziVzFhIWn1W7jqRrf0BLZZphzoVj2el01+9DBcFvmxYBmoHCSGndGS7suaM4iwnGFa9fIWhhTu2YZcf2TNfFMKIb5VPnANQMKNmd/TZGgc7BaIm5XYx1+8Bjzx2AjEGDb/c9BSEAEvqxmbPCew81EzViWba4latX1iBnHcwBH1SddLeQ6de9lgQmawp5p3Mv6lY3hhkWTw0PFQYXCGV8mHugcjMXimitUjUaYPwewK718/KlPeSo5DEMxeOJ1xUhqPPn7M0BvAyeqbva1RfMalE5uQQ9c1E8XJkFF/PMJ2dChSr7RWtb3hj0xTqjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lInKwnjewUZ0O7QKb/uBO/AjMqyVqRBPr9M7mf3tUCw=; b=P8Osvnpzn8sm/ocegjEcFOF1UDLURxScli0yIruqQXG0elYyKe/e2/nGe8vGAB4bO227tfWOunbxi/GkgaXiCim8IPzFAS36C2GxSi17DKIYNK7piOi04BqAkNbDdLFeDjC/xLvCUPiL4eWKsj54fRpQ62oCVVs5QKu0bwEDcjN1LY1hYv2/mtFXp26fzOMczEmhWHNrc1JvY4ffBrlsSI8IPJL7ZG4jJ4Fgz60+Bbsyew6XTDlhOfDJX3vAs0cGjsOuNfVuGyltVWNcC7Kvj37ZeA0OpQlOuo5frwT1lxGoJ0tQD91g+boSa/DlHa6o7ZC+13SvA2z5lk2zGPg8Yw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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 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=lInKwnjewUZ0O7QKb/uBO/AjMqyVqRBPr9M7mf3tUCw=; b=HVhiGau+kshJiUYsD3wG/AseeNz3TPoZ7CAVzRQASZtr00EcGL+9IjQ6PUR00aGPSTS40XZzXvTQeZ9o6NVfLKEeNmHmOHH+eG7NFRpmXJhWTYEDT5y3R9lIdb25CFV95zEEQFPMIj0Ljm3Y3Z8B9m9ujEhJ7UMfCx/5Cng1+Gc= Received: from DS7PR05CA0093.namprd05.prod.outlook.com (2603:10b6:8:56::17) by PH7PR12MB6466.namprd12.prod.outlook.com (2603:10b6:510:1f6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.23; Fri, 2 Dec 2022 07:51:20 +0000 Received: from DM6NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:8:56:cafe::90) by DS7PR05CA0093.outlook.office365.com (2603:10b6:8:56::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8 via Frontend Transport; Fri, 2 Dec 2022 07:51:19 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT055.mail.protection.outlook.com (10.13.173.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Fri, 2 Dec 2022 07:51:19 +0000 Received: from pyuan-Cloudripper.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 2 Dec 2022 01:51:16 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v6 05/11] cpufreq: amd_pstate: implement amd pstate cpu online and offline callback Date: Fri, 2 Dec 2022 15:47:13 +0800 Message-ID: <20221202074719.623673-6-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221202074719.623673-1-perry.yuan@amd.com> References: <20221202074719.623673-1-perry.yuan@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT055:EE_|PH7PR12MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bef6498-c38b-4543-d790-08dad439fff8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NjmGmuRApnVi5H65t7GWLBliij1Zthz0bvIwCsOJNejxplajJVvk8M7NPzRpYT9K6fOH0WrAOTqTHJaLKndG28tK4xyHyyWKtFXX6uuvuz3EVpAlBIIgKeil36dofvWdqxNunqroawWi//c9ycHqGiclAQ809gM8/eOlAXUt6AmV+/MwBpP/dbBhZozubwhOJohzZacVerUncAz28Z/QHOXdvQpIm+3i/GLK9DbRDNO5aqU/mJW/THIfKT5LMz33cB//yEztiHCM+C0EOOq9w1sw5A0O1q5VK63vBabZ2xzigxxnw/iT1NlFpsanDDNpIZ7UkV1uwx9oWS8srWGT3zrqxNimDHN5sBX/iLDn73lCcJqRFppZUjl4O3XVHsP7DPIXtcn62O+QT6XrqgZQfS+U3PeGd8ZRp6PNhiRoXGrLYdaRFC58xkHNAcgoaZj4qpnupQbksmGeVm0c1GpTyVb+o12R0rY7C5FxC2L3D/pccdyXAEwKIEd12FqJc4NDZacKvrqcj2/GzZtpXKttEn6fls9LEKm173YRMxpfsnuVN8fE0sm2bcj6htU1iqo9Ntxm0wdEl7YKPnq9DUQayF/KvdHLlORqNsCjFCOkXH3UrUm5Ovon0SDamDoFRDSwMjmiBvgPHqhIrVnvAwL3ujs2SRj7738fSgK+T5WUmCYW/8q5+t+s6HpfgxJRTaK/SG7DtBecDSsBHJSviX24nwEl/tVJzle7LuIqzQrxnx0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(39860400002)(136003)(396003)(451199015)(36840700001)(46966006)(40470700004)(36756003)(70206006)(44832011)(70586007)(41300700001)(5660300002)(4326008)(8936002)(26005)(2906002)(40460700003)(82310400005)(8676002)(83380400001)(478600001)(336012)(7696005)(2616005)(47076005)(54906003)(186003)(16526019)(86362001)(1076003)(316002)(110136005)(426003)(40480700001)(356005)(81166007)(82740400003)(36860700001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 07:51:19.8287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4bef6498-c38b-4543-d790-08dad439fff8 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6466 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Perry Yuan Adds online and offline driver callback support to allow cpu cores go offline and help to restore the previous working states when core goes back online later for EPP driver mode. Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 89 ++++++++++++++++++++++++++++++++++++ include/linux/amd-pstate.h | 1 + 2 files changed, 90 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 5989d4d25d0f..7545d83a934b 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1197,6 +1197,93 @@ static int amd_pstate_epp_set_policy(struct cpufreq_= policy *policy) return 0; } =20 +static void amd_pstate_epp_reenable(struct amd_cpudata *cpudata) +{ + struct cppc_perf_ctrls perf_ctrls; + u64 value, max_perf; + int ret; + + ret =3D amd_pstate_enable(true); + if (ret) + pr_err("failed to enable amd pstate during resume, return %d\n", ret); + + value =3D READ_ONCE(cpudata->cppc_req_cached); + max_perf =3D READ_ONCE(cpudata->highest_perf); + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); + } else { + perf_ctrls.max_perf =3D max_perf; + perf_ctrls.energy_perf =3D AMD_CPPC_ENERGY_PERF_PREF(cpudata->epp_cached= ); + cppc_set_perf(cpudata->cpu, &perf_ctrls); + } +} + +static int amd_pstate_epp_cpu_online(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata =3D all_cpu_data[policy->cpu]; + + pr_debug("AMD CPU Core %d going online\n", cpudata->cpu); + + if (cppc_active) { + amd_pstate_epp_reenable(cpudata); + cpudata->suspended =3D false; + } + + return 0; +} + +static void amd_pstate_epp_offline(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata =3D all_cpu_data[policy->cpu]; + struct cppc_perf_ctrls perf_ctrls; + int min_perf; + u64 value; + + min_perf =3D READ_ONCE(cpudata->lowest_perf); + value =3D READ_ONCE(cpudata->cppc_req_cached); + + mutex_lock(&amd_pstate_limits_lock); + if (boot_cpu_has(X86_FEATURE_CPPC)) { + cpudata->epp_policy =3D CPUFREQ_POLICY_UNKNOWN; + + /* Set max perf same as min perf */ + value &=3D ~AMD_CPPC_MAX_PERF(~0L); + value |=3D AMD_CPPC_MAX_PERF(min_perf); + value &=3D ~AMD_CPPC_MIN_PERF(~0L); + value |=3D AMD_CPPC_MIN_PERF(min_perf); + wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); + } else { + perf_ctrls.desired_perf =3D 0; + perf_ctrls.max_perf =3D min_perf; + perf_ctrls.energy_perf =3D AMD_CPPC_ENERGY_PERF_PREF(HWP_EPP_POWERSAVE); + cppc_set_perf(cpudata->cpu, &perf_ctrls); + } + mutex_unlock(&amd_pstate_limits_lock); +} + +static int amd_pstate_cpu_offline(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata =3D all_cpu_data[policy->cpu]; + + pr_debug("AMD CPU Core %d going offline\n", cpudata->cpu); + + if (cpudata->suspended) + return 0; + + if (cppc_active) + amd_pstate_epp_offline(policy); + + return 0; +} + +static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy) +{ + amd_pstate_clear_update_util_hook(policy->cpu); + + return amd_pstate_cpu_offline(policy); +} + static void amd_pstate_verify_cpu_policy(struct amd_cpudata *cpudata, struct cpufreq_policy_data *policy) { @@ -1231,6 +1318,8 @@ static struct cpufreq_driver amd_pstate_epp_driver = =3D { .init =3D amd_pstate_epp_cpu_init, .exit =3D amd_pstate_epp_cpu_exit, .update_limits =3D amd_pstate_epp_update_limits, + .offline =3D amd_pstate_epp_cpu_offline, + .online =3D amd_pstate_epp_cpu_online, .name =3D "amd_pstate_epp", .attr =3D amd_pstate_epp_attr, }; diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h index 888af62040f1..3dd26a3d104c 100644 --- a/include/linux/amd-pstate.h +++ b/include/linux/amd-pstate.h @@ -99,6 +99,7 @@ struct amd_cpudata { u64 cppc_cap1_cached; struct update_util_data update_util; struct amd_aperf_mperf sample; + bool suspended; }; =20 /** --=20 2.34.1