From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B095C3DA6E for ; Fri, 23 Dec 2022 08:56:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235080AbiLWI4s (ORCPT ); Fri, 23 Dec 2022 03:56:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbiLWI4p (ORCPT ); Fri, 23 Dec 2022 03:56:45 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F8BB1C10E; Fri, 23 Dec 2022 00:56:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ym8JWqh/WSI9Kiy7EamMZSCnMb6SYQTreHZglxnwDpKnsuO71qV8FADYKNj22pV0TVzlT7dYku+P3wgyyFBdmKDBvVxlXt55bNsL8XMJSrePSgfh0ztlq4+5/qXdhIuL8IompDZLPqaLu1ScmDuxuLvO038KegCTsnecjq3Tn+qiRZFHZVa+iWeUjnWQC8pHrxz7TKhYroYiOAPih9UDeyCPDQe0ZSQLWeWJYz/H3vClVmpr8Um4RE3KUEJ9W1oIQ600SVzCy1/aWX7ZrJr5Ae+FQdxfMmj/zSdk0ZoCEE9NiHPUW9kxet9ulRRLeFW7xfidu4tfQrhBXDTILp3aGg== 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=Kf/i+dt8/shfCYBABa3f9VbzHwcGR+KtV8CmlJthjDY=; b=ahEDSPokJjRvREeh6SYv86nWLEAMeiV3mz0OPVIVG/rJVb3V2ZYbbxNj3FgJJZEvhMjCbcexZleGnmzWyC21/s0B7iMKVPopCIuB7kEvSpBl6ZXYK/YHGUjlHcFTb/uwoB8R26wjAu3mK3hMX1lmWL/f2CZNoiZc/zaYJPPvuyD8SwH9H8jVn7f3bw3DKQAOREPEOV3yPG+1vD77AFM76MFnY9Im3XuYZtdQuHyYfp+ssazHYXPH5WaqrjGHZrsctn+d0FaJ3G1VsV+vn4T9rDaPmBvFxlUDxgGEzBhzutDjjNxO+P4NhI96/lCXtVFu3RAeMxTlqTybz8pa8H+NwA== 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=Kf/i+dt8/shfCYBABa3f9VbzHwcGR+KtV8CmlJthjDY=; b=vu2VsvistHJzblGFhZckJPeBY6E2oX9SmVYcHZZRRfZk4Gu+WN8L8VRhuGiM7BjLu+MQtn7ytC+O7JUQRxHU06olDi84SYg4jbFOB8LRipejvb2rqb/i/8tSlC+xrJmyXahq8LiUn2JoYChLyDPlROKmAKMfI4c/qBQ/xvQk7Xs= 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 DM6PR12MB5024.namprd12.prod.outlook.com (2603:10b6:5:20a::12) 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:56:42 +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:56:42 +0000 Date: Fri, 23 Dec 2022 16:56:20 +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 09/13] cpufreq: amd-pstate: add driver working mode switch support Message-ID: References: <20221219064042.661122-1-perry.yuan@amd.com> <20221219064042.661122-10-perry.yuan@amd.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221219064042.661122-10-perry.yuan@amd.com> X-ClientProxiedBy: TYBP286CA0005.JPNP286.PROD.OUTLOOK.COM (2603:1096:404:ce::17) To DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR12MB2504:EE_|DM6PR12MB5024:EE_ X-MS-Office365-Filtering-Correlation-Id: 0274a16b-e2b2-4d49-5106-08dae4c39c3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sL/38pa7KvVxaAYTiOJWkHyNZB+blwbCMKsM17WS3AkfnSYqaIt4v7E08i0j+Sibr8wNRqmNomgLNOfDmLkugs1DaIgmhHvIc0v1M9TWx4L10FDPNlRYEmTMJ18P4ZIpw9iJ7dPmgguiwVngrLyk+YOVk6pZcSf0Z5tyjWSrzf5Ml213jnWOMmxHnzQZhL6qxkpHZsE0hCj4bwdcOxLMsJKjf3mQTaRUvfTs62zxWEVnUUUD9Wd6jc+D0AWMOWUTkIKRFb3Rae0O9eTuhW0C0Znln7I+ajE340gIYjZVFdshJrBjeaJ45/2BkFxPfX93rv4TdVIaNLE+FnbHLmDG5w2GyCnhoeSDFOb22STJSbfqIAUOxUQCidIVMH3TEzgJLb2Keg/Bg1dKVKHZ5kJCumfc0SEV/lfIv3wNdxjpU2K+rELy7jDvELP+iHG8CoX+tL1Dttf3Vn4YjYeMKDgB3wdUeap+ozJIJGyk3g2nuXCwdbwpeIKSnBHNXsKGvryYrjROMWKVlQbwj1ncrUQcyQA/mxrkCFRqkjiBRC4+oOhy5yAh0uawASr1lgI21kmh/DzmjRz+IZnNEW36mvXYS+mN/a37l/tyhIU8LUD3WxFyLu07AKIWMCWkESsz44Wz5pLdTvfNQxxdcYlUF9AQUA== 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)(396003)(376002)(366004)(39860400002)(346002)(136003)(451199015)(6666004)(8936002)(6862004)(5660300002)(83380400001)(186003)(41300700001)(26005)(6512007)(2906002)(6486002)(316002)(86362001)(37006003)(478600001)(6506007)(54906003)(6636002)(36756003)(2616005)(4326008)(66946007)(66556008)(8676002)(38100700002)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?K9xoY0/p+AH2kGLCRg9H9cwtIdi5qqX+xSo2fFAp2A9GijBJWYB1Bi5qoLov?= =?us-ascii?Q?XtdN5B0YBqUlUlEGykqXWFUJa29IxFlJJZKQeFwj0a0CsS0sFj50aaWxKUis?= =?us-ascii?Q?+u7eNhsafOs034kYmvGG0YPNbe/JbzcAH2ICiUTTd25usn16TS65wymXpli5?= =?us-ascii?Q?gcguesoLoe9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?Q?2tuv4mys7h/jFbpbHPg1yHSFul8vYARd1wzN9nvFvzVlyooIFDXeG4UcB+xC?= =?us-ascii?Q?PWS3LlMsjBcHSpqKzb74g9lCikmf5e86Z19Y5rE5RcyYlGK8cT0YK8LBs2V9?= =?us-ascii?Q?q9BUI5okZYih/CormpINY0tDcsSpIB3kD8ewcq6TLpC3F248AHvA9oABLSPU?= =?us-ascii?Q?+kV/qMYVU28NqceMDOkx+bsm18mPu+I5rtvcNRJCO7tRz6G+s+0FxdLXY7P9?= =?us-ascii?Q?WczJxmTuTj5lbpZof9tox1g1hpCityLuMV2afO1wEBqoIBgvwgP6xAV6L2zw?= =?us-ascii?Q?r9jhOPfPDPA4pWxY5YeJqudecS3aWIvygpaUteYatjrX3UeJ8jDkgF7XRldq?= =?us-ascii?Q?ZyjJOoyR0rX5q5lZPyIjOxLXX3cilJF6YM5JdMOrJTeKARf8qoG8N5n7SKbn?= =?us-ascii?Q?QIwsYa9yX0dXWz0vVPE0JlIRaAZ/m0aB7EekAkFFhdA9iq9tp51ja13cuIwe?= =?us-ascii?Q?IB7D4zDOsPyvQbpB+Qug3E9Yp1d510F8vTScUQRL?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0274a16b-e2b2-4d49-5106-08dae4c39c3b 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:56:41.9110 (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: gEOrcHXczeY2emgV5aP4jpnWEB0Wg/xII9H8WCkEYyRuUpqceueHqIoynK3GRQnjoMcBs9nDY0xC/932rKU8zg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5024 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 19, 2022 at 02:40:38PM +0800, Yuan, Perry wrote: > From: Perry Yuan > > While amd-pstate driver was loaded with specific driver mode, it will > need to check which mode is enabled for the pstate driver,add this sysfs > entry to show the current status > > $ cat /sys/devices/system/cpu/amd-pstate/status > active > > Meanwhile, user can switch the pstate driver mode with writing mode > string to sysfs entry as below. > > Enable passive mode: > $ sudo bash -c "echo passive > /sys/devices/system/cpu/amd-pstate/status" > > Enable active mode (EPP driver mode): > $ sudo bash -c "echo active > /sys/devices/system/cpu/amd-pstate/status" > > Signed-off-by: Perry Yuan > --- > drivers/cpufreq/amd-pstate.c | 128 +++++++++++++++++++++++++++++++++++ > 1 file changed, 128 insertions(+) > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > index fc12d35bc7bd..e8996e937e63 100644 > --- a/drivers/cpufreq/amd-pstate.c > +++ b/drivers/cpufreq/amd-pstate.c > @@ -64,6 +64,7 @@ static struct cpufreq_driver amd_pstate_driver; > static struct cpufreq_driver amd_pstate_epp_driver; > static struct amd_cpudata **all_cpu_data; > static int cppc_state = AMD_PSTATE_DISABLE; > +struct kobject *amd_pstate_kobj; > > static inline int get_mode_idx_from_str(const char *str, size_t size) > { > @@ -90,6 +91,8 @@ static struct amd_pstate_params global_params; > static DEFINE_MUTEX(amd_pstate_limits_lock); > static DEFINE_MUTEX(amd_pstate_driver_lock); > > +static DEFINE_SPINLOCK(cppc_notify_lock); > + > static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached) > { > u64 epp; > @@ -644,6 +647,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy) > policy->driver_data = cpudata; > > amd_pstate_boost_init(cpudata); > + if (!default_pstate_driver->adjust_perf) > + default_pstate_driver->adjust_perf = amd_pstate_adjust_perf; If default_driver is passive driver, it will be programed as amd_pstate_adjust_perf. If not, the epp driver won't need adjust_perf. Thanks, Ray > > return 0; > > @@ -784,12 +789,106 @@ static ssize_t show_energy_performance_preference( > return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]); > } > > +static ssize_t amd_pstate_show_status(char *buf) > +{ > + if (!default_pstate_driver) > + return sysfs_emit(buf, "off\n"); > + > + return sysfs_emit(buf, "%s\n", default_pstate_driver == &amd_pstate_epp_driver ? > + "active" : "passive"); > +} > + > +static void amd_pstate_driver_cleanup(void) > +{ > + unsigned int cpu; > + > + cpus_read_lock(); > + for_each_online_cpu(cpu) { > + if (all_cpu_data[cpu]) { > + spin_lock(&cppc_notify_lock); > + kfree(all_cpu_data[cpu]); > + WRITE_ONCE(all_cpu_data[cpu], NULL); > + spin_unlock(&cppc_notify_lock); > + } > + } > + cpus_read_unlock(); > + > + default_pstate_driver = NULL; > +} > + > +static int amd_pstate_update_status(const char *buf, size_t size) > +{ > + if (size == 3 && !strncmp(buf, "off", size)) { > + if (!default_pstate_driver) > + return -EINVAL; > + > + if (cppc_state == AMD_PSTATE_ACTIVE) > + return -EBUSY; > + > + cpufreq_unregister_driver(default_pstate_driver); > + amd_pstate_driver_cleanup(); > + return 0; > + } > + > + if (size == 6 && !strncmp(buf, "active", size)) { > + if (default_pstate_driver) { > + if (default_pstate_driver == &amd_pstate_epp_driver) > + return 0; > + cpufreq_unregister_driver(default_pstate_driver); > + default_pstate_driver = &amd_pstate_epp_driver; > + cppc_state = AMD_PSTATE_ACTIVE; > + } > + > + return cpufreq_register_driver(default_pstate_driver); > + } > + > + if (size == 7 && !strncmp(buf, "passive", size)) { > + if (default_pstate_driver) { > + if (default_pstate_driver == &amd_pstate_driver) > + return 0; > + cpufreq_unregister_driver(default_pstate_driver); > + cppc_state = AMD_PSTATE_PASSIVE; > + default_pstate_driver = &amd_pstate_driver; > + } > + > + return cpufreq_register_driver(default_pstate_driver); > + } > + > + return -EINVAL; > +} > + > +static ssize_t show_status(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + ssize_t ret; > + > + mutex_lock(&amd_pstate_driver_lock); > + ret = amd_pstate_show_status(buf); > + mutex_unlock(&amd_pstate_driver_lock); > + > + return ret; > +} > + > +static ssize_t store_status(struct kobject *a, struct kobj_attribute *b, > + const char *buf, size_t count) > +{ > + char *p = memchr(buf, '\n', count); > + int ret; > + > + mutex_lock(&amd_pstate_driver_lock); > + ret = amd_pstate_update_status(buf, p ? p - buf : count); > + mutex_unlock(&amd_pstate_driver_lock); > + > + return ret < 0 ? ret : count; > +} > + > cpufreq_freq_attr_ro(amd_pstate_max_freq); > cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq); > > cpufreq_freq_attr_ro(amd_pstate_highest_perf); > cpufreq_freq_attr_rw(energy_performance_preference); > cpufreq_freq_attr_ro(energy_performance_available_preferences); > +define_one_global_rw(status); > > static struct freq_attr *amd_pstate_attr[] = { > &amd_pstate_max_freq, > @@ -807,6 +906,15 @@ static struct freq_attr *amd_pstate_epp_attr[] = { > NULL, > }; > > +static struct attribute *pstate_global_attributes[] = { > + &status.attr, > + NULL > +}; > + > +static const struct attribute_group amd_pstate_global_attr_group = { > + .attrs = pstate_global_attributes, > +}; > + > static inline void update_boost_state(void) > { > u64 misc_en; > @@ -1228,6 +1336,26 @@ static int __init amd_pstate_init(void) > if (ret) > pr_err("failed to register with return %d\n", ret); > > + amd_pstate_kobj = kobject_create_and_add("amd-pstate", &cpu_subsys.dev_root->kobj); > + if (!amd_pstate_kobj) { > + ret = -EINVAL; > + pr_err("global sysfs registration failed.\n"); > + goto kobject_free; > + } > + > + ret = sysfs_create_group(amd_pstate_kobj, &amd_pstate_global_attr_group); > + if (ret) { > + pr_err("sysfs attribute export failed with error %d.\n", ret); > + goto global_attr_free; > + } > + > + return ret; > + > +global_attr_free: > + kobject_put(amd_pstate_kobj); > +kobject_free: > + kfree(cpudata); > + cpufreq_unregister_driver(default_pstate_driver); > return ret; > } > device_initcall(amd_pstate_init); > -- > 2.34.1 >