From patchwork Thu Dec 8 11:18:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632818 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 8A5DDC4332F for ; Thu, 8 Dec 2022 11:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbiLHLTU (ORCPT ); Thu, 8 Dec 2022 06:19:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiLHLTS (ORCPT ); Thu, 8 Dec 2022 06:19:18 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2054.outbound.protection.outlook.com [40.107.237.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D58848419; Thu, 8 Dec 2022 03:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GAdVP5VQz/lHd4Io3cUi+1a9mgzocDFqwHonfqb5ONToRZx7oTjGpHqFmO+vaSbpMJcCfs8KrczTI3L4xtyPiB66bv4CyViXAqFnPWzLgOZie1/1S16XeFw7bT1sRYkrqDmXOpR5Vy28HbGhn6yCXwVpo2jAFNBIxnvnwq/JCB1SYqzkpyxuXtRdaerFce8eqWfubLaYKyi0pCjvs+2hlWPxuOKScGRDc6a2tHhrG8TwsNXm3jX5V6eYuxMtvuaWCpUYv4YMbmgu8mtd+tzhwNMpbB1OWd393i6YMF00DO0IheRvPgGgyLffWiu7XrlJ2t5nrc/VjjVN3k4Yc2No0w== 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=YMaMqujGg/ZWCEQWl3lRYrDw2txqmH8EZFKrR4sMAiA=; b=P0jVbCF8PR8JM5nGxjFnQVBCfgWPlPgP4tgCH81GUUor750+YAOCbHLMa467D+QZvAXV2gDRfRA/8j0Hj5HOQrFtvbPMq9KFXUtAFJJu00lbITMRUa6SMaP2jtntzzNcpB39LosHsSkTkqQmKHzaKtrZAw60guJCwpBuqnlqKOa9Ukvrlap0KRZoxSbSP4XzMrF8kS4TBymwYrb0fl5Bq9/r5d4xzrFJZIowDpLG17ldlg1rn8OXsd+dGbymqTpnXNCYq47T9FJR9xXGjrLzpngHu1I+scKxaV9wDZHCvHKHvKK3A1wxzNrXxksEllAZTzDTfLoFaqnjFtwuX+0A2g== 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=YMaMqujGg/ZWCEQWl3lRYrDw2txqmH8EZFKrR4sMAiA=; b=pR3zvu76BkMffqRl8iVRQV6lS4PpyAhpX3+ooRdfMi5h4+n7RSs19RUnCt7azVMYj6oT3q4iTAFJPIhtSo3p1uu57dSJDZEd1cusxRxms0bBT9W2R82ypv/g2oSF10bMnBACL7HmtGavdUMWaW5nlcZhVkk9gxeAqKWgsc23aTw= Received: from DM6PR06CA0027.namprd06.prod.outlook.com (2603:10b6:5:120::40) by PH7PR12MB7425.namprd12.prod.outlook.com (2603:10b6:510:200::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:19:14 +0000 Received: from DM6NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:5:120:cafe::d9) by DM6PR06CA0027.outlook.office365.com (2603:10b6:5:120::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:19:14 +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 DM6NAM11FT088.mail.protection.outlook.com (10.13.172.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:14 +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; Thu, 8 Dec 2022 05:19:10 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 01/13] ACPI: CPPC: Add AMD pstate energy performance preference cppc control Date: Thu, 8 Dec 2022 19:18:40 +0800 Message-ID: <20221208111852.386731-2-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT088:EE_|PH7PR12MB7425:EE_ X-MS-Office365-Filtering-Correlation-Id: 185e505e-ef63-45b8-0fdc-08dad90e09ec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AzVfe2E32pLfdy+FioQdUHIsEaBzXsr9emSQsqV2hMnhvJ4+vyJETnhNGjdVgYhFt1ErQ1dAVQ9RXSgZ8z3rjQ5Ay/cHq+Ot9XB/mbGrxKHCZAZ/U9J1tDX/l3dgme8uaeZbvqdO0CAE8QUOiR4eNMFhtDG+c3OCn2TKRC3UL6JUaNLBKQWVpYu0VFXudzAM3UIItLY8E/tactuM4c1oR1HlXyp6XRY8YXAJIuVs6ois6KvIst0UUuVg0WexXSbKFLm5DiAkM7TyZTXUT4ezaXtd1V4MxW3Fe245ZsmhsJHmPK+nkaYd4FYbNieEeOtvudjjbs+1T9Op50MVAbzxw9iNGMjpTzSMbgrLXRgowDFYOWzZ7jzkwYoJ05thTnAkXYDUu+sxZFAEV9blp7rAIoy4z/DAH2qUP4L913rrLyf5/+OrEuFTIHDFvsApcBgdyqXdM+5fxvSNQNw081MXN1v8Al1CpHG6PWUSKePG4FEcaCbs9njXr0rrN/lrZLzOLdHqFK6MZycKW1X/6cBktdexj7enKbmDXoUcDMNxsfI5DzcnpPm/yh/3ZuN7jUupTzZzNczfuBoF+rZddpWO17BDJQQ0yqoO3FinHBaapAYAL38ReuQpVpbdl1tyS9AJALPbuWGlG96BhsYLjY23IDyHkJlIbiBIy+mD6vumv4OM9HVt+btmE7HDedsTQUqp2kEDFY3SAXkyBK6AkvYlqxOnl30C/6pHkhIkNzpOpOM= 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)(39860400002)(346002)(376002)(136003)(396003)(451199015)(36840700001)(46966006)(40470700004)(8936002)(70586007)(70206006)(5660300002)(44832011)(8676002)(4326008)(41300700001)(110136005)(478600001)(356005)(81166007)(36756003)(40460700003)(54906003)(316002)(2906002)(86362001)(40480700001)(2616005)(7696005)(1076003)(6666004)(16526019)(336012)(186003)(26005)(83380400001)(82740400003)(426003)(47076005)(82310400005)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:14.4800 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 185e505e-ef63-45b8-0fdc-08dad90e09ec 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: DM6NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7425 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Perry Yuan Add support for setting and querying EPP preferences to the generic CPPC driver. This enables downstream drivers such as amd-pstate to discover and use these values Downstream drivers that want to use the new symbols cppc_get_epp_caps and cppc_set_epp_perf for querying and setting EPP preferences will need to call cppc_set_auto_epp to enable the EPP function first. Signed-off-by: Perry Yuan --- drivers/acpi/cppc_acpi.c | 114 +++++++++++++++++++++++++++++++++++++-- include/acpi/cppc_acpi.h | 12 +++++ 2 files changed, 121 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 093675b1a1ff..37fa75f25f62 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1093,6 +1093,9 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf) { struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum); struct cpc_register_resource *reg; + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum); + struct cppc_pcc_data *pcc_ss_data = NULL; + int ret = -EINVAL; if (!cpc_desc) { pr_debug("No CPC descriptor for CPU:%d\n", cpunum); @@ -1102,10 +1105,6 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf) reg = &cpc_desc->cpc_regs[reg_idx]; if (CPC_IN_PCC(reg)) { - int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum); - struct cppc_pcc_data *pcc_ss_data = NULL; - int ret = 0; - if (pcc_ss_id < 0) return -EIO; @@ -1125,7 +1124,7 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf) cpc_read(cpunum, reg, perf); - return 0; + return ret; } /** @@ -1365,6 +1364,111 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) } EXPORT_SYMBOL_GPL(cppc_get_perf_ctrs); +/** + * cppc_get_epp_caps - Get the energy preference register value. + * @cpunum: CPU from which to get epp preference level. + * @perf_caps: Return address. + * + * Return: 0 for success, -EIO otherwise. + */ +int cppc_get_epp_caps(int cpunum, struct cppc_perf_caps *perf_caps) +{ + struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum); + struct cpc_register_resource *energy_perf_reg; + u64 energy_perf; + + if (!cpc_desc) { + pr_debug("No CPC descriptor for CPU:%d\n", cpunum); + return -ENODEV; + } + + energy_perf_reg = &cpc_desc->cpc_regs[ENERGY_PERF]; + + if (!CPC_SUPPORTED(energy_perf_reg)) + pr_warn_once("energy perf reg update is unsupported!\n"); + + if (CPC_IN_PCC(energy_perf_reg)) { + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum); + struct cppc_pcc_data *pcc_ss_data = NULL; + int ret = 0; + + if (pcc_ss_id < 0) + return -ENODEV; + + pcc_ss_data = pcc_data[pcc_ss_id]; + + down_write(&pcc_ss_data->pcc_lock); + + if (send_pcc_cmd(pcc_ss_id, CMD_READ) >= 0) { + cpc_read(cpunum, energy_perf_reg, &energy_perf); + perf_caps->energy_perf = energy_perf; + } else { + ret = -EIO; + } + + up_write(&pcc_ss_data->pcc_lock); + + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(cppc_get_epp_caps); + +/* + * Set Energy Performance Preference Register value through + * Performance Controls Interface + */ +int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) +{ + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); + struct cpc_register_resource *epp_set_reg; + struct cpc_register_resource *auto_sel_reg; + struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu); + struct cppc_pcc_data *pcc_ss_data = NULL; + int ret = -EINVAL; + + if (!cpc_desc) { + pr_debug("No CPC descriptor for CPU:%d\n", cpu); + return -ENODEV; + } + + auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE]; + epp_set_reg = &cpc_desc->cpc_regs[ENERGY_PERF]; + + if (CPC_IN_PCC(epp_set_reg) || CPC_IN_PCC(auto_sel_reg)) { + if (pcc_ss_id < 0) { + pr_debug("Invalid pcc_ss_id\n"); + return -ENODEV; + } + + if (CPC_SUPPORTED(auto_sel_reg)) { + ret = cpc_write(cpu, auto_sel_reg, enable); + if (ret) + return ret; + } + + if (CPC_SUPPORTED(epp_set_reg)) { + ret = cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf); + if (ret) + return ret; + } + + pcc_ss_data = pcc_data[pcc_ss_id]; + + down_write(&pcc_ss_data->pcc_lock); + /* after writing CPC, transfer the ownership of PCC to platform */ + ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE); + up_write(&pcc_ss_data->pcc_lock); + } else { + ret = -ENOTSUPP; + pr_debug("_CPC in PCC is not supported\n"); + } + + return ret; +} +EXPORT_SYMBOL_GPL(cppc_set_epp_perf); + /** * cppc_set_enable - Set to enable CPPC on the processor by writing the * Continuous Performance Control package EnableRegister field. diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index c5614444031f..a45bb876a19c 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -108,12 +108,14 @@ struct cppc_perf_caps { u32 lowest_nonlinear_perf; u32 lowest_freq; u32 nominal_freq; + u32 energy_perf; }; struct cppc_perf_ctrls { u32 max_perf; u32 min_perf; u32 desired_perf; + u32 energy_perf; }; struct cppc_perf_fb_ctrs { @@ -149,6 +151,8 @@ extern bool cpc_ffh_supported(void); extern bool cpc_supported_by_cpu(void); extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val); extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val); +extern int cppc_get_epp_caps(int cpunum, struct cppc_perf_caps *perf_caps); +extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { @@ -202,6 +206,14 @@ static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val) { return -ENOTSUPP; } +static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) +{ + return -ENOTSUPP; +} +static inline int cppc_get_epp_caps(int cpunum, struct cppc_perf_caps *perf_caps) +{ + return -ENOTSUPP; +} #endif /* !CONFIG_ACPI_CPPC_LIB */ #endif /* _CPPC_ACPI_H*/ From patchwork Thu Dec 8 11:18:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632124 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 1A138C63709 for ; Thu, 8 Dec 2022 11:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbiLHLTW (ORCPT ); Thu, 8 Dec 2022 06:19:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbiLHLTV (ORCPT ); Thu, 8 Dec 2022 06:19:21 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2041.outbound.protection.outlook.com [40.107.92.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C66324733C; Thu, 8 Dec 2022 03:19:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ucfa4za1RZnKCYNkc/Nw0XHgFK6P9onlednDhxS3/kiMG4UWk0gJT0AWT0LJY8zcdGAYgnqvuhnTu4vqhEMv0s9lxJMKbMOcaULhpzpmqCqZ1nMmo7CsOtjSefOhmgxvwtyyIZ02z3H4E3r+4Bh8pEpo/eygCK8Qnqg2JtRZqoPlbBHum0tkkUKnca6s5K5Cv3Keqw5tbaOeP1BZoj7UWVeGMV1Wdu49SD9Apfs/GLg0ewveNVqcMQUUtv2XvoIBPh8EhLexB/KDpZdoJpgDb2Y10Jgz9wg5oq861uyYLgTPo5dP7CC9j9HJNZGOQBWPxZ89S2RfbPVv9EuY0muRQQ== 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=/lHyokvSSTNMOUXwriwhOhupYBjdKujambfB0vTM8Zk=; b=jD6JHI0cInr4YkEP0FwXDMFDxsr/DZYS26GLH/f5+eBOi0RXQWppx7GEMZRUdCr9oYal45WLFNuxAgKwn/NELT8Gm3t8IMKMLNWpJgEpA0zFCQtO/9cSnzTF+dTA0qH+fJl/olw+cmhnGrRZZZZ7LyjOwYGDex3xwlWibAAVUIdiDZM5SYYiXRh4dJSwPKxtUs6+LYnWoch0dD9VQFUyAQHINzLLliwAFlqV3UFy+AVDBKPw0tTW8+MsVLek87ESMS+x965vE1WRk9oQnv5nvOht/jPdEID9l3Nzh0lT+CK2BICPgXsw2mqROvRhJHM99QvTPD6yGUUTgJTUgHukPA== 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=/lHyokvSSTNMOUXwriwhOhupYBjdKujambfB0vTM8Zk=; b=2FPCgmrJhI2FIs2aUgC5kID3VRHqoxwpDeGCrcwn0EepyJZOM44y6OArCT2XFM0OumpWr0KW8hVYobS4uRXoAbVTccvYogUwofbEjDEruZtmlDyZammX3ahOwYyDJc3YYU49RC3F8gBuQxPKAho2OQlq1S02CHBSSC4XjpUoBAo= Received: from DM6PR03CA0080.namprd03.prod.outlook.com (2603:10b6:5:333::13) by LV2PR12MB5990.namprd12.prod.outlook.com (2603:10b6:408:170::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.11; Thu, 8 Dec 2022 11:19:18 +0000 Received: from DM6NAM11FT112.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::8d) by DM6PR03CA0080.outlook.office365.com (2603:10b6:5:333::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:17 +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 DM6NAM11FT112.mail.protection.outlook.com (10.13.173.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:17 +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; Thu, 8 Dec 2022 05:19:14 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 02/13] Documentation: amd-pstate: add EPP profiles introduction Date: Thu, 8 Dec 2022 19:18:41 +0800 Message-ID: <20221208111852.386731-3-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT112:EE_|LV2PR12MB5990:EE_ X-MS-Office365-Filtering-Correlation-Id: aee08f5f-f542-440c-ee4d-08dad90e0bef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ddrwh4sDnClz0FI/09rju+9DXk7vxsMpmC4DmhcCkXZCv/9P6kPimcY6zhnnvtUOPs2iIpR3kYaFu/PyLsNPVZKkLyaJXaOK3zLVg4weRzTwShCQn7W5nIaTWcrDUhfCU9S0dnBebhQbVUjG4OXSAuGYuHa7tqVPabK0Pl7rTVeBNkq3315mEgrATdpvb37O8HJ3aD88LoQEycC6QGFIN1JISkcPaOpfVJR2MOheX+uxXDx+/4OdRqBSWWdQelynCKN+pPtMaha0erP1xMr5IlIR/ss7zabGz5rPYbuLHEX2CNUi428ucVP7YtvRI/DVm06u62EWOGfdcfseAhBfcou/hvcttob3XbvrC9f7Vb4mLEu/r+S4/pP7lrd8xeUK5uq5+WdDauuc4qFhBs2cCyN2JOaCZC3sGL+DGLWT1Xhde+p1lLxQF1VXkFNskMCCz5uRlHvSwg1ET7dl7BWhiylscYuOwWAm5NJVrmpd0IgiBhEo1p1I1zZtcTCZpK1i9Du+mYe/cBgrBAR5J/fsnhWexloBZ+uPELeDtLg2wQZaZrYRJm1vk8XNOZsnfGttCRbS93Q4iWuHIPbZFgWB3hw6M307DKM3B5gPDaMeXa3DYaKgulo2VLJCeaU9iqmOVCfSL99Ljqd3d5TUHGERP9fQTO98/W3Ub8Er8LseVeVrJaN70tmiFC5LhgAJAmIEE8CAFqPGvEhLIwusGGgH7nzPcjttvodEUO1Kjw0oy3U= 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)(39860400002)(376002)(346002)(396003)(136003)(451199015)(40470700004)(46966006)(36840700001)(7696005)(6666004)(26005)(336012)(54906003)(36756003)(1076003)(110136005)(81166007)(40460700003)(36860700001)(86362001)(82740400003)(16526019)(186003)(478600001)(2616005)(40480700001)(426003)(82310400005)(83380400001)(356005)(47076005)(316002)(5660300002)(41300700001)(70206006)(70586007)(4326008)(44832011)(8676002)(8936002)(2906002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:17.8608 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aee08f5f-f542-440c-ee4d-08dad90e0bef 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: DM6NAM11FT112.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5990 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Perry Yuan The patch add AMD pstate EPP feature introduction and what EPP preference supported for AMD processors. User can get supported list from energy_performance_available_preferences attribute file, or update current profile to energy_performance_preference file 1) See all EPP profiles $ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences default performance balance_performance balance_power power 2) Check current EPP profile $ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference performance 3) Set new EPP profile $ sudo bash -c "echo power > /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference" Signed-off-by: Perry Yuan --- Documentation/admin-guide/pm/amd-pstate.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst index 06e23538f79c..33ab8ec8fc2f 100644 --- a/Documentation/admin-guide/pm/amd-pstate.rst +++ b/Documentation/admin-guide/pm/amd-pstate.rst @@ -262,6 +262,25 @@ lowest non-linear performance in `AMD CPPC Performance Capability `_.) This attribute is read-only. +``energy_performance_available_preferences`` + +A list of all the supported EPP preferences that could be used for +``energy_performance_preference`` on this system. +These profiles represent different hints that are provided +to the low-level firmware about the user's desired energy vs efficiency +tradeoff. ``default`` represents the epp value is set by platform +firmware. This attribute is read-only. + +``energy_performance_preference`` + +The current energy performance preference can be read from this attribute. +and user can change current preference according to energy or performance needs +Please get all support profiles list from +``energy_performance_available_preferences`` attribute, all the profiles are +integer values defined between 0 to 255 when EPP feature is enabled by platform +firmware, if EPP feature is disabled, driver will ignore the written value +This attribute is read-write. + Other performance and frequency values can be read back from ``/sys/devices/system/cpu/cpuX/acpi_cppc/``, see :ref:`cppc_sysfs`. From patchwork Thu Dec 8 11:18:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632817 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 A04D4C4332F for ; Thu, 8 Dec 2022 11:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbiLHLTh (ORCPT ); Thu, 8 Dec 2022 06:19:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229684AbiLHLTY (ORCPT ); Thu, 8 Dec 2022 06:19:24 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2065.outbound.protection.outlook.com [40.107.244.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A0334E41A; Thu, 8 Dec 2022 03:19:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bKc/7FMHsOGQNThPhZmcQY/Z+iCpXkAysT71ouyO9MdQ/REqm+ST6ohzckJGdsANCluyl9Lxufyyf975/duyRAgMLNClbB+GnwYvTFoZmISDwYLCjdFXmJUn5aGerqqY2uBjCQzxSDA0tCTFmsqHAvFdlJpL/JvSMku3/UiunI/3aTJcxmWf8al6K/g0dKsddFWak0kWFpDHGOzBFx2DYXWeOxGPM7yz3Tdl0iN58XZn30Xzsjib4RgjnKLN2ng+Pbi5KU75Rtvc7AgmTLTzXZc2XKkf2A1rmx3XZBDMBvuTgdtpUd8QANZu5MqCSSYJG73yXy1BA5sW89oXeW3hLA== 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=508HYr51YNonVzKbhrMdNR33HGNXYzF4bHqF361H0js=; b=VGn7HY18Rr3bit1yH/e15bSGhqVRN3r2FyAlMhiiYHMW73UVY//P3ZzTAww2KzThavCo+thh5tqmSfhKWXx5xVwbs9/LtO3azf1lXDSkOMZVdeUksQF7I6LwtXPdrh+4lLG8DxsaYzKscfbMuQ6aQzQAa3Fe0voZMqmAvtAfExmjYHIj57HKVaVb/Q3pOrQo//CDobHEng/GrNVHpBgOlNTTBto+OTNDkWe8NEpZnq6HSTMlccS3s/BTl6XTChvIsXdJIydrF500dmqrsjkrMf9viuVpmAOnIt5gJpWApYSKazy8qDjHYXKkczrZa4DoMrAayYPm83DYREOrxutWSg== 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=508HYr51YNonVzKbhrMdNR33HGNXYzF4bHqF361H0js=; b=1EpvEa6ZN2z/qRg1MF7yb4kFhYnpDTWONwErF31/KeQySY/jyxaIeHlHomI6t4zrErs1JL3Jm0Y8YrUNMpKOJ8Xn33XmuoHGsHA4hy+HBvt5hpBAHiRfgCwqYApvzooqFkDgxrqiDSOZ30eFrPJ6C+C39WfjvjPXnGvz4sfG3lw= Received: from DM6PR11CA0051.namprd11.prod.outlook.com (2603:10b6:5:14c::28) by BY5PR12MB4918.namprd12.prod.outlook.com (2603:10b6:a03:1df::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:19:22 +0000 Received: from DM6NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:5:14c:cafe::ba) by DM6PR11CA0051.outlook.office365.com (2603:10b6:5:14c::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:21 +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 DM6NAM11FT034.mail.protection.outlook.com (10.13.173.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:21 +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; Thu, 8 Dec 2022 05:19:17 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 03/13] cpufreq: intel_pstate: use common macro definition for Energy Preference Performance(EPP) Date: Thu, 8 Dec 2022 19:18:42 +0800 Message-ID: <20221208111852.386731-4-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT034:EE_|BY5PR12MB4918:EE_ X-MS-Office365-Filtering-Correlation-Id: 86ff73f6-9b05-42e8-6975-08dad90e0e21 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dhn11mzdcGxjkMmZRK8zJ+2OGAjN8dwC2Oc4EJAuyIdjkKDO5CvR7a7Pl70r7TybneZjPLPF6ROnot4isIvXdE+B37tl51pFeyGgueTfN0iEtITFvXaCzBdEzjdRNpJsyF7PVxO9laQb8xNsGj/nXQTqBjbBY3l8FsB9pfJY+uvM0Ggqx5EqXo6nGthEZHF+0uYCjo0h4fNKQATbwUvSQCyX9/OPt+kYwwrng8sRfar7abmdOf2Bf7GmvFEOAxlvSKzqqF3S1T03JmKrSCVgVbqq1RNftMfYAJin7aRL+oRsm4QEDpn3/OY6oKucuT5Eu4BMEjRw/9vvET2kQwOqYsTSSGfuDam+8wQllmbmY7M8xJnV9/UOhi2QiJ1PSjX4b0PCnO1oqhpu+FmeJRxwJWeuvED9IYRecSYoEUaQgi9hz0imTavYSwmtgC6Fn3D+5ZUX6JN2J+0iGAM1i68fGSoMAaXQjw6f/xv/KuKNUHQr3reTrG8HB21sEx6QVAwmqgIRUpXv0iwBYVNDCR44w+kDxulbD1GR2bYGka4EiqG/hQ4NVtNURAN3NR3uUvC/Dolt/7DMvSrsus5W5tiuKnlHLTYYLLBFS4xcemBsmKJpnmrQCxmucoO1rmI8qkoRiqoBynQ0X8tsQ7rZ5LUICPC77/oQexmK4pBq9jc9nRPObKlyA//kaZAxlT0MBu8MbT4AaIGc/j6AYy3pUJyLBqoy1+FFcb9Kzok87HgpLJI= 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)(136003)(346002)(39860400002)(376002)(396003)(451199015)(40470700004)(36840700001)(46966006)(2906002)(36860700001)(83380400001)(40480700001)(16526019)(2616005)(41300700001)(1076003)(40460700003)(336012)(86362001)(82740400003)(36756003)(82310400005)(81166007)(110136005)(356005)(26005)(426003)(44832011)(5660300002)(8676002)(478600001)(8936002)(47076005)(4326008)(70206006)(186003)(70586007)(316002)(6666004)(7696005)(54906003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:21.5405 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 86ff73f6-9b05-42e8-6975-08dad90e0e21 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: DM6NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4918 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org make the energy preference performance strings and profiles using one common header for intel_pstate driver, then the amd_pstate epp driver can use the common header as well. This will simpify the intel_pstate and amd_pstate driver. Signed-off-by: Perry Yuan --- arch/x86/include/asm/msr-index.h | 4 --- drivers/cpufreq/intel_pstate.c | 37 +--------------------- include/linux/cpufreq_common.h | 53 ++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 include/linux/cpufreq_common.h diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 4a2af82553e4..3983378cff5b 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -472,10 +472,6 @@ #define HWP_MAX_PERF(x) ((x & 0xff) << 8) #define HWP_DESIRED_PERF(x) ((x & 0xff) << 16) #define HWP_ENERGY_PERF_PREFERENCE(x) (((unsigned long long) x & 0xff) << 24) -#define HWP_EPP_PERFORMANCE 0x00 -#define HWP_EPP_BALANCE_PERFORMANCE 0x80 -#define HWP_EPP_BALANCE_POWERSAVE 0xC0 -#define HWP_EPP_POWERSAVE 0xFF #define HWP_ACTIVITY_WINDOW(x) ((unsigned long long)(x & 0xff3) << 32) #define HWP_PACKAGE_CONTROL(x) ((unsigned long long)(x & 0x1) << 42) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index ad9be31753b6..1b842ed874ab 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -628,42 +629,6 @@ static int intel_pstate_set_epb(int cpu, s16 pref) return 0; } -/* - * EPP/EPB display strings corresponding to EPP index in the - * energy_perf_strings[] - * index String - *------------------------------------- - * 0 default - * 1 performance - * 2 balance_performance - * 3 balance_power - * 4 power - */ - -enum energy_perf_value_index { - EPP_INDEX_DEFAULT = 0, - EPP_INDEX_PERFORMANCE, - EPP_INDEX_BALANCE_PERFORMANCE, - EPP_INDEX_BALANCE_POWERSAVE, - EPP_INDEX_POWERSAVE, -}; - -static const char * const energy_perf_strings[] = { - [EPP_INDEX_DEFAULT] = "default", - [EPP_INDEX_PERFORMANCE] = "performance", - [EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance", - [EPP_INDEX_BALANCE_POWERSAVE] = "balance_power", - [EPP_INDEX_POWERSAVE] = "power", - NULL -}; -static unsigned int epp_values[] = { - [EPP_INDEX_DEFAULT] = 0, /* Unused index */ - [EPP_INDEX_PERFORMANCE] = HWP_EPP_PERFORMANCE, - [EPP_INDEX_BALANCE_PERFORMANCE] = HWP_EPP_BALANCE_PERFORMANCE, - [EPP_INDEX_BALANCE_POWERSAVE] = HWP_EPP_BALANCE_POWERSAVE, - [EPP_INDEX_POWERSAVE] = HWP_EPP_POWERSAVE, -}; - static int intel_pstate_get_energy_pref_index(struct cpudata *cpu_data, int *raw_epp) { s16 epp; diff --git a/include/linux/cpufreq_common.h b/include/linux/cpufreq_common.h new file mode 100644 index 000000000000..c1224e3bc68b --- /dev/null +++ b/include/linux/cpufreq_common.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * linux/include/linux/cpufreq_common.h + * + * Copyright (C) 2022 Advanced Micro Devices, Inc. + * + * Author: Perry Yuan + */ + +#ifndef _LINUX_CPUFREQ_COMMON_H +#define _LINUX_CPUFREQ_COMMON_H +/* + * EPP/EPB display strings corresponding to EPP index in the + * energy_perf_strings[] + * index String + *------------------------------------- + * 0 default + * 1 performance + * 2 balance_performance + * 3 balance_power + * 4 power + */ + +#define HWP_EPP_PERFORMANCE 0x00 +#define HWP_EPP_BALANCE_PERFORMANCE 0x80 +#define HWP_EPP_BALANCE_POWERSAVE 0xC0 +#define HWP_EPP_POWERSAVE 0xFF + +enum energy_perf_value_index { + EPP_INDEX_DEFAULT = 0, + EPP_INDEX_PERFORMANCE, + EPP_INDEX_BALANCE_PERFORMANCE, + EPP_INDEX_BALANCE_POWERSAVE, + EPP_INDEX_POWERSAVE, +}; + +static const char * const energy_perf_strings[] = { + [EPP_INDEX_DEFAULT] = "default", + [EPP_INDEX_PERFORMANCE] = "performance", + [EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance", + [EPP_INDEX_BALANCE_POWERSAVE] = "balance_power", + [EPP_INDEX_POWERSAVE] = "power", + NULL +}; + +static unsigned int epp_values[] = { + [EPP_INDEX_DEFAULT] = 0, /* Unused index */ + [EPP_INDEX_PERFORMANCE] = HWP_EPP_PERFORMANCE, + [EPP_INDEX_BALANCE_PERFORMANCE] = HWP_EPP_BALANCE_PERFORMANCE, + [EPP_INDEX_BALANCE_POWERSAVE] = HWP_EPP_BALANCE_POWERSAVE, + [EPP_INDEX_POWERSAVE] = HWP_EPP_POWERSAVE, +}; +#endif /* _LINUX_CPUFREQ_COMMON_H */ From patchwork Thu Dec 8 11:18:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632123 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 43504C4332F for ; Thu, 8 Dec 2022 11:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229709AbiLHLTm (ORCPT ); Thu, 8 Dec 2022 06:19:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiLHLTi (ORCPT ); Thu, 8 Dec 2022 06:19:38 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2061.outbound.protection.outlook.com [40.107.100.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 121A75802D; Thu, 8 Dec 2022 03:19:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hAGYeryx57Lb/lDQJJg0j0oxdCxzWf2qUGXad1CLA6vmlwxrRpgQCbophWjNTI1tdyeXchcNWGiV1LbB1JAA00HDLniyrbvGRbcekL68AOR8PHe+HAlWVOt7/LF+RphixRDWydF4y1HZiyNf7Uy2ID9iRSiV3sV7bazVpDxSmwnImueP1s//dnSWw5fAnUEBcMmlqCouembJv7++LdRX3vI2QaTdeJMOH4b9BdzioMgW5/WFNerb9C+tUF+9R4AU8griVIOxpq+1pV0jETpymNal44H9ieMAsGyNwplMCxCrpUIpmN5G4/iPT+BEMLGwjwqWfg94NcR4SF1p3gn9+A== 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=cQLRE1UudFyiuXv3WyY/aE+vOBvMptCqvkvJir3SeaI=; b=HnWYW3cbI7+SpJw53RbOwztteNohFQX7cwhfCuqC0ya40xyGXwJVkJHC2pBjbsMu5zjRmvsXpU8I5UvR3Yq4PzI4alAFXe9Xm2RLCO8aZPwIurwpfdBKD+9DHBksETdyz+f+xXXXmVd5silT/+UKH2INYwdwvtYU9KrZqWxqERV0sfOtlUe6KsPp6TjbXx7Zkg7pqYf446hUW7BLqGuluIt7QycU0rGDJLWDOnBNzxHZoYxXZRD/WzBRQMwxq0eXC4rbPE3hgUkor/B6oABja1FvWZz+daLMLgtYX/4z0771GGuxSXI6NyOm4n+ApcxuuKYxemD9pPZIaeAL67ejqQ== 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=cQLRE1UudFyiuXv3WyY/aE+vOBvMptCqvkvJir3SeaI=; b=uyCHWyhppYgPcJTtwp3tQhy75iSJBD96YcNxPTfbDcPzPzd3n/ub8KZXUmvY9wYUNGFIJvykl5C8fJCxNK9oDsxApZqZV5JfDuOA/agsh5XZ0UFN81Xg0NUueb0vHuQ6tbTnzEyFdjou6Rk+RMhpgGbXY59CpLDTrcBOlLPSfAw= Received: from DM6PR10CA0004.namprd10.prod.outlook.com (2603:10b6:5:60::17) by MW4PR12MB7000.namprd12.prod.outlook.com (2603:10b6:303:20a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:19:24 +0000 Received: from DM6NAM11FT071.eop-nam11.prod.protection.outlook.com (2603:10b6:5:60:cafe::2) by DM6PR10CA0004.outlook.office365.com (2603:10b6:5:60::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:19: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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT071.mail.protection.outlook.com (10.13.173.48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.17 via Frontend Transport; Thu, 8 Dec 2022 11:19:24 +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; Thu, 8 Dec 2022 05:19:21 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 04/13] cpufreq: amd-pstate: fix kernel hang issue while amd-pstate unregistering Date: Thu, 8 Dec 2022 19:18:43 +0800 Message-ID: <20221208111852.386731-5-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT071:EE_|MW4PR12MB7000:EE_ X-MS-Office365-Filtering-Correlation-Id: ee107c24-2338-4cf5-5457-08dad90e100a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Kzzd56z6F6cfCpPNAk4nMeZQnH0Pt3usG5PjbqZr7Q2eNqhuBA9K+Xl9Jm4YRv7rq0WzoDt9tV3HhdTZOJImpk9eTQ1en62BF4kc7OsWvHjc66v22wrJvhJKcil3mfgDJW/j+5Er9xl86zYKvz+fPaLZuN/TwwEr/akRd+QcjYx5q3onIxMsKQfZTuhEgQ4hstqXZITnXQgsNxpEwr+f9h7hAQhjVRp/J5Lm+BeAn6njpQ1XHhC/dTXIs8S26Mz9/xqcErkJFNblnMaYNVVZEqNIWzc3Sz3bhls2kmzBZhS1v9Rv3XJrlL+TIL8TayfvwE3FkBQITJfYSil2b5C/Wmmn/TQY62mgBKVrg+7wCV3OW/EJWXpEqcXoiTBEB7mx9HDIdpC8s4Bo2lhsXz57QySFJ3Ve+/FfomQ3lqxPi/kUTyjrdjIrE0G/SF0GUbVmnN1Ztx7thHmJP6080rWx4aLt1lkFlKiyH6OxVXXWO2WVJJ0EUk9xt+sjIDOOInvd+hNePabIZxXHJ/QBb5bRNMccCl8Y5SIqR5vxBE3n/+Wqu/L0f2j06JGTPVs0HpuoLsAfxUh9jKkKKFNs2uv8T2+CzlBizDso1GTH9iJ+qsmP8rFgwKUihkWNQqBbp36X1kyACsJJnSVaikYQp2KPUpqTU9WAV6dd8gQkfVreexMFmDti6AQXopRpiPLzv8zXqQkcAjqLUsW0IN/5D/cFlrX99Tf/HSeFULJ60WNo9LQ= 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)(396003)(39860400002)(136003)(451199015)(36840700001)(46966006)(40470700004)(16526019)(356005)(2616005)(41300700001)(336012)(186003)(1076003)(82740400003)(81166007)(47076005)(83380400001)(36860700001)(82310400005)(426003)(36756003)(5660300002)(6666004)(40460700003)(8936002)(4744005)(44832011)(2906002)(7696005)(40480700001)(478600001)(26005)(8676002)(86362001)(70206006)(4326008)(70586007)(316002)(54906003)(110136005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:24.7447 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ee107c24-2338-4cf5-5457-08dad90e100a 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: DM6NAM11FT071.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7000 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In the amd_pstate_adjust_perf(), there is one cpufreq_cpu_get() call to increase increments the kobject reference count of policy and make it as busy. Therefore, a corresponding call to cpufreq_cpu_put() is needed to decrement the kobject reference count back, it will resolve the kernel hang issue when unregistering the amd-pstate driver and register the `amd_pstate_epp` driver instance. Signed-off-by: Perry Yuan Acked-by: Huang Rui --- drivers/cpufreq/amd-pstate.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 204e39006dda..c17bd845f5fc 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -307,6 +307,7 @@ static void amd_pstate_adjust_perf(unsigned int cpu, max_perf = min_perf; amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true); + cpufreq_cpu_put(policy); } static int amd_get_min_freq(struct amd_cpudata *cpudata) From patchwork Thu Dec 8 11:18:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632816 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 C12F0C3A5A7 for ; Thu, 8 Dec 2022 11:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbiLHLT7 (ORCPT ); Thu, 8 Dec 2022 06:19:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbiLHLTl (ORCPT ); Thu, 8 Dec 2022 06:19:41 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2053.outbound.protection.outlook.com [40.107.94.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865BF5C0C4; Thu, 8 Dec 2022 03:19:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aePjs9N2a1HqzTM8IuYcTf0XPcXOBhk8AS6rhIPDTQ4cZFuqDyoyOG/At3LK/3QiER6Fz+vzuq149GzeVA80wY4EXAneCFbs50tIlYxJ8h7SO1ed2QKL9pyLs8aUMtl+av8wizFwPaRXvvAd5U5YLFX7LZY4BM7onRU38xpryIvlEDjsYbcmbBDJkJjS5FJ8eecICidzjKhvSzXtnVWlWpZaSd5IDu4Ut5zZg581ztTzVFAe5WQD8rzaplzk4EVuRy07yiLL+kEj9QgAj/1d0shWYQV2pLZRCmBRfPWJRkW2VqnayOGxpNkjCCcorcL+QCCbB64BRadtx2apQAztew== 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=lI/at9ytSjTEQbD79LSsefwJetrxOcRJAiuMJ1ck/iM=; b=NoSMQQ9BxDLOWDLWZWn51faPvhv9tNZ0c4/lZBpciz75nPjQHUeGloYf8m2KwPT5OW9Jrgcu1K4/RUq4hSPlEWTchgrjnXj7DXOrYivXjqFyPuWobVzotJDXr/rjB7ggzaZjx71SQVq7PMJCquBwkLNoflOfWeIytilI4aagb7ix0fk7YsQysbBhK1RlB0AOpm7f82ji+swiIXwSvRTuyKuwohpDDgf3wUY7fpombZYyldZVYgtqWLsqsF7ZMfd3uljgOd+5vQV1J/P0v4uzOzjkxNj18smBR+3ZAuLYGSIbZdrL6CRYZ0EeA0qleJVvDDGOFz7sIvO8iKFWm39+Pg== 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=lI/at9ytSjTEQbD79LSsefwJetrxOcRJAiuMJ1ck/iM=; b=YIqs+clbev9AoeYvspQiuRYGMz3iL0DWqPKFFjqcnRxwxBygUWFnEKTsqzhsmb+nP1h3raFnxlo//VBSd9BWlNzajDcRuqzfCtHrO66ATltyvlVj9QlHqnTvTY0BIAF0pMkh0H1jiX2+8K1TvxavaEHBAQpOUIfMbzZROSTW+9E= Received: from DS7PR05CA0054.namprd05.prod.outlook.com (2603:10b6:8:2f::28) by SN7PR12MB7105.namprd12.prod.outlook.com (2603:10b6:806:2a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:19:28 +0000 Received: from DM6NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2f:cafe::39) by DS7PR05CA0054.outlook.office365.com (2603:10b6:8:2f::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8 via Frontend Transport; Thu, 8 Dec 2022 11:19:28 +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 DM6NAM11FT016.mail.protection.outlook.com (10.13.173.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:28 +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; Thu, 8 Dec 2022 05:19:24 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 05/13] cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors Date: Thu, 8 Dec 2022 19:18:44 +0800 Message-ID: <20221208111852.386731-6-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT016:EE_|SN7PR12MB7105:EE_ X-MS-Office365-Filtering-Correlation-Id: 01c8cd9d-a1af-4e39-8bdc-08dad90e1269 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FRM+tD0Rh+NgUh2FZY7GenJI7eKR3AL8i6bo6qPxUBuYwF8aJAdmeuNfkS86qYlZEc99R9DwtraPByyZwKou13eBZPOy4UqwduwikfFvtfozUoWde3wRyG8urWkEQh5RsKWKvH34IvXyD9rF71VBzxhy+QqSbitfFW88Topg0stovrRUJq19TRQkyYqWW1lDpHQPAOhwlp6rvTwOFyjBSiyPSXVNMN49L0UpoKDy23ur3Na5WMYiZHnZR8OxXdMIO29YSikAs6n26W+NCkna5jKrVNxdMn6BqHdSL1ChP3yZ8EuqabDJOZYCwD6TYyHCYKGNFxjXEU5yzWGOoMFzJrJTQgyhFy03M3xoAbCbwSlSbxcROPu8SiWx7gfA9jboFZfDU0h02Gz33enrfU/34b+K5kU/w//AZN0wgepRqsu26NtaIubhoiODUycqUUAn7w6OgnycIUSCXBhNq1Kf7iXt7Sm84EF+isAPs0/UtjBij3lDOczSG24sUDu5kkExxAsX/aRFiLKs8WLtjLAqDjwI5PTX8QpFjy7xE3xZGBL5VJ/wJz2hNH54QSNZzdn45230Zklwsd6r7dRNnPFNHiyyUEtfZdr32FPuv1HBUhy6GwOGSdTv+c60cTUfCDaDWkpM0V2TOpeNVi+9newc1PYifSlkpxSP9nZNgC4Oi7dNo8ldNTHFO1Km0MtjvKpqn+rNFDg00Q5T/V6wdpfRmqPKUGV3BspJWkNVRRICapc= 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)(39860400002)(346002)(136003)(376002)(396003)(451199015)(40470700004)(36840700001)(46966006)(44832011)(316002)(30864003)(54906003)(41300700001)(110136005)(70206006)(70586007)(8676002)(36756003)(4326008)(47076005)(83380400001)(5660300002)(8936002)(186003)(2616005)(356005)(16526019)(1076003)(81166007)(336012)(36860700001)(40460700003)(478600001)(40480700001)(86362001)(426003)(82310400005)(82740400003)(26005)(6666004)(7696005)(2906002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:28.7241 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 01c8cd9d-a1af-4e39-8bdc-08dad90e1269 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: DM6NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7105 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Perry Yuan Add EPP driver support for AMD SoCs which support a dedicated MSR for CPPC. EPP is used by the DPM controller to configure the frequency that a core operates at during short periods of activity. The SoC EPP targets are configured on a scale from 0 to 255 where 0 represents maximum performance and 255 represents maximum efficiency. The amd-pstate driver exports profile string names to userspace that are tied to specific EPP values. The balance_performance string (0x80) provides the best balance for efficiency versus power on most systems, but users can choose other strings to meet their needs as well. $ cat /sys/devices/system/cpu/cpufreq/policy0/energy_performance_available_preferences default performance balance_performance balance_power power $ cat /sys/devices/system/cpu/cpufreq/policy0/energy_performance_preference balance_performance To enable the driver,it needs to add `amd_pstate=active` to kernel command line and kernel will load the active mode epp driver Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 631 ++++++++++++++++++++++++++++++++++- include/linux/amd-pstate.h | 35 ++ 2 files changed, 660 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index c17bd845f5fc..0a521be1be8a 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -59,9 +60,125 @@ * we disable it by default to go acpi-cpufreq on these processors and add a * module parameter to be able to enable it manually for debugging. */ -static struct cpufreq_driver amd_pstate_driver; +static bool cppc_active; static int cppc_load __initdata; +static struct cpufreq_driver *default_pstate_driver; +static struct amd_cpudata **all_cpu_data; +static struct amd_pstate_params global_params; + +static DEFINE_MUTEX(amd_pstate_limits_lock); +static DEFINE_MUTEX(amd_pstate_driver_lock); + +static bool cppc_boost __read_mostly; + +static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached) +{ + s16 epp; + struct cppc_perf_caps perf_caps; + int ret; + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + if (!cppc_req_cached) { + epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, + &cppc_req_cached); + if (epp) + return epp; + } + epp = (cppc_req_cached >> 24) & 0xFF; + } else { + ret = cppc_get_epp_caps(cpudata->cpu, &perf_caps); + if (ret < 0) { + pr_debug("Could not retrieve energy perf value (%d)\n", ret); + return -EIO; + } + epp = (s16) perf_caps.energy_perf; + } + + return epp; +} + +static int amd_pstate_get_energy_pref_index(struct amd_cpudata *cpudata) +{ + s16 epp; + int index = -EINVAL; + + epp = amd_pstate_get_epp(cpudata, 0); + if (epp < 0) + return epp; + + switch (epp) { + case HWP_EPP_PERFORMANCE: + index = EPP_INDEX_PERFORMANCE; + break; + case HWP_EPP_BALANCE_PERFORMANCE: + index = EPP_INDEX_BALANCE_PERFORMANCE; + break; + case HWP_EPP_BALANCE_POWERSAVE: + index = EPP_INDEX_BALANCE_POWERSAVE; + break; + case HWP_EPP_POWERSAVE: + index = EPP_INDEX_POWERSAVE; + break; + default: + break; + } + + return index; +} + +static int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp) +{ + int ret; + struct cppc_perf_ctrls perf_ctrls; + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + u64 value = READ_ONCE(cpudata->cppc_req_cached); + + value &= ~GENMASK_ULL(31, 24); + value |= (u64)epp << 24; + WRITE_ONCE(cpudata->cppc_req_cached, value); + + ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); + if (!ret) + cpudata->epp_cached = epp; + } else { + perf_ctrls.energy_perf = epp; + ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1); + if (ret) { + pr_debug("failed to set energy perf value (%d)\n", ret); + return ret; + } + cpudata->epp_cached = epp; + } + + return ret; +} + +static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata, + int pref_index) +{ + int epp = -EINVAL; + int ret; + + if (!pref_index) { + pr_debug("EPP pref_index is invalid\n"); + return -EINVAL; + } + + if (epp == -EINVAL) + epp = epp_values[pref_index]; + + if (epp > 0 && cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { + pr_debug("EPP cannot be set under performance policy\n"); + return -EBUSY; + } + + ret = amd_pstate_set_epp(cpudata, epp); + + return ret; +} + static inline int pstate_enable(bool enable) { return wrmsrl_safe(MSR_AMD_CPPC_ENABLE, enable); @@ -70,11 +187,21 @@ static inline int pstate_enable(bool enable) static int cppc_enable(bool enable) { int cpu, ret = 0; + struct cppc_perf_ctrls perf_ctrls; for_each_present_cpu(cpu) { ret = cppc_set_enable(cpu, enable); if (ret) return ret; + + /* Enable autonomous mode for EPP */ + if (!cppc_active) { + /* Set desired perf as zero to allow EPP firmware control */ + perf_ctrls.desired_perf = 0; + ret = cppc_set_perf(cpu, &perf_ctrls); + if (ret) + return ret; + } } return ret; @@ -418,7 +545,7 @@ static void amd_pstate_boost_init(struct amd_cpudata *cpudata) return; cpudata->boost_supported = true; - amd_pstate_driver.boost_enabled = true; + default_pstate_driver->boost_enabled = true; } static void amd_perf_ctl_reset(unsigned int cpu) @@ -592,10 +719,61 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy, return sprintf(&buf[0], "%u\n", perf); } +static ssize_t show_energy_performance_available_preferences( + struct cpufreq_policy *policy, char *buf) +{ + int i = 0; + int offset = 0; + + while (energy_perf_strings[i] != NULL) + offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i++]); + + sysfs_emit_at(buf, offset, "\n"); + + return offset; +} + +static ssize_t store_energy_performance_preference( + struct cpufreq_policy *policy, const char *buf, size_t count) +{ + struct amd_cpudata *cpudata = policy->driver_data; + char str_preference[21]; + ssize_t ret; + + ret = sscanf(buf, "%20s", str_preference); + if (ret != 1) + return -EINVAL; + + ret = match_string(energy_perf_strings, -1, str_preference); + if (ret < 0) + return -EINVAL; + + mutex_lock(&amd_pstate_limits_lock); + ret = amd_pstate_set_energy_pref_index(cpudata, ret); + mutex_unlock(&amd_pstate_limits_lock); + + return ret ?: count; +} + +static ssize_t show_energy_performance_preference( + struct cpufreq_policy *policy, char *buf) +{ + struct amd_cpudata *cpudata = policy->driver_data; + int preference; + + preference = amd_pstate_get_energy_pref_index(cpudata); + if (preference < 0) + return preference; + + return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]); +} + 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_rw(energy_performance_preference); +cpufreq_freq_attr_ro(energy_performance_available_preferences); static struct freq_attr *amd_pstate_attr[] = { &amd_pstate_max_freq, @@ -604,6 +782,424 @@ static struct freq_attr *amd_pstate_attr[] = { NULL, }; +static struct freq_attr *amd_pstate_epp_attr[] = { + &amd_pstate_max_freq, + &amd_pstate_lowest_nonlinear_freq, + &amd_pstate_highest_perf, + &energy_performance_preference, + &energy_performance_available_preferences, + NULL, +}; + +static inline void update_boost_state(void) +{ + u64 misc_en; + struct amd_cpudata *cpudata; + + cpudata = all_cpu_data[0]; + rdmsrl(MSR_K7_HWCR, misc_en); + global_params.cppc_boost_disabled = misc_en & BIT_ULL(25); +} + +static bool amd_pstate_acpi_pm_profile_server(void) +{ + if (acpi_gbl_FADT.preferred_profile == PM_ENTERPRISE_SERVER || + acpi_gbl_FADT.preferred_profile == PM_PERFORMANCE_SERVER) + return true; + + return false; +} + +static int amd_pstate_init_cpu(unsigned int cpunum) +{ + struct amd_cpudata *cpudata; + + cpudata = all_cpu_data[cpunum]; + if (!cpudata) { + cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); + if (!cpudata) + return -ENOMEM; + WRITE_ONCE(all_cpu_data[cpunum], cpudata); + + cpudata->cpu = cpunum; + + if (cppc_active) { + if (amd_pstate_acpi_pm_profile_server()) + cppc_boost = true; + } + + } + cpudata->epp_powersave = -EINVAL; + cpudata->epp_policy = 0; + pr_debug("controlling: cpu %d\n", cpunum); + return 0; +} + +static int __amd_pstate_cpu_init(struct cpufreq_policy *policy) +{ + int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret; + struct amd_cpudata *cpudata; + struct device *dev; + int rc; + u64 value; + + rc = amd_pstate_init_cpu(policy->cpu); + if (rc) + return rc; + + cpudata = all_cpu_data[policy->cpu]; + + dev = get_cpu_device(policy->cpu); + if (!dev) + goto free_cpudata1; + + rc = amd_pstate_init_perf(cpudata); + if (rc) + goto free_cpudata1; + + min_freq = amd_get_min_freq(cpudata); + max_freq = amd_get_max_freq(cpudata); + nominal_freq = amd_get_nominal_freq(cpudata); + lowest_nonlinear_freq = amd_get_lowest_nonlinear_freq(cpudata); + if (min_freq < 0 || max_freq < 0 || min_freq > max_freq) { + dev_err(dev, "min_freq(%d) or max_freq(%d) value is incorrect\n", + min_freq, max_freq); + ret = -EINVAL; + goto free_cpudata1; + } + + policy->min = min_freq; + policy->max = max_freq; + + policy->cpuinfo.min_freq = min_freq; + policy->cpuinfo.max_freq = max_freq; + /* It will be updated by governor */ + policy->cur = policy->cpuinfo.min_freq; + + /* Initial processor data capability frequencies */ + cpudata->max_freq = max_freq; + cpudata->min_freq = min_freq; + cpudata->nominal_freq = nominal_freq; + cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq; + + policy->driver_data = cpudata; + + update_boost_state(); + cpudata->epp_cached = amd_pstate_get_epp(cpudata, value); + + policy->min = policy->cpuinfo.min_freq; + policy->max = policy->cpuinfo.max_freq; + + if (boot_cpu_has(X86_FEATURE_CPPC)) + policy->fast_switch_possible = true; + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value); + if (ret) + return ret; + WRITE_ONCE(cpudata->cppc_req_cached, value); + + ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, &value); + if (ret) + return ret; + WRITE_ONCE(cpudata->cppc_cap1_cached, value); + } + amd_pstate_boost_init(cpudata); + + return 0; + +free_cpudata1: + kfree(cpudata); + return ret; +} + +static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) +{ + int ret; + + ret = __amd_pstate_cpu_init(policy); + if (ret) + return ret; + /* + * Set the policy to powersave to provide a valid fallback value in case + * the default cpufreq governor is neither powersave nor performance. + */ + policy->policy = CPUFREQ_POLICY_POWERSAVE; + + return 0; +} + +static int amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy) +{ + pr_debug("CPU %d exiting\n", policy->cpu); + policy->fast_switch_possible = false; + return 0; +} + +static void amd_pstate_update_max_freq(unsigned int cpu) +{ + struct cpufreq_policy *policy = policy = cpufreq_cpu_get(cpu); + + if (!policy) + return; + + refresh_frequency_limits(policy); + cpufreq_cpu_put(policy); +} + +static void amd_pstate_epp_update_limits(unsigned int cpu) +{ + mutex_lock(&amd_pstate_driver_lock); + update_boost_state(); + if (global_params.cppc_boost_disabled) { + for_each_possible_cpu(cpu) + amd_pstate_update_max_freq(cpu); + } else { + cpufreq_update_policy(cpu); + } + mutex_unlock(&amd_pstate_driver_lock); +} + +static int cppc_boost_hold_time_ns = 3 * NSEC_PER_MSEC; + +static inline void amd_pstate_boost_up(struct amd_cpudata *cpudata) +{ + u64 hwp_req = READ_ONCE(cpudata->cppc_req_cached); + u64 hwp_cap = READ_ONCE(cpudata->cppc_cap1_cached); + u32 max_limit = (hwp_req & 0xff); + u32 min_limit = (hwp_req & 0xff00) >> 8; + u32 boost_level1; + + /* If max and min are equal or already at max, nothing to boost */ + if (max_limit == min_limit) + return; + + /* Set boost max and min to initial value */ + if (!cpudata->cppc_boost_min) + cpudata->cppc_boost_min = min_limit; + + boost_level1 = ((AMD_CPPC_NOMINAL_PERF(hwp_cap) + min_limit) >> 1); + + if (cpudata->cppc_boost_min < boost_level1) + cpudata->cppc_boost_min = boost_level1; + else if (cpudata->cppc_boost_min < AMD_CPPC_NOMINAL_PERF(hwp_cap)) + cpudata->cppc_boost_min = AMD_CPPC_NOMINAL_PERF(hwp_cap); + else if (cpudata->cppc_boost_min == AMD_CPPC_NOMINAL_PERF(hwp_cap)) + cpudata->cppc_boost_min = max_limit; + else + return; + + hwp_req &= ~AMD_CPPC_MIN_PERF(~0L); + hwp_req |= AMD_CPPC_MIN_PERF(cpudata->cppc_boost_min); + wrmsrl(MSR_AMD_CPPC_REQ, hwp_req); + cpudata->last_update = cpudata->sample.time; +} + +static inline void amd_pstate_boost_down(struct amd_cpudata *cpudata) +{ + bool expired; + + if (cpudata->cppc_boost_min) { + expired = time_after64(cpudata->sample.time, cpudata->last_update + + cppc_boost_hold_time_ns); + + if (expired) { + wrmsrl(MSR_AMD_CPPC_REQ, cpudata->cppc_req_cached); + cpudata->cppc_boost_min = 0; + } + } + + cpudata->last_update = cpudata->sample.time; +} + +static inline void amd_pstate_boost_update_util(struct amd_cpudata *cpudata, + u64 time) +{ + cpudata->sample.time = time; + if (smp_processor_id() != cpudata->cpu) + return; + + if (cpudata->sched_flags & SCHED_CPUFREQ_IOWAIT) { + bool do_io = false; + + cpudata->sched_flags = 0; + /* + * Set iowait_boost flag and update time. Since IO WAIT flag + * is set all the time, we can't just conclude that there is + * some IO bound activity is scheduled on this CPU with just + * one occurrence. If we receive at least two in two + * consecutive ticks, then we treat as boost candidate. + * This is leveraged from Intel Pstate driver. + */ + if (time_before64(time, cpudata->last_io_update + 2 * TICK_NSEC)) + do_io = true; + + cpudata->last_io_update = time; + + if (do_io) + amd_pstate_boost_up(cpudata); + + } else { + amd_pstate_boost_down(cpudata); + } +} + +static inline void amd_pstate_cppc_update_hook(struct update_util_data *data, + u64 time, unsigned int flags) +{ + struct amd_cpudata *cpudata = container_of(data, + struct amd_cpudata, update_util); + + cpudata->sched_flags |= flags; + + if (smp_processor_id() == cpudata->cpu) + amd_pstate_boost_update_util(cpudata, time); +} + +static void amd_pstate_clear_update_util_hook(unsigned int cpu) +{ + struct amd_cpudata *cpudata = all_cpu_data[cpu]; + + if (!cpudata->update_util_set) + return; + + cpufreq_remove_update_util_hook(cpu); + cpudata->update_util_set = false; + synchronize_rcu(); +} + +static void amd_pstate_set_update_util_hook(unsigned int cpu_num) +{ + struct amd_cpudata *cpudata = all_cpu_data[cpu_num]; + + if (!cppc_boost) { + if (cpudata->update_util_set) + amd_pstate_clear_update_util_hook(cpudata->cpu); + return; + } + + if (cpudata->update_util_set) + return; + + cpudata->sample.time = 0; + cpufreq_add_update_util_hook(cpu_num, &cpudata->update_util, + amd_pstate_cppc_update_hook); + cpudata->update_util_set = true; +} + +static void amd_pstate_epp_init(unsigned int cpu) +{ + struct amd_cpudata *cpudata = all_cpu_data[cpu]; + u32 max_perf, min_perf; + u64 value; + s16 epp; + + max_perf = READ_ONCE(cpudata->highest_perf); + min_perf = READ_ONCE(cpudata->lowest_perf); + + value = READ_ONCE(cpudata->cppc_req_cached); + + if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) + min_perf = max_perf; + + /* Initial min/max values for CPPC Performance Controls Register */ + value &= ~AMD_CPPC_MIN_PERF(~0L); + value |= AMD_CPPC_MIN_PERF(min_perf); + + value &= ~AMD_CPPC_MAX_PERF(~0L); + value |= AMD_CPPC_MAX_PERF(max_perf); + + /* CPPC EPP feature require to set zero to the desire perf bit */ + value &= ~AMD_CPPC_DES_PERF(~0L); + value |= AMD_CPPC_DES_PERF(0); + + if (cpudata->epp_policy == cpudata->policy) + goto skip_epp; + + cpudata->epp_policy = cpudata->policy; + + if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { + epp = amd_pstate_get_epp(cpudata, value); + cpudata->epp_powersave = epp; + if (epp < 0) + goto skip_epp; + /* force the epp value to be zero for performance policy */ + epp = 0; + } else { + if (cpudata->epp_powersave < 0) + goto skip_epp; + /* Get BIOS pre-defined epp value */ + epp = amd_pstate_get_epp(cpudata, value); + if (epp) + goto skip_epp; + epp = cpudata->epp_powersave; + } + /* Set initial EPP value */ + if (boot_cpu_has(X86_FEATURE_CPPC)) { + value &= ~GENMASK_ULL(31, 24); + value |= (u64)epp << 24; + } + +skip_epp: + WRITE_ONCE(cpudata->cppc_req_cached, value); + amd_pstate_set_epp(cpudata, epp); +} + +static void amd_pstate_set_max_limits(struct amd_cpudata *cpudata) +{ + u64 hwp_cap = READ_ONCE(cpudata->cppc_cap1_cached); + u64 hwp_req = READ_ONCE(cpudata->cppc_req_cached); + u32 max_limit = (hwp_cap >> 24) & 0xff; + + hwp_req &= ~AMD_CPPC_MIN_PERF(~0L); + hwp_req |= AMD_CPPC_MIN_PERF(max_limit); + wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, hwp_req); +} + +static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata; + + if (!policy->cpuinfo.max_freq) + return -ENODEV; + + pr_debug("set_policy: cpuinfo.max %u policy->max %u\n", + policy->cpuinfo.max_freq, policy->max); + + cpudata = all_cpu_data[policy->cpu]; + cpudata->policy = policy->policy; + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + mutex_lock(&amd_pstate_limits_lock); + + if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { + amd_pstate_clear_update_util_hook(policy->cpu); + amd_pstate_set_max_limits(cpudata); + } else { + amd_pstate_set_update_util_hook(policy->cpu); + } + + mutex_unlock(&amd_pstate_limits_lock); + } + amd_pstate_epp_init(policy->cpu); + + return 0; +} + +static void amd_pstate_verify_cpu_policy(struct amd_cpudata *cpudata, + struct cpufreq_policy_data *policy) +{ + update_boost_state(); + cpufreq_verify_within_cpu_limits(policy); +} + +static int amd_pstate_epp_verify_policy(struct cpufreq_policy_data *policy) +{ + amd_pstate_verify_cpu_policy(all_cpu_data[policy->cpu], policy); + pr_debug("policy_max =%d, policy_min=%d\n", policy->max, policy->min); + return 0; +} + static struct cpufreq_driver amd_pstate_driver = { .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS, .verify = amd_pstate_verify, @@ -617,8 +1213,20 @@ static struct cpufreq_driver amd_pstate_driver = { .attr = amd_pstate_attr, }; +static struct cpufreq_driver amd_pstate_epp_driver = { + .flags = CPUFREQ_CONST_LOOPS, + .verify = amd_pstate_epp_verify_policy, + .setpolicy = amd_pstate_epp_set_policy, + .init = amd_pstate_epp_cpu_init, + .exit = amd_pstate_epp_cpu_exit, + .update_limits = amd_pstate_epp_update_limits, + .name = "amd_pstate_epp", + .attr = amd_pstate_epp_attr, +}; + static int __init amd_pstate_init(void) { + static struct amd_cpudata **cpudata; int ret; if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) @@ -645,7 +1253,8 @@ static int __init amd_pstate_init(void) /* capability check */ if (boot_cpu_has(X86_FEATURE_CPPC)) { pr_debug("AMD CPPC MSR based functionality is supported\n"); - amd_pstate_driver.adjust_perf = amd_pstate_adjust_perf; + if (!cppc_active) + default_pstate_driver->adjust_perf = amd_pstate_adjust_perf; } else { pr_debug("AMD CPPC shared memory based functionality is supported\n"); static_call_update(amd_pstate_enable, cppc_enable); @@ -653,6 +1262,10 @@ static int __init amd_pstate_init(void) static_call_update(amd_pstate_update_perf, cppc_update_perf); } + cpudata = vzalloc(array_size(sizeof(void *), num_possible_cpus())); + if (!cpudata) + return -ENOMEM; + WRITE_ONCE(all_cpu_data, cpudata); /* enable amd pstate feature */ ret = amd_pstate_enable(true); if (ret) { @@ -660,9 +1273,9 @@ static int __init amd_pstate_init(void) return ret; } - ret = cpufreq_register_driver(&amd_pstate_driver); + ret = cpufreq_register_driver(default_pstate_driver); if (ret) - pr_err("failed to register amd_pstate_driver with return %d\n", + pr_err("failed to register amd pstate driver with return %d\n", ret); return ret; @@ -677,8 +1290,14 @@ static int __init amd_pstate_param(char *str) if (!strcmp(str, "disable")) { cppc_load = 0; pr_info("driver is explicitly disabled\n"); - } else if (!strcmp(str, "passive")) + } else if (!strcmp(str, "passive")) { cppc_load = 1; + default_pstate_driver = &amd_pstate_driver; + } else if (!strcmp(str, "active")) { + cppc_active = 1; + cppc_load = 1; + default_pstate_driver = &amd_pstate_epp_driver; + } return 0; } diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h index 1c4b8659f171..888af62040f1 100644 --- a/include/linux/amd-pstate.h +++ b/include/linux/amd-pstate.h @@ -25,6 +25,7 @@ struct amd_aperf_mperf { u64 aperf; u64 mperf; u64 tsc; + u64 time; }; /** @@ -47,6 +48,18 @@ struct amd_aperf_mperf { * @prev: Last Aperf/Mperf/tsc count value read from register * @freq: current cpu frequency value * @boost_supported: check whether the Processor or SBIOS supports boost mode + * @epp_powersave: Last saved CPPC energy performance preference + when policy switched to performance + * @epp_policy: Last saved policy used to set energy-performance preference + * @epp_cached: Cached CPPC energy-performance preference value + * @policy: Cpufreq policy value + * @sched_flags: Store scheduler flags for possible cross CPU update + * @update_util_set: CPUFreq utility callback is set + * @last_update: Time stamp of the last performance state update + * @cppc_boost_min: Last CPPC boosted min performance state + * @cppc_cap1_cached: Cached value of the last CPPC Capabilities MSR + * @update_util: Cpufreq utility callback information + * @sample: the stored performance sample * * The amd_cpudata is key private data for each CPU thread in AMD P-State, and * represents all the attributes and goals that AMD P-State requests at runtime. @@ -72,6 +85,28 @@ struct amd_cpudata { u64 freq; bool boost_supported; + + /* EPP feature related attributes*/ + s16 epp_powersave; + s16 epp_policy; + s16 epp_cached; + u32 policy; + u32 sched_flags; + bool update_util_set; + u64 last_update; + u64 last_io_update; + u32 cppc_boost_min; + u64 cppc_cap1_cached; + struct update_util_data update_util; + struct amd_aperf_mperf sample; +}; + +/** + * struct amd_pstate_params - global parameters for the performance control + * @ cppc_boost_disabled wheher the core performance boost disabled + */ +struct amd_pstate_params { + bool cppc_boost_disabled; }; #endif /* _LINUX_AMD_PSTATE_H */ From patchwork Thu Dec 8 11:18:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632812 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 D82F0C4332F for ; Thu, 8 Dec 2022 11:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230031AbiLHLVn (ORCPT ); Thu, 8 Dec 2022 06:21:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbiLHLVT (ORCPT ); Thu, 8 Dec 2022 06:21:19 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2061.outbound.protection.outlook.com [40.107.237.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ADF481DB7; Thu, 8 Dec 2022 03:20:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cDTORSz/Le7i3UxORA3Oz52WE/tmk5b341i45yqiQHk12b3GDzaiIynU7EdtWjg2LHsOoT5z2edcI0oD9XBzL8KthD6U02glxQ0q5cnVJrBz165Q+5BrS9ZfyEUkUYw1hYA2QyW64omVAqKb8/cse/So+DQZMgUZJj0U50isEvXXsOI1+T56rql1qVH9GUQ7j5TCihsE37/G/dtfnYsoW2m0iNOCdvhgsRu17nVPsMIr/6OiP+EgnL8CZ+ofP+PHbAx4S5pTvsvaMrO71k2J6xY/Gr4RUb63YbKA5uSNNZ70+7LDuQbm2/eH2KjMnXucI3//SCkr9qBKRut+RL72xQ== 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=fq/Lr6MF9/gKf2NO7wqeQr5YIPol9/r9wPNA6Rsh8FY=; b=jWHFBUCNXPlt6EreUgzKNXJSzTqeWm0X2Z5mEPP1rtdKOjT76bKKtEWrVWSh8YQvk8/tZ4UxvuzWyxeeGViiWrBVG0zB4GVwWQ/Ks+L5fsPFZpUovzucoHVzWVltLb4I8O+1359xnc/bomWjcnj2TytheI6yMFHMXNJlFadJvZOENSmBuymV7z4QeWHcIMu99VcvZzivqgMK5qJNA6Ww/nYXAHg0w87PybOP5Wiw+u1JHalYtThnxe5H0BNjx6bFfx96O4YBgdWpy9pxMLWoPnN7Et5PdQ7p71o5trIMXMx948FJgpWo3465CiUbgpGqdcMk9Kfi5D4ZfWdYWUrwEw== 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=fq/Lr6MF9/gKf2NO7wqeQr5YIPol9/r9wPNA6Rsh8FY=; b=Ck3TDqSoECk9JHwEbdefux0TmijEfkt1wt3tp3sOLxTNfUKulfrwTYd7c52Wy8AfZdxgkcj1Vv8cJOfs0VrssvLwHDrJGXG4lav3A56tj6Twvbn1XXSGgvnnWfOS3O4DhhVpbJxvNt83y2o1E0Bt4tH3C43xek631iJCNtBPbcQ= Received: from DM6PR05CA0037.namprd05.prod.outlook.com (2603:10b6:5:335::6) by CY5PR12MB6276.namprd12.prod.outlook.com (2603:10b6:930:f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:19:48 +0000 Received: from DM6NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:5:335:cafe::a6) by DM6PR05CA0037.outlook.office365.com (2603:10b6:5:335::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8 via Frontend Transport; Thu, 8 Dec 2022 11:19:48 +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 DM6NAM11FT018.mail.protection.outlook.com (10.13.172.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:48 +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; Thu, 8 Dec 2022 05:19:28 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 06/13] cpufreq: amd-pstate: implement amd pstate cpu online and offline callback Date: Thu, 8 Dec 2022 19:18:45 +0800 Message-ID: <20221208111852.386731-7-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT018:EE_|CY5PR12MB6276:EE_ X-MS-Office365-Filtering-Correlation-Id: 030dd526-deed-4d80-ce09-08dad90e1e0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vPHWTI52xqLoh3/hn9UURDX594j2Ln9bH5ZQnmmszyZCzNfDHMGyszgXmvRBDYRFCifK8gGHo3Z2YOph4bZM6ud2C59hprMX7IkCTEvxySZYNqkVj18hAlIB+LxTq+1du5Q8wLLo3itQIPrwnNtgDLiXT2gMnc3oEqDLmQ19egdgyPHwFydknKnGGTQ4YlTakFZiQm+SBCZ9AM7hr2pIicfQJIO++q2FRS8aS4vSjryvTlnVCwNo3Jns5tJpL7aaw4ZORK6YkZNCq8UhcJqgTLODnFDoH8f4xhsbwuniGlsHuQ6ZEvLWTVYfWaTMyaL7c1VmmtbrNpM28YvSXWA2mQCZ33W0SitIJh+7IK1cpmlHUUQtEiwfOdDKUgRQcNDg9rVksX25jgJjRoAKyHiaLL0ienOS/0mMJ9AJkZJx93mi97XvMh4EEudY1+Pm0cfG6FAgVdhUrUfVdRLNsPWQwQfPcjMgihl8Y4cQLNQ37DjsggK3XZYumCkIdgUF5L3BUbvimfIq4LiJBl/4P5AIBXqvRTpv3AueQoaaj4mL8mnX13VMdVIy77g7PIC40BxqPFlw4HjzbDnixNpeWr+XO56FFdO3pqm0NpYSWxl4Pva6ZDnXm1K1ct74ddmkQPqm1Qk/gPMfKxSUgyY68FHS6y8K3uElmyV3rsz8SN2DEiRRl9KEIb7v3UNATRZVCgvE5tzfVabAxXl54Yz7h3WQoXOfSGO/0wmgTI6kLrYZ5vc= 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)(136003)(376002)(396003)(346002)(39860400002)(451199015)(36840700001)(46966006)(40470700004)(7696005)(54906003)(110136005)(26005)(2906002)(16526019)(86362001)(186003)(83380400001)(336012)(41300700001)(2616005)(1076003)(44832011)(316002)(82310400005)(40460700003)(47076005)(8936002)(426003)(5660300002)(36756003)(40480700001)(70206006)(70586007)(36860700001)(478600001)(82740400003)(356005)(81166007)(4326008)(8676002)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:48.2424 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 030dd526-deed-4d80-ce09-08dad90e1e0b 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: DM6NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6276 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 0a521be1be8a..412accab7bda 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1186,6 +1186,93 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy) return 0; } +static void amd_pstate_epp_reenable(struct amd_cpudata *cpudata) +{ + struct cppc_perf_ctrls perf_ctrls; + u64 value, max_perf; + int ret; + + ret = amd_pstate_enable(true); + if (ret) + pr_err("failed to enable amd pstate during resume, return %d\n", ret); + + value = READ_ONCE(cpudata->cppc_req_cached); + max_perf = 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 = max_perf; + perf_ctrls.energy_perf = 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 = 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 = false; + } + + return 0; +} + +static void amd_pstate_epp_offline(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata = all_cpu_data[policy->cpu]; + struct cppc_perf_ctrls perf_ctrls; + int min_perf; + u64 value; + + min_perf = READ_ONCE(cpudata->lowest_perf); + value = READ_ONCE(cpudata->cppc_req_cached); + + mutex_lock(&amd_pstate_limits_lock); + if (boot_cpu_has(X86_FEATURE_CPPC)) { + cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN; + + /* Set max perf same as min perf */ + value &= ~AMD_CPPC_MAX_PERF(~0L); + value |= AMD_CPPC_MAX_PERF(min_perf); + value &= ~AMD_CPPC_MIN_PERF(~0L); + value |= AMD_CPPC_MIN_PERF(min_perf); + wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); + } else { + perf_ctrls.desired_perf = 0; + perf_ctrls.max_perf = min_perf; + perf_ctrls.energy_perf = 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 = 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) { @@ -1220,6 +1307,8 @@ static struct cpufreq_driver amd_pstate_epp_driver = { .init = amd_pstate_epp_cpu_init, .exit = amd_pstate_epp_cpu_exit, .update_limits = amd_pstate_epp_update_limits, + .offline = amd_pstate_epp_cpu_offline, + .online = amd_pstate_epp_cpu_online, .name = "amd_pstate_epp", .attr = 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; }; /** From patchwork Thu Dec 8 11:18:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632122 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 7D517C3A5A7 for ; Thu, 8 Dec 2022 11:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbiLHLUV (ORCPT ); Thu, 8 Dec 2022 06:20:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbiLHLT7 (ORCPT ); Thu, 8 Dec 2022 06:19:59 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2055.outbound.protection.outlook.com [40.107.92.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B519654B09; Thu, 8 Dec 2022 03:19:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i9GtRoFXPZw7Qvs26WqD2EN9ybeRILPVuzvG7ysxxJCAKxCWCH0PdF0mFrowzDqKZRge/frCUD5hBgO97WARYzDhxNjlJ19C/wmRXJgsGB7Rcu3m9zGVelxlHkyc6KPCck2L5hV0TMAo69nI0BI3e40xb0K/ZdGOEbEmUoVQfrNuTp7m2P5Q10GLbOaursg2obavuYQhh4hO5EbBJYbYeyo11VUAw1bKfthTZb/oF2EyyFJHP+R3T3cXOXVwWR6ZA7bCt0ncDPuYDvwc9LUWT+rMyK5EzF1cOvZnR2oiMlLu54QBRJ/X5L/N92ti/2CvbWli7yyXJYY3YSfRaXolTQ== 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=B1gVu4DnZbs+ofVVp3+AcNEQW/ji3We80lzAAEXf7KU=; b=og9rFNKMlGUbwSwe2Mu0aYk3xPmcJvPblowtLe/HWXHySPNrBUTV+f17KqaTWbw1XUz94uOyuDlwOLFSYhXizLz9fUTwv8XU/LYdwCSHAPeJwDWnVh0hc9rrGFX5kRm6SPMIHBIWADcXCvHfMdH3DerGZcpkLSBkVgAuo9ZLKfR85v4SKcYdnvMrf2ED1D/Csh+K0AlwXkhouA/HDuIYOqqXHdt82o/LohHUaJo0vpeI0LY7sP3CXDg9eLhGQuXX8p+bUa1td/xUrQuckYkQSteVIvVQQTti9nDa7SPDPAqEGnRFac8rRcQpj9xM15kutzOGXIDrVHCYMzXljpSKag== 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=B1gVu4DnZbs+ofVVp3+AcNEQW/ji3We80lzAAEXf7KU=; b=YHbAUU1eh8KAaeqH40wYuRPWepi685j3FWoNIk8T/XMGjgMFo0z+4E0dsZruT16gazEM89VEZMznEp8FiAeOJszkyFoRXjNY7oGZhSmp/a3fXWWQsW1CGZwN6f6e6iXRclI4jycN+O90hpLSWOVoW67x2nwVsWIBbikRGF8sgkA= Received: from DS7PR05CA0048.namprd05.prod.outlook.com (2603:10b6:8:2f::19) by DM6PR12MB4500.namprd12.prod.outlook.com (2603:10b6:5:28f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:19:51 +0000 Received: from DM6NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2f:cafe::b9) by DS7PR05CA0048.outlook.office365.com (2603:10b6:8:2f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.5 via Frontend Transport; Thu, 8 Dec 2022 11:19:51 +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 DM6NAM11FT101.mail.protection.outlook.com (10.13.172.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.17 via Frontend Transport; Thu, 8 Dec 2022 11:19:51 +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; Thu, 8 Dec 2022 05:19:48 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 07/13] cpufreq: amd-pstate: implement suspend and resume callbacks Date: Thu, 8 Dec 2022 19:18:46 +0800 Message-ID: <20221208111852.386731-8-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT101:EE_|DM6PR12MB4500:EE_ X-MS-Office365-Filtering-Correlation-Id: 7623c094-32df-4f52-dcf4-08dad90e2027 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WyNNlO+3SuMYQvCSd5Oy200kihg1mLsaGk6kKDxZxppYZuT2qbyGRXZE+TltJ0oRZYo0GNV+IdUf7+I4Gbb2SKF6el/knrZPgqpF5jwOc4mk4QKeKH+rwAAT5f2LC9KZ+J7h94Mih3xJfFKAL6CkfS8bSeheKWF4Qc/hPrFj/k7JqrXocuWFfqSB2GZW7XEuJBCLCjOT0Mhsmg+CZpsJy+yGSbMc31kviIsprskGV0tFgEb5BlSJR9U8o0oUxJRyUwW/oWgPp4hPvSuyyNEgM/1DMF20wdaTAU6EOMqXvIMaNjOAaiTx9qVONqPrDFq6w1FQ2ds64lrU3nOHop1ypOd/VRXkOKw+N20wgpA0icTX8IlXGFs788ZQu8uQ+SdduV/rhqk8pzu4HF46IrrrqWPkYpGsa0yF6jc/KfVePU1W8bM0E11qSaescZs+lRj+RGQYy2aHarlHvMtuXV4d2xgQv4NMADGRsxXFWzrV4pjxaJ74+Em3T11QxD5beIqIeknzAB24/Q0LAnj+c96N/02ji1BIVEgEi4oriq7zChizTsPHHCujMqw1UAU50km8XfYhdY0/WFqnM53PATZahH7yoVNqeuJX7mq3G4PZsI9oPew11yXgQj/km3VzCOFkGVfGz6rR/7HTVP3YXwNUlhl3bUhQnO7cZp3+OuF3V2mrGCBPmiu6kVg4fLHyrQ1UnE8wrtV992e/Ab1S5nEnzL+U2KchnqEzRniV3z6sAIg= 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)(136003)(346002)(396003)(39860400002)(376002)(451199015)(46966006)(40470700004)(36840700001)(7696005)(186003)(2616005)(316002)(26005)(54906003)(70586007)(70206006)(4326008)(8676002)(478600001)(110136005)(16526019)(426003)(8936002)(336012)(36860700001)(15650500001)(83380400001)(47076005)(2906002)(1076003)(41300700001)(5660300002)(36756003)(81166007)(40480700001)(40460700003)(44832011)(82740400003)(356005)(82310400005)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:51.7818 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7623c094-32df-4f52-dcf4-08dad90e2027 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: DM6NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4500 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Perry Yuan add suspend and resume support for the AMD processors by amd_pstate_epp driver instance. When the CPPC is suspended, EPP driver will set EPP profile to 'power' profile and set max/min perf to lowest perf value. When resume happens, it will restore the MSR registers with previous cached value. Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 412accab7bda..ea9255bdc9ac 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1273,6 +1273,44 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy) return amd_pstate_cpu_offline(policy); } +static int amd_pstate_epp_suspend(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata = all_cpu_data[policy->cpu]; + int ret; + + /* avoid suspending when EPP is not enabled */ + if (!cppc_active) + return 0; + + /* set this flag to avoid setting core offline*/ + cpudata->suspended = true; + + /* disable CPPC in lowlevel firmware */ + ret = amd_pstate_enable(false); + if (ret) + pr_err("failed to suspend, return %d\n", ret); + + return 0; +} + +static int amd_pstate_epp_resume(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata = all_cpu_data[policy->cpu]; + + if (cpudata->suspended) { + mutex_lock(&amd_pstate_limits_lock); + + /* enable amd pstate from suspend state*/ + amd_pstate_epp_reenable(cpudata); + + mutex_unlock(&amd_pstate_limits_lock); + + cpudata->suspended = false; + } + + return 0; +} + static void amd_pstate_verify_cpu_policy(struct amd_cpudata *cpudata, struct cpufreq_policy_data *policy) { @@ -1309,6 +1347,8 @@ static struct cpufreq_driver amd_pstate_epp_driver = { .update_limits = amd_pstate_epp_update_limits, .offline = amd_pstate_epp_cpu_offline, .online = amd_pstate_epp_cpu_online, + .suspend = amd_pstate_epp_suspend, + .resume = amd_pstate_epp_resume, .name = "amd_pstate_epp", .attr = amd_pstate_epp_attr, }; From patchwork Thu Dec 8 11:18:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632815 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 C4483C4332F for ; Thu, 8 Dec 2022 11:20:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbiLHLUW (ORCPT ); Thu, 8 Dec 2022 06:20:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbiLHLT7 (ORCPT ); Thu, 8 Dec 2022 06:19:59 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2082.outbound.protection.outlook.com [40.107.94.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFDB048750; Thu, 8 Dec 2022 03:19:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fMmHVvi6mOYz4nxqrgox+W0sLp2kgYKNVM4jGagm8PHMZ0kWV/aix1jmutgBBI1NGapW7wZbykY+nU2mqxmNUhJLNnAUPgdFs9ve9YU5jpsG4o81Wwee4ZbkfZkEQPucd8aQ5v6NyScV9Gorc5O9yzxE36iF9nM1gDTBM5X0eC1iJbpS/AdTQ8zsZTqpSDgVbV4HfI0PldeBc3J1MFzUS5cNNK06/CBzodXCFg8m4eq43WFDG9V0WEfyNalsANuT/bi008Yj57EMKhuZj8uCogMRPEEjdABULPhaJz8wQgYI/rC3KdzT25QsVNHdumE6MoPGCzK3bO7vAdkesFojjQ== 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=g0lwpZHYOSLcuXFU4J2O5L6ro8sIvaZOvLy4pJNMRbQ=; b=WHXIksrgsFyCSdlHwY7jjit4I9OGNtlTqnTp9hLG3CD2ANQBU0zRPH6qLGX8a0z40isLQ1TmoJ4ttDAx5t/SrdCVAwNYuNcoJwE7HyxaeoHYxaTgBJvXGrxsUXlJgT0ymRGboc8ZMOtEgsBKvBIS6bo/6H5KZnX/R24Pw71ck5CruXBfspXHZvro2rXTj9wD6/KjC1nMDshjP4jIHeAb5QZcBINRTctg1tPcR1JsTecNBzPOj/etrG6LrDbkTgpgDwjN0TgNbkJnymFfaET4fvaf92S1rFSOeEYkjLlQS9QKGGc9nHSfbxa9TYef7pTGEaHzcFmkZLu+WtM+obxSxQ== 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=g0lwpZHYOSLcuXFU4J2O5L6ro8sIvaZOvLy4pJNMRbQ=; b=VJYliuLGz+hFhEaXQy6RcUWE3OFBSJUKKSxWttetx+YPZNXtWcGlF4u2bKiC3NffYfmBU77Y2LKn08gKAk5/pRjKCfKZcz13AlvyiITDegq8Rl76w8FKDoMvmRN53FEQz3Ao5FMplA+23Tn/bkWLf+gVFZIhaTfaT2CP37aETlg= Received: from DM6PR12CA0032.namprd12.prod.outlook.com (2603:10b6:5:1c0::45) by CY8PR12MB7537.namprd12.prod.outlook.com (2603:10b6:930:94::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Thu, 8 Dec 2022 11:19:55 +0000 Received: from DM6NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::40) by DM6PR12CA0032.outlook.office365.com (2603:10b6:5:1c0::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:19:55 +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 DM6NAM11FT025.mail.protection.outlook.com (10.13.172.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.17 via Frontend Transport; Thu, 8 Dec 2022 11:19:55 +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; Thu, 8 Dec 2022 05:19:51 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 08/13] cpufreq: amd-pstate: add frequency dynamic boost sysfs control Date: Thu, 8 Dec 2022 19:18:47 +0800 Message-ID: <20221208111852.386731-9-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT025:EE_|CY8PR12MB7537:EE_ X-MS-Office365-Filtering-Correlation-Id: 970822eb-326a-4a5f-731a-08dad90e222d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TpRFI6N6cHIYz9lBKI/iF2jkZwH03kBtkhs9ZCk0l/r7qN41l2pV4+xsSaE8cFmPUNAY067iXvK8EMf7XTSeCGvnbV6sxQ/HU0Wfj2IGCeOWMSe+euoJSozJfptlssibYvwrh3ttdz/HxEmLXGNZ/7XDb6GZ4AiiXW7glSrS8le0KSBlYqaW90yRsHOq3OhC08Eh+myn+bYoRVZyYMrVGM4HMw/rr4JAxSXFxhQLkh4C02ep4NZWChRJAQcBGiNcvYsG1hw09sktDaB8GLT3GIeMF+awnSLHN/Xs4iOqlSjCy3tfdoBKVD5KUB+PtWL0QJ69///FGPrY317ruXM/qopKpAQ5gZsl+rehqy6gsQj8ZhkMYk59Z2YmBI7fE3X5K/JTFycPKp4TxZDyCnsg4LdeXWyrp0sveUJ3fLmDXiBtEiy0uKU2tKOycutb2oOWt4sxLoG/KNWhGyIzw59Co//XXVzPtPWS/W4xSy3irLP5k3ytIPNtefaXz3GnL8c4TUMaM9t7brPKflFwr87teAQpLQQERmLNDsDMp32mRNoEPJ6+Vk8LIyL0FB3W4BFNS3fwzgGO6SG9QML8Mm44G39I/M4VeyqORQAEJV1oSZdKFCJqJwJ0Vd+cpJh8EARW/dZpQV3jlLZA8BFqS1Ma9IrP+xWIEI3wxEn1fTroXz+RzWpA/XdhrM2QvdfXebh0TYu0CsIxg5k2iSMIb1m8DoktM+OvcW76F2b0nip4goxwjNDO8RofDUaZVdquJ77I4oCYX3KthYroWiiFGBtGFg== 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)(396003)(346002)(376002)(39860400002)(136003)(451199015)(46966006)(40470700004)(36840700001)(336012)(2906002)(426003)(86362001)(26005)(83380400001)(1076003)(8676002)(6666004)(110136005)(7696005)(54906003)(70206006)(47076005)(186003)(2616005)(40460700003)(41300700001)(478600001)(8936002)(82740400003)(5660300002)(44832011)(16526019)(81166007)(356005)(4326008)(70586007)(36860700001)(316002)(36756003)(40480700001)(82310400005)(36900700001)(309714004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:55.1582 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 970822eb-326a-4a5f-731a-08dad90e222d 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: DM6NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7537 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Perry Yuan Add one sysfs entry to control the CPU cores frequency boost state The attribute file can allow user to set max performance boosted or keeping at normal perf level. Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 67 ++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index ea9255bdc9ac..4cd53c010215 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -69,6 +69,7 @@ static struct amd_pstate_params global_params; static DEFINE_MUTEX(amd_pstate_limits_lock); static DEFINE_MUTEX(amd_pstate_driver_lock); +struct kobject *amd_pstate_kobj; static bool cppc_boost __read_mostly; @@ -768,12 +769,46 @@ static ssize_t show_energy_performance_preference( return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]); } +static void amd_pstate_update_policies(void) +{ + int cpu; + + for_each_possible_cpu(cpu) + cpufreq_update_policy(cpu); +} + +static ssize_t show_cppc_dynamic_boost(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%u\n", cppc_boost); +} + +static ssize_t store_cppc_dynamic_boost(struct kobject *a, + struct kobj_attribute *b, + const char *buf, size_t count) +{ + bool new_state; + int ret; + + ret = kstrtobool(buf, &new_state); + if (ret) + return -EINVAL; + + mutex_lock(&amd_pstate_driver_lock); + cppc_boost = !!new_state; + amd_pstate_update_policies(); + mutex_unlock(&amd_pstate_driver_lock); + + return count; +} + 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_rw(energy_performance_preference); cpufreq_freq_attr_ro(energy_performance_available_preferences); +define_one_global_rw(cppc_dynamic_boost); static struct freq_attr *amd_pstate_attr[] = { &amd_pstate_max_freq, @@ -791,6 +826,15 @@ static struct freq_attr *amd_pstate_epp_attr[] = { NULL, }; +static struct attribute *pstate_global_attributes[] = { + &cppc_dynamic_boost.attr, + NULL +}; + +static const struct attribute_group amd_pstate_global_attr_group = { + .attrs = pstate_global_attributes, +}; + static inline void update_boost_state(void) { u64 misc_en; @@ -1404,9 +1448,28 @@ static int __init amd_pstate_init(void) ret = cpufreq_register_driver(default_pstate_driver); if (ret) - pr_err("failed to register amd pstate driver with return %d\n", - ret); + pr_err("failed to register driver with return %d\n", ret); + + amd_pstate_kobj = kobject_create_and_add("amd-pstate", &cpu_subsys.dev_root->kobj); + if (!amd_pstate_kobj) { + ret = -EINVAL; + pr_err("global sysfs registration failed.\n"); + goto kobject_free; + } + + ret = sysfs_create_group(amd_pstate_kobj, &amd_pstate_global_attr_group); + if (ret) { + pr_err("sysfs attribute export failed with error %d.\n", ret); + goto global_attr_free; + } + + return ret; +global_attr_free: + kobject_put(amd_pstate_kobj); +kobject_free: + cpufreq_unregister_driver(default_pstate_driver); + kfree(cpudata); return ret; } device_initcall(amd_pstate_init); From patchwork Thu Dec 8 11:18:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632121 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 BBB28C63709 for ; Thu, 8 Dec 2022 11:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229612AbiLHLUW (ORCPT ); Thu, 8 Dec 2022 06:20:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbiLHLUC (ORCPT ); Thu, 8 Dec 2022 06:20:02 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2081.outbound.protection.outlook.com [40.107.243.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92B8A53EC0; Thu, 8 Dec 2022 03:20:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mfkZuS32D5AmlvzWexZ0jGk5V4oB0P7zyWsK7UIeRDNficjr/JA4QBCrIxj6uC4yC0P9gWcG1a5jE9/9IZjaYzStO1z+33ZsFG4nhaBb7qyNkNagThS+beKvKjFXZGiEMVgSX9IumbnQ7T5Ezn4hFEmLcnPdsxWlC7EOqXFoW6yK0+r/SdXzyIAs8rEvpR08z/AVcaLtNr0UFm11vUcKiGZGlWujbqXcbbSd5Y0saz56w+rU9jPgeI0m9/iRWvXHFEY9SL9y0RUx3JI/puR3iVVK8bO8tIedCK2BJNzkr0iPhqVuhLr0GHcg2E0UxToOIoYR3BjYTeVtt6tqWNUkiA== 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=ca9pfUmcPytt39zB7h6P63d3JQnB2bnK2cKTQZTnm4Y=; b=mWw++XwbKJkCL4M4EuAWwD5VXyraNEoFGYa9HYIPM7DkdC9YNQ29+CWanwTYyjMweaPh3Few4495DPXKlnzblAf/K5Dn5LsKQsGUx1NY6MHKt7oOLk1rpmPpvfjx3mD1heJLvwCp89zkRicJyJpIiNZjxVf9FE2w1stUQDzMJW3nMRPhGe9sFlUMYd1szJM4sKqKb9UYKBQTAUPFRlhMgNCqJabAASr2pKhxGLrKiDxlRunA9GDFM17BHK8TTB91yHc1xXf1oFOkeo0VD0fESE1pEbBzG+G9GpsFDK+BhTvh3L3Vachb/RVWCBh4aZP+Sol6v9Zdvq1L233fSspg/w== 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=ca9pfUmcPytt39zB7h6P63d3JQnB2bnK2cKTQZTnm4Y=; b=f3nTrclCRZT4M2bkkl75QITNAiP+dzS2MWyJXrVB4NA8o5CI59Sbnw9Ls0qO+MYYIvFl9rZdjZXQ2Wnl1oQAOAXxs6np0XAz5axbw5gIwV7ZlPN1MPcDBwkgEHa2ZxltFcEvBmvMDX7Vvgsv/Jc1DjcjOkWX4QOuzCDU9lo1+5I= Received: from DM6PR07CA0124.namprd07.prod.outlook.com (2603:10b6:5:330::34) by MN0PR12MB6320.namprd12.prod.outlook.com (2603:10b6:208:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:19:58 +0000 Received: from DM6NAM11FT084.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::73) by DM6PR07CA0124.outlook.office365.com (2603:10b6:5:330::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:19:58 +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 DM6NAM11FT084.mail.protection.outlook.com (10.13.172.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:19:58 +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; Thu, 8 Dec 2022 05:19:54 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 09/13] cpufreq: amd-pstate: add driver working mode status sysfs entry Date: Thu, 8 Dec 2022 19:18:48 +0800 Message-ID: <20221208111852.386731-10-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT084:EE_|MN0PR12MB6320:EE_ X-MS-Office365-Filtering-Correlation-Id: cb385d86-2d0e-4b5b-3ed5-08dad90e242b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xLvTfXKAn3ydk734rxPLXXliHzXVAW2PPHxURrmnOSlbF3JBpKVeTpOPsB+jUUnuzT87Q4w2NemXSInMwBkXkqxQ+xwwd4rfQRALn3VZcm+KxmemKgJZeBWNnrQ9MokMKES3Ltj9oZJWiVU5GlA/t200f7cM15etOlaReGUYLXYBvyeYWgP1NvBCiQwvAui+LB4zh9a1rKCLcvVrhDnC5RGh81J17QIIbck/fprwScxO2WboSunRmV8gi/RyGljD5q7vg/nlmA8lau7tU20XCOFBYEmgcljmsBFB4q/tbgnB31gt4aIk/Q3qtZXPhyTvqag87dOASDpQfJu6y2YjxluxJKGeQt3bct7lOjHXOccyWb7k/CO19pNlOYXnskquu1O5rXKNxdE59HcmmLzRE/EjaKHNGm2vLEuGuCP0Bdu+UQYWENKjO+dumpQmFYJd6kblvvVflIohsIpRlGo+q07HFFwgEtgpqVx2GOtcXYJUexLWpjiyRyAmkZmFbI56o3Db+ItHIOYat4zJW6KNqq46PsTXCiWbs+gX+2j5vTHEdrw04y7WVBypJJZ960HC7Lj/HSMVMj5A5n7jNInBRLFKIwYduhmIdRSy5m7V7RW7yS35Uf4JCtLQCDwhjx9KrsmhfcTXveUOOmwI7lPhAx2uMYMLv/7Dj3n3sNROiijDAdFHDXfHaTjNWA3VLRmH+NJ3QdQHhRC65b/S037oRM+mVlKUvF2rm11x/cy78Dg= 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)(376002)(396003)(39860400002)(346002)(136003)(451199015)(40470700004)(46966006)(36840700001)(36756003)(2906002)(82740400003)(36860700001)(40460700003)(86362001)(8936002)(44832011)(5660300002)(426003)(47076005)(83380400001)(16526019)(336012)(186003)(2616005)(1076003)(356005)(40480700001)(81166007)(82310400005)(316002)(54906003)(26005)(478600001)(41300700001)(4326008)(8676002)(110136005)(7696005)(70586007)(70206006)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:19:58.5148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cb385d86-2d0e-4b5b-3ed5-08dad90e242b 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: DM6NAM11FT084.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6320 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Perry Yuan While amd-pstate driver was loaded with specific driver mode, it will need to check which mode is enabled for the pstate driver,add this sysfs entry to show the current status $ cat /sys/devices/system/cpu/amd-pstate/status active Meanwhile, user can switch the pstate driver mode with writing mode string to sysfs entry as below. Enable passive mode: $ sudo bash -c "echo passive > /sys/devices/system/cpu/amd-pstate/status" Enable active mode (EPP driver mode): $ sudo bash -c "echo active > /sys/devices/system/cpu/amd-pstate/status" Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 101 +++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 4cd53c010215..c90aee3ee42d 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -64,6 +64,8 @@ static bool cppc_active; static int cppc_load __initdata; static struct cpufreq_driver *default_pstate_driver; +static struct cpufreq_driver amd_pstate_epp_driver; +static struct cpufreq_driver amd_pstate_driver; static struct amd_cpudata **all_cpu_data; static struct amd_pstate_params global_params; @@ -72,6 +74,7 @@ static DEFINE_MUTEX(amd_pstate_driver_lock); struct kobject *amd_pstate_kobj; static bool cppc_boost __read_mostly; +static DEFINE_SPINLOCK(cppc_notify_lock); static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached) { @@ -629,6 +632,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy) policy->driver_data = cpudata; amd_pstate_boost_init(cpudata); + if (!default_pstate_driver->adjust_perf) + default_pstate_driver->adjust_perf = amd_pstate_adjust_perf; return 0; @@ -802,6 +807,100 @@ static ssize_t store_cppc_dynamic_boost(struct kobject *a, return count; } +static ssize_t amd_pstate_show_status(char *buf) +{ + if (!default_pstate_driver) + return sysfs_emit(buf, "off\n"); + + return sysfs_emit(buf, "%s\n", default_pstate_driver == &amd_pstate_epp_driver ? + "active" : "passive"); +} + +static void amd_pstate_clear_update_util_hook(unsigned int cpu); +static void amd_pstate_driver_cleanup(void) +{ + unsigned int cpu; + + cpus_read_lock(); + for_each_online_cpu(cpu) { + if (all_cpu_data[cpu]) { + if (default_pstate_driver == &amd_pstate_epp_driver) + amd_pstate_clear_update_util_hook(cpu); + + spin_lock(&cppc_notify_lock); + kfree(all_cpu_data[cpu]); + WRITE_ONCE(all_cpu_data[cpu], NULL); + spin_unlock(&cppc_notify_lock); + } + } + cpus_read_unlock(); + + default_pstate_driver = NULL; +} + +static int amd_pstate_update_status(const char *buf, size_t size) +{ + if (size == 3 && !strncmp(buf, "off", size)) { + if (!default_pstate_driver) + return -EINVAL; + + if (cppc_active) + return -EBUSY; + + cpufreq_unregister_driver(default_pstate_driver); + amd_pstate_driver_cleanup(); + return 0; + } + + if (size == 6 && !strncmp(buf, "active", size)) { + if (default_pstate_driver) { + if (default_pstate_driver == &amd_pstate_epp_driver) + return 0; + cpufreq_unregister_driver(default_pstate_driver); + default_pstate_driver = &amd_pstate_epp_driver; + } + + return cpufreq_register_driver(default_pstate_driver); + } + + if (size == 7 && !strncmp(buf, "passive", size)) { + if (default_pstate_driver) { + if (default_pstate_driver == &amd_pstate_driver) + return 0; + cpufreq_unregister_driver(default_pstate_driver); + } + default_pstate_driver = &amd_pstate_driver; + return cpufreq_register_driver(default_pstate_driver); + } + + return -EINVAL; +} + +static ssize_t show_status(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + ssize_t ret; + + mutex_lock(&amd_pstate_driver_lock); + ret = amd_pstate_show_status(buf); + mutex_unlock(&amd_pstate_driver_lock); + + return ret; +} + +static ssize_t store_status(struct kobject *a, struct kobj_attribute *b, + const char *buf, size_t count) +{ + char *p = memchr(buf, '\n', count); + int ret; + + mutex_lock(&amd_pstate_driver_lock); + ret = amd_pstate_update_status(buf, p ? p - buf : count); + mutex_unlock(&amd_pstate_driver_lock); + + return ret < 0 ? ret : count; +} + cpufreq_freq_attr_ro(amd_pstate_max_freq); cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq); @@ -809,6 +908,7 @@ cpufreq_freq_attr_ro(amd_pstate_highest_perf); cpufreq_freq_attr_rw(energy_performance_preference); cpufreq_freq_attr_ro(energy_performance_available_preferences); define_one_global_rw(cppc_dynamic_boost); +define_one_global_rw(status); static struct freq_attr *amd_pstate_attr[] = { &amd_pstate_max_freq, @@ -828,6 +928,7 @@ static struct freq_attr *amd_pstate_epp_attr[] = { static struct attribute *pstate_global_attributes[] = { &cppc_dynamic_boost.attr, + &status.attr, NULL }; From patchwork Thu Dec 8 11:18:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632814 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 4AF3AC4332F for ; Thu, 8 Dec 2022 11:20:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbiLHLUv (ORCPT ); Thu, 8 Dec 2022 06:20:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbiLHLUQ (ORCPT ); Thu, 8 Dec 2022 06:20:16 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2041.outbound.protection.outlook.com [40.107.96.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E66014B745; Thu, 8 Dec 2022 03:20:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iUN3AEoEWt0t2SaIgU8m4Mvt0N796svrWuJ/lRJyH7X7pPPVNZ5BjTlPCyAs+HufAYLhMPcABcpCTBwD9wRskVy2F6eTACzqr92fk4sf82xoPE/Mf46oLtFKLFhC7QdWlAi+SQd5lFzaLGwn9R26pBxfNe22iuhgtdSMJSmSGygnz9c/JfqeZrk5t4RvUqZ1bFlpXoy/jy8gOkaVmbXpHLtia6wt0T4YLxbCdY96qW8ktx4pbh6E3iQJ71abSYEYvusBubuwTp/pHV351aADYAYuyGasG4TgU/ro6opdNP6aFvvrnRJsYh8LbtxLXNJOv+EU9hxughoM3FkdDauy2Q== 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=7iLNwCDA2FPuXX0XbspH2ZQmIiCfHs2C+UB1BWc0KDM=; b=VqsO43nskzXg8YuMuc6HaFZ1kjmrjDNXNWeKLFwk9xXZQmhxARqkbGMw5eMwokPKGommNp9ezs/pGQqr3FNWMgI/rSg27ikVF/U1H6SsN2ajsbCrTZ3ukRTaCJmpiDkbuIU0zfBKdsN8baUiLlBBAuLChb1eMOsnjVR1mKgZHVc8tnug0QqSQRXTjT08utBzsl+fScWV0y6FwcqO9bGMKIf04VECo/Y58Bp2L5izQdLPslETZq3TRcV4fTV8YQuCmXVYIcn5Eiv4NybZ4SnXFILt/hhyHG6T9ZGznM/ZRZ5dpF21hNAf464bs0Pn2RmVyw9SjbkhLRGqroksn71NXA== 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=7iLNwCDA2FPuXX0XbspH2ZQmIiCfHs2C+UB1BWc0KDM=; b=a+tf3Bd8xxf0f0ppycA5WlefalOVZeYf7I1aLWeW+n0C24tEXnusVm1hkr6S+RZGMxq+CIpCIEOWnc3fBkMQiAJcEIOKqXOX5/J4oRJBrr4e6uVJtvXCP4xGV9SJ9FW8gFjTejU0ibGfxhSRE4r7nzlCdp8KOhRR0sW4NouhZkI= Received: from DS7PR03CA0153.namprd03.prod.outlook.com (2603:10b6:5:3b2::8) by CY8PR12MB8338.namprd12.prod.outlook.com (2603:10b6:930:7b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:20:14 +0000 Received: from DM6NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b2:cafe::c6) by DS7PR03CA0153.outlook.office365.com (2603:10b6:5:3b2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:20:13 +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 DM6NAM11FT037.mail.protection.outlook.com (10.13.172.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:20:13 +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; Thu, 8 Dec 2022 05:19:58 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 10/13] Documentation: amd-pstate: add amd pstate driver mode introduction Date: Thu, 8 Dec 2022 19:18:49 +0800 Message-ID: <20221208111852.386731-11-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT037:EE_|CY8PR12MB8338:EE_ X-MS-Office365-Filtering-Correlation-Id: 993c7075-13b4-4aff-0130-08dad90e2d53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sxJfxVm7/uct5icJBWGHAlMeZmFQG7eorGIzEeBBAjqhaWf2T9DcSIlqiRfN7hgzSLEGoW/4AEGPdgqfRCAaJIDjSGedCbdW4H+rH1CvXYyvbw7TFPbveErmojqzLEzGNfY7usi8YQ14blOG0wQt13STMKcgdd/h9BQYRp2pqc13s2r1XLsjF8j6b5LLIdFuy8i2Sy/BbtZTnogQontlgQReBuV3KvcsCwuN3mkUzePWmTG7f6aW9MIRox0CG/cSOK2+nXUSA5IsnnDPwntDIUCmXegVmk2q+ImxGwVmeWvS6vEo+cLCQA2UrneQ0X7mboH+e6aSr73d2/3Xm1DyP5piYnskmNUYezXJmZgKRzSdnVR+bHgstAb86DI6Q9veFoWNRbAFfjY8ZdCKW67nw0WHS4EDSmpHRmOSoK7+jITCRSy/jVmeHrdtAW3WExZsnHDD9DQ/YBA7Cg6ml519E6xJ5ms4cj/ti9GxjZXn6T3hJ84brp6drX9yyea6ta/BZjsBhgcsOn2ErB+gqb0fCjAyIDl/wQZixzvJ0k12kcNOsbHEJa/HNF/VAaaqx96MDAaHyXEx6h38ggh+JJ9BANEh2Txx+gzRLYItGbKksuuBfX25gAy9Z7bAC3V5goDtAU62J+88NO/ykgvPpbbhh+DpJ6YNkPHqXh+RwwvSHTAADkuLF8mZbr2zpgwr5Qr/6J/NcGRtHwp16O1x/CXfgwSXTCGDI++C+bWQxivaJm8= 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)(136003)(396003)(346002)(39860400002)(376002)(451199015)(46966006)(40470700004)(36840700001)(36756003)(8936002)(81166007)(86362001)(356005)(44832011)(40460700003)(41300700001)(82740400003)(4326008)(2906002)(5660300002)(36860700001)(83380400001)(54906003)(316002)(110136005)(70586007)(2616005)(8676002)(82310400005)(40480700001)(16526019)(478600001)(70206006)(186003)(6666004)(47076005)(7696005)(26005)(1076003)(426003)(336012)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:20:13.8749 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 993c7075-13b4-4aff-0130-08dad90e2d53 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: DM6NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8338 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Perry Yuan Introduce ``amd-pstate`` CPPC has two operation modes: * CPPC Autonomous (active) mode * CPPC non-autonomous (passive) mode. active mode and passive mode can be chosen by different kernel parameters. Signed-off-by: Perry Yuan --- Documentation/admin-guide/pm/amd-pstate.rst | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst index 33ab8ec8fc2f..62744dae3c5f 100644 --- a/Documentation/admin-guide/pm/amd-pstate.rst +++ b/Documentation/admin-guide/pm/amd-pstate.rst @@ -299,8 +299,30 @@ module which supports the new AMD P-States mechanism on most of the future AMD platforms. The AMD P-States mechanism is the more performance and energy efficiency frequency management method on AMD processors. -Kernel Module Options for ``amd-pstate`` -========================================= + +AMD Pstate Driver Operation Modes +================================= + +``amd_pstate`` CPPC has two operation modes: CPPC Autonomous(active) mode and +CPPC non-autonomous(passive) mode. +active mode and passive mode can be chosen by different kernel parameters. +When in Autonomous mode, CPPC ignores requests done in the Desired Performance +Target register and takes into account only the values set to the Minimum requested +performance, Maximum requested performance, and Energy Performance Preference +registers. When Autonomous is disabled, it only considers the Desired Performance Target. + +Active Mode +------------ + +``amd_pstate=active`` + +This is the low-level firmware control mode which is implemented by ``amd_pstate_epp`` +driver with ``amd_pstate=active`` passed to the kernel in the command line. +In this mode, ``amd_pstate_epp`` driver provides a hint to the hardware if software +wants to bias toward performance (0x0) or energy efficiency (0xff) to the CPPC firmware. +then CPPC power algorithm will calculate the runtime workload and adjust the realtime +cores frequency according to the power supply and thermal, core voltage and some other +hardware conditions. Passive Mode ------------ From patchwork Thu Dec 8 11:18:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632119 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 4E552C3A5A7 for ; Thu, 8 Dec 2022 11:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229937AbiLHLVC (ORCPT ); Thu, 8 Dec 2022 06:21:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbiLHLUg (ORCPT ); Thu, 8 Dec 2022 06:20:36 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2068.outbound.protection.outlook.com [40.107.237.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C15663D60; Thu, 8 Dec 2022 03:20:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=emr0XqOJyTsVY/feWPVzHiubHGCehweHtBPLdI1uDI0oXbbNgEhn5pAJhxx/OjZtJetNdOzZuvRx4AJgLJXfTeVjZ/Mf/f7p9IOah0u/OGR1pPa+eJEOObYx7QvpgtqSy6+6ITEs86qrOEbBK4mRj8nNKGr3wJqJIScLazydIIXhK2goNazrmc7squFGCRUD/sRMF4GGOxqhaiph0imbOFUSJ8TdffITTMxV6bLgYJ2b0ZH+h9j83FS8NwhNUasPeKLwF6xOboZcTX8RnidYyloPHM7clW+FuWWQjydydDYeMgEk/4R7kUnvtGyJtewRDu6TArwzvnFliNQ0St/hIQ== 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=Y7HUaZF2RWtW75YfO1ls7LGL9pKvYziwGx2Mp2RHCeg=; b=Qhc+gKR6hOAvg9RQ9sKn8LX2uFFh3Wrihcqac1+qpeAkiC0WgiKSCiImATcwuk5l2j0dYyqLWmK7LAgSEVpgNeUB2UanEDl3vkGK8Boa9eCwVrgu0ui3DOYvppsQQ1/c+0SzHNRyKZ0DEUElxT6+ilPvT1lLpyxdBI8COB1e4k3+380HRE/MIxXo/7rxmZY8Q8BCsOWbmt4l1ZXN2bl0MVm5bpjlMUmhdNuZYY4f8hB7d/S5S6JG6a0FtcKBU2nzmIsvZOLLLf0b2gYq9Bb72pIoZg2CvgKazRiC6fPycTjjzhcla5EBDLQ9V5vY0QAL9DgwztIKDvrvqHwBxoX3Pw== 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=Y7HUaZF2RWtW75YfO1ls7LGL9pKvYziwGx2Mp2RHCeg=; b=Sd1yfJHViNCIALnkioh0ya/e3jVPkBllv99rcTPS+pghZdrn28/s+c8os8I7/ejMMq+lcnJXrfNVDXmchvChGE5NqgOza8qyF+KurZX5QuZAz7Kof9hoKH9Zh4cw11aDkoWeucgEvvFIGJrv4oJKa5ECW6ipXg95JdGucThpYGs= Received: from DS7PR03CA0167.namprd03.prod.outlook.com (2603:10b6:5:3b2::22) by PH7PR12MB5877.namprd12.prod.outlook.com (2603:10b6:510:1d5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:20:32 +0000 Received: from DM6NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b2:cafe::78) by DS7PR03CA0167.outlook.office365.com (2603:10b6:5:3b2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:20:32 +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 DM6NAM11FT037.mail.protection.outlook.com (10.13.172.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:20:32 +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; Thu, 8 Dec 2022 05:20:01 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 11/13] Documentation: introduce amd pstate active mode kernel command line options Date: Thu, 8 Dec 2022 19:18:50 +0800 Message-ID: <20221208111852.386731-12-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT037:EE_|PH7PR12MB5877:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ed8645f-9d4b-418c-e5f9-08dad90e3873 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7GfFAsZenlzeSVcYcqsQXJ5oFur8adDvyBAZ1UGnJlUpnPIsaFKdz49jUytsJe/8gW6t/ONASb324AWpC5wvxnWhANbV69XN+8i9seEEhFS/ugz23Bw++pRTXAASZExtjmjrl1jvDgeNA0K0n9+BFoVmcXj8Ry8s1p9kUqrJzShsmxoF1FGeewKt3T1+K+qxEBf+Tvq4qvPSy3SXKJYEfJ9Ep5XZwn5NvhrK5HT8KCntB+YrnOH7aGXKthRwGRWQcKFM4JOFtjOvq5x1x5ftlnmazNZ/rrEGZwNxjTspkwamyGjX1Y7DVlrsZxrneys9RBQcX9Y8+pBmNzDv2SynEMhc/X62sWmwilYarg4WbYErcPd2GSndIqW1bhg5gUrTz8F1nl7Hv8e1pp4y+ZSyFozLvnEIDTA80tY4QwkNOm60fv1oO4f4pWPFRJTgJEdmZIJLMa0aiVJMDPNOX6Hgnu/zuEDh8FU2/WftCvg4yWkfzr7Ho2x2qeaGuoRfMopNJrF1okyvTCGfq/a4KNgpVnmnWlIPQAJVRGs09Qj9jQCR+Ueb+3EpDlpfAViwPttqKZdw6NL8nFFcjToxMP0KM569CsqfG8g6jwWS8ef2nzW0kVeupbfTzkbPvtBGP4o0HttfR6J8YuxixuL4mwiP6oKgj0p269kssPVXBYcQTDNjFgub+zxP/BCN5gP7/h2YnXgot7t12ttmlulDVQkniW/0JrUgiYU/0e/pWb8NQeA= 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)(396003)(346002)(39860400002)(136003)(376002)(451199015)(46966006)(36840700001)(40470700004)(36860700001)(86362001)(41300700001)(82310400005)(2906002)(44832011)(83380400001)(5660300002)(8936002)(70586007)(70206006)(8676002)(110136005)(54906003)(316002)(4326008)(16526019)(426003)(40480700001)(356005)(81166007)(336012)(1076003)(47076005)(40460700003)(2616005)(82740400003)(478600001)(26005)(36756003)(7696005)(186003)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:20:32.5298 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ed8645f-9d4b-418c-e5f9-08dad90e3873 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: DM6NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5877 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org AMD Pstate driver support another firmware based autonomous mode with "amd_pstate=active" added to the kernel command line. In autonomous mode SMU firmware decides frequencies at 1 ms timescale based on workload utilization, usage in other IPs, infrastructure limits such as power, thermals and so on. Signed-off-by: Perry Yuan --- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 42af9ca0127e..73a02816f6f8 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6970,3 +6970,10 @@ management firmware translates the requests into actual hardware states (core frequency, data fabric and memory clocks etc.) + active + Use amd_pstate_epp driver instance as the scaling driver, + driver provides a hint to the hardware if software wants + to bias toward performance (0x0) or energy efficiency (0xff) + to the CPPC firmware. then CPPC power algorithm will + calculate the runtime workload and adjust the realtime cores + frequency. From patchwork Thu Dec 8 11:18:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632120 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 90969C63705 for ; Thu, 8 Dec 2022 11:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbiLHLVB (ORCPT ); Thu, 8 Dec 2022 06:21:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbiLHLUg (ORCPT ); Thu, 8 Dec 2022 06:20:36 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2088.outbound.protection.outlook.com [40.107.223.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E05563D54; Thu, 8 Dec 2022 03:20:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dlfm5sYzBvtqhLUzAcIHETim0Ynrr8eT4mWbRoMp1q2IvFY/DQs50CD7u5EYFux/1G9gxMT7n7hTJBI65wqwEvI4GZmaEyVUMciXgqPkkLh5ctuts9YFsc1cOfrOTDPU60BczXI8+B1/jC1n//W1ElDPMsNhWn8Rg7kIpJts+P48wjG3/5oqcY8YpbRVfRbjKmibnaXLqt3iCspwHP8yrXBhPHOsBgBxHVPnSC5/0Y0HrBqejsvKpOrb+CC4UxC+4eZkDGD9WHaQPOg0u2gl3km8PUviNcb6XpFhniozyI5U9c4dVVqsFjtjVddqitgp+YRwlcxpjalKNrnUBhNN0A== 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=04025qQKMJl6SSlMj/7r3MYk863ZKjiPYbB7e2Ml6xY=; b=hNN1SBqwp8rWkbHQJrHicH7EVnSdlAwwHCCqxrKWyTyva1vT2rK/qisoVubYQvloa/87LjIQrnJS94v1ycAEHK3kVohBiuw53IgvceQt6qsNdHWVopv+TVNvJYwlSuMFPTgvT0vXI6E3YTowufamKJYpZ0aY7keLy4+2XN/z6mUvf/IZ8RSz6zRt07XWWCAh0ujF72rRXyOZUOXGvfDiCV2jszt3Ax0JbaqmfyDLNmBNJPNgvvVzKU76UwQ6uBJHz/dFNVZDI+1oYqy9b9t/6rRN/IdPM9mYAFLw1JjXJXbxMyfN8eBl6o6ZzLZQ2gjLmn1WpgA9Ki4gEjZfLjvvtg== 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=04025qQKMJl6SSlMj/7r3MYk863ZKjiPYbB7e2Ml6xY=; b=XqQBM1zLFnsk8pyqWqlYJmKlcQlDGXpk1idm2HmGDzB8468vjItRWchImGiiUWkL0ZCdcAKycmGr5515vTCHPx6yCnBRvZDVYOYb4AvGGqGfUjZ1U5Fpv6bRe1HTSJdXWJPoEVCIE3PiBN29wxEsTMF+FJFHzXQZzBolMA5CuVc= Received: from DS7PR03CA0076.namprd03.prod.outlook.com (2603:10b6:5:3bb::21) by DS7PR12MB5887.namprd12.prod.outlook.com (2603:10b6:8:7a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:20:33 +0000 Received: from DM6NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3bb:cafe::5d) by DS7PR03CA0076.outlook.office365.com (2603:10b6:5:3bb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:20:33 +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 DM6NAM11FT033.mail.protection.outlook.com (10.13.172.221) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:20:33 +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; Thu, 8 Dec 2022 05:20:16 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 12/13] cpufreq: amd-pstate: convert sprintf with sysfs_emit() Date: Thu, 8 Dec 2022 19:18:51 +0800 Message-ID: <20221208111852.386731-13-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT033:EE_|DS7PR12MB5887:EE_ X-MS-Office365-Filtering-Correlation-Id: 52570dbc-819d-4aac-ba9d-08dad90e3914 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EFKWaZB3kgPLO3Lu2WFNCJxmvBkN5pn/U5z5USxX4V8LUln25imPf718NgSjGvJZYgQFxYA9ph3H1/yrIXbEcIuT1lMRQoCoi5pGn86OD4oWLOBS2UBc0pY/z5VTABKsMYPpgKa6YiSFQ1f0+iglKjzohCX9ZcjdDfP53AlmjFycJmNapq2rgKShqHo8iECFsZmqRFBozXwkPt+e0JFub2ROEa7eq3kUIj8j373eTo5GyrZ0HpgpVxyFx9SwbIbdLTbb/lhDY6hWaJkkMDbnzoZx6+698O1rNoFgY6JP7REW8W6376SxO7xs7ETR/XRYcSybSlaDHzMYTBqtWAQ3ZTHsAM0q4omelhzx2vOoGMGSaLaiVzRDkVx7tl9khhzsRWMDdOPjz5Akp36vB9YFfG7/qNTBSuDlo4bB3NvvngjvC1buxQaym1Ti8cZ9B26eI+AxK9hkopAh1laKE7X5AZVCeV6ggB7ST69fPSt8aQY/ejCbAG3bdaEJba1VD4G64BdbyMGEidB7SC0Rz1T6xXQXOwpoFxOZSFzIKciePi86z3sv8gcN0KX5FVJYRPoRmX6XIgQ5rN6TxJSQjCHHVDXMFMqWRP80F/YR2Xsj2x4JqsDlTAkCODueKSmqkjYrV9CVWKhzQdD4l+Y8HdYpxykYahjs+4gzJmNSI8JQG2yHKKrtA6+n0LvVWgVYQ5OZGVclzAnVKG2lO+JF7B27fiVNi0PyxIFfgohN/fiFbSs= 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)(136003)(396003)(39860400002)(376002)(451199015)(46966006)(36840700001)(40470700004)(82310400005)(40480700001)(36756003)(47076005)(26005)(2616005)(1076003)(426003)(478600001)(186003)(6666004)(16526019)(7696005)(336012)(82740400003)(36860700001)(81166007)(356005)(83380400001)(40460700003)(86362001)(41300700001)(5660300002)(8676002)(70586007)(316002)(4326008)(70206006)(54906003)(110136005)(44832011)(2906002)(8936002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:20:33.5994 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 52570dbc-819d-4aac-ba9d-08dad90e3914 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: DM6NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5887 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org replace the sprintf with a more generic sysfs_emit function No potential function impact Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index c90aee3ee42d..f40a312ad56c 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -694,7 +694,7 @@ static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy, if (max_freq < 0) return max_freq; - return sprintf(&buf[0], "%u\n", max_freq); + return sysfs_emit(buf, "%u\n", max_freq); } static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy, @@ -707,7 +707,7 @@ static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *poli if (freq < 0) return freq; - return sprintf(&buf[0], "%u\n", freq); + return sysfs_emit(buf, "%u\n", freq); } /* @@ -722,7 +722,7 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy, perf = READ_ONCE(cpudata->highest_perf); - return sprintf(&buf[0], "%u\n", perf); + return sysfs_emit(buf, "%u\n", perf); } static ssize_t show_energy_performance_available_preferences( From patchwork Thu Dec 8 11:18:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 632813 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 21EA6C63709 for ; Thu, 8 Dec 2022 11:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229943AbiLHLVD (ORCPT ); Thu, 8 Dec 2022 06:21:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbiLHLUl (ORCPT ); Thu, 8 Dec 2022 06:20:41 -0500 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2076.outbound.protection.outlook.com [40.107.212.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D953A59846; Thu, 8 Dec 2022 03:20:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MQZ/1vXQjOaRx3WNFVOp0Wr4+P1vVhe0iDMk3Yq0TzMjgz2NTRSmxWuhi7/Sd4NTx0fi275i7mchy/uq/vNl+CP3gkFvB+xkpi92YIPmqoBdJjirimlgVNtxhkG4oIL//ub4BXw+CD7nGkFgbZf4jxiQ1GaEIn8YhZUoF4OQxdBJr+l4ooOeKSBhqkyNcfV5SSEz3EevjqyVXNEZrui4JkS86nursBzt663YI3u4u3BBbsvMxVU3yqhJj+/J4GsF1zZw2v9RgNcDNK7/R33pG66/rDTReWeJj7b8OoqPJr4jL9UtEosM7NW2mKkOoZXwI5YPVKIjAYwqr1zWXgsyjA== 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=QkrXvP21/lXSUDBYE91jYDjO48MwETjEk3S/rbUPzxI=; b=g9tn4CS53yZbOrtPBCEoQIgGtSgN7rM1qC3dfootdL38oaJ7TkwzKsFN4l5yul1vzAxURVTh9TJp5xeMqXOUj8U02MBMuOY5k3yC8MvH4pEkAjjzqHsOunD8J12joa4IFdjsxuxIt8+6+vDRzRXvbZz1ki1tju7h6TGsB50Pv2OCnRlpkjhfRQtL+wSlavqBxQFJIIYL7zHJFBTTkRkSGkAupS6fwvM56PcMZECVc8lV9PWxLoFt7ztz3hdXVRY/2Gxhj4bTmi3CqKPyMwLii8zqQdXQGZALCR2ndD2V9YBvndD+YSGiVre+LuVBy23mfC7q2nu91+wYtdnunvt7IQ== 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=QkrXvP21/lXSUDBYE91jYDjO48MwETjEk3S/rbUPzxI=; b=pCrbkmCfB+V1m0++ir4qbuORlj8Ezw7f+1MY8IJocaruXZlpswyBO5DPRlroobuSikMxLxehXaYDaecNPgGm0BqIno2XlO9AOY0Mx+u4ovo0UxxVJhT+xnm6tpW+Ni3EoMVT1tUEmYkl9oaf5TMw+kR5qB7duQzV6bGTmBt4NMY= Received: from DS7PR03CA0178.namprd03.prod.outlook.com (2603:10b6:5:3b2::33) by PH7PR12MB6668.namprd12.prod.outlook.com (2603:10b6:510:1aa::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 11:20:35 +0000 Received: from DM6NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b2:cafe::f9) by DS7PR03CA0178.outlook.office365.com (2603:10b6:5:3b2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Thu, 8 Dec 2022 11:20:35 +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 DM6NAM11FT037.mail.protection.outlook.com (10.13.172.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.16 via Frontend Transport; Thu, 8 Dec 2022 11:20:35 +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; Thu, 8 Dec 2022 05:20:32 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v7 13/13] Documentation: amd-pstate: introduce new global sysfs attributes Date: Thu, 8 Dec 2022 19:18:52 +0800 Message-ID: <20221208111852.386731-14-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208111852.386731-1-perry.yuan@amd.com> References: <20221208111852.386731-1-perry.yuan@amd.com> MIME-Version: 1.0 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: DM6NAM11FT037:EE_|PH7PR12MB6668:EE_ X-MS-Office365-Filtering-Correlation-Id: e97cfb31-3870-4748-c7d0-08dad90e3a44 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zm4oGxTejcJzydospRkb2Xoqs+Pi+LL/t6NCHId24guxT9UwscWcjjixqVXov3LnngUARrOutZWNOdiTEOO4N8A3BEQkyHv/q6hSx1ts6QKgQB3AUlVEjSTbmntBoD/+46Xt7qLuKPM+w+r4cuN27ll2eVoKKrbH+sUXWBCYWnZaQgpOl1KHLnDtlX4KlBZfNi7/M8VR15cV6X5CYEfevtislCCcr9PQD3DH1JbBmw/HAr/ss9mkJgRIVezB1ng2jzmhNrd9SYcCXsryjyD7h/qiocX0evbWrf4G2+vGVlX6rzQV6/8F1SrJLTvGB+BX2HX2wA3ZKRclnhKWmR4KBchkW5ZBkxS14i3kzlVXMWZfpP6Zztpxqbf6JTnaSaxP9YEhYWyLAQbFQmPnGDM4tgArQc9fd1jPEYl2W2lsnJQhIWjUVK4gBTgnrA0UA41HRcKyIN00SAjJjkxxUz3JeHqm0P+SdJc63iz73wcjmm/N0FvIfgUUgeaN5UctWjtGgrasfKqZ/Ow/iwN/szKdfQiqHpbuPGO7TvHJPMwCm+TBG52efFp9OnEXL7DAkMXj4AvGMdLZM3mBRe2IImCU9MyhTiQJqnhxQ8H3W5DO33k6TKQTPaXFY4CxTjucWUik0vMLnF8RuE+E1qAOHy889E1IZA5keUMeCCn7wlmxO89JpjvK71cmvpAEcbhb13KNViZutGC+Tt4cFy3+nSVwSjRkNMR2Bhbu7e5P09/y0fU= 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)(39860400002)(346002)(396003)(376002)(136003)(451199015)(46966006)(40470700004)(36840700001)(40480700001)(86362001)(40460700003)(36756003)(81166007)(7696005)(478600001)(26005)(36860700001)(8936002)(6666004)(44832011)(41300700001)(356005)(8676002)(110136005)(2906002)(316002)(4326008)(70586007)(70206006)(54906003)(16526019)(336012)(82310400005)(82740400003)(186003)(2616005)(1076003)(5660300002)(83380400001)(426003)(47076005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 11:20:35.5920 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e97cfb31-3870-4748-c7d0-08dad90e3a44 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: DM6NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6668 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The new amd-pstate driver support to switch the driver working mode and use can switch the driver mode within the sysfs attributes in the below path and check current mode $ cd /sys/devices/system/cpu/amd-pstate check driver mode: $ cat /sys/devices/system/cpu/amd-pstate/status switch mode: sudo bash -c "echo passive > /sys/devices/system/cpu/amd-pstate/status" or sudo bash -c "echo active > /sys/devices/system/cpu/amd-pstate/status" Signed-off-by: Perry Yuan --- Documentation/admin-guide/pm/amd-pstate.rst | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst index 62744dae3c5f..b8e33db3957d 100644 --- a/Documentation/admin-guide/pm/amd-pstate.rst +++ b/Documentation/admin-guide/pm/amd-pstate.rst @@ -339,6 +339,44 @@ processor must provide at least nominal performance requested and go higher if c operating conditions allow. +User Space Interface in ``sysfs`` +================================= + +Global Attributes +----------------- + +``amd-pstate`` exposes several global attributes (files) in ``sysfs`` to +control its functionality at the system level. They are located in the +``/sys/devices/system/cpu/amd-pstate/`` directory and affect all CPUs. + +``status`` + Operation mode of the driver: "active", "passive" or "off". + + "active" + The driver is functional and in the ``active mode`` + + "passive" + The driver is functional and in the ``passive mode`` + + "off" + The driver is unregistered and not functional now. + + This attribute can be written to in order to change the driver's + operation mode or to unregister it. The string written to it must be + one of the possible values of it and, if successful, the write will + cause the driver to switch over to the operation mode represented by + that string - or to be unregistered in the "off" case. + +``cppc_dynamic_boost`` + This attribute is only present if ``amd-pstate`` works in the + `active mode` in the processor. If set to 1, it will cause + the minimum P-state limit to be increased dynamically for a short time + whenever a task previously waiting on I/O is selected to run on a given + logical CPU (the purpose of this mechanism is to improve performance). + when the I/O wait flag cleared, the increased pstate will be restored + to previous state. + + ``cpupower`` tool support for ``amd-pstate`` ===============================================