Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1764240rwb; Fri, 2 Dec 2022 00:21:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf4f6QtT+beMgezzY+Ww2O5NCCPel6v2lEL9F1iD9xzoX/YqNLOa8XbCukWF+1mlWdUjgbiX X-Received: by 2002:aa7:cc8a:0:b0:464:1296:d5d4 with SMTP id p10-20020aa7cc8a000000b004641296d5d4mr61308606edt.83.1669969295831; Fri, 02 Dec 2022 00:21:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669969295; cv=pass; d=google.com; s=arc-20160816; b=sLDiYYPC6wJBLH54tvgZck27IsoEkDreNeRoh1QkF7sNsa0iwDPaZC1vPhwK5NcBhH w0WxmD80pjNxJpRTQintdWSGw57IgSFv3ivw6oUW0C3w4Zf5aGtApyHkfDpsTIILHXrM La5FADubncTgkhN4IT/0KvdqrbjG30HCCeKfq5i1ptfLsaRVA7VIKk0SbsY6uqe0eqKP bC6ogUEs7y9rmTe49khVaFtg4QDGNeQj/SKanLfNkZ/slGf04qnEYviM/nvLPalbL76v mW9JsmKNlpDdXrDa0KmZP0g31d7bT8a9pAvwLwF4/IYGosUTT1FQZhthOEHr7w9dg56A 0LZQ== 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=lInKwnjewUZ0O7QKb/uBO/AjMqyVqRBPr9M7mf3tUCw=; b=Opob4Xur1t9xpR8+7XqrU4j9qmUS388xD1hgybNmThjZKCWSRnZaEd2OABoSBCFukr cgLqZHokLZLvUcsFJyihfVTbpIGSqn82/Rd+MpviEQCLvdQlxafiwlAYTbR87D5MrmDh 3Oo/7ODhl0VT0qKQEivq5QuptHrr/No8ulQtAFXCRrEHLPPPJrJt4WRNOcWsddIN8Aom B2xzJCpQFKj84tfTz/5tBg49nUMduZu5LlTnJpb1teJuRrQCvCzc7tN4Aww4BE/7I5/F H5gJPdQrZerhHoPMTcy40Q2uqa8p3WAbDYrPjsBNLn7ExiSRIVLxaDgWAbzMnBHa4rt2 ef7A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=HVhiGau+; 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 b11-20020a056402084b00b0045dc9b4c034si5912122edz.582.2022.12.02.00.21.14; Fri, 02 Dec 2022 00:21:35 -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=HVhiGau+; 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 S232550AbiLBHvx (ORCPT + 82 others); Fri, 2 Dec 2022 02:51:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232460AbiLBHv3 (ORCPT ); Fri, 2 Dec 2022 02:51:29 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2057.outbound.protection.outlook.com [40.107.243.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0BDFAC6E1; Thu, 1 Dec 2022 23:51:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ir1/nBfXcG6opj7+KjfRkUiKNziVzFhIWn1W7jqRrf0BLZZphzoVj2el01+9DBcFvmxYBmoHCSGndGS7suaM4iwnGFa9fIWhhTu2YZcf2TNfFMKIb5VPnANQMKNmd/TZGgc7BaIm5XYx1+8Bjzx2AjEGDb/c9BSEAEvqxmbPCew81EzViWba4latX1iBnHcwBH1SddLeQ6de9lgQmawp5p3Mv6lY3hhkWTw0PFQYXCGV8mHugcjMXimitUjUaYPwewK718/KlPeSo5DEMxeOJ1xUhqPPn7M0BvAyeqbva1RfMalE5uQQ9c1E8XJkFF/PMJ2dChSr7RWtb3hj0xTqjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lInKwnjewUZ0O7QKb/uBO/AjMqyVqRBPr9M7mf3tUCw=; b=P8Osvnpzn8sm/ocegjEcFOF1UDLURxScli0yIruqQXG0elYyKe/e2/nGe8vGAB4bO227tfWOunbxi/GkgaXiCim8IPzFAS36C2GxSi17DKIYNK7piOi04BqAkNbDdLFeDjC/xLvCUPiL4eWKsj54fRpQ62oCVVs5QKu0bwEDcjN1LY1hYv2/mtFXp26fzOMczEmhWHNrc1JvY4ffBrlsSI8IPJL7ZG4jJ4Fgz60+Bbsyew6XTDlhOfDJX3vAs0cGjsOuNfVuGyltVWNcC7Kvj37ZeA0OpQlOuo5frwT1lxGoJ0tQD91g+boSa/DlHa6o7ZC+13SvA2z5lk2zGPg8Yw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lInKwnjewUZ0O7QKb/uBO/AjMqyVqRBPr9M7mf3tUCw=; b=HVhiGau+kshJiUYsD3wG/AseeNz3TPoZ7CAVzRQASZtr00EcGL+9IjQ6PUR00aGPSTS40XZzXvTQeZ9o6NVfLKEeNmHmOHH+eG7NFRpmXJhWTYEDT5y3R9lIdb25CFV95zEEQFPMIj0Ljm3Y3Z8B9m9ujEhJ7UMfCx/5Cng1+Gc= Received: from DS7PR05CA0093.namprd05.prod.outlook.com (2603:10b6:8:56::17) by PH7PR12MB6466.namprd12.prod.outlook.com (2603:10b6:510:1f6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.23; Fri, 2 Dec 2022 07:51:20 +0000 Received: from DM6NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:8:56:cafe::90) by DS7PR05CA0093.outlook.office365.com (2603:10b6:8:56::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8 via Frontend Transport; Fri, 2 Dec 2022 07:51:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT055.mail.protection.outlook.com (10.13.173.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Fri, 2 Dec 2022 07:51:19 +0000 Received: from pyuan-Cloudripper.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 2 Dec 2022 01:51:16 -0600 From: Perry Yuan To: , , , CC: , , , , , , , , Subject: [PATCH v6 05/11] cpufreq: amd_pstate: implement amd pstate cpu online and offline callback Date: Fri, 2 Dec 2022 15:47:13 +0800 Message-ID: <20221202074719.623673-6-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221202074719.623673-1-perry.yuan@amd.com> References: <20221202074719.623673-1-perry.yuan@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 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: DM6NAM11FT055:EE_|PH7PR12MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bef6498-c38b-4543-d790-08dad439fff8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NjmGmuRApnVi5H65t7GWLBliij1Zthz0bvIwCsOJNejxplajJVvk8M7NPzRpYT9K6fOH0WrAOTqTHJaLKndG28tK4xyHyyWKtFXX6uuvuz3EVpAlBIIgKeil36dofvWdqxNunqroawWi//c9ycHqGiclAQ809gM8/eOlAXUt6AmV+/MwBpP/dbBhZozubwhOJohzZacVerUncAz28Z/QHOXdvQpIm+3i/GLK9DbRDNO5aqU/mJW/THIfKT5LMz33cB//yEztiHCM+C0EOOq9w1sw5A0O1q5VK63vBabZ2xzigxxnw/iT1NlFpsanDDNpIZ7UkV1uwx9oWS8srWGT3zrqxNimDHN5sBX/iLDn73lCcJqRFppZUjl4O3XVHsP7DPIXtcn62O+QT6XrqgZQfS+U3PeGd8ZRp6PNhiRoXGrLYdaRFC58xkHNAcgoaZj4qpnupQbksmGeVm0c1GpTyVb+o12R0rY7C5FxC2L3D/pccdyXAEwKIEd12FqJc4NDZacKvrqcj2/GzZtpXKttEn6fls9LEKm173YRMxpfsnuVN8fE0sm2bcj6htU1iqo9Ntxm0wdEl7YKPnq9DUQayF/KvdHLlORqNsCjFCOkXH3UrUm5Ovon0SDamDoFRDSwMjmiBvgPHqhIrVnvAwL3ujs2SRj7738fSgK+T5WUmCYW/8q5+t+s6HpfgxJRTaK/SG7DtBecDSsBHJSviX24nwEl/tVJzle7LuIqzQrxnx0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(39860400002)(136003)(396003)(451199015)(36840700001)(46966006)(40470700004)(36756003)(70206006)(44832011)(70586007)(41300700001)(5660300002)(4326008)(8936002)(26005)(2906002)(40460700003)(82310400005)(8676002)(83380400001)(478600001)(336012)(7696005)(2616005)(47076005)(54906003)(186003)(16526019)(86362001)(1076003)(316002)(110136005)(426003)(40480700001)(356005)(81166007)(82740400003)(36860700001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 07:51:19.8287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4bef6498-c38b-4543-d790-08dad439fff8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6466 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 5989d4d25d0f..7545d83a934b 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1197,6 +1197,93 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy) return 0; } +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) { @@ -1231,6 +1318,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