Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp286275rwj; Fri, 23 Dec 2022 01:06:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXt/faVAsC16sQkeV54B95irAJuIYOOAjzQQmqSMBhVdfPo8g9vQoBV8USWlQmwSVQY1AeR4 X-Received: by 2002:a17:907:c516:b0:7c1:e78:11ed with SMTP id tq22-20020a170907c51600b007c10e7811edmr7391845ejc.0.1671786384284; Fri, 23 Dec 2022 01:06:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671786384; cv=pass; d=google.com; s=arc-20160816; b=A3MYrP663ul1OF1hHfalMjCcSzvx0B59+6jomjSEejIMErHy1vNyvVqAuhkqXDtNEC TsZ5fCYRQoiQF/00elpPLc5p1amxfil2rT/6jl0DDwto8KwliOF03UhNIXYEBBMesPWF Zm/LlG+f8dEy/PWPk+D+QYMvgEYhI+0OPDmvap4o9A7igM7sRuFRt5oz51Sr6GI33kqJ IYFnEeUeZ0r5jgxhMqGIcFGgWgSTEAmWRK4iCqy8GUUb2fhExjDQV9PZvO1s08yJP13d zhGXuottM7LvLWyN+rFXAAf8o2rHKvcm76ntm4jj3KrwSS4mcUZFoXcXX6gTOt7Xgwk0 eP6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uOK+Z3PtctqLV8X2xz1diJ/2GMbUohddc5cFGVGpGv0=; b=bzMTUZ0OYLVeowsMvkytx3lkgxa5XothK3h8Nm6560i9R2AFopUTllAjj11OxsGOpv LfG//YYk399cehGqeP9sk1/FQZP0MlaUOuLydAKct8GpkhzxF92x/9J5F2oVs8Hb+hbT /vbarmGAjf5h4poWEWZ5c8YtGr2jkodGMqDWKiLx4xvb4tQGB9leiUB2mB7K4sLaEzoV d82kf4bKez5sXSkfrZhuHZo/5dy4e03Xw+Lu2YVTPxEFeDrkDNmw5XjWFOrRQk82s649 w+hl6XbqhZ4tDEYBmUNanSBeniWXFPk5usXnq4cxMrmwn4HKRdXtWrQ+XBndRl9ETtLu OBog== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=v8kAqbyB; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=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 qf1-20020a1709077f0100b007c0d6b34c2bsi2339028ejc.647.2022.12.23.01.06.08; Fri, 23 Dec 2022 01:06:24 -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=v8kAqbyB; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=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 S230199AbiLWILf (ORCPT + 67 others); Fri, 23 Dec 2022 03:11:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235811AbiLWIL0 (ORCPT ); Fri, 23 Dec 2022 03:11:26 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2067.outbound.protection.outlook.com [40.107.244.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D6CA32B9B; Fri, 23 Dec 2022 00:11:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QnoxisCJYjGlv+N1+Pjs8xYYIJWQPOfNjF8vfSBf4IAx0uofMdaNcOWa6hrxeKHz86hRjhemJdqX3t/LNZmUiQN/wiTOen8Xc1SsPchnjDjIEweZrlpaVWSi0zRb9OF38Y8VA5EPXosUvNjkeAR76oGYL/QvDI4/8yO5fL/lXnUNlela+bJ44sj0gOLJlZUzOm3WyIpUPEw/UUdzyDvvU5JpI8UxS3A6KrIiK3irMORcwBVl/UhU6Mg7UJKlYJdF8goLHUEutyAIv+YTVtUvG9ZOhpY2+za9rpN7R4DImv5esmTxkA05P35ueYpzThKQ0jz0J92JKz4IRinEMXS4pA== 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=uOK+Z3PtctqLV8X2xz1diJ/2GMbUohddc5cFGVGpGv0=; b=lSvy1nz1jW1xq/Xfmek9Ne/kcA34aijyJtgcJQfbWCIjJCMhmrJHawmeX16409WpnJd+XelUqGTq1dscU7Zu95nu56nO7q+XB+nxIRZiocCeHkqfwd/b/TQy6qXhlDhutHBaMh4LY9u2x5TSSul7E7uEOEAJxYzamyq+a8xkPAR9pxSBCgZwF++VxDHcfUVb3I02JGC1cRYqF9zuJ1I2DJOgg3aTztQXt1X4HbmT9n/7fNss6MsmfzAgHNeK9orEL+c8sC6uNT4Py0HVayr7+YoOCm428cb35ctJKp4DFuz9W1d7Fwowsc1wo/+GQwlwUfF2YZnitJYds6kxNFHk3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=uOK+Z3PtctqLV8X2xz1diJ/2GMbUohddc5cFGVGpGv0=; b=v8kAqbyB4YWIF3i4MnIWr9gnVeLDWGRp0jYRGgdlRX6WPptFZ6xnAZIQ99H9Zlux1to1jdp5oc9kImSgHcSdfFwE22FnpyaeeIGpalIAUgc2/o80AGH4mNSxKBtMkmVNs1lrA5TamP5rzBJTb0iLtVLMwdKyeQHowkRqsi9tRVQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) by BL0PR12MB4915.namprd12.prod.outlook.com (2603:10b6:208:1c9::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Fri, 23 Dec 2022 08:11:23 +0000 Received: from DM5PR12MB2504.namprd12.prod.outlook.com ([fe80::2443:424:1c7c:17cc]) by DM5PR12MB2504.namprd12.prod.outlook.com ([fe80::2443:424:1c7c:17cc%6]) with mapi id 15.20.5857.023; Fri, 23 Dec 2022 08:11:23 +0000 Date: Fri, 23 Dec 2022 16:11:01 +0800 From: Huang Rui To: "Yuan, Perry" Cc: "rafael.j.wysocki@intel.com" , "Limonciello, Mario" , "viresh.kumar@linaro.org" , "Sharma, Deepak" , "Fontenot, Nathan" , "Deucher, Alexander" , "Huang, Shimmer" , "Du, Xiaojian" , "Meng, Li (Jassmine)" , "Karny, Wyes" , "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v8 07/13] cpufreq: amd-pstate: implement amd pstate cpu online and offline callback Message-ID: References: <20221219064042.661122-1-perry.yuan@amd.com> <20221219064042.661122-8-perry.yuan@amd.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221219064042.661122-8-perry.yuan@amd.com> X-ClientProxiedBy: TYCP286CA0113.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:29c::10) To DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR12MB2504:EE_|BL0PR12MB4915:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c133e73-87a7-4a59-912a-08dae4bd4791 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PN9tj3M2tGjEEVGizM15TqD5g1WTkKFZP8ddrGmmNVur+yuPbZH5DAkWgj6EKoxAE5eqKqsoGECR1ON1dUmCsyl3UoLLm4i21yr6QSjY6PQp1l2kPaOkn12jSW4dAKrj13G4Af5xKF2PoYA70E3lMpn05p5O7sk78Rg50dB446kqdH0x2gWLpLBEGEAvypID4JLbqZnZI2zw+vglF/wzsSTQCobt3LZH/VvxBtWTNsAqyyFPtfmNPZGxBZEzy3KZWf2s4IPDNdY25NV5HV5uRS9syfjRu98mJlvu3H1a3i2irJIkrFARSwA6Jn2P4E5XInmjaY/Ztem2CTcUMkn93PSjP83WY/CJyqqu1KDZ/5EzSf3C966GhRih40V/XMpsFtRU09B8CXFH7xf0l78UnhxVb3v2Rpnkwo1kVWuFyHp4d9bgqt5blwmYoocrmNcj9o5swkGngDdCKhkWInPGaBpvTR3N/cgy+dQKENNaUBACOG/D24Dq5haSWZm3X1H0PuRkrITT4kWduU0ebjZHF8Fj4kT6aGnD0TP4hThoFPLmkaZIN6bZJydhx8Kne4g9xH93+pPDNro5xhUbOReKr4krBQQqJycMqt1BbZa62IfQk4JYjAOfGQ4hTuH3yRnyxXZWe4K7lVnah9Qr3V3lxQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB2504.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(136003)(39860400002)(396003)(376002)(346002)(451199015)(66476007)(6512007)(36756003)(41300700001)(37006003)(4326008)(478600001)(186003)(83380400001)(66946007)(2906002)(8676002)(2616005)(86362001)(5660300002)(8936002)(26005)(6862004)(66556008)(6486002)(6636002)(54906003)(6666004)(316002)(38100700002)(6506007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TuEVO3QoR8Jw6ygl9HyZvecbvqtbY2oDngCasso4fZuWoGeN8JpnjrV5ZsJq?= =?us-ascii?Q?5LSUCqQQV0RYZ0vIvGLpf1icyyC+R/qceht4S9pRQ0by0ZzYCRTqoE4GDrEZ?= =?us-ascii?Q?AUZqJCDqW6P2s7u/C2TavC0dCD4v/4lc0BgJ8Ksc/GTAJ5rvKqNHZoAb17Ka?= =?us-ascii?Q?wj0zQ425gOs0cNLvjyMiUJ/BYgv5FOklRWei6UKQ1sOaV48HyZZ051RHMjKu?= =?us-ascii?Q?CndtnQdFPP3IcIo9b6WzNgchV/pyyuMCm+Rmbt9bLKmOp4YB66UpilqV2je/?= =?us-ascii?Q?d1fpy+dA7ZWgkmusLprfhFa8nN/ij9KvS0KC5fnCnCBmY4msBdf/pkIaN7wF?= =?us-ascii?Q?m8817aKoESiox2DuQ8p7iOK6VsZxykbEHZMgJRw+kBzlmTWrsYPn8sHct9Zg?= =?us-ascii?Q?c6/z28E0ImvIMc+jVS2+9SrhavWjtJwk0rUtePUEPGtcuLODCh0oEvokp/h5?= =?us-ascii?Q?NvqebLYp9Jkg3CJm+7zvlDtY40zBr1bwQsBhhbQ3nphagwCxlkA/AZh02lCk?= =?us-ascii?Q?+cG0xz+QntiFvfhCllteoz3jsIEwncViEztEdWoSRffZHqOVEv2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qU8Oi7g8Fd+FCMYlbaHF8K1NOHQX1yg+?= =?us-ascii?Q?vthhC5P1f7aVEO/5+jgYAEG5IsNr/97TqJEQPlYn/VND/aY1tKzH1wF0EtZ1?= =?us-ascii?Q?5zeBjvVvtVSEImhlUZYXMDnpH+Ai+Pjw7HIo55Mw?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c133e73-87a7-4a59-912a-08dae4bd4791 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB2504.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2022 08:11:22.8426 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DfVuiZYS702TqdHe/rIK9Yntjtk6a4/qbdBThI1mR0/rh5OU4ajOSqLYzt6KVSQFvUcEm7xaWAiHJ55BfruZUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4915 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 On Mon, Dec 19, 2022 at 02:40:36PM +0800, Yuan, Perry wrote: > 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; > }; > > /** > -- > 2.34.1 >