AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Gerry Liu <gerry@linux.alibaba.com>
Cc: alexander.deucher@amd.com, christian.koenig@amd.com,
	Xinhui.Pan@amd.com, airlied@gmail.com, simona@ffwll.ch,
	sunil.khatri@amd.com, lijo.lazar@amd.com, Hawking.Zhang@amd.com,
	xiaogang.chen@amd.com, Kent.Russell@amd.com,
	shuox.liu@linux.alibaba.com, amd-gfx@lists.freedesktop.org
Subject: Re: [RFC v2 10/15] drm/admgpu: make device state machine work in stack like way
Date: Wed, 15 Jan 2025 13:36:42 -0600	[thread overview]
Message-ID: <28fc2420-2b9f-4416-b04c-7267f5f90cbb@amd.com> (raw)
In-Reply-To: <2C342A4B-DF28-41EF-A26E-0D1ABEE076FF@linux.alibaba.com>

On 1/13/2025 19:58, Gerry Liu wrote:
> 
> 
>> 2025年1月14日 06:27,Mario Limonciello <mario.limonciello@amd.com> 写道:
>>
>> On 1/12/2025 19:42, Jiang Liu wrote:
>>> Make the device state machine work in stack like way to better support
>>> suspend/resume by following changes:
>>> 1. amdgpu_driver_load_kms()
>>> 	amdgpu_device_init()
>>> 		amdgpu_device_ip_early_init()
>>> 			ip_blocks[i].early_init()
>>> 			ip_blocks[i].status.valid = true
>>> 		amdgpu_device_ip_init()
>>> 			amdgpu_ras_init()
>>> 			ip_blocks[i].sw_init()
>>> 			ip_blocks[i].status.sw = true
>>> 			ip_blocks[i].hw_init()
>>> 			ip_blocks[i].status.hw = true
>>> 		amdgpu_device_ip_late_init()
>>> 			ip_blocks[i].late_init()
>>> 			ip_blocks[i].status.late_initialized = true
>>> 			amdgpu_ras_late_init()
>>> 				ras_blocks[i].ras_late_init()
>>> 					amdgpu_ras_feature_enable_on_boot()
>>> 2. amdgpu_pmops_suspend()/amdgpu_pmops_freeze()/amdgpu_pmops_poweroff()
>>> 	amdgpu_device_suspend()
>>> 		amdgpu_ras_early_fini()
>>> 			ras_blocks[i].ras_early_fini()
>>> 				amdgpu_ras_feature_disable()
>>> 		amdgpu_ras_suspend()
>>> 			amdgpu_ras_disable_all_features()
>>> +++		ip_blocks[i].early_fini()
>>> +++		ip_blocks[i].status.late_initialized = false
>>> 		ip_blocks[i].suspend()
>>> 3. amdgpu_pmops_resume()/amdgpu_pmops_thaw()/amdgpu_pmops_restore()
>>> 	amdgpu_device_resume()
>>> 		amdgpu_device_ip_resume()
>>> 			ip_blocks[i].resume()
>>> 		amdgpu_device_ip_late_init()
>>> 			ip_blocks[i].late_init()
>>> 			ip_blocks[i].status.late_initialized = true
>>> 			amdgpu_ras_late_init()
>>> 				ras_blocks[i].ras_late_init()
>>> 					amdgpu_ras_feature_enable_on_boot()
>>> 		amdgpu_ras_resume()
>>> 			amdgpu_ras_enable_all_features()
>>> 4. amdgpu_driver_unload_kms()
>>> 	amdgpu_device_fini_hw()
>>> 		amdgpu_ras_early_fini()
>>> 			ras_blocks[i].ras_early_fini()
>>> +++		ip_blocks[i].early_fini()
>>> +++		ip_blocks[i].status.late_initialized = false
>>> 		ip_blocks[i].hw_fini()
>>> 		ip_blocks[i].status.hw = false
>>> 5. amdgpu_driver_release_kms()
>>> 	amdgpu_device_fini_sw()
>>> 		amdgpu_device_ip_fini()
>>> 			ip_blocks[i].sw_fini()
>>> 			ip_blocks[i].status.sw = false
>>> ---			ip_blocks[i].status.valid = false
>>> +++			amdgpu_ras_fini()
>>> 			ip_blocks[i].late_fini()
>>> +++			ip_blocks[i].status.valid = false
>>> ---			ip_blocks[i].status.late_initialized = false
>>> ---			amdgpu_ras_fini()
>>> The main changes include:
>>> 1) invoke ip_blocks[i].early_fini in amdgpu_pmops_suspend().
>>> 2) set ip_blocks[i].status.late_initialized to false after calling
>>>     callback `early_fini`. We have auditted all usages of the
>>>     late_initialized flag and no functional changes found.
>>> 3) only set ip_blocks[i].status.valid = false after calling the
>>>     `late_fini` callback.
>>> 4) call amdgpu_ras_fini() before invoking ip_blocks[i].late_fini.
>>> There's one more task left to analyze GPU reset related state machine
>>> transitions.
>>> Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
>>
>> Ideally I think you should swap the order of patch 10 and 11, what do you think?
> I realized this when working patch 11, many changes introduced by patch 10 are changed again by patch 11.
> But swapping these patches will cause too much rework. How about folding these two patches instead?

It might be too big of a patch because it changes a lot all at same time.

Re-ordering is painful but leads to more reable patches and less 
ping-pong of code.

I think you can do something like this (I've done this myself on big 
patch series):

1) squash the two patches together
    git rebase -i HEAD~15

2) Spit it out as a patch file
    git format-patch -1 $SHA
3) Check out the commit before this combined one
    git checkout -b gerry/rebase $SHA~1
4) Apply the patch using patch -p1 (NOT git am)
    patch -p1 < foo.patch
5) Use vscode (specifically) to stage the lines that should go into 
patch 10.
6) Commit patch 10
7) Stage the lines that go into patch 11.
8) Commit patch 11
9) Note those two commit hashes
10) Go back to your original branch
     git checkout gerry/original
11) Run a rebase again, but swap out the "squashed" hash with the two 
hashes you made.

IE if your two hashes are aaaabbb and bbbccc and it's currently

pick abc123

change it to

pick aaaabbb
pick bbbccc

Then finish the rebase and it should swap them all out for you!

> 
> 
>>
>>> ---
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 22 ++++++++++++++++++++--
>>>   1 file changed, 20 insertions(+), 2 deletions(-)
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> index 6b503fb7e366..c2e4057ecd82 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> @@ -3449,6 +3449,8 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev)
>>>   		adev->ip_blocks[i].status.sw = false;
>>>   	}
>>>   +	amdgpu_ras_fini(adev);
>>> +
>>>   	for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
>>>   		if (!adev->ip_blocks[i].status.valid)
>>>   			continue;
>>> @@ -3457,8 +3459,6 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev)
>>>   		adev->ip_blocks[i].status.valid = false;
>>>   	}
>>>   -	amdgpu_ras_fini(adev);
>>> -
>>>   	return 0;
>>>   }
>>>   @@ -3516,6 +3516,24 @@ static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device *adev)
>>>   	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
>>>   		dev_warn(adev->dev, "Failed to disallow df cstate");
>>>   +	for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
>>> +		if (!adev->ip_blocks[i].status.valid)
>>> +			continue;
>>> +		if (!adev->ip_blocks[i].status.late_initialized)
>>> +			continue;
>>> +
>>> +		if (adev->ip_blocks[i].version->funcs->early_fini) {
>>> +			r = adev->ip_blocks[i].version->funcs->early_fini(&adev->ip_blocks[i]);
>>> +			if (r) {
>>> +				DRM_ERROR(" of IP block <%s> failed %d\n",
>>> +					  adev->ip_blocks[i].version->funcs->name, r);
>>> +				return r;
>>> +			}
>>> +		}
>>> +
>>> +		adev->ip_blocks[i].status.late_initialized = false;
>>> +	}
>>> +
>>>   	for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
>>>   		if (!adev->ip_blocks[i].status.valid)
>>>   			continue;
> 


  reply	other threads:[~2025-01-15 19:36 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13  1:42 [RFC v2 00/15] Enhance device state machine to better support suspend/resume Jiang Liu
2025-01-13  1:42 ` [RFC v2 01/15] drm/amdgpu: add helper functions to track status for ras manager Jiang Liu
2025-01-17  1:13   ` Wang, Yang(Kevin)
2025-01-17  5:03   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 02/15] drm/amdgpu: add a flag to track ras debugfs creation status Jiang Liu
2025-01-17  5:24   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 03/15] drm/amdgpu: free all resources on error recovery path of amdgpu_ras_init() Jiang Liu
2025-01-16 21:02   ` Mario Limonciello
2025-01-17  5:39   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 04/15] drm/amdgpu: introduce a flag to track refcount held for features Jiang Liu
2025-01-17  5:46   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 05/15] drm/amdgpu: enhance amdgpu_ras_block_late_fini() Jiang Liu
2025-01-16 21:10   ` Mario Limonciello
2025-01-17  5:54   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 06/15] drm/amdgpu: enhance amdgpu_ras_pre_fini() to better support SR Jiang Liu
2025-01-16 21:19   ` Mario Limonciello
2025-01-17  6:09   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 07/15] drm/admgpu: rename amdgpu_ras_pre_fini() to amdgpu_ras_early_fini() Jiang Liu
2025-01-16 21:25   ` Mario Limonciello
2025-01-17  1:19   ` Wang, Yang(Kevin)
2025-01-17  8:37   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 08/15] drm/amdgpu: make IP block state machine works in stack like way Jiang Liu
2025-01-17  8:45   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 09/15] drm/amdgpu_dm: enhance amdgpu_dm_early_fini() for PM ops Jiang Liu
2025-01-16 21:30   ` Mario Limonciello
2025-01-13  1:42 ` [RFC v2 10/15] drm/admgpu: make device state machine work in stack like way Jiang Liu
2025-01-13 22:27   ` Mario Limonciello
2025-01-14  1:58     ` Gerry Liu
2025-01-15 19:36       ` Mario Limonciello [this message]
2025-01-17  8:54   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 11/15] drm/amdgpu: convert ip block bool flags into an enum Jiang Liu
2025-01-17  8:57   ` Lazar, Lijo
2025-01-13  1:42 ` [RFC v2 12/15] drm/amdgpu: introduce IP block iterators to reduce duplicated code Jiang Liu
2025-01-13  1:42 ` [RFC v2 13/15] drm/amdgpu: walk IP blocks in reverse order when shutdown Jiang Liu
2025-01-13 22:28   ` Mario Limonciello
2025-01-13  1:42 ` [RFC v2 14/15] drm/amdgpu/nbio: improve the way to manage irq reference count Jiang Liu
2025-01-13  1:42 ` [RFC v2 15/15] drm/amdgpu/asic: make ip block operations symmetric by .early_fini() Jiang Liu
2025-01-20  6:27 ` [RFC v2 00/15] Enhance device state machine to better support suspend/resume Zhang, Hawking
2025-01-23  0:02   ` Mika Laitio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28fc2420-2b9f-4416-b04c-7267f5f90cbb@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Hawking.Zhang@amd.com \
    --cc=Kent.Russell@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=gerry@linux.alibaba.com \
    --cc=lijo.lazar@amd.com \
    --cc=shuox.liu@linux.alibaba.com \
    --cc=simona@ffwll.ch \
    --cc=sunil.khatri@amd.com \
    --cc=xiaogang.chen@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox