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 EFEDEEE49A8 for ; Tue, 22 Aug 2023 06:13:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232944AbjHVGNj (ORCPT ); Tue, 22 Aug 2023 02:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbjHVGNg (ORCPT ); Tue, 22 Aug 2023 02:13:36 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2044.outbound.protection.outlook.com [40.107.93.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92D0911C for ; Mon, 21 Aug 2023 23:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hQUIfzYO/d4cE6BIuyQ6qI+L2zu/KUCoLoV95AuTRCTiHOGlwnMyNfEMgjBc0cYBIn1wD1U9NsXlK2XtjaHFcGbVGj7+PsF1NKDnYActZoB52G51il7iV+CVrsgx61gBAThxl46LEtqBl0PovvnxHNfq0v8Ygs+3QYy2Zf2uHowmyf7GMg5mAGNPzZ6hyP2Z7dm8UXFU9u671MuQoA4ADUwNuI/cyXK6JmJu552lJZPqdJAQxhf85iqqSjx6YP0Bqbq5t8UZuGsOuhqI1+kHZd6964CNC6XX1Rghxm2Hupxr0tPMK+H/3SV1UyAa6NDiLPpJsHETALeJueNw1eR4ng== 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=rqQvajFHBnj+YXKq7O1T6nGj43S6SPxplK0nrlK1svk=; b=PyfrYTS5BRIcCM6fqOmLeq6nRwdAmVh+hYDwt1/lFoTd/3sVCLgdZccRJ6f2al0yzfvtRvXIwbXAqtmiApdYFSnleUMKchHSAC0GCwiyvigTxExn1eAYEvjO8xAztIsixHYTa6rqaQ6G3wRUrd/IIFTL6BHzLMxdhwnziIVt2BUjCozjax7l9Th9y/n+nvBAy7hkBXLhw2iAgWkJLsQqA6HZAka+BOC4FQsK8pxGGDA13aswFl3bs22l7A0Ibevc7NiTBhRdaLmAMjrr4dXFldX/gh6+txrciz1Y1IUHhQxf55Ii8s2mSIMEveyCUyetCbU6VS0T6hhBWpJ2DWqdBA== 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=rqQvajFHBnj+YXKq7O1T6nGj43S6SPxplK0nrlK1svk=; b=1MY/s7W/KEkaNoIMUjV4u3rmSMb14K9Fuv4t/trwW9ZLeuIyitWX8CYAQdtIhbtI7PAWN/BeeiNZMs4mjZaiIqEow3zMPjnTR8XNECYWbfcjLQLHpqfV/T2VgWDMK5dwIXjU7/LBtAjVlYAr8sBDjUtxVO9fg77RSa2fNqxYBXs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB6000.namprd12.prod.outlook.com (2603:10b6:510:1dc::15) by PH7PR12MB6394.namprd12.prod.outlook.com (2603:10b6:510:1fe::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Tue, 22 Aug 2023 06:13:32 +0000 Received: from PH7PR12MB6000.namprd12.prod.outlook.com ([fe80::f78e:33f4:56d2:1ef4]) by PH7PR12MB6000.namprd12.prod.outlook.com ([fe80::f78e:33f4:56d2:1ef4%7]) with mapi id 15.20.6699.020; Tue, 22 Aug 2023 06:13:31 +0000 Message-ID: Date: Tue, 22 Aug 2023 11:43:18 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v2 2/7] drm/amdgpu: Add new function to set GPU power profile Content-Language: en-US To: Alex Deucher Cc: Arvind Yadav , Christian.Koenig@amd.com, alexander.deucher@amd.com, shashank.sharma@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, Felix.Kuehling@amd.com, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org References: <20230821064759.94223-1-Arvind.Yadav@amd.com> <20230821064759.94223-3-Arvind.Yadav@amd.com> From: "Yadav, Arvind" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: PN2PR01CA0163.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:26::18) To PH7PR12MB6000.namprd12.prod.outlook.com (2603:10b6:510:1dc::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB6000:EE_|PH7PR12MB6394:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e6978e8-5f0f-4952-7470-08dba2d6e884 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: brSFkvT6l3fix1b2Wh9+ASDeQCcbnpxACZFfudTCM+40PcpF1QHktJOA/ZKh1kM/hzbs+jf2BGh3QAoVIfGSolqGZeor1XlqaJqhnj5dMN7iJPDAqEuWDX48S0/vU/MxMYhrGaFk6uRVKqE6Jb1xl4tzaaKxU8gv7LfXFrjWeFN6EguvRbwJAMgKQxNsUb4QHk1ka2GAXzvYcTGZ6kfjIKByV7YJXww5XG50v7gx0WIbV4gXlXjcTTEJRGJU9SNdXRMqlXdX21DK+u+b7UMNZo8QPEdLuyLZHKPGUnkw1bCcMmkA9CphBX2CQQEfsQGhqsqnO1ukWICiOKfKQUA2c/4pzmBBT0uSQxJrMZQuN+3J+fzVo7IWxn2Yi/R131cnBNOh0OxkLQL2UmXCqjWzOF86EgRSYwmwK08gZ9mzRdPGLQqkBsfQW3ehh6R1iK6UDR0OrubVdrc4PbbWDrFwQRo7bgtdm3aRXXuQq3fd7A3Sv0vWa6VQaIaOn66bdLxA2MD3vmT5Q4RNHli7IcAE44PlrEA5qT+vpD3UZswRU4eO6YDzpAgduvXu+Se6TINafaSt7j9JiflNNZ6HqFQRsEzBNt5uXTN4Cc4sxYuWuMy9lNl9cTH+RHs0r12I/8drVtlZFtN2wNHNydFkAtR8rw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR12MB6000.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(39860400002)(396003)(366004)(346002)(376002)(186009)(1800799009)(451199024)(6916009)(66476007)(66556008)(316002)(6512007)(66946007)(8676002)(8936002)(2616005)(4326008)(36756003)(41300700001)(478600001)(6666004)(38100700002)(53546011)(6506007)(6486002)(83380400001)(2906002)(31686004)(31696002)(5660300002)(26005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Y3FIVkdLM1dYVjBmWUVSRnlhYk81MnRTZGtwcXBFTUFtNENaQkdpZEhQdUwy?= =?utf-8?B?WktVbjBpVldSZG40Nk95a2Z1UGc5NVA5SkdJMjV6MWJvNU0zN0JjNjVsUG9i?= =?utf-8?B?eWdJc3poM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UVXJjaFpqbHhP?= =?utf-8?B?aWREWE96RGZNLzNHS0Y2a3RLdnczd29tcnc2UjV5MFJVQk5VRlo3WHcrT0Qw?= =?utf-8?B?elYwemZmbzdoendBQ2RmeEtEeWhHQnNNM2luanlYaDRHSStKclh2NmtlRkY0?= =?utf-8?B?czlNTWFuVS9mVVpjRFBveTdCaXhBYkZXK0NyMXZKTldYUnpXY3RCOXdaZjRx?= =?utf-8?Q?PFMasUCvBfxC2jKd/WkXo9j3h?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e6978e8-5f0f-4952-7470-08dba2d6e884 X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB6000.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 06:13:31.4921 (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: iIBzxErC2n64+aybySYVCuwbxEaPd4hKAYAiqjiuUk/3AXty9u+GQLt03XD2yuV4ThmonzRJZxr06UmKoPMCCQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6394 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/21/2023 11:40 PM, Alex Deucher wrote: > On Mon, Aug 21, 2023 at 1:54 PM Yadav, Arvind wrote: >> >> On 8/21/2023 9:52 PM, Alex Deucher wrote: >>> On Mon, Aug 21, 2023 at 2:55 AM Arvind Yadav wrote: >>>> This patch adds a function which will change the GPU >>>> power profile based on a submitted job. This can optimize >>>> the power performance when the workload is on. >>>> >>>> v2: >>>> - Splitting workload_profile_set and workload_profile_put >>>> into two separate patches. >>>> - Addressed review comment. >>>> >>>> Cc: Shashank Sharma >>>> Cc: Christian Koenig >>>> Cc: Alex Deucher >>>> Signed-off-by: Arvind Yadav >>>> --- >>>> drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c | 56 +++++++++++++++++++ >>>> drivers/gpu/drm/amd/include/amdgpu_workload.h | 3 + >>>> 2 files changed, 59 insertions(+) >>>> >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c >>>> index 32166f482f77..e661cc5b3d92 100644 >>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c >>>> @@ -24,6 +24,62 @@ >>>> >>>> #include "amdgpu.h" >>>> >>>> +static enum PP_SMC_POWER_PROFILE >>>> +ring_to_power_profile(uint32_t ring_type) >>>> +{ >>>> + switch (ring_type) { >>>> + case AMDGPU_RING_TYPE_GFX: >>>> + return PP_SMC_POWER_PROFILE_FULLSCREEN3D; >>>> + case AMDGPU_RING_TYPE_COMPUTE: >>>> + return PP_SMC_POWER_PROFILE_COMPUTE; >>>> + case AMDGPU_RING_TYPE_UVD: >>>> + case AMDGPU_RING_TYPE_VCE: >>>> + case AMDGPU_RING_TYPE_UVD_ENC: >>>> + case AMDGPU_RING_TYPE_VCN_DEC: >>>> + case AMDGPU_RING_TYPE_VCN_ENC: >>>> + case AMDGPU_RING_TYPE_VCN_JPEG: >>>> + return PP_SMC_POWER_PROFILE_VIDEO; >>>> + default: >>>> + return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT; >>>> + } >>>> +} >>>> + >>>> +static int >>>> +amdgpu_power_profile_set(struct amdgpu_device *adev, >>>> + enum PP_SMC_POWER_PROFILE profile) >>>> +{ >>>> + int ret = amdgpu_dpm_switch_power_profile(adev, profile, true); >>>> + >>>> + if (!ret) { >>>> + /* Set the bit for the submitted workload profile */ >>>> + adev->smu_workload.submit_workload_status |= (1 << profile); >>>> + atomic_inc(&adev->smu_workload.power_profile_ref[profile]); >>>> + } >>>> + >>>> + return ret; >>>> +} >>>> + >>>> +void amdgpu_workload_profile_set(struct amdgpu_device *adev, >>>> + uint32_t ring_type) >>>> +{ >>>> + struct amdgpu_smu_workload *workload = &adev->smu_workload; >>>> + enum PP_SMC_POWER_PROFILE profile = ring_to_power_profile(ring_type); >>>> + int ret; >>>> + >>>> + if (profile == PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT) >>>> + return; >>> Why is this one skipped? How do we get back to the boot up profile? >> Hi Alex, >> >> enum PP_SMC_POWER_PROFILE { >> PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT = 0x0, >> PP_SMC_POWER_PROFILE_FULLSCREEN3D = 0x1, >> PP_SMC_POWER_PROFILE_POWERSAVING = 0x2, >> PP_SMC_POWER_PROFILE_VIDEO = 0x3, >> PP_SMC_POWER_PROFILE_VR = 0x4, >> PP_SMC_POWER_PROFILE_COMPUTE = 0x5, >> PP_SMC_POWER_PROFILE_CUSTOM = 0x6, >> PP_SMC_POWER_PROFILE_WINDOW3D = 0x7, >> PP_SMC_POWER_PROFILE_COUNT, >> }; >> >> These are all the profiles. We are using which is > >> PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT. >> Now suppose the profile was DEFAULT and we set it to VIDEO, SMU will >> move the profile to a higher level. >> When we reset the VIDEO profile then SMU will move back to the DEFAULT one. >> >> Our job is to set the profile and reset it after the job is done. >> SMU will take care to move to a higher profile and after reset, it will >> move back to DEFAULT. > I guess that is the part I'm missing. How does the call to the SMU to > set the profile back to DEFAULT actually happen? It seems that both > the put and get functions return early in this case. SMU is calculating a workload for given the profile and setting it when we call the *get and *put function. When we call *set function for VIDEO then SMU will calculate a workload for VIDEO and set it. Now We call *put function for the same profile then SMU calculates a workload which will be lower or DEFAULT (0) and then it will set it. Suppose we have called *set function for VIDEO profile then SMU will calculate the workload = 4 and set it. Now we have called *put function for the same profile then SMU will calculate the workload = 0 and set it. please see the below smu code where index will be DEFAULT (0) or lower for *put function. if (!en) { // put function         smu->workload_mask &= ~(1 << smu->workload_prority[type]);         index = fls(smu->workload_mask);         index = index > 0 && index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;         workload = smu->workload_setting[index]; } else { // set function.         smu->workload_mask |= (1 << smu->workload_prority[type]);         index = fls(smu->workload_mask);         index = index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;         workload = smu->workload_setting[index]; } In our case the *set function will set the GPU  power profile and the *put function will schedule the smu_delayed_work task after 100ms delay. This smu_delayed_work task will clear a GPU power profile if any new jobs are not scheduled within 100 ms. But if any new job comes within 100ms then the *set function will cancel this work and set the GPU power profile based on preferences. Thank You ~Arvind > > Alex > > > Alex > > >> ThankYou, >> ~Arvind >> >>> Alex >>> >>>> + >>>> + mutex_lock(&workload->workload_lock); >>>> + >>>> + ret = amdgpu_power_profile_set(adev, profile); >>>> + if (ret) { >>>> + DRM_WARN("Failed to set workload profile to %s, error = %d\n", >>>> + amdgpu_workload_mode_name[profile], ret); >>>> + } >>>> + >>>> + mutex_unlock(&workload->workload_lock); >>>> +} >>>> + >>>> void amdgpu_workload_profile_init(struct amdgpu_device *adev) >>>> { >>>> adev->smu_workload.adev = adev; >>>> diff --git a/drivers/gpu/drm/amd/include/amdgpu_workload.h b/drivers/gpu/drm/amd/include/amdgpu_workload.h >>>> index 5d0f068422d4..5022f28fc2f9 100644 >>>> --- a/drivers/gpu/drm/amd/include/amdgpu_workload.h >>>> +++ b/drivers/gpu/drm/amd/include/amdgpu_workload.h >>>> @@ -46,6 +46,9 @@ static const char * const amdgpu_workload_mode_name[] = { >>>> "Window3D" >>>> }; >>>> >>>> +void amdgpu_workload_profile_set(struct amdgpu_device *adev, >>>> + uint32_t ring_type); >>>> + >>>> void amdgpu_workload_profile_init(struct amdgpu_device *adev); >>>> >>>> void amdgpu_workload_profile_fini(struct amdgpu_device *adev); >>>> -- >>>> 2.34.1 >>>>