From patchwork Thu Nov 10 17:58: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: 18260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp294617wru; Thu, 10 Nov 2022 10:08:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM7ykIpVDebtiF0ToTGH5fBD9wQbDikp9/eFeVTPAp4wysVTC6djCKhTcaONT1uDNE0sDRff X-Received: by 2002:a63:1a23:0:b0:46f:c464:ee5a with SMTP id a35-20020a631a23000000b0046fc464ee5amr3006075pga.399.1668103693420; Thu, 10 Nov 2022 10:08:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668103693; cv=pass; d=google.com; s=arc-20160816; b=aKr8qLtD6vhAvIn4KroQxNrTWLTR3brtVScPNKxwIlOYoovqUCLqvx/D7W3aGjIFJx 0qHl55zW0GMYs0KtM9vUH/X6lDP35ZAAe9qR4KrWIklQdqmOkLTy3DWIaxIhlIiKAVPh h3vLUIPW1ZfIBmLc5YZLa6ehH5hOX2vXb4tN8Jr5DnjKX1KG2y0UqtYW7ZzS33oynVKE hA72Xexyyl7ow4GmHg5rUHBFpuikUw9jN6LnfEjXCOt4hRwetW2e2xrQ5dJG4HfLU+hd tqYs31oXa1S4Sl+gu9m6ULAucBVozcrtokcs/LrfwT6UvojN/Aw8POXFqOj15K+K3LBn bQTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nqKZeO5kKpEC7sJX7NI7io5dvJwXoaa7bGyUL+075Rs=; b=vpOTtGRselKYWNABlu5g8qMjT4ycYlySsb2unkUi6AZ/UEb0bcTDDOCyBKzHJ3n6ba IeLAEqXI/f/yZzKxwsjCZA+Ol/hsBbmq4oxh6u2zBRK+UQ7b3PZyKh6yWONWgq2TMD9Z 2PJ4VvD1cDx5sQQoQJF+FVo87XwZ0q4bqEgcT57LXtBSBOrVNszYA/0I4qrRt6G73Hp2 vzJiyfZythMzAWxvwC2GTBvWXv/hNJqqw62CO00pimGgRLJM7+sfHTgV0mA/bMd1zw3t p0vChTCg7x2GoltBhFIUjNc5Kc2APR8GIUl2hcFwgnnGCHmeRC/V7fr65OfCpaU1wBQ+ xlVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=TroB4fTX; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c17-20020aa78e11000000b00557c8a20395si16843572pfr.120.2022.11.10.10.07.59; Thu, 10 Nov 2022 10:08:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=TroB4fTX; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229588AbiKJSAC (ORCPT + 99 others); Thu, 10 Nov 2022 13:00:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231639AbiKJR7f (ORCPT ); Thu, 10 Nov 2022 12:59:35 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2077.outbound.protection.outlook.com [40.107.223.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4233443858; Thu, 10 Nov 2022 09:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AUp2jOlvO/jOY557maRI9v8eZ/2kiGBQ3/HlNNBlFugI8dd/FYqbdVT8ou54w4KSVh76AtUVnD0SH+JP0m66xS1NoU/QWPnZdxrYo8g4fzcQ6c3ypA7THtaBhqX+3vy9QBlPbkp8BdOa+P8BkbCVWSPsXYr4uxVQPEZzmLRjQq0GKtjj1ji8rU9MsHDmp6hXLygSKMCWZ1MOru67X0DQF/nTmyA6cH1/Un0RBzM6DPgfv0uRecb7XFhhecGLU0vLqANq1+NhPGSn/f37zRUO6pzH08uvGxndhVsZV3z2i/qgmRWSMZzJOZ5B3vzgJGINm61bSRI1xv6ifAb1U+h6sA== 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=nqKZeO5kKpEC7sJX7NI7io5dvJwXoaa7bGyUL+075Rs=; b=NLIsTFf0HiRan4fQgDDDoYpxGnIz/Tjm0MDAa0dkUJWHs4ZnRYrythy3YsvZYKtdkDOTK2VtlPlYAybWcHEAII9gjg5I9VuuJrqDNcxkbtDFpDMibaYCcET3RzPjRXTUkP8x2DippTti1l5pSp3cyjUMwilztzWAI89lTRfbIIX24yjdKetJev+af+k5/lpYchKv8VplxdnS/wykicB/XgZtT1q6+npxUypU5Z3VQfs0bxi1CSk87kBOhsJoBi3TWkiP+5LrqWr31we7goRgcbKsVmkQuJj+31rjhYNZ+kx36vw4dDN/o5d6mP8gYZ5bqagGLukNbPrme6Uu5LhOEw== 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=nqKZeO5kKpEC7sJX7NI7io5dvJwXoaa7bGyUL+075Rs=; b=TroB4fTXpV653iDlnXO1oTPzT6x4xDohQ9+Xv3++il4OaYA9STWQa+DaPo05NzmHPlBRnGfjexecaMCtRsDQRSpw7PVhTzBrMTYOerFlNPG7tCtmbKYR/auLfvlW7SrF5C5YxbCFjuzwafyKu/Fv93YXrqdpLv/ugByuB3Mwrfc= Received: from BN9PR03CA0355.namprd03.prod.outlook.com (2603:10b6:408:f6::30) by CH2PR12MB4040.namprd12.prod.outlook.com (2603:10b6:610:ac::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12; Thu, 10 Nov 2022 17:59:31 +0000 Received: from BN8NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::76) by BN9PR03CA0355.outlook.office365.com (2603:10b6:408:f6::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13 via Frontend Transport; Thu, 10 Nov 2022 17:59:31 +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 BN8NAM11FT025.mail.protection.outlook.com (10.13.177.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5813.12 via Frontend Transport; Thu, 10 Nov 2022 17:59:30 +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.31; Thu, 10 Nov 2022 11:59:27 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , , Perry Yuan , "Mario Limonciello" Subject: [PATCH v4 5/9] cpufreq: amd_pstate: implement amd pstate cpu online and offline callback Date: Fri, 11 Nov 2022 01:58:43 +0800 Message-ID: <20221110175847.3098728-6-Perry.Yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221110175847.3098728-1-Perry.Yuan@amd.com> References: <20221110175847.3098728-1-Perry.Yuan@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT025:EE_|CH2PR12MB4040:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ad52e69-d97b-43c9-5d45-08dac3455141 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dM3TTYwc6iipndRAkR1p4piEZe7EHQw50E35gk2W4TJyd2ToeqVl+52ZMHj8ViROEq1TQP33moMZFaa1N8WXQzcIIerA9cz7FWh7fmIOAMqEDrtYIHuT4v+GQixh93LKC76/4HH2XWRHOEbOK0CgvlHOCztlSYz9NDFz0nnHWtIstVt4MBuaabOdz+0aztc8Zv5BCzmtLLlqruKiZQJOo1MdAggkLR+zakJtvjDLGpJlQpLDblkLJYvVl7R17LxCN/Pd3MzvC/4UzsREGurVgybRA1V8S1jPQtSc1lizJjEFwtWR2mJc7FdCKHRDjIIa/36WQaGDjdnQfdvbNpUZNKz+UBcI7xvHdojS2/VjTc0XrOWdEpA13472oC7QuTHQQ7CpTpv4bWevTMuOOsGfApGE9hsUGo7INYGNaUU8WkCPAZ0hAHJjn0ZYLvbat1cAKW3xgXifSXjYjmWYA8zO+WzimwZe5ZKIT9M8ECsqmEpUN87FxjJ30dqQoqI4r/ftxbuF/gVjpyFPFFOq5c1lcnAutT0YVpFsmTR3pR0R/hStCeLBRmftt2jesXsduHlDGMPnkhxtHPwho8C27TIGCCunZOHyx/nycaAp+cNRBCW8Zee2n0ZkX+Dm4K0nEzJVXnVcgcH93HTjiUt1WkQsPSolMjdSCmP4bt0QCqUzarez0mZOy7+mzQQ8kDkygNiIMp4XLNtmDFnVCU3uFi2Wej4k+q8J+ClfzyNJqxgq4Fl0bQoEA6ae9jLRd6XIEQ0/Mc4eJN34CrOaEDi5bHKqI3fAO9jXP3rqm+l/0z9Mn/2lyYgbMBkK12vSReZB+u5p 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)(39860400002)(376002)(346002)(136003)(451199015)(46966006)(40470700004)(36840700001)(426003)(36860700001)(86362001)(83380400001)(82740400003)(81166007)(356005)(47076005)(4326008)(41300700001)(40480700001)(82310400005)(5660300002)(8936002)(2906002)(8676002)(7696005)(26005)(6666004)(16526019)(186003)(2616005)(40460700003)(70206006)(316002)(70586007)(110136005)(478600001)(336012)(1076003)(54906003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2022 17:59:30.9275 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ad52e69-d97b-43c9-5d45-08dac3455141 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: BN8NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4040 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749133498683707718?= X-GMAIL-MSGID: =?utf-8?q?1749133498683707718?= 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. Reviewed-by: Mario Limonciello 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 7b3a12772582..9a9abb755a18 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1174,6 +1174,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(AMD_CPPC_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) { @@ -1208,6 +1295,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 7e6e8cab97b3..c0ad7eedcae3 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; }; /**