<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="en-CN" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><br>
thaw() is called before writing the hiberation image to swap disk. See <br>
the doc here.<br>
<a href="https://github.com/torvalds/linux/blob/v6.14/Documentation/driver-api/pm/devices.rst?plain=1#L552">https://github.com/torvalds/linux/blob/v6.14/Documentation/driver-api/pm/devices.rst?plain=1#L552</a><br>
<br>
And amdgpu implemented thaw() callback by calling amdgpu_device_resume().<br>
<a href="https://github.com/torvalds/linux/blob/v6.14/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c#L2572">https://github.com/torvalds/linux/blob/v6.14/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c#L2572</a><br>
<br>
This patch is skip amdgpu_amdkfd_resume_process() call in thaw() during <br>
hibernation. it is not skipped in restore() during resume from <br>
hibernation when system boot again.<br>
<br>
<br>
I just found the following kernel doc. Thaw() is intended to resume the <br>
storage device for saving the hibernation image. Our GPU is not involved <br>
in it, it is not necessary to resume our GPU in thaw().<br>
<a href="https://github.com/torvalds/linux/blob/v6.14/Documentation/power/pci.rst?plain=1#L588">https://github.com/torvalds/linux/blob/v6.14/Documentation/power/pci.rst?plain=1#L588</a><br>
<br>
So another implementation is to remove the amdgpu_device_resume() call <br>
in amdgpu_pmops_thaw(), and skip amdgpu_device_ip_suspend() call in <br>
amdgpu_pci_shutdown()</span><span lang="EN-US" style="font-size:11.0pt"> for hibernation</span><span style="font-size:11.0pt">.<br>
Initial tests show it's working fine for hibernation successful case. <br>
Should I switch to this implementation?<br>
<br>
But thaw() is also called to restore the GPU when hibernation is aborted <br>
due to some error in hibernation image creation stage. In this case, <br>
amdgpu_device_resume() is needed in thaw().<br>
<br>
So I need a method to check if hibernation is aborted or not to <br>
conditionally skip amdgpu_device_resume() in thaw(). Currently I don't <br>
know how to do this.<br>
<br>
<br>
Regards<br>
Sam<br>
<br>
<br>
On 2025/6/30 19:58, Christian König wrote:<br>
> On 30.06.25 12:41, Samuel Zhang wrote:<br>
>> The hibernation successful workflow:<br>
>> - prepare: evict VRAM and swapout GTT BOs<br>
>> - freeze<br>
>> - create the hibernation image in system memory<br>
>> - thaw: swapin and restore BOs<br>
> Why should a thaw happen here in between?<br>
><br>
>> - complete<br>
>> - write hibernation image to disk<br>
>> - amdgpu_pci_shutdown<br>
>> - goto S5, turn off the system.<br>
>><br>
>> During prepare stage of hibernation, VRAM and GTT BOs will be swapout to<br>
>> shmem. Then in thaw stage, all BOs will be swapin and restored.<br>
> That's not correct. This is done by the application starting again and not during thaw.<br>
><br>
>> On server with 192GB VRAM * 8 dGPUs and 1.7TB system memory,<br>
>> the swapin and restore BOs takes too long (50 minutes) and it is not<br>
>> necessary since the follow-up stages does not use GPU.<br>
>><br>
>> This patch is to skip BOs restore during thaw to reduce the hibernation<br>
>> time.<br>
> 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.<br>
><br>
> Regards,<br>
> Christian.<br>
><br>
>> Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com><br>
>> ---<br>
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-<br>
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 2 ++<br>
>>   2 files changed, 3 insertions(+), 1 deletion(-)<br>
>><br>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> index a8f4697deb1b..b550d07190a2 100644<br>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> @@ -5328,7 +5328,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)<br>
>>               amdgpu_virt_init_data_exchange(adev);<br>
>>               amdgpu_virt_release_full_gpu(adev, true);<br>
>>   <br>
>> -            if (!adev->in_s0ix && !r && !adev->in_runpm)<br>
>> +            if (!adev->in_s0ix && !r && !adev->in_runpm && !adev->in_s4)<br>
>>                       r = amdgpu_amdkfd_resume_process(adev);<br>
>>       }<br>
>>   <br>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
>> index 571b70da4562..23b76e8ac2fd 100644<br>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
>> @@ -2734,7 +2734,9 @@ static int amdgpu_pmops_poweroff(struct device *dev)<br>
>>   static int amdgpu_pmops_restore(struct device *dev)<br>
>>   {<br>
>>       struct drm_device *drm_dev = dev_get_drvdata(dev);<br>
>> +    struct amdgpu_device *adev = drm_to_adev(drm_dev);<br>
>>   <br>
>> +    adev->in_s4 = false;<br>
>>       return amdgpu_device_resume(drm_dev, true);<br>
>>   }<br>
>>   <o:p></o:p></span></p>
</div>
</div>
</body>
</html>