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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19739C433F5 for ; Wed, 10 Nov 2021 16:05:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9CE2761205 for ; Wed, 10 Nov 2021 16:05:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9CE2761205 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 020F36E922; Wed, 10 Nov 2021 16:05:09 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2065.outbound.protection.outlook.com [40.107.236.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0CF4A6E922 for ; Wed, 10 Nov 2021 16:05:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KUd2eVl/QAeOaMqsjsYptFk9q3EIRM7J00iwfsIWkR1kWKi2bLki2Y4NPxm0ZUAj3ReSQ6Rsi4OxD/y6cJ4+pdgboenxR5MSmleUBnrX8NgYG/Hd12sg0WmqoAZabHpPmlrWiJu/eTfbFEMfUv8e2xHYf2sf+8cgKeSEDqwzDBiUbu+MxzJN4oeB4I7GauF7Da8XlkxoHAPDwb5CF22yIBFfm4zdXfmqxJxpQlkToSl9THYr2Aff5xdKtsBFMfqoQ+UrD7dvvebD71XGNaUItEVdSVlgPFALZ3bJZNAT0FAiTSzXyZIIePvGbf1o0vsKgjJNoqR5XFJ0b1h7sI6YPg== 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=T41ipBDSr6O/HoL0JvUqjEoHbMfdbkDFzuCqztMp1+4=; b=hNsbB0t4D28yOTVb98IOy9W/ZR+RI7x7dhjH2fFpf1EjeHNnhRjNiJQMOEhYqslKjnNpjGQd+clBIB7DYJPqPwZZCqVODDOGCCg+BKaAdPeHDVz4YW9lYkqJPSydomVWoj3UzxLG9T8emYq84Ir1Xh+VQgC/i7IyqAv12xpWlOIe7UGu1fl48v6I9bOAgMyxR8L1fsFHq2ELVW1eYOuSHhyIulI2d2jU6oR5jSsUZZw3a09ayrgj7FbgYdJfZZ6Sbr4uvadoDJbrx1EUyhEwl+LNaSrkmb+2LA4kC3R2scw3Brci8NP6ijGONlZ3x/cIpIxBcCGN/diAK3oDsdrOaA== 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=T41ipBDSr6O/HoL0JvUqjEoHbMfdbkDFzuCqztMp1+4=; b=ShBV3yTOKVdazN3yUrcRlIt2mCGRPPr10oc+7OcZcU9bqIhMGfzuukMK8PjJBnKE5MUdL1z73OhGOrgKnQfOtDOKKOLa8FJgJJiz5DhdXjhU3B9YcJNWDc4q1U1D8tB/xY1604HekzftqHR27i8yuq6VUx7eufZ6pnK+7Je1IVI= Received: from DM6PR12MB3930.namprd12.prod.outlook.com (2603:10b6:5:1c9::19) by DM6PR12MB4012.namprd12.prod.outlook.com (2603:10b6:5:1cc::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.16; Wed, 10 Nov 2021 16:05:05 +0000 Received: from DM6PR12MB3930.namprd12.prod.outlook.com ([fe80::591a:8986:aca2:c560]) by DM6PR12MB3930.namprd12.prod.outlook.com ([fe80::591a:8986:aca2:c560%3]) with mapi id 15.20.4669.016; Wed, 10 Nov 2021 16:05:05 +0000 From: "Lazar, Lijo" To: Alex Deucher , "Limonciello, Mario" Subject: Re: [RFC 2/2] drm/amd/pm: Add support for reacting to platform profile notification Thread-Topic: [RFC 2/2] drm/amd/pm: Add support for reacting to platform profile notification Thread-Index: AQHX1fuN+Gs9jWQ/l0O92ikqoZKw0Kv83zWAgAAM12A= Date: Wed, 10 Nov 2021 16:05:05 +0000 Message-ID: References: <20211110062343.10041-1-mario.limonciello@amd.com> <20211110062343.10041-3-mario.limonciello@amd.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Enabled=True; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_SetDate=2021-11-10T16:00:06.9552235Z; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_ContentBits=0; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Method=Privileged authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d491ce34-ba22-41b4-2098-08d9a463dc48 x-ms-traffictypediagnostic: DM6PR12MB4012: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3044; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LAKmFJ6oc8YgmrM7+WQv1SeV5H4ks6vLCzbLjAmtNoa7rOEoD6N0bp4o7d/m6wSEVzWT/IoUW39ZHS0uOvV46g5e7dFy+3/Mg6SByzJmV3YIF3CPd66401CJfG2bMBGEXcjUiyPXqg0B1/ANINmyCIKvnHFy2KkbpjHGzMzoYqCT+5tSfVds65mxp9jxtpJ+rEJRjZX/qBiMIfgJrKJytKIG6Z4r0T5j/JXzGslBtOPBqSmGk958ctwnVUvSJHxP8mjl6t+V5dPV3kaV74JqmXNGh2X43dlDfs17kmoLNA7XhiSSW/jDkl06uxgGM5FOyKFT7Q5ICWGbOyYu+uBBWK8EsxOD7ZRtT4sRD+NdMBXPRlXcVP5SbENVBzouTEDbvMARjRKRqQIQdLYyejGR0ZYYRGDvFj+H+NoZNd2eSyzg7F34ntLaqWju2ILsn+WVEIPbvVM3prtnKJR8nseV6q7V2EIXHZyxfqmSau5Qz7lvDkpTLgNMG8gb6z2uKB0XBAarvTqcPKnrLNQeYnXH10Lw1mKmbIEKRuo3cIKcZOIIvYZH/zVI6yKP8HtEq6RlUVuloFG++mK7SqcJF+prVB4/Fe8+ftBc/Aqwb+Sb632Ykq9+0R1bQ4nEPurGCH0y1ATKq3DbXfkVbs7Y/GHPMhBJR863k3HSksNjod6Jvq5gBSC7djVxC3IBplqjcw/7QingPohD2W4MO7wRxorjzQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB3930.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(6506007)(53546011)(8676002)(38070700005)(26005)(110136005)(86362001)(33656002)(52536014)(64756008)(122000001)(2906002)(66446008)(66556008)(316002)(5660300002)(66946007)(91956017)(71200400001)(8936002)(76116006)(66476007)(4326008)(55016002)(15650500001)(9686003)(186003)(83380400001)(508600001)(6636002)(38100700002)(7696005); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?W4eNp9sH8c2wzlFwWrINuyQOkKQnKInaj00HzYGTc7xHB7abTCHbORFuui1Y?= =?us-ascii?Q?7SG+65rzU+bdrFJE2dp86ix0DQguA8db1yVOAUF96I8jE9uVAipglAope7hI?= =?us-ascii?Q?JEbnOyszyypUFK8EcKnuj7jBVnRglMYp2NJkuKEsSPsmTJNTTNFo7W7dz7Ry?= =?us-ascii?Q?lEWkb7Z5oG3zmAN9LSIw85Lp+wBYbBiLMqegNO6gRAKFL+P60M0V1PaN1T6p?= =?us-ascii?Q?3taC7GXmO4fYkpGAwNCoigNNU7cHLvqkciseetPuEjxXOySW+mfndGWmLiiD?= =?us-ascii?Q?1fRlTGqF54WuOB1zhfm5GSdvaGthbvVGEqB0FMqAoazj1+sg3jxZYZETMWWy?= =?us-ascii?Q?xatCvFhiIDv+snhnkYBwmYYLHFLpDcsSCY4N1CTiX6qQ4F9ce7QYi+SPYydY?= =?us-ascii?Q?V023myRIhVejJ1soC6oXJ1nveSzBC6mTWXrE2OkY5JR4w7e+VSQMj37EFemE?= =?us-ascii?Q?/uwuVo9CAVrKMdfCHSRqekF5MBYCxsIC2tTYbasM0DiaVgV78+iezBNbJpf5?= =?us-ascii?Q?c6ROQF5LB6Mkl3u8SPsymCm1HPTiPQ38F+jnQC50HeLtZWA7VJUCF3snfGm0?= =?us-ascii?Q?L6Rij8/uKdfAwFDMQFKi0dMLCYRs9BROeOsyoCafARhyMYU8G/Xnk0BrytSx?= =?us-ascii?Q?xSgf4tTwzwU9jkVAjWEIV+/6BBxCJEnvxBfooFfq8atdDhbxHNP8GAPsYAL2?= =?us-ascii?Q?4PsEw9rM3mdRqvNPFqqUIN+tbU913cO4Lcym+ODvx2dan8U8St9v/1iqK84h?= =?us-ascii?Q?tcSV5o3y8QKTdRplLbIQ9JEOt1BQK+kss93+Q7qNDWeIatLxh4v+juBUffSp?= =?us-ascii?Q?q0/SBkFqN0Gz1WFRtD35jSGrdpywNxHD5gOXmE+wsxok7LiON+uIPcXsWtBY?= =?us-ascii?Q?EUiPdtQXoUaKZJdFGBLgPK3mlKc50cmKFA16r0StMtyedqJK/mc41T5fYDs8?= =?us-ascii?Q?HjYGvsqAenB0rF0DyhJaPWT94oESlH08Say/Ycpa6SOcBVIZ9locqIuQ4a0M?= =?us-ascii?Q?YC5zJWZz6517aEie6Tb/h9pNLzvA0z9LHsGHpo3BtAbRPL7nLYHXn7xNDGGA?= =?us-ascii?Q?gTfztODHT2dobzLXcuLPbYDT9oAoOuTkre9Iq9SzanbeHg0VYBogKbmgJljv?= =?us-ascii?Q?vOnxc8K6sgq6lnD/nBti0IcpnKKvWATQyFtxCeZiwsSSuHWGFN1UVhMZClKP?= =?us-ascii?Q?iooReHdTXK1S8PBCL7yZxw9CLwku1bqWSrLmmxfznbUMnXPaGwCTx5i3O1zT?= =?us-ascii?Q?jOOQLRqBQ0WVrwhwJYkplC6bogJvAM78y7OsA16GFOveR+Th90NnLS093DXY?= =?us-ascii?Q?IslaDupqTMI2zud0PLcw7v3AjZYphnxcc6M+vxcfLjr9Zu+yb9Fsut+TpMiC?= =?us-ascii?Q?Uo/hxCBnfLx3NSkC2KLcryi/ubImKNA7tsJ9wj5R1z2iv8FMi9e75hEi36jh?= =?us-ascii?Q?zzcKap4BvYCo/Za2cLUf50WLMtNRcff3FAgPdx4ZH6uM8rJoagiPkJm3yHYM?= =?us-ascii?Q?TclRBSHZcQ6DcvjXTLfVWju/CrKizs24tOIxTKqvGtqoSbzDwghsDsnt+Yh1?= =?us-ascii?Q?dD6+1hClpFK56W37U1dY6ZBBocJweoT8nwFO9wFb?= Content-Type: multipart/alternative; boundary="_000_DM6PR12MB39300185FB03556E914290C297939DM6PR12MB3930namp_" MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3930.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d491ce34-ba22-41b4-2098-08d9a463dc48 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2021 16:05:05.2468 (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: +7SaByU3/JcfdLk03zSTrib2dg4/jHuFM5ytXQ7YWVSLcl4KMhnP8gAzxe5qCWQ0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4012 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amd-gfx list Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" --_000_DM6PR12MB39300185FB03556E914290C297939DM6PR12MB3930namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [Public] I feel it's better to leave to platform vendors. For ex: for APU cases they= may have implementations in which their BIOSes talk to PMFW and this might= be driving something else here. Also, not sure how to handle a case like, say a laptop with Intel CPU and A= MD dgpu. Thanks, Lijo ________________________________ From: amd-gfx on behalf of Alex Deu= cher Sent: Wednesday, 10 November 2021, 8:44 pm To: Limonciello, Mario Cc: amd-gfx list Subject: Re: [RFC 2/2] drm/amd/pm: Add support for reacting to platform pro= file notification On Wed, Nov 10, 2021 at 1:24 AM Mario Limonciello wrote: > > Various drivers provide platform profile support to let users set a hint > in their GUI whether they want to run in a high performance, low battery > life or balanced configuration. > > Drivers that provide this typically work with the firmware on their syste= m > to configure hardware. In the case of AMDGPU however, the notification > path doesn't come through firmware and can instead be provided directly > to the driver from a notification chain. > > Use the information of the newly selected profile to tweak > `dpm_force_performance_level` to that profile IFF the user hasn't manuall= y > selected `manual` or any other `profile_*` options. I don't think we want to force the performance level. This interface forces various fixed clock configurations for debugging and profiling. I think what we'd want to select here is the power profile (see amdgpu_set_pp_power_profile_mode()). For this interface you can select various profiles (BOOTUP_DEFAULT, 3D_FULL_SCREEN, POWER_SAVING, VIDEO, VR, COMPUTE, etc.). These still use dynamic power management, but they adjust the heuristics used by the GPU to select power states so the GPU performance ramps up/down more or less aggressively. Alex > > Signed-off-by: Mario Limonciello > --- > drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 + > drivers/gpu/drm/amd/pm/amdgpu_pm.c | 105 +++++++++++++++++++++++----- > 2 files changed, 90 insertions(+), 18 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/am= dgpu/amdgpu.h > index b85b67a88a3d..27b0be23b6ac 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > @@ -1097,6 +1097,9 @@ struct amdgpu_device { > > struct amdgpu_reset_control *reset_cntl; > uint32_t ip_versions[HW_ID_MAX][HWIP_MAX_I= NSTANCE]; > + > + /* platform profile notifications */ > + struct notifier_block platform_profile_notifier; > }; > > static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev) > diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/= amdgpu_pm.c > index 41472ed99253..33fc52b90d4c 100644 > --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c > +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > #include > #include > #include "hwmgr.h" > @@ -200,6 +201,33 @@ static ssize_t amdgpu_set_power_dpm_state(struct dev= ice *dev, > return count; > } > > +static int amdgpu_get_forced_level(struct device *dev, enum amd_dpm_forc= ed_level *level) > +{ > + struct drm_device *ddev =3D dev_get_drvdata(dev); > + struct amdgpu_device *adev =3D drm_to_adev(ddev); > + int ret; > + > + if (amdgpu_in_reset(adev)) > + return -EPERM; > + if (adev->in_suspend && !adev->in_runpm) > + return -EPERM; > + > + ret =3D pm_runtime_get_sync(ddev->dev); > + if (ret < 0) { > + pm_runtime_put_autosuspend(ddev->dev); > + return ret; > + } > + > + if (adev->powerplay.pp_funcs->get_performance_level) > + *level =3D amdgpu_dpm_get_performance_level(adev); > + else > + *level =3D adev->pm.dpm.forced_level; > + > + pm_runtime_mark_last_busy(ddev->dev); > + pm_runtime_put_autosuspend(ddev->dev); > + > + return 0; > +} > > /** > * DOC: power_dpm_force_performance_level > @@ -264,29 +292,13 @@ static ssize_t amdgpu_get_power_dpm_force_performan= ce_level(struct device *dev, > struct device= _attribute *attr, > char *buf) > { > - struct drm_device *ddev =3D dev_get_drvdata(dev); > - struct amdgpu_device *adev =3D drm_to_adev(ddev); > enum amd_dpm_forced_level level =3D 0xff; > int ret; > > - if (amdgpu_in_reset(adev)) > - return -EPERM; > - if (adev->in_suspend && !adev->in_runpm) > - return -EPERM; > + ret =3D amdgpu_get_forced_level(dev, &level); > > - ret =3D pm_runtime_get_sync(ddev->dev); > - if (ret < 0) { > - pm_runtime_put_autosuspend(ddev->dev); > + if (ret < 0) > return ret; > - } > - > - if (adev->powerplay.pp_funcs->get_performance_level) > - level =3D amdgpu_dpm_get_performance_level(adev); > - else > - level =3D adev->pm.dpm.forced_level; > - > - pm_runtime_mark_last_busy(ddev->dev); > - pm_runtime_put_autosuspend(ddev->dev); > > return sysfs_emit(buf, "%s\n", > (level =3D=3D AMD_DPM_FORCED_LEVEL_AUTO) ? "aut= o" : > @@ -405,6 +417,59 @@ static ssize_t amdgpu_set_power_dpm_force_performanc= e_level(struct device *dev, > return count; > } > > +static void amdgpu_update_profile(struct device *dev, enum platform_prof= ile_option *profile) > +{ > + enum amd_dpm_forced_level level; > + const char *str; > + int ret; > + > + ret =3D amdgpu_get_forced_level(dev, &level); > + if (ret < 0) > + return; > + > + /* only update profile if we're in fixed modes right now that nee= d updating */ > + switch (level) { > + case AMD_DPM_FORCED_LEVEL_LOW: > + if (*profile < PLATFORM_PROFILE_BALANCED) > + return; > + break; > + case AMD_DPM_FORCED_LEVEL_HIGH: > + if (*profile > PLATFORM_PROFILE_BALANCED) > + return; > + break; > + case AMD_DPM_FORCED_LEVEL_AUTO: > + if (*profile =3D=3D PLATFORM_PROFILE_BALANCED) > + return; > + break; > + default: > + dev_dbg(dev, "refusing to update amdgpu profile from %d\n= ", level); > + return; > + } > + if (*profile > PLATFORM_PROFILE_BALANCED) > + str =3D "high"; > + else if (*profile < PLATFORM_PROFILE_BALANCED) > + str =3D "low"; > + else > + str =3D "auto"; > + > + dev_dbg(dev, "updating platform profile to %s\n", str); > + amdgpu_set_power_dpm_force_performance_level(dev, NULL, str, 0); > +} > + > +static int amdgpu_platform_profile_notifier_call(struct notifier_block *= nb, > + unsigned long action, v= oid *data) > +{ > + if (action =3D=3D PLATFORM_PROFILE_CHANGED) { > + enum platform_profile_option *profile =3D data; > + struct amdgpu_device *adev; > + > + adev =3D container_of(nb, struct amdgpu_device, platform_= profile_notifier); > + amdgpu_update_profile(adev->dev, profile); > + } > + > + return NOTIFY_OK; > +} > + > static ssize_t amdgpu_get_pp_num_states(struct device *dev, > struct device_attribute *attr, > char *buf) > @@ -3506,6 +3571,9 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev= ) > if (ret) > return ret; > > + adev->platform_profile_notifier.notifier_call =3D amdgpu_platform= _profile_notifier_call; > + platform_profile_register_notifier(&adev->platform_profile_notifi= er); > + > adev->pm.sysfs_initialized =3D true; > > return 0; > @@ -3519,6 +3587,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *ade= v) > if (adev->pm.int_hwmon_dev) > hwmon_device_unregister(adev->pm.int_hwmon_dev); > > + platform_profile_unregister_notifier(&adev->platform_profile_noti= fier); > amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list); > } > > -- > 2.25.1 > --_000_DM6PR12MB39300185FB03556E914290C297939DM6PR12MB3930namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

[Public]


I feel it's better to leave to platform vendors. For ex: for APU cases they= may have implementations in which their BIOSes talk to PMFW and this might= be driving something else here.

Also, not sure how to handle a case like, say a laptop with Intel CPU and A= MD dgpu.

Thanks,
Lijo


From: amd-gfx <amd-gfx-bounce= s@lists.freedesktop.org> on behalf of Alex Deucher <alexdeucher@gmail= .com>
Sent: Wednesday, 10 November 2021, 8:44 pm
To: Limonciello, Mario
Cc: amd-gfx list
Subject: Re: [RFC 2/2] drm/amd/pm: Add support for reactin= g to platform profile notification

On Wed, Nov 10, 2021 at 1:24 AM Mario Limonciello<= br> <mario.limonciello@amd.com> wrote:
>
> Various drivers provide platform profile support to let users set a hi= nt
> in their GUI whether they want to run in a high performance, low batte= ry
> life or balanced configuration.
>
> Drivers that provide this typically work with the firmware on their sy= stem
> to configure hardware.  In the case of AMDGPU however, the notifi= cation
> path doesn't come through firmware and can instead be provided directl= y
> to the driver from a notification chain.
>
> Use the information of the newly selected profile to tweak
> `dpm_force_performance_level` to that profile IFF the user hasn't manu= ally
> selected `manual` or any other `profile_*` options.

I don't think we want to force the performance level.  This interface<= br> forces various fixed clock configurations for debugging and profiling.
I think what we'd want to select here is the power profile (see
amdgpu_set_pp_power_profile_mode()).  For this interface you can
select various profiles (BOOTUP_DEFAULT, 3D_FULL_SCREEN, POWER_SAVING,
VIDEO, VR, COMPUTE, etc.).  These still use dynamic power management,<= br> but they adjust the heuristics used by the GPU to select power states
so the GPU performance ramps up/down more or less aggressively.

Alex

>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   3 +
>  drivers/gpu/drm/amd/pm/amdgpu_pm.c  | 105 +++++++++++++++++= ++++++-----
>  2 files changed, 90 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd= /amdgpu/amdgpu.h
> index b85b67a88a3d..27b0be23b6ac 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1097,6 +1097,9 @@ struct amdgpu_device {
>
>         struct amdgpu_reset_co= ntrol     *reset_cntl;
>         uint32_t  &n= bsp;            = ;         ip_versions[HW_ID_MAX][HW= IP_MAX_INSTANCE];
> +
> +       /* platform profile notification= s */
> +       struct notifier_block  = ;         platform_profile_notifier= ;
>  };
>
>  static inline struct amdgpu_device *drm_to_adev(struct drm_devic= e *ddev)
> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/= pm/amdgpu_pm.c
> index 41472ed99253..33fc52b90d4c 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> @@ -32,6 +32,7 @@
>  #include <linux/hwmon.h>
>  #include <linux/hwmon-sysfs.h>
>  #include <linux/nospec.h>
> +#include <linux/platform_profile.h>
>  #include <linux/pm_runtime.h>
>  #include <asm/processor.h>
>  #include "hwmgr.h"
> @@ -200,6 +201,33 @@ static ssize_t amdgpu_set_power_dpm_state(struct = device *dev,
>         return count;
>  }
>
> +static int amdgpu_get_forced_level(struct device *dev, enum amd_dpm_f= orced_level *level)
> +{
> +       struct drm_device *ddev =3D dev_= get_drvdata(dev);
> +       struct amdgpu_device *adev =3D d= rm_to_adev(ddev);
> +       int ret;
> +
> +       if (amdgpu_in_reset(adev))
> +           &nb= sp;   return -EPERM;
> +       if (adev->in_suspend &&am= p; !adev->in_runpm)
> +           &nb= sp;   return -EPERM;
> +
> +       ret =3D pm_runtime_get_sync(ddev= ->dev);
> +       if (ret < 0) {
> +           &nb= sp;   pm_runtime_put_autosuspend(ddev->dev);
> +           &nb= sp;   return ret;
> +       }
> +
> +       if (adev->powerplay.pp_funcs-= >get_performance_level)
> +           &nb= sp;   *level =3D amdgpu_dpm_get_performance_level(adev);
> +       else
> +           &nb= sp;   *level =3D adev->pm.dpm.forced_level;
> +
> +       pm_runtime_mark_last_busy(ddev-&= gt;dev);
> +       pm_runtime_put_autosuspend(ddev-= >dev);
> +
> +       return 0;
> +}
>
>  /**
>   * DOC: power_dpm_force_performance_level
> @@ -264,29 +292,13 @@ static ssize_t amdgpu_get_power_dpm_force_perfor= mance_level(struct device *dev,
>            = ;            &n= bsp;            = ;            &n= bsp;           struct dev= ice_attribute *attr,
>            = ;            &n= bsp;            = ;            &n= bsp;           char *buf)=
>  {
> -       struct drm_device *ddev =3D dev_= get_drvdata(dev);
> -       struct amdgpu_device *adev =3D d= rm_to_adev(ddev);
>         enum amd_dpm_forced_le= vel level =3D 0xff;
>         int ret;
>
> -       if (amdgpu_in_reset(adev))
> -           &nb= sp;   return -EPERM;
> -       if (adev->in_suspend &&am= p; !adev->in_runpm)
> -           &nb= sp;   return -EPERM;
> +       ret =3D amdgpu_get_forced_level(= dev, &level);
>
> -       ret =3D pm_runtime_get_sync(ddev= ->dev);
> -       if (ret < 0) {
> -           &nb= sp;   pm_runtime_put_autosuspend(ddev->dev);
> +       if (ret < 0)
>            = ;     return ret;
> -       }
> -
> -       if (adev->powerplay.pp_funcs-= >get_performance_level)
> -           &nb= sp;   level =3D amdgpu_dpm_get_performance_level(adev);
> -       else
> -           &nb= sp;   level =3D adev->pm.dpm.forced_level;
> -
> -       pm_runtime_mark_last_busy(ddev-&= gt;dev);
> -       pm_runtime_put_autosuspend(ddev-= >dev);
>
>         return sysfs_emit(buf,= "%s\n",
>            = ;            &n= bsp;  (level =3D=3D AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" : > @@ -405,6 +417,59 @@ static ssize_t amdgpu_set_power_dpm_force_perform= ance_level(struct device *dev,
>         return count;
>  }
>
> +static void amdgpu_update_profile(struct device *dev, enum platform_p= rofile_option *profile)
> +{
> +       enum amd_dpm_forced_level level;=
> +       const char *str;
> +       int ret;
> +
> +       ret =3D amdgpu_get_forced_level(= dev, &level);
> +       if (ret < 0)
> +           &nb= sp;   return;
> +
> +       /* only update profile if we're = in fixed modes right now that need updating */
> +       switch (level) {
> +       case AMD_DPM_FORCED_LEVEL_LOW: > +           &nb= sp;   if (*profile < PLATFORM_PROFILE_BALANCED)
> +           &nb= sp;           return;
> +           &nb= sp;   break;
> +       case AMD_DPM_FORCED_LEVEL_HIGH:<= br> > +           &nb= sp;   if (*profile > PLATFORM_PROFILE_BALANCED)
> +           &nb= sp;           return;
> +           &nb= sp;   break;
> +       case AMD_DPM_FORCED_LEVEL_AUTO:<= br> > +           &nb= sp;   if (*profile =3D=3D PLATFORM_PROFILE_BALANCED)
> +           &nb= sp;           return;
> +           &nb= sp;   break;
> +       default:
> +           &nb= sp;   dev_dbg(dev, "refusing to update amdgpu profile from %= d\n", level);
> +           &nb= sp;   return;
> +       }
> +       if (*profile > PLATFORM_PROFI= LE_BALANCED)
> +           &nb= sp;   str =3D "high";
> +       else if (*profile < PLATFORM_= PROFILE_BALANCED)
> +           &nb= sp;   str =3D "low";
> +       else
> +           &nb= sp;   str =3D "auto";
> +
> +       dev_dbg(dev, "updating plat= form profile to %s\n", str);
> +       amdgpu_set_power_dpm_force_perfo= rmance_level(dev, NULL, str, 0);
> +}
> +
> +static int amdgpu_platform_profile_notifier_call(struct notifier_bloc= k *nb,
> +           &nb= sp;            =             &nb= sp;            unsig= ned long action, void *data)
> +{
> +       if (action =3D=3D PLATFORM_PROFI= LE_CHANGED) {
> +           &nb= sp;   enum platform_profile_option *profile =3D data;
> +           &nb= sp;   struct amdgpu_device *adev;
> +
> +           &nb= sp;   adev =3D container_of(nb, struct amdgpu_device, platform_pr= ofile_notifier);
> +           &nb= sp;   amdgpu_update_profile(adev->dev, profile);
> +       }
> +
> +       return NOTIFY_OK;
> +}
> +
>  static ssize_t amdgpu_get_pp_num_states(struct device *dev,
>            = ;     struct device_attribute *attr,
>            = ;     char *buf)
> @@ -3506,6 +3571,9 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *a= dev)
>         if (ret)
>            = ;     return ret;
>
> +       adev->platform_profile_notifi= er.notifier_call =3D amdgpu_platform_profile_notifier_call;
> +       platform_profile_register_notifi= er(&adev->platform_profile_notifier);
> +
>         adev->pm.sysfs_init= ialized =3D true;
>
>         return 0;
> @@ -3519,6 +3587,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *= adev)
>         if (adev->pm.int_hw= mon_dev)
>            = ;     hwmon_device_unregister(adev->pm.int_hwmon_dev= );
>
> +       platform_profile_unregister_noti= fier(&adev->platform_profile_notifier);
>         amdgpu_device_attr_rem= ove_groups(adev, &adev->pm.pm_attr_list);
>  }
>
> --
> 2.25.1
>

--_000_DM6PR12MB39300185FB03556E914290C297939DM6PR12MB3930namp_--