From patchwork Mon Dec 19 06:40:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 34414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2229907wrn; Sun, 18 Dec 2022 22:44:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf47aBHPNGcgqGMfuUgHc6+dPdwuMCzXbuybGW8qeHI43uS65nNtPxkh0uILttv+fMKjhN0P X-Received: by 2002:a05:6a20:d48f:b0:9d:efbe:a0f5 with SMTP id im15-20020a056a20d48f00b0009defbea0f5mr50069454pzb.5.1671432243917; Sun, 18 Dec 2022 22:44:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671432243; cv=pass; d=google.com; s=arc-20160816; b=c2ocsZBj7xwK2Jt0gcUnqc0qWwZLMAaP/ofuLccgmrIXvFVnPvxKcselYFR0O9PJ72 uVnKzrYkiddRmh4OovfqHxyScdOV/d9xiqTYuE7WChVcBt85ZdSFpuvpcLP7gysOX+0f rpEU+HCBGtNRMCAkJQbPDQAQrJ0bBa+lsX+Ad3SGehkCl4jJgrN4a7PSOBz3TDJpnTSB ANh9APSPvHBsRms88N4D3smGDrY3KasEXcUXBmQigxin58cXpcPHWuyTSs2smcijh728 2Q4OYLUhi3f03RJB9i6ykERPuooXQRYvSpWRFM2gyTlNIUp/8aAWzG6yKROgMplxTvPj 6XUg== 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=3YrZ7+v7EZNlDhE1A+hEUN+oR5A/hp8m0nagqv1/LmY=; b=AAgihhT0FBkOSa0LSSWCoNO9CohwSrsOHzGKds29fT2Fx1azhcYDw021+9R9VQJGBr lL8Pxdtd6wQzfQoYwqDcw/1Jn+bYbnMbV4OtfxHkjX89IzfV9eZzgkJrl2/lKR5y+3l+ 1aMYW6c3Gw+qJdiLjXc9OgGof5K8adPRUP7kTOISo29kYMzYYciLoDeZGzNYH9CqZSNq SYeihYzY7c4Tqw+38WyC+jYw1+FBcw1ifkEpNrpLAp7gtBgjdO9XXHwGVhPTlDRs7slS 4qL65e8acmiM5dz8/Icmj11/a+bNqoncAMlfrAzyzjkETg3O2x/V2V44F3L6F4hPBp2a 7daA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=XgoGKZic; 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 v22-20020a636116000000b00478e26efc94si9950148pgb.422.2022.12.18.22.43.50; Sun, 18 Dec 2022 22:44:03 -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=XgoGKZic; 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 S231433AbiLSGmu (ORCPT + 99 others); Mon, 19 Dec 2022 01:42:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231378AbiLSGmQ (ORCPT ); Mon, 19 Dec 2022 01:42:16 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2065.outbound.protection.outlook.com [40.107.243.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D8B3D2C6; Sun, 18 Dec 2022 22:41:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GW6C5/EiG43WSvmOu+bcKAwB8mq36p/HC61J2myfOS1a4eMl1frJ5YlTHCwfgks7V7QV+EzWWc/G6PIt/SHFI/4WTwNRuI1C61FmkNPTHr2ZnWBUzfkrMl6qyQckYoLzeMwN6gdyF8O06O6PbmwfXT/Uud58nCBxi8He6uv/d/ojQ9uPYdyXG9Xij4deds0FIBRv6P80bc7UlXrPF0ZuC4gBG1ixjGlLhnsn6uoOUTz4qsYF8UUXhTL9ie+D72l5YQBvZWyjwQlZ4J/2rnFuT0at9vNqFB/nqlkW+4XKYV6txB7eCzWHEVgNQMPe9TII1raaf/eHXJNnw5MVigJSeA== 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=3YrZ7+v7EZNlDhE1A+hEUN+oR5A/hp8m0nagqv1/LmY=; b=RlNcgWCXrlJteZI208iNhnMzXD+Z8tdekj4kxApuLYn75cpDd4AdOX8Oxv9y0n9A+jnv8JqwvYfWD9OPbQ9i/PGXsyLlrMAh6CS0VC34PkF3oQ/9eXIr46DO8ZLWOW30Ep53+U+y6ciIi29g87Eefd18dRGeApT/+4lZshX9x8wOI3YpWjPO7FRRQfe4sqylvF1BrGaRvTXOHiqnSgCB7rhAkQahuFaH7Na9GERJkmysczYeUzcjzhhFCcMmzL+y5B53bjb326qeiq7nJD91bCdt5JWM5UOsymO+xQpiO8Es8CiKhPNbWFYWelSeLszAS9lZPpFj+QoqkazTZVGyDQ== 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=3YrZ7+v7EZNlDhE1A+hEUN+oR5A/hp8m0nagqv1/LmY=; b=XgoGKZiczaCpSkcT8lDgH+182rwHL487irTlMXVuNpUbzRMfVQw2psjACZNFqxtFV4EsKQLjzMs6XljA810n+Ryyw4qAJl7Kl1yw3bXcHdx8ZHFRGWvSSuBYbfGTluhWnqj11J2vrdpe3vN9sF8bfTRWsCeN2CXisNHnuoMGaAk= Received: from DM6PR04CA0028.namprd04.prod.outlook.com (2603:10b6:5:334::33) by SJ1PR12MB6219.namprd12.prod.outlook.com (2603:10b6:a03:456::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Mon, 19 Dec 2022 06:41:45 +0000 Received: from DM6NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:5:334:cafe::88) by DM6PR04CA0028.outlook.office365.com (2603:10b6:5:334::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.20 via Frontend Transport; Mon, 19 Dec 2022 06:41:45 +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 DM6NAM11FT056.mail.protection.outlook.com (10.13.173.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.16 via Frontend Transport; Mon, 19 Dec 2022 06:41:44 +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; Mon, 19 Dec 2022 00:41:40 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v8 07/13] cpufreq: amd-pstate: implement amd pstate cpu online and offline callback Date: Mon, 19 Dec 2022 14:40:36 +0800 Message-ID: <20221219064042.661122-8-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221219064042.661122-1-perry.yuan@amd.com> References: <20221219064042.661122-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: DM6NAM11FT056:EE_|SJ1PR12MB6219:EE_ X-MS-Office365-Filtering-Correlation-Id: 58f1e912-7c53-4708-0fe1-08dae18c187a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f6DQ5lFX9NknbZOZr8ZtfiUXNsbi6H15VsS0KMy8q2oTXFbZNW7fOp1JNkFDpQ/BWzr05m9DKIDeDtbKBEuRpXpiRn5+cvWaTtcLloOHBvj3+c6xRL2r+VAanpQi89xYW8UYs6CG1lnERJj4yro1BXevOpA3G1mx81IHKOX/6q2mfuonCfK6hm2779Cm9CjTlHV9OcXsEQkkdF/5EBpMkq4im3KkccF6OkpuO5cLWzwRVZ3i2cfg0ILHjY0UmpJu2/Y58ZakjHsoanwJaXkN9iQAkowUlq4bOxu9lQZyi/Y15dq7x46MHs8enlD1ATOf3td0w7dXjmIfCi2kp9ksemh9BvPhNAqKI8pnsoyBnVV/GhNDQu9Yb7tinOvet2QDAeIyKnebNrlKVA8WmMO4iNWc59DiB5keWNMgz5lxd5qmN2NNhIWr7sWz7jXAEA3JBK9qoSJTaIU8XkLZnc/AzYOCSPKL6RRgXeYOX6WoYcCiP6Rt1+ECTp4wmj6rL8DZ3Z9Jx5V4Gwow1smmtO/6EiN+EAmqtH7rqjmP977UKW8iL5OQ1kzWO4NC4/BjN3Mbg5vbGn4HXGwLbTce9DrRSaDPd0uEMLxKW2lVIXTy3yY7oLQMQdDa/tkWHD8xKDvXTTkOIRrAw9jx6P5zLYg4s1+hae5B6r94uvNKKQgajRGo7iB2WkOpsReAoCips7uW8s/iUW/09OjzAiVu58h/Yn5Z9AMoCAS4/O5H54SXKdY= 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)(346002)(376002)(136003)(451199015)(36840700001)(40470700004)(46966006)(44832011)(83380400001)(2906002)(336012)(41300700001)(356005)(8936002)(426003)(5660300002)(47076005)(82310400005)(40480700001)(86362001)(36860700001)(36756003)(40460700003)(81166007)(316002)(7696005)(54906003)(110136005)(478600001)(82740400003)(186003)(26005)(70586007)(16526019)(70206006)(2616005)(6666004)(4326008)(1076003)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 06:41:44.7888 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58f1e912-7c53-4708-0fe1-08dae18c187a 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: DM6NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6219 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?1752623736565194920?= X-GMAIL-MSGID: =?utf-8?q?1752623736565194920?= 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. Reviewed-by: Mario Limonciello Signed-off-by: Perry Yuan Acked-by: Huang Rui --- drivers/cpufreq/amd-pstate.c | 82 ++++++++++++++++++++++++++++++++++++ include/linux/amd-pstate.h | 1 + 2 files changed, 83 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 66b39457a312..cb647f55a169 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1020,6 +1020,86 @@ 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_state == AMD_PSTATE_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_BALANCE_POWERSAVE); + cppc_set_perf(cpudata->cpu, &perf_ctrls); + } + mutex_unlock(&amd_pstate_limits_lock); +} + +static int amd_pstate_epp_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_state == AMD_PSTATE_ACTIVE) + amd_pstate_epp_offline(policy); + + return 0; +} + static int amd_pstate_epp_verify_policy(struct cpufreq_policy_data *policy) { cpufreq_verify_within_cpu_limits(policy); @@ -1047,6 +1127,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 fe1aef743c09..1424b09ef543 100644 --- a/include/linux/amd-pstate.h +++ b/include/linux/amd-pstate.h @@ -82,6 +82,7 @@ struct amd_cpudata { s16 epp_cached; u32 policy; u64 cppc_cap1_cached; + bool suspended; }; /**