Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp899550rwb; Thu, 8 Dec 2022 04:31:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7rY0nzEUENCjD32lqoz0Lmg5JL58S8YeJd4aqn41hfyKA25zulkM3mFF+AWqqNFoyB6et6 X-Received: by 2002:a17:903:1106:b0:189:528b:7a14 with SMTP id n6-20020a170903110600b00189528b7a14mr69454428plh.62.1670502696950; Thu, 08 Dec 2022 04:31:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1670502696; cv=pass; d=google.com; s=arc-20160816; b=Q44BQYtk7qT0iS7wjt1Fx+gVgXCFhZvGRlp3Hdr2kJ6Poi5E9Waf8LATjSzHsx1ZvW AEYvlZpEXZoZhoJm96ITmhPv9A4SsV19BJ3oR24kx7D1ah1e927qHd1Ty1W1iLx2rbtW 7BhgWPrXeq/aD+tKg50461vSayzqWSgwwWbcoGidNDNYML4qDIuNfNUeXDmFWhFnNC9j SZxFqDcwQm+0FCXmDskhZkNCAPzQ0ZN6D9Sdc5bHgdtAc3mvgMOHy8Z1GNsWcM4orbr9 j0lf/XUpR4KF+3Wn7850miY3tr1W4NbIRearF9HPmuElXn2lMp90iFOTMdnsFFTTfqgQ +RkQ== 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=fq/Lr6MF9/gKf2NO7wqeQr5YIPol9/r9wPNA6Rsh8FY=; b=kN2z1fInZw8Tly0s4gHE4FxfaNmDKo6di3iHztlGdI+saQD2oCtBoEQdrHvFtynQMi M2niynxQbLIHiDE2KsKHEmpOqCV0VsFbJd/f75TtNgEwp++alSw7y+tVolcnCETuxoFM dhTUqa4JvV0t1fIOyfuIQwKDV/+v7euRFWqIZK8+45WFAoKVi7Fd29gVsaC7xTsUemKo N9l382imSfjla27imKIFT5SVxOfrYKgbwzE6sySc/Y+1YKfJJc96vng6R54S70EMGrKy j/+yvT6Vs6N+4zC3nGy353Cp6LYRYqFqUgp1JUcFRFwZPrtVvZ78jOxdnaHyJfOZiLhw NEKw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Ck3TDqSo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s11-20020a65584b000000b004774d8c6191si23367459pgr.413.2022.12.08.04.31.26; Thu, 08 Dec 2022 04:31:36 -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=Ck3TDqSo; 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 S229941AbiLHLVq (ORCPT + 72 others); Thu, 8 Dec 2022 06:21:46 -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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 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 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; }; /** -- 2.34.1