All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, GuoQing (Sam)" <GuoQing.Zhang@amd.com>
To: "Koenig, Christian" <Christian.Koenig@amd.com>,
	"Zhang, GuoQing (Sam)" <GuoQing.Zhang@amd.com>,
	"rafael@kernel.org" <rafael@kernel.org>,
	"len.brown@intel.com" <len.brown@intel.com>,
	"pavel@kernel.org" <pavel@kernel.org>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Limonciello, Mario" <Mario.Limonciello@amd.com>,
	"Lazar, Lijo" <Lijo.Lazar@amd.com>
Cc: "Zhao, Victor" <Victor.Zhao@amd.com>,
	"Chang, HaiJun" <HaiJun.Chang@amd.com>,
	"Ma, Qing (Mark)" <Qing.Ma@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] drm/amdgpu: skip kfd resume_process for dev_pm_ops.thaw()
Date: Tue, 1 Jul 2025 08:03:49 +0000	[thread overview]
Message-ID: <8eb1700d-4d60-4a1e-9d09-718f65baaf1e@amd.com> (raw)
In-Reply-To: <8806781b-90d1-4b99-a798-dd1d29d4c8c0@amd.com>

[-- Attachment #1: Type: text/plain, Size: 4148 bytes --]


thaw() is called before writing the hiberation image to swap disk. See
the doc here.
https://github.com/torvalds/linux/blob/v6.14/Documentation/driver-api/pm/devices.rst?plain=1#L552

And amdgpu implemented thaw() callback by calling amdgpu_device_resume().
https://github.com/torvalds/linux/blob/v6.14/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c#L2572

This patch is skip amdgpu_amdkfd_resume_process() call in thaw() during
hibernation. it is not skipped in restore() during resume from
hibernation when system boot again.


I just found the following kernel doc. Thaw() is intended to resume the
storage device for saving the hibernation image. Our GPU is not involved
in it, it is not necessary to resume our GPU in thaw().
https://github.com/torvalds/linux/blob/v6.14/Documentation/power/pci.rst?plain=1#L588

So another implementation is to remove the amdgpu_device_resume() call
in amdgpu_pmops_thaw(), and skip amdgpu_device_ip_suspend() call in
amdgpu_pci_shutdown() for hibernation.
Initial tests show it's working fine for hibernation successful case.
Should I switch to this implementation?

But thaw() is also called to restore the GPU when hibernation is aborted
due to some error in hibernation image creation stage. In this case,
amdgpu_device_resume() is needed in thaw().

So I need a method to check if hibernation is aborted or not to
conditionally skip amdgpu_device_resume() in thaw(). Currently I don't
know how to do this.


Regards
Sam


On 2025/6/30 19:58, Christian König wrote:
> On 30.06.25 12:41, Samuel Zhang wrote:
>> The hibernation successful workflow:
>> - prepare: evict VRAM and swapout GTT BOs
>> - freeze
>> - create the hibernation image in system memory
>> - thaw: swapin and restore BOs
> Why should a thaw happen here in between?
>
>> - complete
>> - write hibernation image to disk
>> - amdgpu_pci_shutdown
>> - goto S5, turn off the system.
>>
>> During prepare stage of hibernation, VRAM and GTT BOs will be swapout to
>> shmem. Then in thaw stage, all BOs will be swapin and restored.
> That's not correct. This is done by the application starting again and not during thaw.
>
>> On server with 192GB VRAM * 8 dGPUs and 1.7TB system memory,
>> the swapin and restore BOs takes too long (50 minutes) and it is not
>> necessary since the follow-up stages does not use GPU.
>>
>> This patch is to skip BOs restore during thaw to reduce the hibernation
>> time.
> As far as I can see that doesn't make sense. The KFD processes need to be resumed here and that can't be skipped.
>
> Regards,
> Christian.
>
>> Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 2 ++
>>   2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> index a8f4697deb1b..b550d07190a2 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> @@ -5328,7 +5328,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)
>>               amdgpu_virt_init_data_exchange(adev);
>>               amdgpu_virt_release_full_gpu(adev, true);
>>
>> -            if (!adev->in_s0ix && !r && !adev->in_runpm)
>> +            if (!adev->in_s0ix && !r && !adev->in_runpm && !adev->in_s4)
>>                       r = amdgpu_amdkfd_resume_process(adev);
>>       }
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
>> index 571b70da4562..23b76e8ac2fd 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
>> @@ -2734,7 +2734,9 @@ static int amdgpu_pmops_poweroff(struct device *dev)
>>   static int amdgpu_pmops_restore(struct device *dev)
>>   {
>>       struct drm_device *drm_dev = dev_get_drvdata(dev);
>> +    struct amdgpu_device *adev = drm_to_adev(drm_dev);
>>
>> +    adev->in_s4 = false;
>>       return amdgpu_device_resume(drm_dev, true);
>>   }
>>

[-- Attachment #2: Type: text/html, Size: 7195 bytes --]

  reply	other threads:[~2025-07-01  8:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-30 10:41 [PATCH 0/3] reduce system memory requirement for hibernation Samuel Zhang
2025-06-30 10:41 ` [PATCH 1/3] drm/amdgpu: move GTT to SHM after eviction " Samuel Zhang
2025-06-30 11:54   ` Christian König
2025-07-01  8:18     ` Zhang, GuoQing (Sam)
2025-07-01  8:22       ` Christian König
2025-07-02  7:28         ` Samuel Zhang
2025-07-02  7:48           ` Christian König
2025-06-30 10:41 ` [PATCH 2/3] PM: hibernate: shrink shmem pages after dev_pm_ops.prepare() Samuel Zhang
2025-06-30 20:21   ` Rafael J. Wysocki
2025-06-30 10:41 ` [PATCH 3/3] drm/amdgpu: skip kfd resume_process for dev_pm_ops.thaw() Samuel Zhang
2025-06-30 11:58   ` Christian König
2025-07-01  8:03     ` Zhang, GuoQing (Sam) [this message]
2025-07-01  8:32       ` Christian König
2025-07-01 16:07         ` Alex Deucher
2025-07-02  7:23           ` Sam
2025-07-02 13:54             ` Alex Deucher
2025-07-02 14:07               ` Lazar, Lijo
2025-07-04 10:24                 ` Zhang, GuoQing (Sam)

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=8eb1700d-4d60-4a1e-9d09-718f65baaf1e@amd.com \
    --to=guoqing.zhang@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=HaiJun.Chang@amd.com \
    --cc=Lijo.Lazar@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=Qing.Ma@amd.com \
    --cc=Victor.Zhao@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.